Skip to content

Commit 5bc08b1

Browse files
committed
Merge rust-bitcoin#4154: update secp256k1 to 0.30.0
f80cf2c update secp256k1 to 0.30.0 (19年梦醒) Pull request description: ACKs for top commit: apoelstra: ACK f80cf2c; successfully ran local tests tcharding: ACK f80cf2c Tree-SHA512: 83b8bb72372025c4a4b81c2b7973a7808a4a1d9d6450adef8b60a890e128b2559b55832159c25fa91daac1856049b070cd910d87313fed2851ced9e72ae5ddf5
2 parents 43814eb + f80cf2c commit 5bc08b1

File tree

13 files changed

+74
-32
lines changed

13 files changed

+74
-32
lines changed

Cargo-minimal.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies = [
5555
"bech32",
5656
"bincode",
5757
"bitcoin-internals",
58-
"bitcoin-io",
58+
"bitcoin-io 0.2.0",
5959
"bitcoin-primitives",
6060
"bitcoin-units",
6161
"bitcoin_hashes 0.16.0",
@@ -92,6 +92,12 @@ dependencies = [
9292
"serde_json",
9393
]
9494

95+
[[package]]
96+
name = "bitcoin-io"
97+
version = "0.1.3"
98+
source = "registry+https://github.com/rust-lang/crates.io-index"
99+
checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
100+
95101
[[package]]
96102
name = "bitcoin-io"
97103
version = "0.2.0"
@@ -132,6 +138,7 @@ version = "0.14.0"
132138
source = "registry+https://github.com/rust-lang/crates.io-index"
133139
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
134140
dependencies = [
141+
"bitcoin-io 0.1.3",
135142
"hex-conservative 0.2.0",
136143
]
137144

@@ -333,9 +340,9 @@ checksum = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
333340

334341
[[package]]
335342
name = "secp256k1"
336-
version = "0.29.0"
343+
version = "0.30.0"
337344
source = "registry+https://github.com/rust-lang/crates.io-index"
338-
checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
345+
checksum = "b50c5943d326858130af85e049f2661ba3c78b26589b8ab98e65e80ae44a1252"
339346
dependencies = [
340347
"bitcoin_hashes 0.14.0",
341348
"rand",

Cargo-recent.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies = [
5454
"bech32",
5555
"bincode",
5656
"bitcoin-internals",
57-
"bitcoin-io",
57+
"bitcoin-io 0.2.0",
5858
"bitcoin-primitives",
5959
"bitcoin-units",
6060
"bitcoin_hashes 0.16.0",
@@ -91,6 +91,12 @@ dependencies = [
9191
"serde_json",
9292
]
9393

94+
[[package]]
95+
name = "bitcoin-io"
96+
version = "0.1.3"
97+
source = "registry+https://github.com/rust-lang/crates.io-index"
98+
checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
99+
94100
[[package]]
95101
name = "bitcoin-io"
96102
version = "0.2.0"
@@ -131,6 +137,7 @@ version = "0.14.0"
131137
source = "registry+https://github.com/rust-lang/crates.io-index"
132138
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
133139
dependencies = [
140+
"bitcoin-io 0.1.3",
134141
"hex-conservative 0.2.1",
135142
]
136143

@@ -334,9 +341,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
334341

335342
[[package]]
336343
name = "secp256k1"
337-
version = "0.29.1"
344+
version = "0.30.0"
338345
source = "registry+https://github.com/rust-lang/crates.io-index"
339-
checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113"
346+
checksum = "b50c5943d326858130af85e049f2661ba3c78b26589b8ab98e65e80ae44a1252"
340347
dependencies = [
341348
"bitcoin_hashes 0.14.0",
342349
"rand",

bitcoin/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exclude = ["tests", "contrib"]
1717
[features]
1818
default = [ "std", "secp-recovery" ]
1919
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "primitives/std", "secp256k1/std", "units/std", "bitcoinconsensus?/std"]
20-
rand-std = ["secp256k1/rand-std", "std"]
20+
rand-std = ["secp256k1/rand", "std"]
2121
rand = ["secp256k1/rand"]
2222
serde = ["dep:serde", "hashes/serde", "internals/serde", "primitives/serde", "secp256k1/serde", "units/serde"]
2323
secp-lowmemory = ["secp256k1/lowmemory"]
@@ -32,7 +32,7 @@ hex = { package = "hex-conservative", version = "0.3.0", default-features = fals
3232
internals = { package = "bitcoin-internals", version = "0.4.0", features = ["alloc"] }
3333
io = { package = "bitcoin-io", version = "0.2.0", default-features = false, features = ["alloc", "hashes"] }
3434
primitives = { package = "bitcoin-primitives", version = "0.101.0", default-features = false, features = ["alloc"] }
35-
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }
35+
secp256k1 = { version = "0.30.0", default-features = false, features = ["hashes", "alloc", "rand"] }
3636
units = { package = "bitcoin-units", version = "0.2.0", default-features = false, features = ["alloc"] }
3737

3838
arbitrary = { version = "1.4", optional = true }

bitcoin/examples/sign-tx-taproot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() {
7171
// Sign the sighash using the secp256k1 library (exported by rust-bitcoin).
7272
let tweaked: TweakedKeypair = keypair.tap_tweak(&secp, None);
7373
let msg = Message::from(sighash);
74-
let signature = secp.sign_schnorr(&msg, &tweaked.to_inner());
74+
let signature = secp.sign_schnorr(msg.as_ref(), &tweaked.to_inner());
7575

7676
// Update the witness stack.
7777
let signature = bitcoin::taproot::Signature { signature, sighash_type };

bitcoin/examples/taproot-psbt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ fn sign_psbt_taproot(
749749
};
750750

751751
let msg = secp256k1::Message::from(hash);
752-
let signature = secp.sign_schnorr(&msg, &keypair);
752+
let signature = secp.sign_schnorr(msg.as_ref(), &keypair);
753753

754754
let final_signature = taproot::Signature { signature, sighash_type };
755755

bitcoin/src/bip32.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ impl Xpriv {
593593
depth: 0,
594594
parent_fingerprint: Default::default(),
595595
child_number: ChildNumber::ZERO_NORMAL,
596-
private_key: secp256k1::SecretKey::from_slice(&hmac_result.as_ref()[..32])?,
596+
private_key: secp256k1::SecretKey::from_byte_array(
597+
&hmac_result.as_ref()[..32].try_into().expect("Slice should be exactly 32 bytes"),
598+
)?,
597599
chain_code: ChainCode::from_hmac(hmac_result),
598600
})
599601
}
@@ -665,8 +667,10 @@ impl Xpriv {
665667

666668
hmac_engine.input(&u32::from(i).to_be_bytes());
667669
let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
668-
let sk = secp256k1::SecretKey::from_slice(&hmac_result.as_ref()[..32])
669-
.expect("statistically impossible to hit");
670+
let sk = secp256k1::SecretKey::from_byte_array(
671+
&hmac_result.as_ref()[..32].try_into().expect("statistically impossible to hit"),
672+
)
673+
.expect("statistically impossible to hit");
670674
let tweaked =
671675
sk.add_tweak(&self.private_key.into()).expect("statistically impossible to hit");
672676

@@ -705,7 +709,9 @@ impl Xpriv {
705709
chain_code: data[13..45]
706710
.try_into()
707711
.expect("45 - 13 == 32, which is the ChainCode length"),
708-
private_key: secp256k1::SecretKey::from_slice(&data[46..78])?,
712+
private_key: secp256k1::SecretKey::from_byte_array(
713+
&data[46..78].try_into().expect("Slice should be exactly 32 bytes"),
714+
)?,
709715
})
710716
}
711717

@@ -812,8 +818,11 @@ impl Xpub {
812818
hmac_engine.input(&n.to_be_bytes());
813819

814820
let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
815-
816-
let private_key = secp256k1::SecretKey::from_slice(&hmac_result.as_ref()[..32])?;
821+
let private_key = secp256k1::SecretKey::from_byte_array(
822+
&hmac_result.as_ref()[..32]
823+
.try_into()
824+
.expect("Slice should be exactly 32 bytes"),
825+
)?;
817826
let chain_code = ChainCode::from_hmac(hmac_result);
818827
Ok((private_key, chain_code))
819828
}

bitcoin/src/crypto/key.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,12 @@ impl PrivateKey {
464464
data: &[u8],
465465
network: impl Into<NetworkKind>,
466466
) -> Result<PrivateKey, secp256k1::Error> {
467-
Ok(PrivateKey::new(secp256k1::SecretKey::from_slice(data)?, network))
467+
Ok(PrivateKey::new(
468+
secp256k1::SecretKey::from_byte_array(
469+
data[..32].try_into().expect("Slice should be exactly 32 bytes"),
470+
)?,
471+
network,
472+
))
468473
}
469474

470475
/// Formats the private key to WIF format.
@@ -519,7 +524,9 @@ impl PrivateKey {
519524
Ok(PrivateKey {
520525
compressed,
521526
network,
522-
inner: secp256k1::SecretKey::from_slice(&data[1..33])?,
527+
inner: secp256k1::SecretKey::from_byte_array(
528+
&data[1..33].try_into().expect("Slice should be exactly 32 bytes"),
529+
)?,
523530
})
524531
}
525532
}

