Skip to content

Commit 658cb9f

Browse files
authored
Merge pull request #22414 from karalabe/unship-2315
core, eth: unship EIP 2315
2 parents dab90e4 + 430f69e commit 658cb9f

15 files changed

+50
-428
lines changed

core/vm/contract.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ func (c *Contract) validJumpdest(dest *uint256.Int) bool {
9696
return c.isCode(udest)
9797
}
9898

99-
func (c *Contract) validJumpSubdest(udest uint64) bool {
100-
// PC cannot go beyond len(code) and certainly can't be bigger than 63 bits.
101-
// Don't bother checking for BEGINSUB in that case.
102-
if int64(udest) < 0 || udest >= uint64(len(c.Code)) {
103-
return false
104-
}
105-
// Only BEGINSUBs allowed for destinations
106-
if OpCode(c.Code[udest]) != BEGINSUB {
107-
return false
108-
}
109-
return c.isCode(udest)
110-
}
111-
11299
// isCode returns true if the provided PC location is an actual opcode, as
113100
// opposed to a data-segment following a PUSHN operation.
114101
func (c *Contract) isCode(udest uint64) bool {

core/vm/eips.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var activators = map[int]func(*JumpTable){
2929
2200: enable2200,
3030
1884: enable1884,
3131
1344: enable1344,
32-
2315: enable2315,
3332
}
3433

3534
// EnableEIP enables the given EIP on the config.
@@ -108,34 +107,6 @@ func enable2200(jt *JumpTable) {
108107
jt[SSTORE].dynamicGas = gasSStoreEIP2200
109108
}
110109

111-
// enable2315 applies EIP-2315 (Simple Subroutines)
112-
// - Adds opcodes that jump to and return from subroutines
113-
func enable2315(jt *JumpTable) {
114-
// New opcode
115-
jt[BEGINSUB] = &operation{
116-
execute: opBeginSub,
117-
constantGas: GasQuickStep,
118-
minStack: minStack(0, 0),
119-
maxStack: maxStack(0, 0),
120-
}
121-
// New opcode
122-
jt[JUMPSUB] = &operation{
123-
execute: opJumpSub,
124-
constantGas: GasSlowStep,
125-
minStack: minStack(1, 0),
126-
maxStack: maxStack(1, 0),
127-
jumps: true,
128-
}
129-
// New opcode
130-
jt[RETURNSUB] = &operation{
131-
execute: opReturnSub,
132-
constantGas: GasFastStep,
133-
minStack: minStack(0, 0),
134-
maxStack: maxStack(0, 0),
135-
jumps: true,
136-
}
137-
}
138-
139110
// enable2929 enables "EIP-2929: Gas cost increases for state access opcodes"
140111
// https://eips.ethereum.org/EIPS/eip-2929
141112
func enable2929(jt *JumpTable) {

core/vm/gen_structlog.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/vm/instructions.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -547,38 +547,6 @@ func opJumpdest(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) (
547547
return nil, nil
548548
}
549549

550-
func opBeginSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
551-
return nil, ErrInvalidSubroutineEntry
552-
}
553-
554-
func opJumpSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
555-
if len(callContext.rstack.data) >= 1023 {
556-
return nil, ErrReturnStackExceeded
557-
}
558-
pos := callContext.stack.pop()
559-
if !pos.IsUint64() {
560-
return nil, ErrInvalidJump
561-
}
562-
posU64 := pos.Uint64()
563-
if !callContext.contract.validJumpSubdest(posU64) {
564-
return nil, ErrInvalidJump
565-
}
566-
callContext.rstack.push(uint32(*pc))
567-
*pc = posU64 + 1
568-
return nil, nil
569-
}
570-
571-
func opReturnSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
572-
if len(callContext.rstack.data) == 0 {
573-
return nil, ErrInvalidRetsub
574-
}
575-
// Other than the check that the return stack is not empty, there is no
576-
// need to validate the pc from 'returns', since we only ever push valid
577-
//values onto it via jumpsub.
578-
*pc = uint64(callContext.rstack.pop()) + 1
579-
return nil, nil
580-
}
581-
582550
func opPc(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
583551
callContext.stack.push(new(uint256.Int).SetUint64(*pc))
584552
return nil, nil

core/vm/instructions_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu
9494
var (
9595
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
9696
stack = newstack()
97-
rstack = newReturnStack()
9897
pc = uint64(0)
9998
evmInterpreter = env.interpreter.(*EVMInterpreter)
10099
)
@@ -105,7 +104,7 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu
105104
expected := new(uint256.Int).SetBytes(common.Hex2Bytes(test.Expected))
106105
stack.push(x)
107106
stack.push(y)
108-
opFn(&pc, evmInterpreter, &callCtx{nil, stack, rstack, nil})
107+
opFn(&pc, evmInterpreter, &callCtx{nil, stack, nil})
109108
if len(stack.data) != 1 {
110109
t.Errorf("Expected one item on stack after %v, got %d: ", name, len(stack.data))
111110
}
@@ -220,7 +219,7 @@ func TestAddMod(t *testing.T) {
220219
stack.push(z)
221220
stack.push(y)
222221
stack.push(x)
223-
opAddmod(&pc, evmInterpreter, &callCtx{nil, stack, nil, nil})
222+
opAddmod(&pc, evmInterpreter, &callCtx{nil, stack, nil})
224223
actual := stack.pop()
225224
if actual.Cmp(expected) != 0 {
226225
t.Errorf("Testcase %d, expected %x, got %x", i, expected, actual)
@@ -231,18 +230,18 @@ func TestAddMod(t *testing.T) {
231230
// getResult is a convenience function to generate the expected values
232231
func getResult(args []*twoOperandParams, opFn executionFunc) []TwoOperandTestcase {
233232
var (
234-
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
235-
stack, rstack = newstack(), newReturnStack()
236-
pc = uint64(0)
237-
interpreter = env.interpreter.(*EVMInterpreter)
233+
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
234+
stack = newstack()
235+
pc = uint64(0)
236+
interpreter = env.interpreter.(*EVMInterpreter)
238237
)
239238
result := make([]TwoOperandTestcase, len(args))
240239
for i, param := range args {
241240
x := new(uint256.Int).SetBytes(common.Hex2Bytes(param.x))
242241
y := new(uint256.Int).SetBytes(common.Hex2Bytes(param.y))
243242
stack.push(x)
244243
stack.push(y)
245-
opFn(&pc, interpreter, &callCtx{nil, stack, rstack, nil})
244+
opFn(&pc, interpreter, &callCtx{nil, stack, nil})
246245
actual := stack.pop()
247246
result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)}
248247
}
@@ -282,7 +281,7 @@ func TestJsonTestcases(t *testing.T) {
282281
func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
283282
var (
284283
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
285-
stack, rstack = newstack(), newReturnStack()
284+
stack = newstack()
286285
evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
287286
)
288287

@@ -300,7 +299,7 @@ func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
300299
a.SetBytes(arg)
301300
stack.push(a)
302301
}
303-
op(&pc, evmInterpreter, &callCtx{nil, stack, rstack, nil})
302+
op(&pc, evmInterpreter, &callCtx{nil, stack, nil})
304303
stack.pop()
305304
}
306305
}
@@ -516,7 +515,7 @@ func BenchmarkOpIsZero(b *testing.B) {
516515
func TestOpMstore(t *testing.T) {
517516
var (
518517
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
519-
stack, rstack = newstack(), newReturnStack()
518+
stack = newstack()
520519
mem = NewMemory()
521520
evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
522521
)
@@ -526,12 +525,12 @@ func TestOpMstore(t *testing.T) {
526525
pc := uint64(0)
527526
v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700"
528527
stack.pushN(*new(uint256.Int).SetBytes(common.Hex2Bytes(v)), *new(uint256.Int))
529-
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, rstack, nil})
528+
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil})
530529
if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v {
531530
t.Fatalf("Mstore fail, got %v, expected %v", got, v)
532531
}
533532
stack.pushN(*new(uint256.Int).SetUint64(0x1), *new(uint256.Int))
534-
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, rstack, nil})
533+
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil})
535534
if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" {
536535
t.Fatalf("Mstore failed to overwrite previous value")
537536
}
@@ -540,7 +539,7 @@ func TestOpMstore(t *testing.T) {
540539
func BenchmarkOpMstore(bench *testing.B) {
541540
var (
542541
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
543-
stack, rstack = newstack(), newReturnStack()
542+
stack = newstack()
544543
mem = NewMemory()
545544
evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
546545
)
@@ -554,14 +553,14 @@ func BenchmarkOpMstore(bench *testing.B) {
554553
bench.ResetTimer()
555554
for i := 0; i < bench.N; i++ {
556555
stack.pushN(*value, *memStart)
557-
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, rstack, nil})
556+
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil})
558557
}
559558
}
560559

