Skip to content

Commit b8d85c9

Browse files
committed
Use new feature to gate test vectors behind
To match the local signatures found in test vectors, we must make sure we don't use any additional randomess when generating signatures, as we'll arrive at a different signature otherwise.
1 parent 21be311 commit b8d85c9

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

ci/ci-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
3737
cargo test --verbose --color always --features no-std
3838
# check that things still pass without grind_signatures
3939
# note that outbound_commitment_test only runs in this mode, because of hardcoded signature values
40-
cargo test --verbose --color always --no-default-features --features std
40+
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
4141
# check if there is a conflict between no-std and the c_bindings cfg
4242
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
4343
popd

lightning/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ max_level_trace = []
2929
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
3030
unsafe_revoked_tx_signing = []
3131
_bench_unstable = []
32+
# Override signing to not include randomness when generating signatures for test vectors.
33+
_test_vectors = []
3234

3335
no-std = ["hashbrown", "bitcoin/no-std", "core2/alloc"]
3436
std = ["bitcoin/std"]

lightning/src/ln/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7516,7 +7516,7 @@ mod tests {
75167516
}
75177517
}
75187518

7519-
#[cfg(not(feature = "grind_signatures"))]
7519+
#[cfg(feature = "_test_vectors")]
75207520
#[test]
75217521
fn outbound_commitment_test() {
75227522
use bitcoin::util::sighash;

lightning/src/util/crypto.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
6262
break sig;
6363
}
6464
};
65-
#[cfg(not(feature = "grind_signatures"))]
65+
#[cfg(all(not(feature = "grind_signatures"), not(feature = "_test_vectors")))]
6666
let sig = ctx.sign_ecdsa_with_noncedata(msg, sk, &entropy_source.get_secure_random_bytes());
67+
#[cfg(all(not(feature = "grind_signatures"), feature = "_test_vectors"))]
68+
let sig = sign(ctx, msg, sk);
6769
sig
6870
}

0 commit comments

Comments
 (0)