Skip to content

Commit c9a56db

Browse files
axicjagdeep sidhu
authored andcommitted
core/vm: implement EIP-3855: PUSH0 instruction (ethereum#24039)
* core/vm: Implement PUSH0 * Move PUSH0 to enable3855 * Add method doc
1 parent 41782ee commit c9a56db

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

core/vm/eips.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
)
2626

2727
var activators = map[int]func(*JumpTable){
28+
3855: enable3855,
2829
3529: enable3529,
2930
3198: enable3198,
3031
2929: enable2929,
@@ -174,3 +175,20 @@ func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
174175
scope.Stack.push(baseFee)
175176
return nil, nil
176177
}
178+
179+
// enable3855 applies EIP-3855 (PUSH0 opcode)
180+
func enable3855(jt *JumpTable) {
181+
// New opcode
182+
jt[PUSH0] = &operation{
183+
execute: opPush0,
184+
constantGas: GasQuickStep,
185+
minStack: minStack(0, 1),
186+
maxStack: maxStack(0, 1),
187+
}
188+
}
189+
190+
// opPush0 implements the PUSH0 opcode
191+
func opPush0(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
192+
scope.Stack.push(new(uint256.Int))
193+
return nil, nil
194+
}

core/vm/opcodes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const (
118118
MSIZE OpCode = 0x59
119119
GAS OpCode = 0x5a
120120
JUMPDEST OpCode = 0x5b
121+
PUSH0 OpCode = 0x5f
121122
)
122123

123124
// 0x60 range - pushes.
@@ -301,6 +302,7 @@ var opCodeToString = map[OpCode]string{
301302
MSIZE: "MSIZE",
302303
GAS: "GAS",
303304
JUMPDEST: "JUMPDEST",
305+
PUSH0: "PUSH0",
304306

305307
// 0x60 range - push.
306308
PUSH1: "PUSH1",
@@ -466,6 +468,7 @@ var stringToOp = map[string]OpCode{
466468
"MSIZE": MSIZE,
467469
"GAS": GAS,
468470
"JUMPDEST": JUMPDEST,
471+
"PUSH0": PUSH0,
469472
"PUSH1": PUSH1,
470473
"PUSH2": PUSH2,
471474
"PUSH3": PUSH3,

0 commit comments

Comments
 (0)