diff --git a/packages/vm/src/evm/precompiles/01-ecrecover.ts b/packages/vm/src/evm/precompiles/01-ecrecover.ts index 0557210d45..8d5a96d249 100644 --- a/packages/vm/src/evm/precompiles/01-ecrecover.ts +++ b/packages/vm/src/evm/precompiles/01-ecrecover.ts @@ -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)