Skip to content

Commit

Permalink
Modify rvgo for local context support
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Feb 1, 2024
1 parent 91ea1ac commit 69f7d22
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rvgo/fast/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
22 changes: 14 additions & 8 deletions rvgo/fast/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions rvgo/slow/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package slow
import (
"encoding/binary"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 69f7d22

Please sign in to comment.