Skip to content

Commit 07ff2c4

Browse files
committed
Revert secp256k1 crate upgrade due wasm compilation issues. Set node version to 20.x in .github/workflows/wasm.yml
1 parent 35563c9 commit 07ff2c4

14 files changed

Lines changed: 38 additions & 95 deletions

File tree

.github/workflows/wasm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
strategy:
2323
matrix:
24-
node-version: [18.x]
24+
node-version: [20.x]
2525

2626
steps:
2727
- name: Checkout the repository

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ quote = "1.0"
222222
rand = "0.10"
223223
rand_core = "0.10"
224224
rand_0_8 = { version = "0.8", package = "rand" }
225-
rand_0_9 = { version = "0.9", package = "rand" }
226225
rand_chacha = "0.10"
227226
rayon = "1.10"
228227
reedline = "0.38"
@@ -237,7 +236,7 @@ rstest = "0.24"
237236
rstest_reuse = "0.7"
238237
rusqlite = "0.33"
239238
schnorrkel = "0.11"
240-
secp256k1 = { version = "0.31", default-features = false }
239+
secp256k1 = { version = "0.29", default-features = false }
241240
semver = "1.0"
242241
serde = "1.0"
243242
serde_json = "1.0"

blockprod/src/detail/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ mod process_block_with_custom_id {
19511951

19521952
let mut rng = make_seedable_rng(seed);
19531953

1954-
let jobs_to_create = rng.random_range(1..=20);
1954+
let jobs_to_create = 10 + rng.random_range(1..=20);
19551955

19561956
let block_production = BlockProduction::new(
19571957
chain_config,

crypto/src/key/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub use signature::Signature;
3737

3838
#[derive(thiserror::Error, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
3939
pub enum SignatureError {
40-
#[error("Wrong signature size")]
41-
WrongSignatureSize,
40+
#[error("Failed to construct a valid signature")]
41+
SignatureConstructionError,
4242
}
4343

4444
#[must_use]

crypto/src/key/secp256k1/extended_keys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hmac::{Hmac, Mac};
1919
use secp256k1;
2020
use sha2::Sha512;
2121

22-
use randomness::{adapters::Rng09Adapter, CryptoRng};
22+
use randomness::{adapters::Rng08Adapter, CryptoRng};
2323
use serialization::{Decode, Encode};
2424

2525
use crate::{
@@ -64,7 +64,7 @@ fn to_key_and_chain_code(
6464
mac: Hmac<Sha512>,
6565
) -> Result<(secp256k1::SecretKey, ChainCode), DerivationError> {
6666
util::to_key_and_chain_code(mac, |secret_key_bytes| {
67-
secp256k1::SecretKey::from_byte_array(*secret_key_bytes)
67+
secp256k1::SecretKey::from_slice(secret_key_bytes)
6868
.map_err(|_| DerivationError::KeyDerivationError)
6969
})
7070
}
@@ -92,7 +92,7 @@ impl Secp256k1ExtendedPrivateKey {
9292
let mut chain_code = [0u8; 32];
9393
rng.fill_bytes(&mut chain_code);
9494
let chain_code = chain_code.into();
95-
let private_key = secp256k1::SecretKey::new(&mut Rng09Adapter(rng)).into();
95+
let private_key = secp256k1::SecretKey::new(&mut Rng08Adapter(rng)).into();
9696
// Generate a new private key
9797
let ext_priv = Secp256k1ExtendedPrivateKey {
9898
derivation_path: DerivationPath::empty(),

crypto/src/key/secp256k1/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod extended_keys;
1818
use secp256k1;
1919
use zeroize::Zeroize;
2020

21-
use randomness::{adapters::Rng09Adapter, CryptoRng};
21+
use randomness::{adapters::Rng08Adapter, CryptoRng};
2222
use serialization::{Decode, Encode};
2323

2424
use crate::{
@@ -46,7 +46,7 @@ impl Encode for Secp256k1PrivateKey {
4646
impl Decode for Secp256k1PrivateKey {
4747
fn decode<I: serialization::Input>(input: &mut I) -> Result<Self, serialization::Error> {
4848
let mut v = <[u8; secp256k1::constants::SECRET_KEY_SIZE]>::decode(input)?;
49-
let result = secp256k1::SecretKey::from_byte_array(v)
49+
let result = secp256k1::SecretKey::from_slice(&v)
5050
.map(|r| Secp256k1PrivateKey { data: r })
5151
.map_err(|_| serialization::Error::from("Private Key deserialization failed"));
5252
v.zeroize();
@@ -63,7 +63,7 @@ impl From<secp256k1::SecretKey> for Secp256k1PrivateKey {
6363
impl Secp256k1PrivateKey {
6464
pub fn new<R: CryptoRng>(rng: &mut R) -> (Secp256k1PrivateKey, Secp256k1PublicKey) {
6565
let secp = secp256k1::Secp256k1::new();
66-
let (secret, public) = secp.generate_keypair(&mut Rng09Adapter(rng));
66+
let (secret, public) = secp.generate_keypair(&mut Rng08Adapter(rng));
6767
(
6868
Secp256k1PrivateKey::from_native(secret),
6969
Secp256k1PublicKey::from_native(public),
@@ -75,9 +75,7 @@ impl Secp256k1PrivateKey {
7575
}
7676

7777
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Secp256k1KeyError> {
78-
let bytes_arr: [u8; secp256k1::constants::SECRET_KEY_SIZE] =
79-
bytes.try_into().map_err(|_| Secp256k1KeyError::InvalidData)?;
80-
secp256k1::SecretKey::from_byte_array(bytes_arr)
78+
secp256k1::SecretKey::from_slice(bytes)
8179
.map(|r| Secp256k1PrivateKey { data: r })
8280
.map_err(|_| Secp256k1KeyError::InvalidData)
8381
}
@@ -98,14 +96,15 @@ impl Secp256k1PrivateKey {
9896
let secp = secp256k1::Secp256k1::new();
9997
// Hash the message
10098
let e = Blake2b32Stream::new().write(msg).finalize();
101-
let msg_hash = secp256k1::Message::from_digest(e.into());
99+
let msg_hash =
100+
secp256k1::Message::from_digest_slice(e.as_slice()).expect("Blake2b32 is 32 bytes");
102101
// Sign the hash
103102
// TODO(SECURITY) erase keypair after signing
104103
let keypair = self.data.keypair(&secp);
105104

106105
let aux_data = aux_data_provider.get_secp256k1_schnorr_aux_data();
107106

108-
secp.sign_schnorr_with_aux_rand(msg_hash.as_ref(), &keypair, &aux_data)
107+
secp.sign_schnorr_with_aux_rand(&msg_hash, &keypair, &aux_data)
109108
}
110109
}
111110

@@ -191,7 +190,7 @@ impl Secp256k1PublicKey {
191190
VERIFIER
192191
.verify_schnorr(
193192
signature,
194-
msg_hashed.as_ref(),
193+
msg_hashed,
195194
&self.pubkey_data.x_only_public_key().0,
196195
)
197196
.is_ok()
@@ -371,11 +370,9 @@ mod test {
371370
#[case] is_valid: bool,
372371
) {
373372
let pk = Secp256k1PublicKey::from_bytes(&hex::decode(pk).unwrap()).unwrap();
374-
let sig = secp256k1::schnorr::Signature::from_byte_array(
375-
hex::decode(sig).unwrap().try_into().unwrap(),
376-
);
373+
let sig = secp256k1::schnorr::Signature::from_slice(&hex::decode(sig).unwrap()).unwrap();
377374
let msg_hash =
378-
secp256k1::Message::from_digest(hex::decode(msg_hash).unwrap().try_into().unwrap());
375+
secp256k1::Message::from_digest_slice(&hex::decode(msg_hash).unwrap()).unwrap();
379376
assert_eq!(pk.verify_message_hashed(&sig, &msg_hash), is_valid);
380377
}
381378

@@ -396,7 +393,7 @@ mod test {
396393
assert!(pk.verify_message(&sig1, &msg));
397394
assert!(pk.verify_message(&sig2, &msg));
398395
assert_eq!(sig1, sig2);
399-
assert_eq!(sig1.to_byte_array(), sig2.to_byte_array());
396+
assert_eq!(sig1.serialize(), sig2.serialize());
400397
}
401398

402399
#[rstest]

crypto/src/key/signature/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl Decode for Signature {
6565
match sig_kind {
6666
SignatureKind::Secp256k1Schnorr => {
6767
let data = <[u8; secp256k1::constants::SCHNORR_SIGNATURE_SIZE]>::decode(input)?;
68-
let sig = secp256k1::schnorr::Signature::from_byte_array(data);
68+
let sig = secp256k1::schnorr::Signature::from_slice(&data)
69+
.map_err(|_| serialization::Error::from("Signature deserialization failed"))?;
6970
Ok(Signature::Secp256k1Schnorr(sig))
7071
}
7172
}
@@ -84,9 +85,8 @@ impl Signature {
8485
) -> Result<Self, SignatureError> {
8586
match kind {
8687
SignatureKind::Secp256k1Schnorr => {
87-
let decoded_sig = secp256k1::schnorr::Signature::from_byte_array(
88-
data.as_ref().try_into().map_err(|_| SignatureError::WrongSignatureSize)?,
89-
);
88+
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
89+
.map_err(|_| SignatureError::SignatureConstructionError)?;
9090
Ok(Self::Secp256k1Schnorr(decoded_sig))
9191
}
9292
}

crypto/src/util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn new_hmac_sha_512(key: &[u8]) -> Hmac<Sha512> {
3131

3232
pub fn to_key_and_chain_code<SecretKey>(
3333
mac: Hmac<Sha512>,
34-
to_key: impl FnOnce(&[u8; 32]) -> Result<SecretKey, DerivationError>,
34+
to_key: impl FnOnce(&[u8]) -> Result<SecretKey, DerivationError>,
3535
) -> Result<(SecretKey, ChainCode), DerivationError> {
3636
// Finalize the hmac
3737
let mut result = mac.finalize().into_bytes();
@@ -44,7 +44,7 @@ pub fn to_key_and_chain_code<SecretKey>(
4444
result.zeroize();
4545

4646
// Create the secret key key
47-
let secret_key = to_key(&secret_key_bytes.into())?;
47+
let secret_key = to_key(secret_key_bytes.as_slice())?;
4848
secret_key_bytes.zeroize();
4949

5050
// Chain code

randomness/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ license.workspace = true
99
rand.workspace = true
1010
rand_core.workspace = true
1111
rand_0_8.workspace = true
12-
rand_0_9.workspace = true
1312

1413
[dev-dependencies]
1514
static_assertions.workspace = true

0 commit comments

Comments
 (0)