Skip to content

Commit a1ff166

Browse files
authored
Merge pull request #2000 from CosmWasm/add-wycheproof
Add secp256k1_verify/secp256k1_recover_pubkey tests from Project Wycheproof
2 parents b794e5a + 0e9624a commit a1ff166

File tree

9 files changed

+27398
-11
lines changed

9 files changed

+27398
-11
lines changed

Cargo.lock

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

packages/crypto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ criterion = "0.5.1"
2929
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
3030
serde_json = "1.0.40"
3131
sha2 = "0.10"
32+
sha3 = "0.10"
3233
hex = "0.4"
3334
hex-literal = "0.3.1"
3435
english-numbers = "0.3"

packages/crypto/src/secp256k1.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,14 @@ mod tests {
380380
assert_eq!(hash.as_slice(), message_hash.as_slice());
381381

382382
// Since the recovery param is missing in the test vectors, we try both 0 and 1
383-
let try0 = secp256k1_recover_pubkey(&message_hash, &signature, 0);
384-
let try1 = secp256k1_recover_pubkey(&message_hash, &signature, 1);
385-
match (try0, try1) {
386-
(Ok(recovered0), Ok(recovered1)) => {
387-
// Got two different pubkeys. Without the recovery param, we don't know which one is the right one.
388-
assert!(recovered0 == public_key || recovered1 == public_key)
389-
},
390-
(Ok(recovered), Err(_)) => assert_eq!(recovered, public_key),
391-
(Err(_), Ok(recovered)) => assert_eq!(recovered, public_key),
392-
(Err(_), Err(_)) => panic!("secp256k1_recover_pubkey failed (test case {i} in {COSMOS_SECP256K1_TESTS_JSON})"),
393-
}
383+
let recovered0 = secp256k1_recover_pubkey(&message_hash, &signature, 0).unwrap();
384+
let recovered1 = secp256k1_recover_pubkey(&message_hash, &signature, 1).unwrap();
385+
// Got two different pubkeys. Without the recovery param, we don't know which one is the right one.
386+
assert_ne!(recovered0, recovered1);
387+
assert!(
388+
recovered0 == public_key || recovered1 == public_key,
389+
"Did not find correct pubkey (test case {i} in {COSMOS_SECP256K1_TESTS_JSON})"
390+
);
394391
}
395392
}
396393

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Wycheproof test data
2+
3+
This folder contains test vectors from
4+
[Project Wycheproof](https://github.com/google/wycheproof) to increase the test
5+
coverage of signature verification implementations.
6+
7+
This test data is used by integration tests in `test/wycheproof_*.rs`.
8+
9+
## Update
10+
11+
To ensure integrity of the files and update them to the latest version, run this
12+
from the repo root:
13+
14+
```sh
15+
(cd packages/crypto/testdata/wycheproof \
16+
&& curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha256_test.json > ecdsa_secp256k1_sha256_test.json \
17+
&& curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha512_test.json > ecdsa_secp256k1_sha512_test.json \
18+
&& curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha3_256_test.json > ecdsa_secp256k1_sha3_256_test.json \
19+
&& curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha3_512_test.json > ecdsa_secp256k1_sha3_512_test.json \
20+
)
21+
```

0 commit comments

Comments
 (0)