Skip to content

Commit

Permalink
vm: fix ecrecover precompile for v=0 and v=1
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed May 30, 2022
1 parent 8168d3f commit f2dbdaa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/vm/src/evm/precompiles/01-ecrecover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export default function (opts: PrecompileInput): ExecResult {

const msgHash = data.slice(0, 32)
const v = data.slice(32, 64)
const vBN = new BN(v)

// Guard against util's `ecrecover`: without providing chainId this will return
// a signature in most of the cases in the cases that `v=0` or `v=1`
// However, this should throw, only 27 and 28 is allowed as input
if (!vBN.eqn(27) && !vBN.eqn(28)) {
return {
gasUsed,
returnValue: Buffer.alloc(0),
}
}

const r = data.slice(64, 96)
const s = data.slice(96, 128)

Expand Down

0 comments on commit f2dbdaa

Please sign in to comment.