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 5e6db03 commit 7642f22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 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]
)
25 changes: 17 additions & 8 deletions rvgo/fast/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"errors"
"fmt"

"github.com/ethereum-optimism/optimism/op-preimage"
preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum/go-ethereum/common"
)

type LocalContext common.Hash

type StepWitness struct {
// encoded state witness
State []byte
Expand All @@ -27,19 +30,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

0 comments on commit 7642f22

Please sign in to comment.