diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index f98ff8445d..0305e218f6 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -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 @@ -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) @@ -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 } diff --git a/eth/tracers/native/tracer_arbitrum.go b/eth/tracers/native/tracer_arbitrum.go index db6d18d68a..3ede5682de 100644 --- a/eth/tracers/native/tracer_arbitrum.go +++ b/eth/tracers/native/tracer_arbitrum.go @@ -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) {