From 90759d6f6b56379bff3e2905b98be98d58e8504d Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 20 Mar 2024 05:47:18 +0400 Subject: [PATCH] review fixes --- crates/cheatcodes/src/utils.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/cheatcodes/src/utils.rs b/crates/cheatcodes/src/utils.rs index aa024658312d..f9edc8e40d7c 100644 --- a/crates/cheatcodes/src/utils.rs +++ b/crates/cheatcodes/src/utils.rs @@ -157,6 +157,10 @@ fn create_wallet(private_key: &U256, label: Option<&str>, state: &mut Cheatcodes .abi_encode()) } +fn encode_vrs(v: u8, r: U256, s: U256) -> Vec { + (U256::from(v), B256::from(r), B256::from(s)).abi_encode() +} + pub(super) fn sign(private_key: &U256, digest: &B256) -> Result { // The `ecrecover` precompile does not use EIP-155. No chain ID is needed. let wallet = parse_wallet(private_key)?; @@ -166,11 +170,9 @@ pub(super) fn sign(private_key: &U256, digest: &B256) -> Result { assert_eq!(recovered, wallet.address()); - let v = U256::from(sig.v().y_parity_byte_non_eip155().unwrap_or(sig.v().y_parity_byte())); - let r = B256::from(sig.r()); - let s = B256::from(sig.s()); + let v = sig.v().y_parity_byte_non_eip155().unwrap_or(sig.v().y_parity_byte()); - Ok((v, r, s).abi_encode()) + Ok(encode_vrs(v, sig.r(), sig.s())) } pub(super) fn sign_with_wallet( @@ -207,11 +209,7 @@ pub(super) fn sign_with_wallet( let recovered = sig.recover(digest.to_ethers()).map_err(|err| fmt_err!("{err}"))?; assert_eq!(recovered.to_alloy(), signer); - let v = U256::from(sig.v); - let r = B256::from(sig.r.to_alloy()); - let s = B256::from(sig.s.to_alloy()); - - Ok((v, r, s).abi_encode()) + Ok(encode_vrs(sig.v as u8, sig.r.to_alloy(), sig.s.to_alloy())) } pub(super) fn sign_p256(private_key: &U256, digest: &B256, _state: &mut Cheatcodes) -> Result {