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