diff --git a/core/vm/eips.go b/core/vm/eips.go index d7ed18648e..3252c1adc4 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -41,6 +41,7 @@ var activators = map[int]func(*JumpTable){ 1153: enable1153, 4762: enable4762, 7702: enable7702, + 7904: enable7904, 7939: enable7939, } @@ -556,3 +557,80 @@ func enable7702(jt *JumpTable) { jt[STATICCALL].dynamicGas = gasStaticCallEIP7702 jt[DELEGATECALL].dynamicGas = gasDelegateCallEIP7702 } + +// enable7904 enables the EIP-7907 gas cost changes. +func enable7904(jt *JumpTable) { + jt[ADD].constantGas = GasBaseCost + jt[MUL].constantGas = GasBaseCost + jt[SUB].constantGas = GasBaseCost + jt[DIV].constantGas = GasBaseCost + jt[SDIV].constantGas = GasBaseCost + jt[MOD].constantGas = GasBaseCost + jt[SMOD].constantGas = GasBaseCost + jt[ADDMOD].constantGas = GasFastCost + jt[MULMOD].constantGas = GasMidCost + //jt[EXP].constantGas = GasMidCost + jt[SIGNEXTEND].constantGas = GasBaseCost + jt[LT].constantGas = GasBaseCost + jt[GT].constantGas = GasBaseCost + jt[SLT].constantGas = GasBaseCost + jt[SGT].constantGas = GasBaseCost + jt[EQ].constantGas = GasBaseCost + jt[ISZERO].constantGas = GasBaseCost + jt[AND].constantGas = GasBaseCost + jt[OR].constantGas = GasBaseCost + jt[XOR].constantGas = GasBaseCost + jt[NOT].constantGas = GasBaseCost + jt[BYTE].constantGas = GasBaseCost + jt[SHL].constantGas = GasBaseCost + jt[SHR].constantGas = GasBaseCost + jt[SAR].constantGas = GasBaseCost + jt[ADDRESS].constantGas = GasBaseCost + //jt[BALANCE].constantGas = GasBaseCost + + jt[ORIGIN].constantGas = GasBaseCost + jt[CALLER].constantGas = GasBaseCost + jt[CALLVALUE].constantGas = GasBaseCost + jt[CALLDATALOAD].constantGas = GasBaseCost + jt[CALLDATASIZE].constantGas = GasBaseCost + //jt[CALLDATACOPY].constantGas = GasBaseCost + jt[CODESIZE].constantGas = GasBaseCost + //jt[CODECOPY].constantGas = GasBaseCost + jt[GASPRICE].constantGas = GasBaseCost + //jt[EXTCODESIZE].constantGas = GasBaseCost + //jt[EXTCODECOPY].constantGas = GasBaseCost + jt[RETURNDATASIZE].constantGas = GasBaseCost + //jt[RETURNDATACOPY].constantGas = GasBaseCost + //jt[EXTCODEHASH].constantGas = GasBaseCost + jt[COINBASE].constantGas = GasBaseCost + jt[TIMESTAMP].constantGas = GasBaseCost + jt[NUMBER].constantGas = GasBaseCost + jt[GASLIMIT].constantGas = GasBaseCost + jt[CHAINID].constantGas = GasBaseCost + jt[SELFBALANCE].constantGas = GasBaseCost + jt[POP].constantGas = GasBaseCost + jt[MLOAD].constantGas = GasBaseCost + //jt[MSTORE].constantGas = GasBaseCost + //jt[MSTORE8].constantGas = GasBaseCost + jt[JUMP].constantGas = GasBaseCost + jt[JUMPI].constantGas = GasBaseCost + jt[PC].constantGas = GasBaseCost + jt[MSIZE].constantGas = GasBaseCost + jt[TLOAD].constantGas = GasWarmStorageCost + jt[TSTORE].constantGas = GasWarmStorageCost + jt[JUMPDEST].constantGas = GasBaseCost + //jt[MCOPY].constantGas = GasBaseCost + jt[PUSH0].constantGas = GasBaseCost + for i := PUSH1; i < PUSH32; i++ { + jt[i].constantGas = GasBaseCost + } + for i := PUSH1; i < PUSH32; i++ { + jt[i].constantGas = GasBaseCost + } + for i := DUP1; i < DUP16; i++ { + jt[i].constantGas = GasBaseCost + } + for i := SWAP1; i < SWAP16; i++ { + jt[i].constantGas = GasBaseCost + } +} diff --git a/core/vm/evm.go b/core/vm/evm.go index 88ef1cf121..a72f51e3dc 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -149,6 +149,8 @@ func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainCon evm.precompiles = activePrecompiledContracts(evm.chainRules) switch { + case evm.chainRules.IsAmsterdam: + evm.table = &amsterdamInstructionSet case evm.chainRules.IsOsaka: evm.table = &osakaInstructionSet case evm.chainRules.IsVerkle: diff --git a/core/vm/gas.go b/core/vm/gas.go index 5fe589bce6..8033005987 100644 --- a/core/vm/gas.go +++ b/core/vm/gas.go @@ -22,13 +22,17 @@ import ( // Gas costs const ( - GasQuickStep uint64 = 2 - GasFastestStep uint64 = 3 - GasFastishStep uint64 = 4 - GasFastStep uint64 = 5 - GasMidStep uint64 = 8 - GasSlowStep uint64 = 10 - GasExtStep uint64 = 20 + GasQuickStep uint64 = 2 + GasFastestStep uint64 = 3 + GasFastishStep uint64 = 4 + GasFastStep uint64 = 5 + GasMidStep uint64 = 8 + GasSlowStep uint64 = 10 + GasExtStep uint64 = 20 + GasBaseCost uint64 = 1 + GasFastCost uint64 = 2 + GasMidCost uint64 = 3 + GasWarmStorageCost uint64 = 5 ) // callGas returns the actual gas cost of the call. diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index d7a4d9da1d..fd85477c9c 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -63,6 +63,7 @@ var ( verkleInstructionSet = newVerkleInstructionSet() pragueInstructionSet = newPragueInstructionSet() osakaInstructionSet = newOsakaInstructionSet() + amsterdamInstructionSet = newAmsterdamInstructionSet() ) // JumpTable contains the EVM opcodes supported at a given fork. @@ -92,6 +93,12 @@ func newVerkleInstructionSet() JumpTable { return validate(instructionSet) } +func newAmsterdamInstructionSet() JumpTable { + instructionSet := newOsakaInstructionSet() + enable7904(&instructionSet) // EIP-7904 (gas repricings) + return validate(instructionSet) +} + func newOsakaInstructionSet() JumpTable { instructionSet := newPragueInstructionSet() enable7939(&instructionSet) // EIP-7939 (CLZ opcode)