Correct Ethereum

This commit is contained in:
Luke Parker 2023-03-07 05:10:14 -05:00
parent b0730e3fdf
commit 6bff3866ea
No known key found for this signature in database
4 changed files with 9 additions and 7 deletions

1
Cargo.lock generated
View file

@ -2007,7 +2007,6 @@ dependencies = [
"ethers-solc",
"eyre",
"group",
"hex-literal",
"k256 0.12.0",
"modular-frost",
"rand_core 0.6.4",

View file

@ -13,7 +13,6 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
hex-literal = "0.3"
thiserror = "1"
rand_core = "0.6"

View file

@ -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);

View file

@ -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::<Sha256>(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<bool>
{
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]));