Skip to content

Commit

Permalink
Add function selector check for slow vm
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Dec 16, 2024
1 parent 8ff9318 commit 81ee551
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rvgo/slow/vm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package slow

import (
"bytes"
"encoding/binary"
"fmt"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81ee551

Please sign in to comment.