From dd2c0f3c55e49c88858c0c677422e2dd70736252 Mon Sep 17 00:00:00 2001 From: byeongsu-hong Date: Wed, 23 Aug 2023 11:41:36 +0900 Subject: [PATCH] fix(va): apply ERC155 and some code cleanup --- contracts/va/src/contract.rs | 5 +++-- contracts/va/src/tests/contracts.rs | 2 +- integration-test/tests/validator.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/contracts/va/src/contract.rs b/contracts/va/src/contract.rs index 8a9dda7d..b265a597 100644 --- a/contracts/va/src/contract.rs +++ b/contracts/va/src/contract.rs @@ -86,7 +86,7 @@ pub fn execute( let validator = deps.api.addr_validate(raw_validator.as_str())?; let replay_id = keccak256_hash( - vec![ + [ bech32_decode(validator.as_str())?, storage_location.as_bytes().to_vec(), ] @@ -115,7 +115,8 @@ pub fn execute( let recovered = deps.api.secp256k1_recover_pubkey( &announcement_hash, &signature.as_slice()[..64], - signature[64], + // We subs 27 according to this - https://eips.ethereum.org/EIPS/eip-155 + signature[64] - 27, )?; let recovered_addr = pub_to_addr(Binary(recovered), &ADDR_PREFIX.load(deps.storage)?)?; diff --git a/contracts/va/src/tests/contracts.rs b/contracts/va/src/tests/contracts.rs index 437dce8d..80dc20b6 100644 --- a/contracts/va/src/tests/contracts.rs +++ b/contracts/va/src/tests/contracts.rs @@ -54,7 +54,7 @@ impl<'a> TestData<'a> { fn pack_signature((rs, v): (Signature, RecoveryId)) -> Binary { let mut bz = rs.to_bytes().to_vec(); - bz.push(v.to_byte()); + bz.push(v.to_byte() + 27u8); Binary(bz) } diff --git a/integration-test/tests/validator.rs b/integration-test/tests/validator.rs index 72cb7ef5..af534957 100644 --- a/integration-test/tests/validator.rs +++ b/integration-test/tests/validator.rs @@ -134,7 +134,7 @@ impl TestValidators { .iter() .map(|v| { let (mut signature, recov_id) = v.sign(digest); - signature.0.extend(vec![recov_id.to_byte()].into_iter()); + signature.0.extend(vec![recov_id.to_byte()]); signature }) .collect::>();