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

core/evm: Set Indestructible Opcode (AA Work) #6

Next Next commit
Set Indestructable
Added an indestructable property to a contract instance
  • Loading branch information
technicallyty committed Nov 22, 2020
commit a944cee9a5d33e6698adbb4a88a8b65683158a12
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

Indestructable bool

Gas uint64
value *big.Int
}
Expand Down
24 changes: 21 additions & 3 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,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
func enable1344(jt *JumpTable) {
// New opcode
jt[CHAINID] = &operation{
Expand All @@ -95,10 +107,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.Indestructable = 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)
return nil, nil
}

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 := newIstanbulInstructionSet()
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