bitcoin/src/crypto/sighash.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,8 @@ mod tests {
20252025
.unwrap();
20262026

20272027
let msg = secp256k1::Message::from(sighash);
2028-
let key_spend_sig = secp.sign_schnorr_with_aux_rand(&msg, &tweaked_keypair, &[0u8; 32]);
2028+
let key_spend_sig =
2029+
secp.sign_schnorr_with_aux_rand(msg.as_ref(), &tweaked_keypair, &[0u8; 32]);
20292030

20302031
assert_eq!(expected.internal_pubkey, internal_key);
20312032
assert_eq!(expected.tweak, tweak);

bitcoin/src/crypto/taproot.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ impl Signature {
3232
match sl.len() {
3333
64 => {
3434
// default type
35-
let signature = secp256k1::schnorr::Signature::from_slice(sl)?;
35+
let signature = secp256k1::schnorr::Signature::from_byte_array(
36+
sl[0..64].try_into().expect("Slice should be exactly 64 bytes"),
37+
);
3638
Ok(Signature { signature, sighash_type: TapSighashType::Default })
3739
}
3840
65 => {
3941
let (sighash_type, signature) = sl.split_last().expect("slice len checked == 65");
4042
let sighash_type = TapSighashType::from_consensus_u8(*sighash_type)?;
41-
let signature = secp256k1::schnorr::Signature::from_slice(signature)?;
43+
let signature = secp256k1::schnorr::Signature::from_byte_array(
44+
signature[0..64].try_into().expect("Slice should be exactly 64 bytes"),
45+
);
4246
Ok(Signature { signature, sighash_type })
4347
}
4448
len => Err(SigFromSliceError::InvalidSignatureSize(len)),
@@ -70,7 +74,7 @@ impl Signature {
7074
/// You can get a slice from it using deref coercions or turn it into an iterator.
7175
pub fn serialize(self) -> SerializedSignature {
7276
let mut buf = [0; serialized_signature::MAX_LEN];
73-
let ser_sig = self.signature.serialize();
77+
let ser_sig = self.signature.to_byte_array();
7478
buf[..64].copy_from_slice(&ser_sig);
7579
let len = if self.sighash_type == TapSighashType::Default {
7680
// default sighash type, don't add extra sighash byte
@@ -140,7 +144,9 @@ impl<'a> Arbitrary<'a> for Signature {
140144
let arbitrary_bytes: [u8; secp256k1::constants::SCHNORR_SIGNATURE_SIZE] = u.arbitrary()?;
141145

142146
Ok(Signature {
143-
signature: secp256k1::schnorr::Signature::from_slice(&arbitrary_bytes).unwrap(),
147+
signature: secp256k1::schnorr::Signature::from_byte_array(
148+
arbitrary_bytes[0..64].try_into().expect("Slice should be exactly 64 bytes"),
149+
),
144150
sighash_type: TapSighashType::arbitrary(u)?,
145151
})
146152
}

bitcoin/src/psbt/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ impl Psbt {
445445
.to_inner();
446446

447447
#[cfg(feature = "rand-std")]
448-
let signature = secp.sign_schnorr(&msg, &key_pair);
448+
let signature = secp.sign_schnorr(msg.as_ref(), &key_pair);
449449
#[cfg(not(feature = "rand-std"))]
450-
let signature = secp.sign_schnorr_no_aux_rand(&msg, &key_pair);
450+
let signature = secp.sign_schnorr_no_aux_rand(msg.as_ref(), &key_pair);
451451

452452
let signature = taproot::Signature { signature, sighash_type };
453453
input.tap_key_sig = Some(signature);
@@ -472,9 +472,9 @@ impl Psbt {
472472
self.sighash_taproot(input_index, cache, Some(lh))?;
473473

474474
#[cfg(feature = "rand-std")]
475-
let signature = secp.sign_schnorr(&msg, &key_pair);
475+
let signature = secp.sign_schnorr(msg.as_ref(), &key_pair);
476476
#[cfg(not(feature = "rand-std"))]
477-
let signature = secp.sign_schnorr_no_aux_rand(&msg, &key_pair);
477+
let signature = secp.sign_schnorr_no_aux_rand(msg.as_ref(), &key_pair);
478478

479479
let signature = taproot::Signature { signature, sighash_type };
480480
input.tap_script_sigs.insert((xonly, lh), signature);

0 commit comments

Comments
 (0)