561560
func BenchmarkOpSHA3(bench *testing.B) {
562561
var (
563562
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
564-
stack, rstack = newstack(), newReturnStack()
563+
stack = newstack()
565564
mem = NewMemory()
566565
evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
567566
)
@@ -573,7 +572,7 @@ func BenchmarkOpSHA3(bench *testing.B) {
573572
bench.ResetTimer()
574573
for i := 0; i < bench.N; i++ {
575574
stack.pushN(*uint256.NewInt().SetUint64(32), *start)
576-
opSha3(&pc, evmInterpreter, &callCtx{mem, stack, rstack, nil})
575+
opSha3(&pc, evmInterpreter, &callCtx{mem, stack, nil})
577576
}
578577
}
579578

core/vm/interpreter.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ type Interpreter interface {
6767
type callCtx struct {
6868
memory *Memory
6969
stack *Stack
70-
rstack *ReturnStack
7170
contract *Contract
7271
}
7372

@@ -161,14 +160,12 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
161160
}
162161

163162
var (
164-
op OpCode // current opcode
165-
mem = NewMemory() // bound memory
166-
stack = newstack() // local stack
167-
returns = newReturnStack() // local returns stack
163+
op OpCode // current opcode
164+
mem = NewMemory() // bound memory
165+
stack = newstack() // local stack
168166
callContext = &callCtx{
169167
memory: mem,
170168
stack: stack,
171-
rstack: returns,
172169
contract: contract,
173170
}
174171
// For optimisation reason we're using uint64 as the program counter.
@@ -187,17 +184,16 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
187184
// they are returned to the pools
188185
defer func() {
189186
returnStack(stack)
190-
returnRStack(returns)
191187
}()
192188
contract.Input = input
193189

194190
if in.cfg.Debug {
195191
defer func() {
196192
if err != nil {
197193
if !logged {
198-
in.cfg.Tracer.CaptureState(in.evm, pcCopy, op, gasCopy, cost, mem, stack, returns, in.returnData, contract, in.evm.depth, err)
194+
in.cfg.Tracer.CaptureState(in.evm, pcCopy, op, gasCopy, cost, mem, stack, in.returnData, contract, in.evm.depth, err)
199195
} else {
200-
in.cfg.Tracer.CaptureFault(in.evm, pcCopy, op, gasCopy, cost, mem, stack, returns, contract, in.evm.depth, err)
196+
in.cfg.Tracer.CaptureFault(in.evm, pcCopy, op, gasCopy, cost, mem, stack, contract, in.evm.depth, err)
201197
}
202198
}
203199
}()
@@ -279,7 +275,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
279275
}
280276

281277
if in.cfg.Debug {
282-
in.cfg.Tracer.CaptureState(in.evm, pc, op, gasCopy, cost, mem, stack, returns, in.returnData, contract, in.evm.depth, err)
278+
in.cfg.Tracer.CaptureState(in.evm, pc, op, gasCopy, cost, mem, stack, in.returnData, contract, in.evm.depth, err)
283279
logged = true
284280
}
285281

core/vm/jump_table.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ type JumpTable [256]*operation
6666
// contantinople, istanbul, petersburg and berlin instructions.
6767
func newBerlinInstructionSet() JumpTable {
6868
instructionSet := newIstanbulInstructionSet()
69-
enable2315(&instructionSet) // Subroutines - https://eips.ethereum.org/EIPS/eip-2315
7069
enable2929(&instructionSet) // Access lists for trie accesses https://eips.ethereum.org/EIPS/eip-2929
7170
return instructionSet
7271
}

0 commit comments

Comments
 (0)