From 81ee55117cad1b545ff4d91da4b08b6546805c42 Mon Sep 17 00:00:00 2001 From: Minhyuk Kim Date: Sun, 15 Dec 2024 17:58:20 +0900 Subject: [PATCH] Add function selector check for slow vm --- rvgo/slow/vm.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rvgo/slow/vm.go b/rvgo/slow/vm.go index 458f00c..6dc1820 100644 --- a/rvgo/slow/vm.go +++ b/rvgo/slow/vm.go @@ -1,6 +1,7 @@ package slow import ( + "bytes" "encoding/binary" "fmt" @@ -121,6 +122,12 @@ func Step(calldata []byte, po PreimageOracle) (stateHash common.Hash, outErr err return } + // First 4 bytes of keccak256("step(bytes,bytes,bytes32)") + expectedSelector := []byte{0xe1, 0x4c, 0xed, 0x32} + if len(calldata) < 4 || !bytes.Equal(calldata[:4], expectedSelector) { + panic("invalid function selector") + } + stateContentOffset := uint8(4 + 32 + 32 + 32 + 32) if iszero(eq(b32asBEWord(calldataload(toU64(4+32*3))), shortToU256(stateSize))) { // user-provided state size must match expected state size