Skip to content

Commit

Permalink
core/state: mark account as dirty when resetObject occurs (#27339)
Browse files Browse the repository at this point in the history
This changes the journal logic to mark the state object dirty immediately when it
is reset. 

We're mostly adding this change to appease the fuzzer. Marking it dirty immediately
makes no difference in practice because accounts will always be modified by EVM
right after creation.
  • Loading branch information
rjl493456442 committed Jun 1, 2023
1 parent 2372fb2 commit 15bd21f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type (
account *common.Address
}
resetObjectChange struct {
account *common.Address
prev *stateObject
prevdestruct bool
}
Expand Down Expand Up @@ -162,7 +163,7 @@ func (ch resetObjectChange) revert(s *StateDB) {
}

func (ch resetObjectChange) dirtied() *common.Address {
return nil
return ch.account
}

func (ch suicideChange) revert(s *StateDB) {
Expand Down
14 changes: 5 additions & 9 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,15 @@ func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
// the given address, it is overwritten and returned as the second return value.
func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) {
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!

var prevdestruct bool
if prev != nil {
_, prevdestruct = s.stateObjectsDestruct[prev.address]
if !prevdestruct {
s.stateObjectsDestruct[prev.address] = struct{}{}
}
}
newobj = newObject(s, addr, types.StateAccount{})
if prev == nil {
s.journal.append(createObjectChange{account: &addr})
} else {
s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct})
_, prevdestruct := s.stateObjectsDestruct[prev.address]
if !prevdestruct {
s.stateObjectsDestruct[prev.address] = struct{}{}
}
s.journal.append(resetObjectChange{account: &addr, prev: prev, prevdestruct: prevdestruct})
}
s.setStateObject(newobj)
if prev != nil && !prev.deleted {
Expand Down

0 comments on commit 15bd21f

Please sign in to comment.