Skip to content

Commit

Permalink
Fix edge cases where account and storage slots are incorrectly added …
Browse files Browse the repository at this point in the history
…to txn trace
  • Loading branch information
cffls committed Mar 22, 2024
1 parent d4f18f1 commit 8388b00
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ func (sdb *IntraBlockState) GetIncarnation(addr libcommon.Address) uint64 {
return 0
}

func (sdb *IntraBlockState) HasLiveAccount(addr libcommon.Address) bool {
if stateObject := sdb.stateObjects[addr]; stateObject != nil {
return true
}
return false
}

func (sdb *IntraBlockState) HasLiveState(addr libcommon.Address, key *libcommon.Hash) bool {
if stateObject := sdb.stateObjects[addr]; stateObject != nil {
if _, ok := stateObject.originStorage[*key]; ok {
Expand Down
1 change: 1 addition & 0 deletions core/vm/evmtypes/evmtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type IntraBlockState interface {
GetCommittedState(common.Address, *common.Hash, *uint256.Int)
GetState(address common.Address, slot *common.Hash, outValue *uint256.Int)
SetState(common.Address, *common.Hash, uint256.Int)
HasLiveAccount(addr common.Address) bool
HasLiveState(addr common.Address, key *common.Hash) bool

GetTransientState(addr common.Address, key common.Hash) uint256.Int
Expand Down
12 changes: 8 additions & 4 deletions eth/tracers/native/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ func (t *zeroTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sco
slot := libcommon.Hash(stackData[stackLen-1].Bytes32())

// If the SSTORE is out of gas and the slot is in live state, we will add the slot to account read
if err == vm.ErrOutOfGas && t.env.IntraBlockState().HasLiveState(caller, &slot) {
t.addAccountToTrace(caller)
t.addSLOADToAccount(caller, slot)
if err == vm.ErrOutOfGas {
if t.env.IntraBlockState().HasLiveState(caller, &slot) {
t.addAccountToTrace(caller)
t.addSLOADToAccount(caller, slot)
}
return
}
t.addAccountToTrace(caller)
Expand All @@ -138,7 +140,9 @@ func (t *zeroTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sco

// If the call is out of gas, we will add account but not the opcode
if err == vm.ErrOutOfGas && op == vm.CALL {
t.addAccountToTrace(addr)
if t.env.IntraBlockState().HasLiveAccount(addr) {
t.addAccountToTrace(addr)
}
return
}
t.addAccountToTrace(addr)
Expand Down

0 comments on commit 8388b00

Please sign in to comment.