Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate curve point evaluation output (it could not be infinity) #186

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions precompiles/P256VERIFY.yul
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ object "P256VERIFY" {
let t1 := outOfMontgomeryForm(montgomeryMul(r, s1, N(), N_PRIME()), N(), N_PRIME())

let xr, yr, zr := shamirLinearCombination(x, y, z, t0, t1)
if iszero(zr) {
mstore(0, 0)
return(0, 32)
}

// As we only need xr in affine form, we can skip transforming the `y` coordinate.
let z_inv := montgomeryModularInverse(zr, P(), R2_MOD_P())
Expand Down
16 changes: 15 additions & 1 deletion tests/tests/p256verify_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn p256verify_valid_signature_two() {
}

#[tokio::test]
async fn p256verify_invalid_signature() {
async fn p256verify_invalid_signature_one() {
let era_response = era_call(
P256VERIFTY_PRECOMPILE_ADDRESS,
None,
Expand Down Expand Up @@ -147,3 +147,17 @@ async fn p256verify_public_key_not_in_curve() {

assert_eq!(era_response, EXECUTION_REVERTED)
}

#[tokio::test]
async fn p256verify_invalid_signature_two() {
let era_response = era_call(
P256VERIFTY_PRECOMPILE_ADDRESS,
None,
Some(Bytes::from(hex::decode("5ad83880e16658d7521d4e878521defaf6b43dec1dbd69e514c09ab8f1f2ffe25ad83880e16658d7521d4e878521defaf6b43dec1dbd69e514c09ab8f1f2ffe2871c518be8c56e7f5c901933fdab317efafc588b3e04d19d9a27b29aad8d9e696b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296b01cbd1c01e58065711814b583f061e9d431cca994cea1313449bf97c840ae0a").unwrap())),
)
.await
.unwrap();
let (era_output, gas_used) = parse_call_result(&era_response);
write_p256verify_gas_result(gas_used);
assert_eq!(era_output, Bytes::from(RESPONSE_INVALID))
}