Skip to content

Commit c421d7f

Browse files
committed
Test that off-curve pubkeys fail signature verify
1 parent 251f974 commit c421d7f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ solana-sdk-macro-frozen-abi = { path = "macro-frozen-abi", version = "1.3.0" }
6060
rustversion = "1.0.3"
6161

6262
[dev-dependencies]
63+
curve25519-dalek = "2.1.0"
6364
tiny-bip39 = "0.7.0"
6465

6566
[package.metadata.docs.rs]

sdk/src/signature.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,4 +579,25 @@ mod tests {
579579
pubkeys(&[&alice, &bob])
580580
);
581581
}
582+
583+
#[test]
584+
fn test_off_curve_pubkey_verify_fails() {
585+
// Golden point off the ed25519 curve
586+
let off_curve_bytes = bs58::decode("9z5nJyQar1FUxVJxpBXzon6kHehbomeYiDaLi9WAMhCq")
587+
.into_vec()
588+
.unwrap();
589+
590+
// Confirm golden's off-curvedness
591+
let mut off_curve_bits = [0u8; 32];
592+
off_curve_bits.copy_from_slice(&off_curve_bytes);
593+
let off_curve_point = curve25519_dalek::edwards::CompressedEdwardsY(off_curve_bits);
594+
assert_eq!(off_curve_point.decompress(), None);
595+
596+
let pubkey = Pubkey::new(&off_curve_bytes);
597+
let signature = Signature::default();
598+
// Unfortunately, ed25519-dalek doesn't surface the internal error types that we'd ideally
599+
// `source()` out of the `SignatureError` returned by `verify_strict()`. So the best we
600+
// can do is `is_err()` here.
601+
assert!(signature.verify_verbose(pubkey.as_ref(), &[0u8]).is_err());
602+
}
582603
}

0 commit comments

Comments
 (0)