Skip to content

Commit 08faaba

Browse files
committed
core/state: supply origin-value when reverting storage change
1 parent 708f319 commit 08faaba

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

core/state/setjournal.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ type addrSlot struct {
4747
slot common.Hash
4848
}
4949

50+
type doubleHash struct {
51+
origin common.Hash
52+
prev common.Hash
53+
}
54+
5055
// scopedJournal represents all changes within a single callscope. These changes
5156
// are either all reverted, or all committed -- they cannot be partially applied.
5257
type scopedJournal struct {
@@ -57,7 +62,7 @@ type scopedJournal struct {
5762
accessListAddresses []common.Address
5863
accessListAddrSlots []addrSlot
5964

60-
storageChanges map[common.Address]map[common.Hash]common.Hash
65+
storageChanges map[common.Address]map[common.Hash]doubleHash
6166
tStorageChanges map[common.Address]map[common.Hash]common.Hash
6267
}
6368

@@ -79,7 +84,7 @@ func (j *scopedJournal) deepCopy() *scopedJournal {
7984
accessListAddrSlots: slices.Clone(j.accessListAddrSlots),
8085
}
8186
if j.storageChanges != nil {
82-
cpy.storageChanges = make(map[common.Address]map[common.Hash]common.Hash)
87+
cpy.storageChanges = make(map[common.Address]map[common.Hash]doubleHash)
8388
for addr, changes := range j.storageChanges {
8489
cpy.storageChanges[addr] = maps.Clone(changes)
8590
}
@@ -147,18 +152,18 @@ func (j *scopedJournal) journalAccessListAddSlot(addr common.Address, slot commo
147152
j.accessListAddrSlots = append(j.accessListAddrSlots, addrSlot{addr, slot})
148153
}
149154

150-
func (j *scopedJournal) journalSetState(addr common.Address, key common.Hash, prev common.Hash) {
155+
func (j *scopedJournal) journalSetState(addr common.Address, key, prev, origin common.Hash) {
151156
if j.storageChanges == nil {
152-
j.storageChanges = make(map[common.Address]map[common.Hash]common.Hash)
157+
j.storageChanges = make(map[common.Address]map[common.Hash]doubleHash)
153158
}
154159
changes, ok := j.storageChanges[addr]
155160
if !ok {
156-
changes = make(map[common.Hash]common.Hash)
161+
changes = make(map[common.Hash]doubleHash)
157162
j.storageChanges[addr] = changes
158163
}
159164
// Do not overwrite a previous value!
160165
if _, ok := changes[key]; !ok {
161-
changes[key] = prev
166+
changes[key] = doubleHash{origin: origin, prev: prev}
162167
}
163168
}
164169

@@ -186,10 +191,7 @@ func (j *scopedJournal) revert(s *StateDB) {
186191
for addr, changes := range j.storageChanges {
187192
obj := s.getStateObject(addr)
188193
for key, val := range changes {
189-
// OBS!
190-
// TODO @holiman, it's not correct to pass empty hash here!
191-
// OBS!
192-
obj.setState(key, val, common.Hash{})
194+
obj.setState(key, val.prev, val.origin)
193195
}
194196
}
195197
// Revert t-store changes
@@ -449,8 +451,8 @@ func (j *sparseJournal) accessListAddSlot(addr common.Address, slot common.Hash)
449451
j.entries[len(j.entries)-1].journalAccessListAddSlot(addr, slot)
450452
}
451453

452-
func (j *sparseJournal) storageChange(addr common.Address, key common.Hash, prev common.Hash, origin common.Hash) {
453-
j.entries[len(j.entries)-1].journalSetState(addr, key, prev)
454+
func (j *sparseJournal) storageChange(addr common.Address, key, prev, origin common.Hash) {
455+
j.entries[len(j.entries)-1].journalSetState(addr, key, prev, origin)
454456
}
455457

456458
func (j *sparseJournal) transientStateChange(addr common.Address, key, prev common.Hash) {

0 commit comments

Comments
 (0)