Skip to content

Commit

Permalink
feat: change BLOCKHASH opcode behavior to `keccak(chain_id || block…
Browse files Browse the repository at this point in the history
…_number)`
  • Loading branch information
HAOYUatHZ committed Dec 11, 2023
1 parent ee9b3d9 commit 4f9b290
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,22 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
lower = upper - 256
}
if num64 >= lower && num64 < upper {
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
chainId := interpreter.evm.ChainConfig().ChainID
chainIdBuf := make([]byte, 8)
binary.BigEndian.PutUint64(chainIdBuf, chainId.Uint64())
num64Buf := make([]byte, 8)
binary.BigEndian.PutUint64(num64Buf, num64)

if interpreter.hasher == nil {
interpreter.hasher = sha3.NewLegacyKeccak256().(keccakState)
} else {
interpreter.hasher.Reset()
}
interpreter.hasher.Write(chainIdBuf)
interpreter.hasher.Write(num64Buf)
interpreter.hasher.Read(interpreter.hasherBuf[:])

num.SetBytes(interpreter.hasherBuf[:])
} else {
num.Clear()
}
Expand Down

0 comments on commit 4f9b290

Please sign in to comment.