Skip to content

Commit

Permalink
v can only be 27 or 28 prefixed only with zeros (polkadot-evm#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Jan 16, 2023
1 parent 3568a86 commit cd30e82
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frame/evm/precompile/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ impl LinearCostPrecompile for ECRecover {
let mut sig = [0u8; 65];

msg[0..32].copy_from_slice(&input[0..32]);
sig[0..32].copy_from_slice(&input[64..96]);
sig[32..64].copy_from_slice(&input[96..128]);
sig[64] = input[63];
sig[0..32].copy_from_slice(&input[64..96]); // r
sig[32..64].copy_from_slice(&input[96..128]); // s
sig[64] = input[63]; // v

// v can only be 27 or 28 on the full 32 bytes value.
// https://github.com/ethereum/go-ethereum/blob/a907d7e81aaeea15d80b2d3209ad8e08e3bf49e0/core/vm/contracts.go#L177
if input[32..63] != [0u8; 31] || ![27, 28].contains(&input[63]) {
return Ok((ExitSucceed::Returned, [0u8; 0].to_vec()));
}

let result = match sp_io::crypto::secp256k1_ecdsa_recover(&sig, &msg) {
Ok(pubkey) => {
Expand Down

0 comments on commit cd30e82

Please sign in to comment.