diff --git a/core/state/journal.go b/core/state/journal.go index 94f7e0ad39..b042e0cf3f 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -20,6 +20,7 @@ import ( "maps" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/holiman/uint256" ) @@ -159,12 +160,8 @@ func (j *journal) JournalBalanceChange(addr common.Address, previous *uint256.In }) } -func (j *journal) JournalSetCode(address common.Address, prevcode, prevHash []byte) { - j.append(codeChange{ - account: &address, - prevhash: prevHash, - prevcode: prevcode, - }) +func (j *journal) JournalSetCode(address common.Address) { + j.append(codeChange{account: &address}) } func (j *journal) JournalNonceChange(address common.Address, prev uint64) { @@ -220,8 +217,7 @@ type ( origvalue common.Hash } codeChange struct { - account *common.Address - prevcode, prevhash []byte + account *common.Address } // Changes to other state values. @@ -348,7 +344,7 @@ func (ch nonceChange) copy() journalEntry { } func (ch codeChange) revert(s *StateDB) { - s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode) + s.getStateObject(*ch.account).setCode(types.EmptyCodeHash, nil) } func (ch codeChange) dirtied() *common.Address { @@ -356,11 +352,7 @@ func (ch codeChange) dirtied() *common.Address { } func (ch codeChange) copy() journalEntry { - return codeChange{ - account: ch.account, - prevhash: common.CopyBytes(ch.prevhash), - prevcode: common.CopyBytes(ch.prevcode), - } + return codeChange{account: ch.account} } func (ch storageChange) revert(s *StateDB) { diff --git a/core/state/state_object.go b/core/state/state_object.go index 44a628acfc..7a2935a918 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -574,7 +574,7 @@ func (s *stateObject) CodeSize() int { } func (s *stateObject) SetCode(codeHash common.Hash, code []byte) { - s.db.journal.JournalSetCode(s.address, s.Code(), s.CodeHash()) + s.db.journal.JournalSetCode(s.address) if s.db.logger != nil && s.db.logger.OnCodeChange != nil { // TODO remove prevcode from this callback s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), nil, codeHash, code) diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 2ce2b868fa..9256329ddc 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -372,6 +372,12 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction { { name: "SetCode", fn: func(a testAction, s *StateDB) { + // SetCode can only be performed in case the addr does + // not already hold code + if c := s.GetCode(addr); len(c) > 0 { + // no-op + return + } code := make([]byte, 16) binary.BigEndian.PutUint64(code, uint64(a.args[0])) binary.BigEndian.PutUint64(code[8:], uint64(a.args[1]))