Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Dec 17, 2024
1 parent 7470c19 commit bddfe08
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 63 deletions.
4 changes: 2 additions & 2 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ type (
LogHook = func(log *types.Log)

CaptureArbitrumTransferHook = func(from, to *common.Address, value *big.Int, before bool, purpose string)
CaptureArbitrumStorageGetHook = func(addr common.Address, key, mappedKey common.Hash, depth int, before bool)
CaptureArbitrumStorageSetHook = func(addr common.Address, key, mappedKey, value common.Hash, depth int, before bool)
CaptureArbitrumStorageGetHook = func(key common.Hash, depth int, before bool)
CaptureArbitrumStorageSetHook = func(key, value common.Hash, depth int, before bool)

CaptureStylusHostioHook = func(name string, args, outs []byte, startInk, endInk uint64)
)
Expand Down
22 changes: 8 additions & 14 deletions eth/tracers/native/gen_account_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ func (t *muxTracer) OnLog(log *types.Log) {
}
}

func (t *muxTracer) CaptureArbitrumStorageGet(addr common.Address, key, mappedKey common.Hash, depth int, before bool) {
func (t *muxTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {
for _, t := range t.tracers {
if t.CaptureArbitrumStorageGet != nil {
t.CaptureArbitrumStorageGet(addr, key, mappedKey, depth, before)
t.CaptureArbitrumStorageGet(key, depth, before)
}
}
}

func (t *muxTracer) CaptureArbitrumStorageSet(addr common.Address, key, mappedKey, value common.Hash, depth int, before bool) {
func (t *muxTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {
for _, t := range t.tracers {
if t.CaptureArbitrumStorageSet != nil {
t.CaptureArbitrumStorageSet(addr, key, mappedKey, value, depth, before)
t.CaptureArbitrumStorageSet(key, value, depth, before)
}
}
}
Expand Down
42 changes: 5 additions & 37 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ type account struct {
Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
empty bool

ArbitrumStorage map[common.Hash]common.Hash `json:"arbitrumStorage,omitempty"`
arbStorageKeyMap map[common.Hash]common.Hash
}

func (a *account) exists() bool {
return a.Nonce > 0 || len(a.Code) > 0 || len(a.Storage) > 0 || (a.Balance != nil && a.Balance.Sign() != 0) || len(a.ArbitrumStorage) > 0
return a.Nonce > 0 || len(a.Code) > 0 || len(a.Storage) > 0 || (a.Balance != nil && a.Balance.Sign() != 0)
}

type accountMarshaling struct {
Expand Down Expand Up @@ -214,7 +211,6 @@ func (t *prestateTracer) processDiffState() {
}
modified := false
postAccount := &account{Storage: make(map[common.Hash]common.Hash)}
postAccount.ArbitrumStorage = make(map[common.Hash]common.Hash)
newBalance := t.env.StateDB.GetBalance(addr).ToBig()
newNonce := t.env.StateDB.GetNonce(addr)
newCode := t.env.StateDB.GetCode(addr)
Expand Down Expand Up @@ -250,24 +246,6 @@ func (t *prestateTracer) processDiffState() {
}
}

for key, val := range state.ArbitrumStorage {
// don't include the empty slot
if val == (common.Hash{}) {
delete(t.pre[addr].ArbitrumStorage, key)
}

newVal := t.env.StateDB.GetState(types.ArbosStateAddress, state.arbStorageKeyMap[key])
if val == newVal {
// Omit unchanged slots
delete(t.pre[addr].ArbitrumStorage, key)
} else {
modified = true
if newVal != (common.Hash{}) {
postAccount.ArbitrumStorage[key] = newVal
}
}
}

if modified {
t.post[addr] = postAccount
} else {
Expand All @@ -285,12 +263,10 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
}

acc := &account{
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
Nonce: t.env.StateDB.GetNonce(addr),
Code: t.env.StateDB.GetCode(addr),
Storage: make(map[common.Hash]common.Hash),
ArbitrumStorage: make(map[common.Hash]common.Hash),
arbStorageKeyMap: make(map[common.Hash]common.Hash),
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
Nonce: t.env.StateDB.GetNonce(addr),
Code: t.env.StateDB.GetCode(addr),
Storage: make(map[common.Hash]common.Hash),
}
if !acc.exists() {
acc.empty = true
Expand All @@ -307,11 +283,3 @@ func (t *prestateTracer) lookupStorage(addr common.Address, key common.Hash) {
}
t.pre[addr].Storage[key] = t.env.StateDB.GetState(addr, key)
}

func (t *prestateTracer) lookupArbitrumStorage(addr common.Address, key, mappedKey common.Hash) {
if _, ok := t.pre[addr].ArbitrumStorage[key]; ok {
return
}
t.pre[addr].ArbitrumStorage[key] = t.env.StateDB.GetState(types.ArbosStateAddress, mappedKey)
t.pre[addr].arbStorageKeyMap[key] = mappedKey
}
13 changes: 7 additions & 6 deletions eth/tracers/native/tracer_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

type arbitrumTransfer struct {
Expand Down Expand Up @@ -74,14 +75,14 @@ func (t *flatCallTracer) CaptureArbitrumTransfer(from, to *common.Address, value
}
}

func (t *prestateTracer) CaptureArbitrumStorageGet(addr common.Address, key, mappedKey common.Hash, depth int, before bool) {
t.lookupAccount(addr)
t.lookupArbitrumStorage(addr, key, mappedKey)
func (t *prestateTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {
t.lookupAccount(types.ArbosStateAddress)
t.lookupStorage(types.ArbosStateAddress, key)
}

func (t *prestateTracer) CaptureArbitrumStorageSet(addr common.Address, key, mappedKey, value common.Hash, depth int, before bool) {
t.lookupAccount(addr)
t.lookupArbitrumStorage(addr, key, mappedKey)
func (t *prestateTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {
t.lookupAccount(types.ArbosStateAddress)
t.lookupStorage(types.ArbosStateAddress, key)
}

func bigToHex(n *big.Int) string {
Expand Down

0 comments on commit bddfe08

Please sign in to comment.