Skip to content

Commit e77f33f

Browse files
committed
Merge #794: Followups to #716 (add musig2 API)
d611a4f musig: weaken/simplify warnings about nonce reuse (Andrew Poelstra) 8a43317 musig: add a bunch of unit tests (Andrew Poelstra) 40a8b65 musig: explicitly panic when given an empty slice of pubkeys to aggregate (Andrew Poelstra) ebdaec7 musig: clarify doc comment about aggregate nonce proxy (Andrew Poelstra) dc04575 musig: a couple small improvements of byte array APIs (Andrew Poelstra) c492c75 key: move pubkey_sort to method on Secp256k1; rename (Andrew Poelstra) ec66003 musig: remove SessionSecretRand::new constructor (Andrew Poelstra) 6d938d3 musig: add missing Panics sections to docs (Andrew Poelstra) 00c8c75 musig: remove outdated doc references to ZeroSession error (Andrew Poelstra) 3b0232a musig: fix all the doctests (Andrew Poelstra) 4dd861f stop using deprecated thread_rng (Andrew Poelstra) 9615ec8 context: whitelist new compiler warning (Andrew Poelstra) 7c56bcc clippy: whitelist a bunch of lints (Andrew Poelstra) 07922fd musig: fix a couple FFI bindings (Andrew Poelstra) f5f90af fmt: stop blacklisting secp256k1-sys; just fmt whole crate (Andrew Poelstra) Pull request description: This PR needs to be merged before the next release because the existing code has one instance of UB when passing an empty array to the aggregate nonce function. (Ok, there's a rust panic in our alignment code so maybe no bad pointers make it across the C boundary and we're ok. But it's near-UB.) This PR is the first one I created using jujutsu. One thing I notice is that the tool encourages you to produce way more commits than you would with git. Most of these are small. Let me know if you want me to squash any. ACKs for top commit: jlest01: ACK d611a4f jonasnick: ACK d611a4f modulo my comments on the PR (secret dependent branches) and that I only looked at the musig/libsecp-relevant bits. Tree-SHA512: a504912639bcb6296bd6fdf7a0533464ce9e9064d1c2bf06bf142b7749b4aaf75ed4bae10f9912b92191c64a453bcf56bbd001e3c99ab383e02de4676c7c6a69
2 parents 4d36fef + d611a4f commit e77f33f

File tree

14 files changed

+1299
-642
lines changed

14 files changed

+1299
-642
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,13 @@ required-features = ["rand", "std"]
7373
[workspace]
7474
members = ["secp256k1-sys"]
7575
exclude = ["no_std_test"]
76+
77+
[lints.clippy]
78+
# Exclude lints we don't think are valuable.
79+
large_enum_variant = "allow" # docs say "measure before paying attention to this"; why is it on by default??
80+
similar_names = "allow" # Too many (subjectively) false positives.
81+
uninlined_format_args = "allow" # This is a subjective style choice.
82+
indexing_slicing = "allow" # Too many false positives ... would be cool though
83+
match_bool = "allow" # Adds extra indentation and LOC.
84+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
85+
must_use_candidate = "allow" # Useful for audit but many false positives.

examples/musig.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use secp256k1::musig::{
44
new_nonce_pair, AggregatedNonce, KeyAggCache, PartialSignature, PublicNonce, Session,
55
SessionSecretRand,
66
};
7-
use secp256k1::{pubkey_sort, Keypair, Message, PublicKey, Scalar, Secp256k1, SecretKey};
7+
use secp256k1::{Keypair, Message, PublicKey, Scalar, Secp256k1, SecretKey};
88

99
fn main() {
1010
let secp = Secp256k1::new();
11-
let mut rng = rand::thread_rng();
11+
let mut rng = rand::rng();
1212

1313
let (seckey1, pubkey1) = secp.generate_keypair(&mut rng);
1414

@@ -19,7 +19,7 @@ fn main() {
1919
let mut pubkeys_ref: Vec<&PublicKey> = pubkeys.iter().collect();
2020
let pubkeys_ref = pubkeys_ref.as_mut_slice();
2121

22-
pubkey_sort(&secp, pubkeys_ref);
22+
secp.musig_sort_pubkeys(pubkeys_ref);
2323

2424
let mut musig_key_agg_cache = KeyAggCache::new(&secp, pubkeys_ref);
2525

rustfmt.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Eventually this shoud be: ignore = []
2-
ignore = [
3-
"secp256k1-sys"
4-
]
5-
61
hard_tabs = false
72
tab_spaces = 4
83
newline_style = "Auto"

secp256k1-sys/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ alloc = []
3535

3636
[lints.rust]
3737
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fuzz)', 'cfg(rust_secp_no_symbol_renaming)'] }
38+
39+
[lints.clippy]
40+
# Exclude lints we don't think are valuable.
41+
large_enum_variant = "allow" # docs say "measure before paying attention to this"; why is it on by default??
42+
similar_names = "allow" # Too many (subjectively) false positives.
43+
uninlined_format_args = "allow" # This is a subjective style choice.
44+
indexing_slicing = "allow" # Too many false positives ... would be cool though
45+
match_bool = "allow" # Adds extra indentation and LOC.
46+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
47+
must_use_candidate = "allow" # Useful for audit but many false positives.

secp256k1-sys/build.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ use std::env;
1616
fn main() {
1717
// Actual build
1818
let mut base_config = cc::Build::new();
19-
base_config.include("depend/secp256k1/")
20-
.include("depend/secp256k1/include")
21-
.include("depend/secp256k1/src")
22-
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
23-
.flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning
24-
.define("SECP256K1_API", Some(""))
25-
.define("ENABLE_MODULE_ECDH", Some("1"))
26-
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
27-
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
28-
.define("ENABLE_MODULE_ELLSWIFT", Some("1"))
29-
.define("ENABLE_MODULE_MUSIG", Some("1"))
30-
// upstream sometimes introduces calls to printf, which we cannot compile
31-
// with WASM due to its lack of libc. printf is never necessary and we can
32-
// just #define it away.
33-
.define("printf(...)", Some(""));
19+
base_config
20+
.include("depend/secp256k1/")
21+
.include("depend/secp256k1/include")
22+
.include("depend/secp256k1/src")
23+
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
24+
.flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning
25+
.define("SECP256K1_API", Some(""))
26+
.define("ENABLE_MODULE_ECDH", Some("1"))
27+
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
28+
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
29+
.define("ENABLE_MODULE_ELLSWIFT", Some("1"))
30+
.define("ENABLE_MODULE_MUSIG", Some("1"))
31+
// upstream sometimes introduces calls to printf, which we cannot compile
32+
// with WASM due to its lack of libc. printf is never necessary and we can
33+
// just #define it away.
34+
.define("printf(...)", Some(""));
3435

3536
if cfg!(feature = "lowmemory") {
3637
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory
@@ -45,15 +46,15 @@ fn main() {
4546

4647
// WASM headers and size/align defines.
4748
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "wasm32" {
48-
base_config.include("wasm/wasm-sysroot")
49-
.file("wasm/wasm.c");
49+
base_config.include("wasm/wasm-sysroot").file("wasm/wasm.c");
5050
}
5151

5252
// secp256k1
53-
base_config.file("depend/secp256k1/contrib/lax_der_parsing.c")
54-
.file("depend/secp256k1/src/precomputed_ecmult_gen.c")
55-
.file("depend/secp256k1/src/precomputed_ecmult.c")
56-
.file("depend/secp256k1/src/secp256k1.c");
53+
base_config
54+
.file("depend/secp256k1/contrib/lax_der_parsing.c")
55+
.file("depend/secp256k1/src/precomputed_ecmult_gen.c")
56+
.file("depend/secp256k1/src/precomputed_ecmult.c")
57+
.file("depend/secp256k1/src/secp256k1.c");
5758

5859
if base_config.try_compile("libsecp256k1.a").is_err() {
5960
// Some embedded platforms may not have, eg, string.h available, so if the build fails
@@ -63,4 +64,3 @@ fn main() {
6364
base_config.compile("libsecp256k1.a");
6465
}
6566
}
66-

0 commit comments

Comments
 (0)