Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Sep 4, 2024
1 parent 264587f commit 2a2149b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
30 changes: 13 additions & 17 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ func init() {
type stateMap = map[common.Address]*account

type account struct {
Balance *big.Int `json:"balance,omitempty"`
Code []byte `json:"code,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *big.Int `json:"balance,omitempty"`
Code []byte `json:"code,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`

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

empty bool
Expand Down Expand Up @@ -122,7 +123,7 @@ func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scop
switch {
case stackLen >= 1 && (op == vm.SLOAD || op == vm.SSTORE):
slot := common.Hash(stackData[stackLen-1].Bytes32())
t.lookupStorage(caller, slot, common.Hash{}, false)
t.lookupStorage(caller, slot)
case stackLen >= 1 && (op == vm.EXTCODECOPY || op == vm.EXTCODEHASH || op == vm.EXTCODESIZE || op == vm.BALANCE || op == vm.SELFDESTRUCT):
addr := common.Address(stackData[stackLen-1].Bytes20())
t.lookupAccount(addr)
Expand Down Expand Up @@ -305,22 +306,17 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
// lookupStorage fetches the requested storage slot and adds
// it to the prestate of the given contract. It assumes `lookupAccount`
// has been performed on the contract before.
func (t *prestateTracer) lookupStorage(addr common.Address, key, mappedKey common.Hash, isArbitrumStorage bool) {
if isArbitrumStorage {
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
return
}
func (t *prestateTracer) lookupStorage(addr common.Address, key common.Hash) {
if _, ok := t.pre[addr].Storage[key]; ok {
return
}
t.pre[addr].Storage[key] = t.env.StateDB.GetState(addr, key)
}

func (t *prestateTracer) captureArbitrumStorageOps(addr common.Address, key, mappedKey common.Hash) {
t.lookupAccount(addr)
t.lookupStorage(addr, key, mappedKey, true)
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
}
6 changes: 4 additions & 2 deletions eth/tracers/native/tracer_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ 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.captureArbitrumStorageOps(addr, key, mappedKey)
t.lookupAccount(addr)
t.lookupArbitrumStorage(addr, key, mappedKey)
}

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

func (*callTracer) CaptureArbitrumStorageGet(addr common.Address, key, mappedKey common.Hash, depth int, before bool) {
Expand Down

0 comments on commit 2a2149b

Please sign in to comment.