paritytech / libsecp256k1

Pure Rust Implementation of secp256k1.
Apache License 2.0
175 stars 84 forks source link

scalar multiplication is broken in --release #58

Closed LLFourn closed 4 years ago

LLFourn commented 4 years ago

Running cargo test --release --no-fail-fast gives the following test failures on stable and nightly. Quick poking around seems to show it's to do with the pregen multiplication tables.

cargo test --release --no-fail-fast
    Finished release [optimized] target(s) in 0.03s
     Running target/release/deps/libsecp256k1-a03a00350fa6ef12

running 1 test
test tests::secret_key_inverse_is_sane ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/release/deps/serde-82b9567b029f1baa

running 2 tests
test test_deserialize_public_key ... FAILED
test test_serialize_public_key ... FAILED

failures:

---- test_deserialize_public_key stdout ----
thread 'test_deserialize_public_key' panicked at 'assertion failed: `(left == right)`
  left: `PublicKey(Affine { x: Field { n: [31262607, 33389173, 27261377, 13730080, 30875160, 44990809, 30666074, 26280549, 22444818, 450865], magnitude: 1, normalized: true }, y: Field { n: [27846865, 11869850, 60679442, 8560600, 48226177, 11627216, 65890916, 22041631, 59725963, 1847211], magnitude: 1, normalized: true }, infinity: false })`,
 right: `PublicKey(Affine { x: Field { n: [192306, 40206006, 26019251, 46272818, 38900612, 40079564, 65689187, 56690991, 19109204, 449584], magnitude: 1, normalized: false }, y: Field { n: [60304222, 10438730, 64516166, 22810055, 41842044, 56876599, 3603739, 59093824, 54969783, 1583710], magnitude: 1, normalized: false }, infinity: false })`', tests/serde.rs:25:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test_serialize_public_key stdout ----
thread 'test_serialize_public_key' panicked at 'assertion failed: `(left == right)`
  left: `"\"BBtwwSOVVNhCS/6lZjmOQzJRk4SwhEyY0Fs5lfrYAu8yYKl7RsW34WzQA2/RvY943n51fFcDcf2HBGJ9ISuYK14=\""`,
 right: `"\"BBuExVZ7EmRAmV0+1aq6BWXXHhg0YEgZ/5wX9enV3QePcL6vj1iLVBUH/tamQsWrQt/fgSCn9jneUSLUemmo6NE=\""`', tests/serde.rs:19:5

failures:
    test_deserialize_public_key
    test_serialize_public_key

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/release/deps/verify-656a8ccd0e033494

running 14 tests
test secret_clear_on_drop ... ok
test signatures::test_failing_sign_verify ... FAILED
test signatures::test_shared_secret ... ok
test signatures::test_signature_der ... ok
test test_convert_key1 ... FAILED
test test_convert_anykey ... FAILED
test test_convert_key2 ... FAILED
test test_pubkey_combine ... ok
test test_pubkey_equality ... FAILED
test test_signature_der_lax ... ok
test signatures::test_sign_verify ... FAILED
test test_recover ... ok
test test_low_s ... ok
test test_verify ... ok

failures:

---- signatures::test_failing_sign_verify stdout ----
thread 'signatures::test_failing_sign_verify' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidSignature', tests/verify.rs:132:32
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test_convert_key1 stdout ----
thread 'test_convert_key1' panicked at 'assertion failed: `(left == right)`
  left: `[4, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17, 8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184]`,
 right: `[4, 247, 78, 178, 188, 178, 252, 7, 0, 45, 237, 206, 219, 62, 162, 224, 247, 156, 230, 50, 56, 117, 134, 58, 77, 135, 57, 135, 56, 215, 179, 178, 118, 25, 149, 163, 182, 54, 140, 107, 98, 227, 81, 35, 247, 237, 110, 250, 179, 211, 231, 122, 171, 78, 176, 234, 102, 193, 169, 145, 203, 218, 49, 191, 6]`', tests/verify.rs:363:5

---- test_convert_anykey stdout ----
thread 'test_convert_anykey' panicked at 'assertion failed: `(left == right)`
  left: `[4, 240, 212, 31, 66, 132, 106, 200, 239, 174, 127, 161, 125, 177, 55, 135, 174, 237, 98, 6, 152, 49, 108, 41, 66, 9, 69, 190, 245, 179, 132, 207, 204, 155, 65, 37, 235, 101, 107, 31, 62, 31, 36, 234, 222, 234, 129, 53, 45, 86, 108, 94, 6, 20, 179, 144, 222, 125, 163, 201, 246, 80, 98, 209, 239]`,
 right: `[4, 43, 222, 83, 204, 118, 72, 73, 41, 110, 192, 182, 127, 227, 127, 0, 157, 17, 179, 123, 169, 31, 194, 50, 8, 234, 202, 177, 103, 187, 85, 165, 250, 193, 139, 250, 255, 109, 86, 70, 225, 78, 200, 173, 52, 66, 17, 167, 106, 7, 250, 109, 21, 90, 159, 111, 242, 139, 61, 247, 221, 102, 214, 85, 147]`', tests/verify.rs:421:5

---- test_convert_key2 stdout ----
thread 'test_convert_key2' panicked at 'assertion failed: `(left == right)`
  left: `[4, 63, 168, 192, 140, 101, 168, 63, 107, 78, 163, 224, 78, 28, 199, 12, 190, 60, 211, 145, 73, 158, 62, 5, 171, 125, 237, 242, 138, 255, 154, 252, 83, 130, 0, 255, 147, 227, 242, 178, 203, 80, 41, 240, 60, 126, 190, 232, 32, 214, 58, 76, 90, 149, 65, 200, 58, 206, 190, 41, 63, 84, 202, 207, 14]`,
 right: `[4, 239, 255, 184, 252, 226, 2, 236, 211, 29, 20, 159, 80, 118, 26, 152, 70, 36, 88, 80, 220, 222, 192, 103, 25, 188, 137, 120, 229, 65, 3, 85, 183, 56, 109, 246, 185, 131, 189, 190, 111, 146, 221, 194, 5, 58, 123, 133, 112, 161, 54, 46, 200, 103, 81, 67, 165, 159, 233, 230, 224, 195, 227, 82, 197]`', tests/verify.rs:384:5

---- test_pubkey_equality stdout ----
thread 'test_pubkey_equality' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidPublicKey', tests/verify.rs:458:23

---- signatures::test_sign_verify stdout ----
thread 'signatures::test_sign_verify' panicked at 'assertion failed: verify(&message, &sig, &pubkey)', tests/verify.rs:87:9

failures:
    signatures::test_failing_sign_verify
    signatures::test_sign_verify
    test_convert_anykey
    test_convert_key1
    test_convert_key2
    test_pubkey_equality

test result: FAILED. 8 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests libsecp256k1

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed.

I tested on:

rustc --version --verbose
rustc 1.44.0 (49cae5576 2020-06-01)
binary: rustc
commit-hash: 49cae55760da0a43428eba73abcb659bb70cf2e4
commit-date: 2020-06-01
host: x86_64-unknown-linux-gnu
release: 1.44.0
LLVM version: 9.0