Skip to content

Commit

Permalink
chore(deps): bump secp256k1 to 0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Mar 27, 2024
1 parent 09de0ac commit ac97aa0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
29 changes: 14 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ tower = "0.4"
tower-http = "0.4"

# p2p
discv5 = "0.4"
discv5 = "0.4.1"
igd-next = "0.14.3"

# rpc
Expand All @@ -325,12 +325,12 @@ jsonrpsee-core = "0.20"
jsonrpsee-types = "0.20"

# crypto
secp256k1 = { version = "0.27.0", default-features = false, features = [
secp256k1 = { version = "0.28", default-features = false, features = [
"global-context",
"rand-std",
"recovery",
] }
enr = { version = "=0.10.0", default-features = false, features = ["k256"] }
enr = { version = "0.10", default-features = false, features = ["k256"] }

# for eip-4844
c-kzg = "1.0.0"
Expand Down
14 changes: 7 additions & 7 deletions crates/interfaces/src/test_utils/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reth_primitives::{
SealedHeader, StorageEntry, Transaction, TransactionKind, TransactionSigned, TxLegacy, B256,
U256,
};
use secp256k1::{KeyPair, Secp256k1};
use secp256k1::{Keypair, Secp256k1};
use std::{
cmp::{max, min},
collections::{hash_map::DefaultHasher, BTreeMap},
Expand Down Expand Up @@ -92,22 +92,22 @@ pub fn random_tx<R: Rng>(rng: &mut R) -> Transaction {
/// - There is no guarantee that the nonce is not used twice for the same account
pub fn random_signed_tx<R: Rng>(rng: &mut R) -> TransactionSigned {
let secp = Secp256k1::new();
let key_pair = KeyPair::new(&secp, rng);
let key_pair = Keypair::new(&secp, rng);
let tx = random_tx(rng);
sign_tx_with_key_pair(key_pair, tx)
}

/// Signs the [Transaction] with the given key pair.
pub fn sign_tx_with_key_pair(key_pair: KeyPair, tx: Transaction) -> TransactionSigned {
pub fn sign_tx_with_key_pair(key_pair: Keypair, tx: Transaction) -> TransactionSigned {
let signature =
sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap();
TransactionSigned::from_transaction_and_signature(tx, signature)
}

/// Generates a set of [KeyPair]s based on the desired count.
pub fn generate_keys<R: Rng>(rng: &mut R, count: usize) -> Vec<KeyPair> {
/// Generates a set of [Keypair]s based on the desired count.
pub fn generate_keys<R: Rng>(rng: &mut R, count: usize) -> Vec<Keypair> {
let secp = Secp256k1::new();
(0..count).map(|_| KeyPair::new(&secp, rng)).collect()
(0..count).map(|_| Keypair::new(&secp, rng)).collect()
}

/// Generate a random block filled with signed transactions (generated using
Expand Down Expand Up @@ -405,7 +405,7 @@ mod tests {
let signature_hash = tx.signature_hash();

for _ in 0..100 {
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
let key_pair = Keypair::new(&secp, &mut rand::thread_rng());

let signature =
sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), signature_hash)
Expand Down
6 changes: 3 additions & 3 deletions crates/net/ecies/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl ECIES {
let msg = x ^ self.nonce;
let (rec_id, sig) = SECP256K1
.sign_ecdsa_recoverable(
&secp256k1::Message::from_slice(msg.as_slice()).unwrap(),
&secp256k1::Message::from_digest(msg.0),
&self.ephemeral_secret_key,
)
.serialize_compact();
Expand Down Expand Up @@ -473,7 +473,7 @@ impl ECIES {

let x = ecdh_x(&self.remote_public_key.unwrap(), &self.secret_key);
self.remote_ephemeral_public_key = Some(SECP256K1.recover_ecdsa(
&secp256k1::Message::from_slice((x ^ self.remote_nonce.unwrap()).as_ref()).unwrap(),
&secp256k1::Message::from_digest((x ^ self.remote_nonce.unwrap()).0),
&signature,
)?);
self.ephemeral_shared_secret =
Expand Down Expand Up @@ -631,7 +631,7 @@ impl ECIES {
let tag = self.egress_mac.as_mut().unwrap().digest();

out.reserve(ECIES::header_len());
out.extend_from_slice(&header);
out.extend_from_slice(&header[..]);
out.extend_from_slice(tag.as_slice());
}

Expand Down
24 changes: 12 additions & 12 deletions crates/primitives/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod allocator {
use alloy_genesis::GenesisAccount;
use secp256k1::{
rand::{thread_rng, RngCore},
KeyPair, Secp256k1,
Keypair, Secp256k1,
};
use std::collections::{hash_map::Entry, BTreeMap, HashMap};

Expand Down Expand Up @@ -73,9 +73,9 @@ mod allocator {
/// Add a funded account to the genesis alloc.
///
/// Returns the key pair for the account and the account's address.
pub fn new_funded_account(&mut self, balance: U256) -> (KeyPair, Address) {
pub fn new_funded_account(&mut self, balance: U256) -> (Keypair, Address) {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(address, GenesisAccount::default().with_balance(balance));
Expand All @@ -90,9 +90,9 @@ mod allocator {
&mut self,
balance: U256,
code: Bytes,
) -> (KeyPair, Address) {
) -> (Keypair, Address) {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(
Expand All @@ -110,9 +110,9 @@ mod allocator {
&mut self,
balance: U256,
storage: BTreeMap<B256, B256>,
) -> (KeyPair, Address) {
) -> (Keypair, Address) {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(
Expand All @@ -130,9 +130,9 @@ mod allocator {
&mut self,
code: Bytes,
storage: BTreeMap<B256, B256>,
) -> (KeyPair, Address) {
) -> (Keypair, Address) {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(
Expand All @@ -146,9 +146,9 @@ mod allocator {
/// Adds an account with code to the genesis alloc.
///
/// Returns the key pair for the account and the account's address.
pub fn new_account_with_code(&mut self, code: Bytes) -> (KeyPair, Address) {
pub fn new_account_with_code(&mut self, code: Bytes) -> (Keypair, Address) {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(address, GenesisAccount::default().with_code(Some(code)));
Expand All @@ -169,7 +169,7 @@ mod allocator {
/// Returns the key pair for the account and the account's address.
pub fn add_account(&mut self, account: GenesisAccount) -> Address {
let secp = Secp256k1::new();
let pair = KeyPair::new(&secp, &mut self.rng);
let pair = Keypair::new(&secp, &mut self.rng);
let address = public_key_to_address(pair.public_key());

self.alloc.insert(address, account);
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ mod tests {
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
use bytes::BytesMut;
use reth_codecs::Compact;
use secp256k1::{KeyPair, Secp256k1};
use secp256k1::{Keypair, Secp256k1};
use std::str::FromStr;

#[test]
Expand Down Expand Up @@ -1970,7 +1970,7 @@ mod tests {
tx.set_chain_id(chain_id % (u64::MAX / 2 - 36));
}

let key_pair = KeyPair::new(&secp, &mut rng);
let key_pair = Keypair::new(&secp, &mut rng);

let signature =
sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/transaction/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ pub(crate) mod secp256k1 {
let sig =
RecoverableSignature::from_compact(&sig[0..64], RecoveryId::from_i32(sig[64] as i32)?)?;

let public = SECP256K1.recover_ecdsa(&Message::from_slice(&msg[..32])?, &sig)?;
let public = SECP256K1.recover_ecdsa(&Message::from_digest(*msg), &sig)?;
Ok(public_key_to_address(public))
}

/// Signs message with the given secret key.
/// Returns the corresponding signature.
pub fn sign_message(secret: B256, message: B256) -> Result<Signature, secp256k1::Error> {
let sec = SecretKey::from_slice(secret.as_ref())?;
let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_slice(&message[..])?, &sec);
let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_digest(message.0), &sec);
let (rec_id, data) = s.serialize_compact();

let signature = Signature {
Expand Down

0 comments on commit ac97aa0

Please sign in to comment.