diff --git a/rvgo/fast/evm.go b/rvgo/fast/evm.go index 696a0fc1..f90ed3d5 100644 --- a/rvgo/fast/evm.go +++ b/rvgo/fast/evm.go @@ -3,7 +3,7 @@ package fast import "github.com/ethereum/go-ethereum/crypto" var ( - StepBytes4 = crypto.Keccak256([]byte("step(bytes,bytes)"))[:4] + StepBytes4 = crypto.Keccak256([]byte("step(bytes,bytes,bytes32)"))[:4] CheatBytes4 = crypto.Keccak256([]byte("cheat(uint256,bytes32,bytes32,uint256)"))[:4] LoadKeccak256PreimagePartBytes4 = crypto.Keccak256([]byte("loadKeccak256PreimagePart(uint256,bytes)"))[:4] ) diff --git a/rvgo/fast/witness.go b/rvgo/fast/witness.go index 549005b8..1fa2a885 100644 --- a/rvgo/fast/witness.go +++ b/rvgo/fast/witness.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/ethereum-optimism/optimism/op-preimage" + preimage "github.com/ethereum-optimism/optimism/op-preimage" ) type StepWitness struct { @@ -27,19 +27,25 @@ func uint64ToBytes32(v uint64) []byte { func (wit *StepWitness) EncodeStepInput() []byte { abiStatePadding := (32 - (uint64(len(wit.State)) % 32)) % 32 + abiProofPadding := (32 - (uint64(len(wit.MemProof)) % 32)) % 32 var input []byte input = append(input, StepBytes4...) - input = append(input, uint64ToBytes32(32*2)...) // state data offset in bytes - input = append(input, uint64ToBytes32(32*2+32+uint64(len(wit.State))+abiStatePadding)...) // proof data offset in bytes - // TODO pad state data to multiple of 32 bytes - // TODO also pad proof data - - input = append(input, uint64ToBytes32(uint64(len(wit.State)))...) // state data length in bytes + // state data offset in bytes + input = append(input, uint64ToBytes32(32*3)...) + // proof data offset in bytes + input = append(input, uint64ToBytes32(32*3+32+uint64(len(wit.State))+abiStatePadding)...) + // dummy localContext + input = append(input, make([]byte, 32)...) + + // state data length in bytes + input = append(input, uint64ToBytes32(uint64(len(wit.State)))...) input = append(input, wit.State[:]...) input = append(input, make([]byte, abiStatePadding)...) - input = append(input, uint64ToBytes32(uint64(len(wit.MemProof)))...) // proof data length in bytes + // proof data length in bytes + input = append(input, uint64ToBytes32(uint64(len(wit.MemProof)))...) input = append(input, wit.MemProof[:]...) + input = append(input, make([]byte, abiProofPadding)...) return input } diff --git a/rvgo/slow/vm.go b/rvgo/slow/vm.go index f72141b8..b841df66 100644 --- a/rvgo/slow/vm.go +++ b/rvgo/slow/vm.go @@ -3,6 +3,7 @@ package slow import ( "encoding/binary" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" ) @@ -103,8 +104,8 @@ func Step(calldata []byte, po PreimageOracle) (stateHash common.Hash, outErr err // TODO: validate abi offset values? - stateContentOffset := uint8(4 + 32 + 32 + 32) - if iszero(eq(b32asBEWord(calldataload(toU64(4+32*2))), shortToU256(stateSize))) { + 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 panic("invalid state size input") }