core/state: add nil guard

This commit is contained in:
Gary Rong 2026-04-23 16:07:38 +08:00 committed by Jared Wasinger
parent f196057728
commit a42743c2ce
3 changed files with 10 additions and 6 deletions

View file

@ -179,7 +179,8 @@ func (j *journal) stashBalance(addr common.Address, prev *uint256.Int) {
if s.balanceSet {
return
}
s.balance = prev.Clone()
// The balance is already deep-copied in the StateDB
s.balance = prev
s.balanceSet = true
}
@ -199,7 +200,8 @@ func (j *journal) stashCode(addr common.Address, prev []byte) {
if s.codeSet {
return
}
s.code = slices.Clone(prev)
// The code is already deep-copied in the StateDB
s.code = prev
s.codeSet = true
}

View file

@ -184,8 +184,9 @@ func (s *stateObject) getState(key common.Hash) (common.Hash, common.Hash) {
// without any mutations caused in the current execution.
func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
// Record slot access regardless of whether the storage slot exists.
s.db.stateAccessList.StorageRead(s.address, key)
if s.db.stateAccessList != nil {
s.db.stateAccessList.StorageRead(s.address, key)
}
// If we have a pending write or clean cached, return that
if value, pending := s.pendingStorage[key]; pending {
return value

View file

@ -590,8 +590,9 @@ func (s *StateDB) deleteStateObject(addr common.Address) {
// the object is not found or was deleted in this execution context.
func (s *StateDB) getStateObject(addr common.Address) *stateObject {
// Record state access regardless of whether the account exists.
s.stateAccessList.AccountRead(addr)
if s.stateAccessList != nil {
s.stateAccessList.AccountRead(addr)
}
// Prefer live objects if any is available
if obj := s.stateObjects[addr]; obj != nil {
return obj