Skip to content

Commit

Permalink
fix(va): apply ERC155 and some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Aug 23, 2023
1 parent 649dcd4 commit dd2c0f3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions contracts/va/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]
Expand Down Expand Up @@ -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)?)?;
Expand Down
2 changes: 1 addition & 1 deletion contracts/va/src/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion integration-test/tests/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
Expand Down

0 comments on commit dd2c0f3

Please sign in to comment.