mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
core/state, core/vm: fix
This commit is contained in:
parent
85c387f60b
commit
214ada862c
6 changed files with 33 additions and 31 deletions
|
|
@ -128,7 +128,7 @@ type (
|
|||
account *common.Address
|
||||
prevcode, prevhash []byte
|
||||
}
|
||||
destructibleChange struct {
|
||||
eip6780DeletableChange struct {
|
||||
account common.Address
|
||||
}
|
||||
|
||||
|
|
@ -257,16 +257,16 @@ func (ch codeChange) copy() journalEntry {
|
|||
}
|
||||
}
|
||||
|
||||
func (ch destructibleChange) revert(s *StateDB) {
|
||||
s.getStateObject(ch.account).destructible = false
|
||||
func (ch eip6780DeletableChange) revert(s *StateDB) {
|
||||
s.getStateObject(ch.account).eip6780Deletable = false
|
||||
}
|
||||
|
||||
func (ch destructibleChange) dirtied() *common.Address {
|
||||
return nil // destruct-eligible flag is not considered as dirty
|
||||
func (ch eip6780DeletableChange) dirtied() *common.Address {
|
||||
return nil // this flag is not considered as dirty
|
||||
}
|
||||
|
||||
func (ch destructibleChange) copy() journalEntry {
|
||||
return destructibleChange{
|
||||
func (ch eip6780DeletableChange) copy() journalEntry {
|
||||
return eip6780DeletableChange{
|
||||
account: ch.account,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ type stateObject struct {
|
|||
selfDestructed bool
|
||||
|
||||
// This is an EIP-6780 flag indicating if the object is eligible for
|
||||
// self-destruct. Potential scenarios as follows:
|
||||
// - object is created in the current transaction
|
||||
// - object was previously existent and is being deployed in current transaction
|
||||
destructible bool
|
||||
// self-destruct by EIP-6780. Potential scenarios as follows:
|
||||
// - object is created within the same transaction
|
||||
// - object was previously existent and is being deployed within same transaction
|
||||
eip6780Deletable bool
|
||||
}
|
||||
|
||||
// empty returns whether the account is considered empty.
|
||||
|
|
@ -80,6 +80,7 @@ func (s *stateObject) empty() bool {
|
|||
|
||||
// newObject creates a state object.
|
||||
func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *stateObject {
|
||||
origin := acct
|
||||
if acct == nil {
|
||||
acct = types.NewEmptyStateAccount()
|
||||
}
|
||||
|
|
@ -87,7 +88,7 @@ func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *s
|
|||
db: db,
|
||||
address: address,
|
||||
addrHash: crypto.Keccak256Hash(address[:]),
|
||||
origin: acct,
|
||||
origin: origin,
|
||||
data: *acct,
|
||||
originStorage: make(Storage),
|
||||
pendingStorage: make(Storage),
|
||||
|
|
@ -244,7 +245,7 @@ func (s *stateObject) finalise(prefetch bool) {
|
|||
if len(s.dirtyStorage) > 0 {
|
||||
s.dirtyStorage = make(Storage)
|
||||
}
|
||||
s.destructible = false // unset the flag at the end of transaction
|
||||
s.eip6780Deletable = false // unset the flag at the end of transaction
|
||||
}
|
||||
|
||||
// updateTrie is responsible for persisting cached storage changes into the
|
||||
|
|
@ -449,7 +450,7 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
|
|||
obj.dirtyStorage = s.dirtyStorage.Copy()
|
||||
obj.dirtyCode = s.dirtyCode
|
||||
obj.selfDestructed = s.selfDestructed
|
||||
obj.destructible = s.destructible
|
||||
obj.eip6780Deletable = s.eip6780Deletable
|
||||
return obj
|
||||
}
|
||||
|
||||
|
|
@ -529,14 +530,14 @@ func (s *stateObject) setNonce(nonce uint64) {
|
|||
s.data.Nonce = nonce
|
||||
}
|
||||
|
||||
func (s *stateObject) SetDestructible() {
|
||||
if s.destructible {
|
||||
func (s *stateObject) SetEIP6780Deletable() {
|
||||
if s.eip6780Deletable {
|
||||
return // might be possible in fuzzing
|
||||
}
|
||||
s.db.journal.append(destructibleChange{
|
||||
s.db.journal.append(eip6780DeletableChange{
|
||||
account: s.address,
|
||||
})
|
||||
s.destructible = true
|
||||
s.eip6780Deletable = true
|
||||
}
|
||||
|
||||
func (s *stateObject) CodeHash() []byte {
|
||||
|
|
|
|||
|
|
@ -497,7 +497,7 @@ func (s *StateDB) Selfdestruct6780(addr common.Address) {
|
|||
if stateObject == nil {
|
||||
return
|
||||
}
|
||||
if stateObject.destructible {
|
||||
if stateObject.eip6780Deletable {
|
||||
s.SelfDestruct(addr)
|
||||
}
|
||||
}
|
||||
|
|
@ -660,16 +660,17 @@ func (s *StateDB) createObject(addr common.Address) *stateObject {
|
|||
// consensus bug eventually.
|
||||
func (s *StateDB) CreateAccount(addr common.Address) {
|
||||
obj := s.createObject(addr)
|
||||
obj.SetDestructible()
|
||||
obj.SetEIP6780Deletable()
|
||||
}
|
||||
|
||||
// SetDestructible marks the object with specific address as destructible.
|
||||
func (s *StateDB) SetDestructible(addr common.Address) {
|
||||
// SetEIP6780Deletable marks the object with specific address as deletable
|
||||
// by EIP6780.
|
||||
func (s *StateDB) SetEIP6780Deletable(addr common.Address) {
|
||||
obj := s.getStateObject(addr)
|
||||
if obj == nil {
|
||||
return // might be possible in fuzzing
|
||||
}
|
||||
obj.SetDestructible()
|
||||
obj.SetEIP6780Deletable()
|
||||
}
|
||||
|
||||
// Copy creates a deep, independent copy of the state.
|
||||
|
|
|
|||
|
|
@ -398,9 +398,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "SetDestructible",
|
||||
name: "SetEIP6780Deletable",
|
||||
fn: func(a testAction, s *StateDB) {
|
||||
s.SetDestructible(addr)
|
||||
s.SetEIP6780Deletable(addr)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -904,7 +904,7 @@ func TestSelfDestructAccountAfterDeploy(t *testing.T) {
|
|||
|
||||
// Revert the group of self-destruct operations. None of them should be applied.
|
||||
id := state.Snapshot()
|
||||
state.SetDestructible(addr)
|
||||
state.SetEIP6780Deletable(addr)
|
||||
state.SetCode(addr, []byte{0x1})
|
||||
state.Selfdestruct6780(addr)
|
||||
state.RevertToSnapshot(id)
|
||||
|
|
@ -918,7 +918,7 @@ func TestSelfDestructAccountAfterDeploy(t *testing.T) {
|
|||
}
|
||||
|
||||
// Self-destruct the account with destructible flag setting
|
||||
state.SetDestructible(addr)
|
||||
state.SetEIP6780Deletable(addr)
|
||||
state.SetCode(addr, []byte{0x1})
|
||||
state.Selfdestruct6780(addr)
|
||||
|
||||
|
|
|
|||
|
|
@ -463,9 +463,9 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
|
|||
evm.StateDB.CreateAccount(address)
|
||||
} else {
|
||||
// The account with the designated address previously existed but is
|
||||
// still eligible for deployment. Explicitly set it as destructible
|
||||
// to adhere to EIP-6780.
|
||||
evm.StateDB.SetDestructible(address)
|
||||
// still eligible for deployment. Explicitly set it as deletable to
|
||||
// adhere to EIP-6780.
|
||||
evm.StateDB.SetEIP6780Deletable(address)
|
||||
}
|
||||
if evm.chainRules.IsEIP158 {
|
||||
evm.StateDB.SetNonce(address, 1)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ type StateDB interface {
|
|||
|
||||
SelfDestruct(common.Address)
|
||||
HasSelfDestructed(common.Address) bool
|
||||
SetDestructible(addr common.Address)
|
||||
SetEIP6780Deletable(addr common.Address)
|
||||
|
||||
Selfdestruct6780(common.Address)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue