mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-05 20:51:16 +00:00
Merge pull request #837 from gzliudan/eip_6780
core/state, core/vm: implement EIP 6780
This commit is contained in:
commit
d1b72bf8ac
6 changed files with 49 additions and 0 deletions
|
|
@ -93,6 +93,9 @@ type stateObject struct {
|
||||||
// the end of transaction and no longer accessible anymore.
|
// the end of transaction and no longer accessible anymore.
|
||||||
deleted bool
|
deleted bool
|
||||||
|
|
||||||
|
// Flag whether the object was created in the current transaction
|
||||||
|
created bool
|
||||||
|
|
||||||
touched bool
|
touched bool
|
||||||
|
|
||||||
onDirty func(addr common.Address) // Callback method to mark a state object newly dirty
|
onDirty func(addr common.Address) // Callback method to mark a state object newly dirty
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,17 @@ func (s *StateDB) SelfDestruct(addr common.Address) {
|
||||||
stateObject.data.Balance = new(big.Int)
|
stateObject.data.Balance = new(big.Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StateDB) Selfdestruct6780(addr common.Address) {
|
||||||
|
stateObject := s.getStateObject(addr)
|
||||||
|
if stateObject == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if stateObject.created {
|
||||||
|
s.SelfDestruct(addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetTransientState sets transient storage for a given account. It
|
// SetTransientState sets transient storage for a given account. It
|
||||||
// adds the change to the journal so that it can be rolled back
|
// adds the change to the journal so that it can be rolled back
|
||||||
// to its previous value if there is a revert.
|
// to its previous value if there is a revert.
|
||||||
|
|
@ -547,6 +558,9 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
|
||||||
} else {
|
} else {
|
||||||
s.journal = append(s.journal, resetObjectChange{prev: prev})
|
s.journal = append(s.journal, resetObjectChange{prev: prev})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newobj.created = true
|
||||||
|
|
||||||
s.setStateObject(newobj)
|
s.setStateObject(newobj)
|
||||||
return newobj, prev
|
return newobj, prev
|
||||||
}
|
}
|
||||||
|
|
@ -683,6 +697,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
stateObject.updateRoot(s.db)
|
stateObject.updateRoot(s.db)
|
||||||
s.updateStateObject(stateObject)
|
s.updateStateObject(stateObject)
|
||||||
}
|
}
|
||||||
|
stateObject.created = false
|
||||||
}
|
}
|
||||||
// Invalidate journal because reverting across transactions is not allowed.
|
// Invalidate journal because reverting across transactions is not allowed.
|
||||||
s.clearJournalAndRefund()
|
s.clearJournalAndRefund()
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
|
|
||||||
var activators = map[int]func(*JumpTable){
|
var activators = map[int]func(*JumpTable){
|
||||||
5656: enable5656,
|
5656: enable5656,
|
||||||
|
6780: enable6780,
|
||||||
3855: enable3855,
|
3855: enable3855,
|
||||||
3860: enable3860,
|
3860: enable3860,
|
||||||
3529: enable3529,
|
3529: enable3529,
|
||||||
|
|
@ -254,3 +255,14 @@ func opMcopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
|
||||||
scope.Memory.Copy(dst.Uint64(), src.Uint64(), length.Uint64())
|
scope.Memory.Copy(dst.Uint64(), src.Uint64(), length.Uint64())
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enable6780 applies EIP-6780 (deactivate SELFDESTRUCT)
|
||||||
|
func enable6780(jt *JumpTable) {
|
||||||
|
jt[SELFDESTRUCT] = &operation{
|
||||||
|
execute: opSelfdestruct6780,
|
||||||
|
dynamicGas: gasSelfdestructEIP3529,
|
||||||
|
constantGas: params.SelfdestructGasEIP150,
|
||||||
|
minStack: minStack(1, 0),
|
||||||
|
maxStack: maxStack(1, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -843,6 +843,22 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
|
||||||
return nil, errStopToken
|
return nil, errStopToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
|
if interpreter.readOnly {
|
||||||
|
return nil, ErrWriteProtection
|
||||||
|
}
|
||||||
|
beneficiary := scope.Stack.pop()
|
||||||
|
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
|
||||||
|
interpreter.evm.StateDB.SubBalance(scope.Contract.Address(), balance)
|
||||||
|
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
|
||||||
|
interpreter.evm.StateDB.Selfdestruct6780(scope.Contract.Address())
|
||||||
|
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
|
||||||
|
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
|
||||||
|
tracer.CaptureExit([]byte{}, 0, nil)
|
||||||
|
}
|
||||||
|
return nil, errStopToken
|
||||||
|
}
|
||||||
|
|
||||||
// following functions are used by the instruction jump table
|
// following functions are used by the instruction jump table
|
||||||
|
|
||||||
// make log instruction function
|
// make log instruction function
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ type StateDB interface {
|
||||||
SelfDestruct(common.Address)
|
SelfDestruct(common.Address)
|
||||||
HasSelfDestructed(common.Address) bool
|
HasSelfDestructed(common.Address) bool
|
||||||
|
|
||||||
|
Selfdestruct6780(common.Address)
|
||||||
|
|
||||||
// Exist reports whether the given account exists in state.
|
// Exist reports whether the given account exists in state.
|
||||||
// Notably this should also return true for self-destructed accounts.
|
// Notably this should also return true for self-destructed accounts.
|
||||||
Exist(common.Address) bool
|
Exist(common.Address) bool
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ func newCancunInstructionSet() JumpTable {
|
||||||
instructionSet := newEip1559InstructionSet()
|
instructionSet := newEip1559InstructionSet()
|
||||||
enable1153(&instructionSet) // EIP-1153 "Transient Storage"
|
enable1153(&instructionSet) // EIP-1153 "Transient Storage"
|
||||||
enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)
|
enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)
|
||||||
|
enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction
|
||||||
return validate(instructionSet)
|
return validate(instructionSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue