Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AA Work #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Contract struct {
CodeAddr *common.Address
Input []byte

Indestructible bool

Gas uint64
value *big.Int
}
Expand Down
28 changes: 25 additions & 3 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var activators = map[int]func(*JumpTable){
1884: enable1884,
1344: enable1344,
2315: enable2315,
2937: enable2937,
}

// EnableEIP enables the given EIP on the config.
Expand All @@ -44,10 +45,13 @@ func EnableEIP(eipNum int, jt *JumpTable) error {
return nil
}

// ValidEip checks if an eip is in the activators table
func ValidEip(eipNum int) bool {
_, ok := activators[eipNum]
return ok
}

// ActivateableEips returns the available activatble eips
func ActivateableEips() []string {
var nums []string
for k := range activators {
Expand Down Expand Up @@ -83,8 +87,20 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx
return nil, nil
}

// enable2937 applies EIP-2937 (SET_INDESRUCTIBLE Opcode)
// - Adds an opcode that prevents contract from calling SELFDESTRUCT (0xFF)
func enable2937(jt *JumpTable) {
// New opcode
jt[SETINDESTRUCTIBLE] = &operation{
execute: opSetIndestructible,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}
}

// enable1344 applies EIP-1344 (ChainID Opcode)
// - Adds an opcode that returns the current chains EIP-155 unique identifier
// - Adds an opcode that returns the current chain's EIP-155 unique identifier
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, the geth team prefers PRs which modify only code which pertain to the work at hand. I recommend reverting this change and apply in a separate PR upstream.

func enable1344(jt *JumpTable) {
// New opcode
jt[CHAINID] = &operation{
Expand All @@ -95,10 +111,16 @@ func enable1344(jt *JumpTable) {
}
}

// opSetIndestructible implements forbidding a contract from calling SELFDESTRUCT
func opSetIndestructible(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
callContext.contract.Indestructible = true
return nil, nil
}

// opChainID implements CHAINID opcode
func opChainID(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
chainId, _ := uint256.FromBig(interpreter.evm.chainConfig.ChainID)
callContext.stack.push(chainId)
chainID, _ := uint256.FromBig(interpreter.evm.chainConfig.ChainID)
callContext.stack.push(chainID)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I recommend reverting this and instead apply the change upstream.

return nil, nil
}

Expand Down
1 change: 1 addition & 0 deletions core/vm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
ErrGasUintOverflow = errors.New("gas uint64 overflow")
ErrInvalidRetsub = errors.New("invalid retsub")
ErrReturnStackExceeded = errors.New("return stack limit reached")
ErrContractIndestructible = errors.New("contract is indestructible")
)

// ErrStackUnderflow wraps an evm error when the items on the stack less
Expand Down
15 changes: 9 additions & 6 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,14 @@ func opStop(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]by
}

func opSuicide(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
beneficiary := callContext.stack.pop()
balance := interpreter.evm.StateDB.GetBalance(callContext.contract.Address())
interpreter.evm.StateDB.AddBalance(common.Address(beneficiary.Bytes20()), balance)
interpreter.evm.StateDB.Suicide(callContext.contract.Address())
return nil, nil
if !callContext.contract.Indestructible {
beneficiary := callContext.stack.pop()
balance := interpreter.evm.StateDB.GetBalance(callContext.contract.Address())
interpreter.evm.StateDB.AddBalance(common.Address(beneficiary.Bytes20()), balance)
interpreter.evm.StateDB.Suicide(callContext.contract.Address())
return nil, nil
}
return nil, ErrContractIndestructible
}

// following functions are used by the instruction jump table
Expand Down Expand Up @@ -855,7 +858,7 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]b
codeLen = uint64(len(callContext.contract.Code))
integer = new(uint256.Int)
)
*pc += 1
*pc++
if *pc < codeLen {
callContext.stack.push(integer.SetUint64(uint64(callContext.contract.Code[*pc])))
} else {
Expand Down
9 changes: 9 additions & 0 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ var (
constantinopleInstructionSet = newConstantinopleInstructionSet()
istanbulInstructionSet = newIstanbulInstructionSet()
yoloV2InstructionSet = newYoloV2InstructionSet()
bastanchuryInstructionSet = newBastanchuryInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]*operation

// newBastanchuryInstructionSet returns the instruction set containing
// - "EIP-2937: SET_INDESTRUCTIBLE opcode"
func newBastanchuryInstructionSet() JumpTable {
instructionSet := newYoloV2InstructionSet()
enable2937(&instructionSet)
return instructionSet
}

// newYoloV2InstructionSet creates an instructionset containing
// - "EIP-2315: Simple Subroutines"
// - "EIP-2929: Gas cost increases for state access opcodes"
Expand Down
Loading