Skip to content

Commit 7949a92

Browse files
core/vm: implement 7904 repricings for basic opcodes
1 parent 5143a43 commit 7949a92

File tree

4 files changed

+98
-7
lines changed

4 files changed

+98
-7
lines changed

core/vm/eips.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var activators = map[int]func(*JumpTable){
4141
1153: enable1153,
4242
4762: enable4762,
4343
7702: enable7702,
44+
7904: enable7904,
4445
7939: enable7939,
4546
}
4647

@@ -556,3 +557,80 @@ func enable7702(jt *JumpTable) {
556557
jt[STATICCALL].dynamicGas = gasStaticCallEIP7702
557558
jt[DELEGATECALL].dynamicGas = gasDelegateCallEIP7702
558559
}
560+
561+
// enable7904 enables the EIP-7907 gas cost changes.
562+
func enable7904(jt *JumpTable) {
563+
jt[ADD].constantGas = GasBaseCost
564+
jt[MUL].constantGas = GasBaseCost
565+
jt[SUB].constantGas = GasBaseCost
566+
jt[DIV].constantGas = GasBaseCost
567+
jt[SDIV].constantGas = GasBaseCost
568+
jt[MOD].constantGas = GasBaseCost
569+
jt[SMOD].constantGas = GasBaseCost
570+
jt[ADDMOD].constantGas = GasFastCost
571+
jt[MULMOD].constantGas = GasMidCost
572+
//jt[EXP].constantGas = GasMidCost
573+
jt[SIGNEXTEND].constantGas = GasBaseCost
574+
jt[LT].constantGas = GasBaseCost
575+
jt[GT].constantGas = GasBaseCost
576+
jt[SLT].constantGas = GasBaseCost
577+
jt[SGT].constantGas = GasBaseCost
578+
jt[EQ].constantGas = GasBaseCost
579+
jt[ISZERO].constantGas = GasBaseCost
580+
jt[AND].constantGas = GasBaseCost
581+
jt[OR].constantGas = GasBaseCost
582+
jt[XOR].constantGas = GasBaseCost
583+
jt[NOT].constantGas = GasBaseCost
584+
jt[BYTE].constantGas = GasBaseCost
585+
jt[SHL].constantGas = GasBaseCost
586+
jt[SHR].constantGas = GasBaseCost
587+
jt[SAR].constantGas = GasBaseCost
588+
jt[ADDRESS].constantGas = GasBaseCost
589+
//jt[BALANCE].constantGas = GasBaseCost
590+
591+
jt[ORIGIN].constantGas = GasBaseCost
592+
jt[CALLER].constantGas = GasBaseCost
593+
jt[CALLVALUE].constantGas = GasBaseCost
594+
jt[CALLDATALOAD].constantGas = GasBaseCost
595+
jt[CALLDATASIZE].constantGas = GasBaseCost
596+
//jt[CALLDATACOPY].constantGas = GasBaseCost
597+
jt[CODESIZE].constantGas = GasBaseCost
598+
//jt[CODECOPY].constantGas = GasBaseCost
599+
jt[GASPRICE].constantGas = GasBaseCost
600+
//jt[EXTCODESIZE].constantGas = GasBaseCost
601+
//jt[EXTCODECOPY].constantGas = GasBaseCost
602+
jt[RETURNDATASIZE].constantGas = GasBaseCost
603+
//jt[RETURNDATACOPY].constantGas = GasBaseCost
604+
//jt[EXTCODEHASH].constantGas = GasBaseCost
605+
jt[COINBASE].constantGas = GasBaseCost
606+
jt[TIMESTAMP].constantGas = GasBaseCost
607+
jt[NUMBER].constantGas = GasBaseCost
608+
jt[GASLIMIT].constantGas = GasBaseCost
609+
jt[CHAINID].constantGas = GasBaseCost
610+
jt[SELFBALANCE].constantGas = GasBaseCost
611+
jt[POP].constantGas = GasBaseCost
612+
jt[MLOAD].constantGas = GasBaseCost
613+
//jt[MSTORE].constantGas = GasBaseCost
614+
//jt[MSTORE8].constantGas = GasBaseCost
615+
jt[JUMP].constantGas = GasBaseCost
616+
jt[JUMPI].constantGas = GasBaseCost
617+
jt[PC].constantGas = GasBaseCost
618+
jt[MSIZE].constantGas = GasBaseCost
619+
jt[TLOAD].constantGas = GasWarmStorageCost
620+
jt[TSTORE].constantGas = GasWarmStorageCost
621+
jt[JUMPDEST].constantGas = GasBaseCost
622+
//jt[MCOPY].constantGas = GasBaseCost
623+
jt[PUSH0].constantGas = GasBaseCost
624+
for i := PUSH1; i < PUSH32; i++ {
625+
jt[i].constantGas = GasBaseCost
626+
}
627+
for i := PUSH1; i < PUSH32; i++ {
628+
jt[i].constantGas = GasBaseCost
629+
}
630+
for i := DUP1; i < DUP16; i++ {
631+
jt[i].constantGas = GasBaseCost
632+
}
633+
for i := SWAP1; i < SWAP16; i++ {
634+
jt[i].constantGas = GasBaseCost
635+
}
636+
}

core/vm/evm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainCon
149149
evm.precompiles = activePrecompiledContracts(evm.chainRules)
150150

151151
switch {
152+
case evm.chainRules.IsAmsterdam:
153+
evm.table = &amsterdamInstructionSet
152154
case evm.chainRules.IsOsaka:
153155
evm.table = &osakaInstructionSet
154156
case evm.chainRules.IsVerkle:

core/vm/gas.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ import (
2222

2323
// Gas costs
2424
const (
25-
GasQuickStep uint64 = 2
26-
GasFastestStep uint64 = 3
27-
GasFastishStep uint64 = 4
28-
GasFastStep uint64 = 5
29-
GasMidStep uint64 = 8
30-
GasSlowStep uint64 = 10
31-
GasExtStep uint64 = 20
25+
GasQuickStep uint64 = 2
26+
GasFastestStep uint64 = 3
27+
GasFastishStep uint64 = 4
28+
GasFastStep uint64 = 5
29+
GasMidStep uint64 = 8
30+
GasSlowStep uint64 = 10
31+
GasExtStep uint64 = 20
32+
GasBaseCost uint64 = 1
33+
GasFastCost uint64 = 2
34+
GasMidCost uint64 = 3
35+
GasWarmStorageCost uint64 = 5
3236
)
3337

3438
// callGas returns the actual gas cost of the call.

core/vm/jump_table.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var (
6363
verkleInstructionSet = newVerkleInstructionSet()
6464
pragueInstructionSet = newPragueInstructionSet()
6565
osakaInstructionSet = newOsakaInstructionSet()
66+
amsterdamInstructionSet = newAmsterdamInstructionSet()
6667
)
6768

6869
// JumpTable contains the EVM opcodes supported at a given fork.
@@ -92,6 +93,12 @@ func newVerkleInstructionSet() JumpTable {
9293
return validate(instructionSet)
9394
}
9495

96+
func newAmsterdamInstructionSet() JumpTable {
97+
instructionSet := newOsakaInstructionSet()
98+
enable7904(&instructionSet) // EIP-7904 (gas repricings)
99+
return validate(instructionSet)
100+
}
101+
95102
func newOsakaInstructionSet() JumpTable {
96103
instructionSet := newPragueInstructionSet()
97104
enable7939(&instructionSet) // EIP-7939 (CLZ opcode)

0 commit comments

Comments
 (0)