From 6bff3866ea3b9720418eb7059d7db42e708708b4 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 7 Mar 2023 05:10:14 -0500 Subject: [PATCH] Correct Ethereum --- Cargo.lock | 1 - coins/ethereum/Cargo.toml | 1 - coins/ethereum/tests/contract.rs | 3 ++- coins/ethereum/tests/crypto.rs | 11 +++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2a311f3..b6c86581 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2007,7 +2007,6 @@ dependencies = [ "ethers-solc", "eyre", "group", - "hex-literal", "k256 0.12.0", "modular-frost", "rand_core 0.6.4", diff --git a/coins/ethereum/Cargo.toml b/coins/ethereum/Cargo.toml index 4e837f0e..262be7ae 100644 --- a/coins/ethereum/Cargo.toml +++ b/coins/ethereum/Cargo.toml @@ -13,7 +13,6 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [dependencies] -hex-literal = "0.3" thiserror = "1" rand_core = "0.6" diff --git a/coins/ethereum/tests/contract.rs b/coins/ethereum/tests/contract.rs index 70f3320a..06b18d65 100644 --- a/coins/ethereum/tests/contract.rs +++ b/coins/ethereum/tests/contract.rs @@ -11,6 +11,7 @@ use ethers::{ use frost::{ curve::Secp256k1, + Participant, algorithm::Schnorr as Algo, tests::{key_gen, algorithm_machines, sign}, }; @@ -44,7 +45,7 @@ async fn test_ecrecover_hack() { let chain_id = U256::from(chain_id); let keys = key_gen::<_, Secp256k1>(&mut OsRng); - let group_key = keys[&1].group_key(); + let group_key = keys[&Participant::new(1).unwrap()].group_key(); const MESSAGE: &[u8] = b"Hello, World!"; let hashed_message = keccak256(MESSAGE); diff --git a/coins/ethereum/tests/crypto.rs b/coins/ethereum/tests/crypto.rs index 82f61e01..01413ece 100644 --- a/coins/ethereum/tests/crypto.rs +++ b/coins/ethereum/tests/crypto.rs @@ -2,7 +2,7 @@ use k256::{ elliptic_curve::{bigint::ArrayEncoding, ops::Reduce, sec1::ToEncodedPoint}, ProjectivePoint, Scalar, U256, }; -use frost::curve::Secp256k1; +use frost::{curve::Secp256k1, Participant}; use ethereum_serai::crypto::*; @@ -21,7 +21,10 @@ fn test_ecrecover() { .as_nonzero_scalar() .try_sign_prehashed_rfc6979::(Keccak256::digest(MESSAGE), b"") .unwrap(); - assert_eq!(public.verify_digest(Keccak256::new_with_prefix(MESSAGE), &sig).unwrap(), ()); + #[allow(clippy::unit_cmp)] // Intended to assert this wasn't changed to Result + { + assert_eq!(public.verify_digest(Keccak256::new_with_prefix(MESSAGE), &sig).unwrap(), ()); + } assert_eq!( ecrecover(hash_to_scalar(MESSAGE), recovery_id.unwrap().is_y_odd().into(), *sig.r(), *sig.s()) @@ -39,7 +42,7 @@ fn test_signing() { use rand_core::OsRng; let keys = key_gen::<_, Secp256k1>(&mut OsRng); - let _group_key = keys[&1].group_key(); + let _group_key = keys[&Participant::new(1).unwrap()].group_key(); const MESSAGE: &[u8] = b"Hello, World!"; @@ -62,7 +65,7 @@ fn test_ecrecover_hack() { use rand_core::OsRng; let keys = key_gen::<_, Secp256k1>(&mut OsRng); - let group_key = keys[&1].group_key(); + let group_key = keys[&Participant::new(1).unwrap()].group_key(); let group_key_encoded = group_key.to_encoded_point(true); let group_key_compressed = group_key_encoded.as_ref(); let group_key_x = Scalar::from_uint_reduced(U256::from_be_slice(&group_key_compressed[1 .. 33]));