From ad2816f216334c5bb57bc316de96583130acad76 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 3 Mar 2026 12:29:57 -0500 Subject: [PATCH 01/61] refactor(spec-specs): add opcode gas constants --- src/ethereum/forks/amsterdam/vm/gas.py | 40 +++++++++++++++++++ .../amsterdam/vm/instructions/arithmetic.py | 33 +++++++++------ .../amsterdam/vm/instructions/bitwise.py | 31 +++++++++----- .../amsterdam/vm/instructions/comparison.py | 22 ++++++---- .../amsterdam/vm/instructions/control_flow.py | 12 ++++-- .../amsterdam/vm/instructions/environment.py | 22 +++++++--- .../forks/amsterdam/vm/instructions/memory.py | 16 +++++--- .../forks/amsterdam/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 39 ++++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../arrow_glacier/vm/instructions/bitwise.py | 28 ++++++++----- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 22 +++++++--- .../arrow_glacier/vm/instructions/memory.py | 10 +++-- .../arrow_glacier/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/berlin/vm/gas.py | 39 ++++++++++++++++++ .../berlin/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/berlin/vm/instructions/bitwise.py | 28 ++++++++----- .../berlin/vm/instructions/comparison.py | 22 ++++++---- .../berlin/vm/instructions/control_flow.py | 12 ++++-- .../berlin/vm/instructions/environment.py | 22 +++++++--- .../forks/berlin/vm/instructions/memory.py | 10 +++-- .../forks/berlin/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/bpo1/vm/gas.py | 40 +++++++++++++++++++ .../forks/bpo1/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/bpo1/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/bpo1/vm/instructions/comparison.py | 22 ++++++---- .../bpo1/vm/instructions/control_flow.py | 12 ++++-- .../forks/bpo1/vm/instructions/environment.py | 22 +++++++--- .../forks/bpo1/vm/instructions/memory.py | 16 +++++--- .../forks/bpo1/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/bpo2/vm/gas.py | 40 +++++++++++++++++++ .../forks/bpo2/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/bpo2/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/bpo2/vm/instructions/comparison.py | 22 ++++++---- .../bpo2/vm/instructions/control_flow.py | 12 ++++-- .../forks/bpo2/vm/instructions/environment.py | 22 +++++++--- .../forks/bpo2/vm/instructions/memory.py | 16 +++++--- .../forks/bpo2/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/bpo3/vm/gas.py | 40 +++++++++++++++++++ .../forks/bpo3/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/bpo3/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/bpo3/vm/instructions/comparison.py | 22 ++++++---- .../bpo3/vm/instructions/control_flow.py | 12 ++++-- .../forks/bpo3/vm/instructions/environment.py | 22 +++++++--- .../forks/bpo3/vm/instructions/memory.py | 16 +++++--- .../forks/bpo3/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/bpo4/vm/gas.py | 40 +++++++++++++++++++ .../forks/bpo4/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/bpo4/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/bpo4/vm/instructions/comparison.py | 22 ++++++---- .../bpo4/vm/instructions/control_flow.py | 12 ++++-- .../forks/bpo4/vm/instructions/environment.py | 22 +++++++--- .../forks/bpo4/vm/instructions/memory.py | 16 +++++--- .../forks/bpo4/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/bpo5/vm/gas.py | 40 +++++++++++++++++++ .../forks/bpo5/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/bpo5/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/bpo5/vm/instructions/comparison.py | 22 ++++++---- .../bpo5/vm/instructions/control_flow.py | 12 ++++-- .../forks/bpo5/vm/instructions/environment.py | 22 +++++++--- .../forks/bpo5/vm/instructions/memory.py | 16 +++++--- .../forks/bpo5/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/byzantium/vm/gas.py | 36 +++++++++++++++++ .../byzantium/vm/instructions/arithmetic.py | 33 +++++++++------ .../byzantium/vm/instructions/bitwise.py | 19 ++++++--- .../byzantium/vm/instructions/comparison.py | 22 ++++++---- .../byzantium/vm/instructions/control_flow.py | 12 ++++-- .../byzantium/vm/instructions/environment.py | 22 +++++++--- .../forks/byzantium/vm/instructions/memory.py | 10 +++-- .../forks/byzantium/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/cancun/vm/gas.py | 40 +++++++++++++++++++ .../cancun/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/cancun/vm/instructions/bitwise.py | 28 ++++++++----- .../cancun/vm/instructions/comparison.py | 22 ++++++---- .../cancun/vm/instructions/control_flow.py | 12 ++++-- .../cancun/vm/instructions/environment.py | 22 +++++++--- .../forks/cancun/vm/instructions/memory.py | 16 +++++--- .../forks/cancun/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/constantinople/vm/gas.py | 39 ++++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../constantinople/vm/instructions/bitwise.py | 28 ++++++++----- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 22 +++++++--- .../constantinople/vm/instructions/memory.py | 10 +++-- .../constantinople/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/dao_fork/vm/gas.py | 35 ++++++++++++++++ .../dao_fork/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/dao_fork/vm/instructions/bitwise.py | 19 ++++++--- .../dao_fork/vm/instructions/comparison.py | 22 ++++++---- .../dao_fork/vm/instructions/control_flow.py | 12 ++++-- .../dao_fork/vm/instructions/environment.py | 16 ++++++-- .../forks/dao_fork/vm/instructions/memory.py | 10 +++-- .../forks/dao_fork/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/frontier/vm/gas.py | 35 ++++++++++++++++ .../frontier/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/frontier/vm/instructions/bitwise.py | 19 ++++++--- .../frontier/vm/instructions/comparison.py | 22 ++++++---- .../frontier/vm/instructions/control_flow.py | 12 ++++-- .../frontier/vm/instructions/environment.py | 16 ++++++-- .../forks/frontier/vm/instructions/memory.py | 10 +++-- .../forks/frontier/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/gray_glacier/vm/gas.py | 39 ++++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../gray_glacier/vm/instructions/bitwise.py | 28 ++++++++----- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 22 +++++++--- .../gray_glacier/vm/instructions/memory.py | 10 +++-- .../gray_glacier/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/homestead/vm/gas.py | 35 ++++++++++++++++ .../homestead/vm/instructions/arithmetic.py | 33 +++++++++------ .../homestead/vm/instructions/bitwise.py | 19 ++++++--- .../homestead/vm/instructions/comparison.py | 22 ++++++---- .../homestead/vm/instructions/control_flow.py | 12 ++++-- .../homestead/vm/instructions/environment.py | 16 ++++++-- .../forks/homestead/vm/instructions/memory.py | 10 +++-- .../forks/homestead/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/istanbul/vm/gas.py | 39 ++++++++++++++++++ .../istanbul/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/istanbul/vm/instructions/bitwise.py | 28 ++++++++----- .../istanbul/vm/instructions/comparison.py | 22 ++++++---- .../istanbul/vm/instructions/control_flow.py | 12 ++++-- .../istanbul/vm/instructions/environment.py | 22 +++++++--- .../forks/istanbul/vm/instructions/memory.py | 10 +++-- .../forks/istanbul/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/london/vm/gas.py | 39 ++++++++++++++++++ .../london/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/london/vm/instructions/bitwise.py | 28 ++++++++----- .../london/vm/instructions/comparison.py | 22 ++++++---- .../london/vm/instructions/control_flow.py | 12 ++++-- .../london/vm/instructions/environment.py | 22 +++++++--- .../forks/london/vm/instructions/memory.py | 10 +++-- .../forks/london/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/muir_glacier/vm/gas.py | 39 ++++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../muir_glacier/vm/instructions/bitwise.py | 28 ++++++++----- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 22 +++++++--- .../muir_glacier/vm/instructions/memory.py | 10 +++-- .../muir_glacier/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/osaka/vm/gas.py | 40 +++++++++++++++++++ .../forks/osaka/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/osaka/vm/instructions/bitwise.py | 31 +++++++++----- .../forks/osaka/vm/instructions/comparison.py | 22 ++++++---- .../osaka/vm/instructions/control_flow.py | 12 ++++-- .../osaka/vm/instructions/environment.py | 22 +++++++--- .../forks/osaka/vm/instructions/memory.py | 16 +++++--- .../forks/osaka/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/paris/vm/gas.py | 39 ++++++++++++++++++ .../forks/paris/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/paris/vm/instructions/bitwise.py | 28 ++++++++----- .../forks/paris/vm/instructions/comparison.py | 22 ++++++---- .../paris/vm/instructions/control_flow.py | 12 ++++-- .../paris/vm/instructions/environment.py | 22 +++++++--- .../forks/paris/vm/instructions/memory.py | 10 +++-- .../forks/paris/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/prague/vm/gas.py | 40 +++++++++++++++++++ .../prague/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/prague/vm/instructions/bitwise.py | 28 ++++++++----- .../prague/vm/instructions/comparison.py | 22 ++++++---- .../prague/vm/instructions/control_flow.py | 12 ++++-- .../prague/vm/instructions/environment.py | 22 +++++++--- .../forks/prague/vm/instructions/memory.py | 16 +++++--- .../forks/prague/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/shanghai/vm/gas.py | 39 ++++++++++++++++++ .../shanghai/vm/instructions/arithmetic.py | 33 +++++++++------ .../forks/shanghai/vm/instructions/bitwise.py | 28 ++++++++----- .../shanghai/vm/instructions/comparison.py | 22 ++++++---- .../shanghai/vm/instructions/control_flow.py | 12 ++++-- .../shanghai/vm/instructions/environment.py | 22 +++++++--- .../forks/shanghai/vm/instructions/memory.py | 10 +++-- .../forks/shanghai/vm/instructions/stack.py | 14 +++++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 35 ++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../vm/instructions/bitwise.py | 19 ++++++--- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 16 ++++++-- .../spurious_dragon/vm/instructions/memory.py | 10 +++-- .../spurious_dragon/vm/instructions/stack.py | 14 +++++-- .../forks/tangerine_whistle/vm/gas.py | 35 ++++++++++++++++ .../vm/instructions/arithmetic.py | 33 +++++++++------ .../vm/instructions/bitwise.py | 19 ++++++--- .../vm/instructions/comparison.py | 22 ++++++---- .../vm/instructions/control_flow.py | 12 ++++-- .../vm/instructions/environment.py | 16 ++++++-- .../vm/instructions/memory.py | 10 +++-- .../vm/instructions/stack.py | 14 +++++-- 192 files changed, 3224 insertions(+), 1073 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 6807cba420b..a3fc26c1187 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -87,6 +87,46 @@ GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index f5f89bdfa59..98b03e02b9d 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -178,7 +181,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +239,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -294,7 +300,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -454,7 +463,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 7ac4146d8cf..53f88a41363 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -64,6 +64,45 @@ GAS_WARM_ACCESS = Uint(100) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index fe1b70c1269..c7018574c29 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 80441f0e4fd..2d54c75993c 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -65,6 +65,45 @@ GAS_WARM_ACCESS = Uint(100) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/berlin/vm/instructions/bitwise.py b/src/ethereum/forks/berlin/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/berlin/vm/instructions/bitwise.py +++ b/src/ethereum/forks/berlin/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/berlin/vm/instructions/comparison.py b/src/ethereum/forks/berlin/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/berlin/vm/instructions/comparison.py +++ b/src/ethereum/forks/berlin/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 63733aca3d5..8798f5a4b7b 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 51b439cd0a0..7eb9aabb9eb 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo1/vm/instructions/comparison.py b/src/ethereum/forks/bpo1/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo1/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 5c30cd6a340..c72c32ac9b5 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo2/vm/instructions/comparison.py b/src/ethereum/forks/bpo2/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo2/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 5c30cd6a340..c72c32ac9b5 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo3/vm/instructions/comparison.py b/src/ethereum/forks/bpo3/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo3/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 5c30cd6a340..c72c32ac9b5 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo4/vm/instructions/comparison.py b/src/ethereum/forks/bpo4/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo4/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 5c30cd6a340..c72c32ac9b5 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo5/vm/instructions/comparison.py b/src/ethereum/forks/bpo5/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo5/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index c4aa9846029..a62a1b4f05b 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -64,6 +64,42 @@ GAS_RETURN_DATA_COPY = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py +++ b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/byzantium/vm/instructions/comparison.py b/src/ethereum/forks/byzantium/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/comparison.py +++ b/src/ethereum/forks/byzantium/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 0fa98ce55a5..2fb6855f846 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -25,8 +25,11 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +170,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -225,7 +228,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -283,7 +289,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -424,7 +433,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 0523287c6cf..87ad7a90aab 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -74,6 +74,46 @@ BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/cancun/vm/instructions/bitwise.py b/src/ethereum/forks/cancun/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/cancun/vm/instructions/bitwise.py +++ b/src/ethereum/forks/cancun/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/cancun/vm/instructions/comparison.py b/src/ethereum/forks/cancun/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/cancun/vm/instructions/comparison.py +++ b/src/ethereum/forks/cancun/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index f59699f0347..86aa9f2d4eb 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -65,6 +65,45 @@ GAS_CODE_HASH = Uint(400) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py +++ b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/constantinople/vm/instructions/comparison.py b/src/ethereum/forks/constantinople/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/comparison.py +++ b/src/ethereum/forks/constantinople/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index d5572be1b4a..f935b995c17 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -27,8 +27,11 @@ GAS_CODE_HASH, GAS_COPY, GAS_EXTERNAL, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, calculate_gas_extend_memory, charge_gas, ) @@ -169,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +230,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -285,7 +291,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -426,7 +435,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index fc01397ceb0..7ca04137dde 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -63,6 +63,41 @@ GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 83eb5528226..f2c91716993 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -24,7 +24,9 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -165,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +225,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -281,7 +286,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index fc01397ceb0..7ca04137dde 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -63,6 +63,41 @@ GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/frontier/vm/instructions/bitwise.py b/src/ethereum/forks/frontier/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/frontier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/frontier/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/frontier/vm/instructions/comparison.py b/src/ethereum/forks/frontier/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/frontier/vm/instructions/comparison.py +++ b/src/ethereum/forks/frontier/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 83eb5528226..f2c91716993 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -24,7 +24,9 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -165,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +225,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -281,7 +286,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 7ac4146d8cf..53f88a41363 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -64,6 +64,45 @@ GAS_WARM_ACCESS = Uint(100) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index fe1b70c1269..c7018574c29 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index fc01397ceb0..7ca04137dde 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -63,6 +63,41 @@ GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/homestead/vm/instructions/bitwise.py b/src/ethereum/forks/homestead/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/homestead/vm/instructions/bitwise.py +++ b/src/ethereum/forks/homestead/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/homestead/vm/instructions/comparison.py b/src/ethereum/forks/homestead/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/homestead/vm/instructions/comparison.py +++ b/src/ethereum/forks/homestead/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 83eb5528226..f2c91716993 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -24,7 +24,9 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -165,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +225,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -281,7 +286,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 8425495cd13..e577426c407 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -67,6 +67,45 @@ GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py +++ b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/istanbul/vm/instructions/comparison.py b/src/ethereum/forks/istanbul/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/comparison.py +++ b/src/ethereum/forks/istanbul/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index f0cc93e67d8..a77ca394884 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COPY, GAS_EXTERNAL, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, calculate_gas_extend_memory, charge_gas, ) @@ -170,7 +173,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -228,7 +231,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -286,7 +292,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -427,7 +436,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 7ac4146d8cf..53f88a41363 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -64,6 +64,45 @@ GAS_WARM_ACCESS = Uint(100) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/london/vm/instructions/bitwise.py b/src/ethereum/forks/london/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/london/vm/instructions/bitwise.py +++ b/src/ethereum/forks/london/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/london/vm/instructions/comparison.py b/src/ethereum/forks/london/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/london/vm/instructions/comparison.py +++ b/src/ethereum/forks/london/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index fe1b70c1269..c7018574c29 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 8425495cd13..e577426c407 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -67,6 +67,45 @@ GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index f0cc93e67d8..a77ca394884 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COPY, GAS_EXTERNAL, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, calculate_gas_extend_memory, charge_gas, ) @@ -170,7 +173,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -228,7 +231,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -286,7 +292,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -427,7 +436,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 99ccfb48145..3184160596d 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -84,6 +84,46 @@ GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_CLZ = GAS_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/osaka/vm/instructions/bitwise.py b/src/ethereum/forks/osaka/vm/instructions/bitwise.py index cc6fa2fbb23..0614ff61fed 100644 --- a/src/ethereum/forks/osaka/vm/instructions/bitwise.py +++ b/src/ethereum/forks/osaka/vm/instructions/bitwise.py @@ -14,7 +14,18 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_LOW, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_CLZ, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +45,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +70,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +95,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +119,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +145,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +180,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +210,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +240,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +273,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/osaka/vm/instructions/comparison.py b/src/ethereum/forks/osaka/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/osaka/vm/instructions/comparison.py +++ b/src/ethereum/forks/osaka/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 7ac4146d8cf..53f88a41363 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -64,6 +64,45 @@ GAS_WARM_ACCESS = Uint(100) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/paris/vm/instructions/bitwise.py b/src/ethereum/forks/paris/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/paris/vm/instructions/bitwise.py +++ b/src/ethereum/forks/paris/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/paris/vm/instructions/comparison.py b/src/ethereum/forks/paris/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/paris/vm/instructions/comparison.py +++ b/src/ethereum/forks/paris/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index ba2bb42a425..00e43488ea9 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 121292173ef..d57a2f0abea 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -81,6 +81,46 @@ GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_MCOPY = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/prague/vm/instructions/bitwise.py b/src/ethereum/forks/prague/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/prague/vm/instructions/bitwise.py +++ b/src/ethereum/forks/prague/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/prague/vm/instructions/comparison.py b/src/ethereum/forks/prague/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/prague/vm/instructions/comparison.py +++ b/src/ethereum/forks/prague/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 5848530a960..589e9d7fcba 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -28,8 +28,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_blob_gas_price, calculate_gas_extend_memory, @@ -176,7 +179,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -234,7 +237,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -292,7 +298,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -446,7 +455,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 6e111051ee3..1e650339074 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -20,7 +20,10 @@ from ..gas import ( GAS_BASE, GAS_COPY, - GAS_VERY_LOW, + GAS_OPCODE_MCOPY, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +52,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -80,7 +83,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -108,7 +111,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +169,10 @@ def mcopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 44d049d552f..c1d4f7408b6 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -65,6 +65,45 @@ GAS_CODE_INIT_PER_WORD = Uint(2) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_SHL = GAS_VERY_LOW +GAS_OPCODE_SHR = GAS_VERY_LOW +GAS_OPCODE_SAR = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py index 41dabe8185b..4e36a1a7959 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py +++ b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py @@ -14,7 +14,17 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_SAR, + GAS_OPCODE_SHL, + GAS_OPCODE_SHR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +44,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +69,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +94,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +118,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +144,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +179,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +209,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +239,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/shanghai/vm/instructions/comparison.py b/src/ethereum/forks/shanghai/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/comparison.py +++ b/src/ethereum/forks/shanghai/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index ba2bb42a425..00e43488ea9 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -26,8 +26,11 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, + GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, - GAS_VERY_LOW, GAS_WARM_ACCESS, calculate_gas_extend_memory, charge_gas, @@ -173,7 +176,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -231,7 +234,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -289,7 +295,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -443,7 +452,10 @@ def returndatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index 0007a28acd4..a58e1e66e3f 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -65,7 +71,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +101,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +133,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 937e953a145..26f7aa77539 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -63,6 +63,41 @@ GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 83eb5528226..f2c91716993 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -24,7 +24,9 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -165,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +225,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -281,7 +286,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 56a9451c117..7d668fa5b55 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -63,6 +63,41 @@ GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) +# Opcode specific vars used for repricing +GAS_OPCODE_ADD = GAS_VERY_LOW +GAS_OPCODE_SUB = GAS_VERY_LOW +GAS_OPCODE_MUL = GAS_LOW +GAS_OPCODE_DIV = GAS_LOW +GAS_OPCODE_SDIV = GAS_LOW +GAS_OPCODE_MOD = GAS_LOW +GAS_OPCODE_SMOD = GAS_LOW +GAS_OPCODE_ADDMOD = GAS_MID +GAS_OPCODE_MULMOD = GAS_MID +GAS_OPCODE_SIGNEXTEND = GAS_LOW +GAS_OPCODE_LT = GAS_VERY_LOW +GAS_OPCODE_GT = GAS_VERY_LOW +GAS_OPCODE_SLT = GAS_VERY_LOW +GAS_OPCODE_SGT = GAS_VERY_LOW +GAS_OPCODE_EQ = GAS_VERY_LOW +GAS_OPCODE_ISZERO = GAS_VERY_LOW +GAS_OPCODE_AND = GAS_VERY_LOW +GAS_OPCODE_OR = GAS_VERY_LOW +GAS_OPCODE_XOR = GAS_VERY_LOW +GAS_OPCODE_NOT = GAS_VERY_LOW +GAS_OPCODE_BYTE = GAS_VERY_LOW +GAS_OPCODE_JUMP = GAS_MID +GAS_OPCODE_JUMPI = GAS_HIGH +GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW +GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW +GAS_OPCODE_CODECOPY = GAS_VERY_LOW +GAS_OPCODE_MLOAD = GAS_VERY_LOW +GAS_OPCODE_MSTORE = GAS_VERY_LOW +GAS_OPCODE_MSTORE8 = GAS_VERY_LOW +GAS_OPCODE_PUSH_N = GAS_VERY_LOW +GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP_N = GAS_VERY_LOW + + @dataclass class ExtendMemory: """ diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index b7b1a370ad4..d74f7425823 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -20,9 +20,16 @@ from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_LOW, - GAS_MID, - GAS_VERY_LOW, + GAS_OPCODE_ADD, + GAS_OPCODE_ADDMOD, + GAS_OPCODE_DIV, + GAS_OPCODE_MOD, + GAS_OPCODE_MUL, + GAS_OPCODE_MULMOD, + GAS_OPCODE_SDIV, + GAS_OPCODE_SIGNEXTEND, + GAS_OPCODE_SMOD, + GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -44,7 +51,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -71,7 +78,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -98,7 +105,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -125,7 +132,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -158,7 +165,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -191,7 +198,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -221,7 +228,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -252,7 +259,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -283,7 +290,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -346,7 +353,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_LOW) + charge_gas(evm, GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py index 2a506f55751..cb37f6eca7d 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py @@ -14,7 +14,14 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_AND, + GAS_OPCODE_BYTE, + GAS_OPCODE_NOT, + GAS_OPCODE_OR, + GAS_OPCODE_XOR, + charge_gas, +) from ..stack import pop, push @@ -34,7 +41,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +66,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +91,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +115,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +141,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py index a6a3d99bc86..f18a1f221e8 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py @@ -14,7 +14,15 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_OPCODE_EQ, + GAS_OPCODE_GT, + GAS_OPCODE_ISZERO, + GAS_OPCODE_LT, + GAS_OPCODE_SGT, + GAS_OPCODE_SLT, + charge_gas, +) from ..stack import pop, push @@ -34,7 +42,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +68,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +95,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +121,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +148,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +174,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index b3b1f2316a7..3207f00d738 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -13,7 +13,13 @@ from ethereum_types.numeric import U256, Uint -from ...vm.gas import GAS_BASE, GAS_HIGH, GAS_JUMPDEST, GAS_MID, charge_gas +from ...vm.gas import ( + GAS_BASE, + GAS_JUMPDEST, + GAS_OPCODE_JUMP, + GAS_OPCODE_JUMPI, + charge_gas, +) from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -57,7 +63,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_MID) + charge_gas(evm, GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +90,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_HIGH) + charge_gas(evm, GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 83eb5528226..f2c91716993 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -24,7 +24,9 @@ GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY, + GAS_OPCODE_CALLDATALOAD, + GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -165,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +225,10 @@ def calldatacopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -281,7 +286,10 @@ def codecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_VERY_LOW + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index 3a242ba2f7a..74a9396629a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -17,7 +17,9 @@ from .. import Evm from ..gas import ( GAS_BASE, - GAS_VERY_LOW, + GAS_OPCODE_MLOAD, + GAS_OPCODE_MSTORE, + GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -77,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -105,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_VERY_LOW + extend_memory.cost) + charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 0fc0d3fe4b5..4f1b8171e51 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -17,7 +17,13 @@ from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import GAS_BASE, GAS_VERY_LOW, charge_gas +from ..gas import ( + GAS_BASE, + GAS_OPCODE_DUP_N, + GAS_OPCODE_PUSH_N, + GAS_OPCODE_SWAP_N, + charge_gas, +) from ..memory import buffer_read @@ -62,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -92,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -124,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_VERY_LOW) + charge_gas(evm, GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( From 3c81ee4a52dc115a6b455958b565423156d8a488 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 3 Mar 2026 15:09:34 -0500 Subject: [PATCH 02/61] refactor(spec-specs): renamed GAS_BLOBHASH_OPCODE to GAS_BLOBHASH to more clearly differentiate between intermediate constants and existing ones --- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++-- src/ethereum/forks/amsterdam/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/bpo1/vm/gas.py | 4 ++-- src/ethereum/forks/bpo1/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 4 ++-- src/ethereum/forks/bpo2/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 4 ++-- src/ethereum/forks/bpo3/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 4 ++-- src/ethereum/forks/bpo4/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 4 ++-- src/ethereum/forks/bpo5/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/cancun/vm/gas.py | 4 ++-- src/ethereum/forks/cancun/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/osaka/vm/gas.py | 4 ++-- src/ethereum/forks/osaka/vm/instructions/environment.py | 4 ++-- src/ethereum/forks/prague/vm/instructions/environment.py | 4 ++-- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index a3fc26c1187..c38ced2595f 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -67,8 +67,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 98b03e02b9d..ea48276dd30 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -583,7 +583,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 7eb9aabb9eb..94a25483454 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(10) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index c72c32ac9b5..c4ec74aeabe 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index c72c32ac9b5..c4ec74aeabe 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index c72c32ac9b5..c4ec74aeabe 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index c72c32ac9b5..c4ec74aeabe 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 87ad7a90aab..a3004b0eab9 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -65,8 +65,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(393216) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 3184160596d..7be8b0ec959 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -66,8 +66,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(6) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 589e9d7fcba..7a2f15c7001 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -24,7 +24,7 @@ from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, - GAS_BLOBHASH_OPCODE, + GAS_BLOBHASH, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, @@ -573,7 +573,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH_OPCODE) + charge_gas(evm, GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): From 78aa88bd015217825ebd2299455214929575e6df Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 3 Mar 2026 15:10:29 -0500 Subject: [PATCH 03/61] refactor(testing): add per-opcode gas constants to GasCosts Add 39 GAS_OPCODE_* fields to the GasCosts dataclass and update opcode_gas_map() in all forks to reference per-opcode fields instead of shared tier constants. --- .../execution_testing/forks/forks/forks.py | 109 +++++++++++++----- .../src/execution_testing/forks/gas_costs.py | 41 +++++++ 2 files changed, 118 insertions(+), 32 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 92eeb70a89a..b19a129ea16 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -164,6 +164,46 @@ def gas_costs(cls) -> GasCosts: GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR=0, GAS_PRECOMPILE_P256VERIFY=0, GAS_BLOCK_ACCESS_LIST_ITEM=0, + # Opcode specific gas constants for repricing + GAS_OPCODE_ADD=3, + GAS_OPCODE_SUB=3, + GAS_OPCODE_MUL=5, + GAS_OPCODE_DIV=5, + GAS_OPCODE_SDIV=5, + GAS_OPCODE_MOD=5, + GAS_OPCODE_SMOD=5, + GAS_OPCODE_ADDMOD=8, + GAS_OPCODE_MULMOD=8, + GAS_OPCODE_SIGNEXTEND=5, + GAS_OPCODE_LT=3, + GAS_OPCODE_GT=3, + GAS_OPCODE_SLT=3, + GAS_OPCODE_SGT=3, + GAS_OPCODE_EQ=3, + GAS_OPCODE_ISZERO=3, + GAS_OPCODE_AND=3, + GAS_OPCODE_OR=3, + GAS_OPCODE_XOR=3, + GAS_OPCODE_NOT=3, + GAS_OPCODE_BYTE=3, + GAS_OPCODE_SHL=3, + GAS_OPCODE_SHR=3, + GAS_OPCODE_SAR=3, + GAS_OPCODE_CLZ=5, + GAS_OPCODE_BLOBHASH=3, + GAS_OPCODE_JUMP=8, + GAS_OPCODE_JUMPI=10, + GAS_OPCODE_CALLDATALOAD=3, + GAS_OPCODE_CALLDATACOPY=3, + GAS_OPCODE_CODECOPY=3, + GAS_OPCODE_RETURNDATACOPY=3, + GAS_OPCODE_MLOAD=3, + GAS_OPCODE_MSTORE=3, + GAS_OPCODE_MSTORE8=3, + GAS_OPCODE_MCOPY=3, + GAS_OPCODE_PUSH_N=3, + GAS_OPCODE_DUP_N=3, + GAS_OPCODE_SWAP_N=3, ) @classmethod @@ -297,33 +337,33 @@ def opcode_gas_map( return { # Stop and arithmetic operations Opcodes.STOP: 0, - Opcodes.ADD: gas_costs.GAS_VERY_LOW, - Opcodes.MUL: gas_costs.GAS_LOW, - Opcodes.SUB: gas_costs.GAS_VERY_LOW, - Opcodes.DIV: gas_costs.GAS_LOW, - Opcodes.SDIV: gas_costs.GAS_LOW, - Opcodes.MOD: gas_costs.GAS_LOW, - Opcodes.SMOD: gas_costs.GAS_LOW, - Opcodes.ADDMOD: gas_costs.GAS_MID, - Opcodes.MULMOD: gas_costs.GAS_MID, + Opcodes.ADD: gas_costs.GAS_OPCODE_ADD, + Opcodes.MUL: gas_costs.GAS_OPCODE_MUL, + Opcodes.SUB: gas_costs.GAS_OPCODE_SUB, + Opcodes.DIV: gas_costs.GAS_OPCODE_DIV, + Opcodes.SDIV: gas_costs.GAS_OPCODE_SDIV, + Opcodes.MOD: gas_costs.GAS_OPCODE_MOD, + Opcodes.SMOD: gas_costs.GAS_OPCODE_SMOD, + Opcodes.ADDMOD: gas_costs.GAS_OPCODE_ADDMOD, + Opcodes.MULMOD: gas_costs.GAS_OPCODE_MULMOD, Opcodes.EXP: lambda op: ( gas_costs.GAS_EXPONENTIATION + gas_costs.GAS_EXPONENTIATION_PER_BYTE * ((op.metadata["exponent"].bit_length() + 7) // 8) ), - Opcodes.SIGNEXTEND: gas_costs.GAS_LOW, + Opcodes.SIGNEXTEND: gas_costs.GAS_OPCODE_SIGNEXTEND, # Comparison & bitwise logic operations - Opcodes.LT: gas_costs.GAS_VERY_LOW, - Opcodes.GT: gas_costs.GAS_VERY_LOW, - Opcodes.SLT: gas_costs.GAS_VERY_LOW, - Opcodes.SGT: gas_costs.GAS_VERY_LOW, - Opcodes.EQ: gas_costs.GAS_VERY_LOW, - Opcodes.ISZERO: gas_costs.GAS_VERY_LOW, - Opcodes.AND: gas_costs.GAS_VERY_LOW, - Opcodes.OR: gas_costs.GAS_VERY_LOW, - Opcodes.XOR: gas_costs.GAS_VERY_LOW, - Opcodes.NOT: gas_costs.GAS_VERY_LOW, - Opcodes.BYTE: gas_costs.GAS_VERY_LOW, + Opcodes.LT: gas_costs.GAS_OPCODE_LT, + Opcodes.GT: gas_costs.GAS_OPCODE_GT, + Opcodes.SLT: gas_costs.GAS_OPCODE_SLT, + Opcodes.SGT: gas_costs.GAS_OPCODE_SGT, + Opcodes.EQ: gas_costs.GAS_OPCODE_EQ, + Opcodes.ISZERO: gas_costs.GAS_OPCODE_ISZERO, + Opcodes.AND: gas_costs.GAS_OPCODE_AND, + Opcodes.OR: gas_costs.GAS_OPCODE_OR, + Opcodes.XOR: gas_costs.GAS_OPCODE_XOR, + Opcodes.NOT: gas_costs.GAS_OPCODE_NOT, + Opcodes.BYTE: gas_costs.GAS_OPCODE_BYTE, # SHA3 Opcodes.SHA3: cls._with_memory_expansion( lambda op: ( @@ -339,15 +379,17 @@ def opcode_gas_map( Opcodes.ORIGIN: gas_costs.GAS_BASE, Opcodes.CALLER: gas_costs.GAS_BASE, Opcodes.CALLVALUE: gas_costs.GAS_BASE, - Opcodes.CALLDATALOAD: gas_costs.GAS_VERY_LOW, + Opcodes.CALLDATALOAD: gas_costs.GAS_OPCODE_CALLDATALOAD, Opcodes.CALLDATASIZE: gas_costs.GAS_BASE, Opcodes.CALLDATACOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.GAS_VERY_LOW, gas_costs), + cls._with_data_copy( + gas_costs.GAS_OPCODE_CALLDATACOPY, gas_costs + ), memory_expansion_calculator, ), Opcodes.CODESIZE: gas_costs.GAS_BASE, Opcodes.CODECOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.GAS_VERY_LOW, gas_costs), + cls._with_data_copy(gas_costs.GAS_OPCODE_CODECOPY, gas_costs), memory_expansion_calculator, ), Opcodes.GASPRICE: gas_costs.GAS_BASE, @@ -369,13 +411,16 @@ def opcode_gas_map( # Stack, memory, storage and flow operations Opcodes.POP: gas_costs.GAS_BASE, Opcodes.MLOAD: cls._with_memory_expansion( - gas_costs.GAS_VERY_LOW, memory_expansion_calculator + gas_costs.GAS_OPCODE_MLOAD, + memory_expansion_calculator, ), Opcodes.MSTORE: cls._with_memory_expansion( - gas_costs.GAS_VERY_LOW, memory_expansion_calculator + gas_costs.GAS_OPCODE_MSTORE, + memory_expansion_calculator, ), Opcodes.MSTORE8: cls._with_memory_expansion( - gas_costs.GAS_VERY_LOW, memory_expansion_calculator + gas_costs.GAS_OPCODE_MSTORE8, + memory_expansion_calculator, ), Opcodes.SLOAD: lambda op: ( gas_costs.GAS_WARM_SLOAD @@ -385,25 +430,25 @@ def opcode_gas_map( Opcodes.SSTORE: lambda op: cls._calculate_sstore_gas( op, gas_costs ), - Opcodes.JUMP: gas_costs.GAS_MID, - Opcodes.JUMPI: gas_costs.GAS_HIGH, + Opcodes.JUMP: gas_costs.GAS_OPCODE_JUMP, + Opcodes.JUMPI: gas_costs.GAS_OPCODE_JUMPI, Opcodes.PC: gas_costs.GAS_BASE, Opcodes.MSIZE: gas_costs.GAS_BASE, Opcodes.GAS: gas_costs.GAS_BASE, Opcodes.JUMPDEST: gas_costs.GAS_JUMPDEST, # Push operations (PUSH1 through PUSH32) **{ - getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_VERY_LOW + getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_OPCODE_PUSH_N for i in range(1, 33) }, # Dup operations (DUP1 through DUP16) **{ - getattr(Opcodes, f"DUP{i}"): gas_costs.GAS_VERY_LOW + getattr(Opcodes, f"DUP{i}"): gas_costs.GAS_OPCODE_DUP_N for i in range(1, 17) }, # Swap operations (SWAP1 through SWAP16) **{ - getattr(Opcodes, f"SWAP{i}"): gas_costs.GAS_VERY_LOW + getattr(Opcodes, f"SWAP{i}"): gas_costs.GAS_OPCODE_SWAP_N for i in range(1, 17) }, # Logging operations diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index c41b6519d8d..2ca266ce46f 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -91,3 +91,44 @@ class GasCosts: REFUND_AUTH_PER_EXISTING_ACCOUNT: int GAS_BLOCK_ACCESS_LIST_ITEM: int + + # Opcode specific gas constants for repricing + GAS_OPCODE_ADD: int + GAS_OPCODE_SUB: int + GAS_OPCODE_MUL: int + GAS_OPCODE_DIV: int + GAS_OPCODE_SDIV: int + GAS_OPCODE_MOD: int + GAS_OPCODE_SMOD: int + GAS_OPCODE_ADDMOD: int + GAS_OPCODE_MULMOD: int + GAS_OPCODE_SIGNEXTEND: int + GAS_OPCODE_LT: int + GAS_OPCODE_GT: int + GAS_OPCODE_SLT: int + GAS_OPCODE_SGT: int + GAS_OPCODE_EQ: int + GAS_OPCODE_ISZERO: int + GAS_OPCODE_AND: int + GAS_OPCODE_OR: int + GAS_OPCODE_XOR: int + GAS_OPCODE_NOT: int + GAS_OPCODE_BYTE: int + GAS_OPCODE_SHL: int + GAS_OPCODE_SHR: int + GAS_OPCODE_SAR: int + GAS_OPCODE_CLZ: int + GAS_OPCODE_BLOBHASH: int + GAS_OPCODE_JUMP: int + GAS_OPCODE_JUMPI: int + GAS_OPCODE_CALLDATALOAD: int + GAS_OPCODE_CALLDATACOPY: int + GAS_OPCODE_CODECOPY: int + GAS_OPCODE_RETURNDATACOPY: int + GAS_OPCODE_MLOAD: int + GAS_OPCODE_MSTORE: int + GAS_OPCODE_MSTORE8: int + GAS_OPCODE_MCOPY: int + GAS_OPCODE_PUSH_N: int + GAS_OPCODE_DUP_N: int + GAS_OPCODE_SWAP_N: int From 30fb2ae5fcbc036e029f627345bb2fdf79e45a6f Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 9 Mar 2026 22:44:20 -0400 Subject: [PATCH 04/61] refactor: move post-frontier opcodes --- .../src/execution_testing/forks/forks/forks.py | 7 ------- .../src/execution_testing/forks/gas_costs.py | 16 +++++++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index b19a129ea16..cd400395496 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -186,21 +186,14 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_XOR=3, GAS_OPCODE_NOT=3, GAS_OPCODE_BYTE=3, - GAS_OPCODE_SHL=3, - GAS_OPCODE_SHR=3, - GAS_OPCODE_SAR=3, - GAS_OPCODE_CLZ=5, - GAS_OPCODE_BLOBHASH=3, GAS_OPCODE_JUMP=8, GAS_OPCODE_JUMPI=10, GAS_OPCODE_CALLDATALOAD=3, GAS_OPCODE_CALLDATACOPY=3, GAS_OPCODE_CODECOPY=3, - GAS_OPCODE_RETURNDATACOPY=3, GAS_OPCODE_MLOAD=3, GAS_OPCODE_MSTORE=3, GAS_OPCODE_MSTORE8=3, - GAS_OPCODE_MCOPY=3, GAS_OPCODE_PUSH_N=3, GAS_OPCODE_DUP_N=3, GAS_OPCODE_SWAP_N=3, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 2ca266ce46f..58407c09935 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -114,21 +114,23 @@ class GasCosts: GAS_OPCODE_XOR: int GAS_OPCODE_NOT: int GAS_OPCODE_BYTE: int - GAS_OPCODE_SHL: int - GAS_OPCODE_SHR: int - GAS_OPCODE_SAR: int - GAS_OPCODE_CLZ: int - GAS_OPCODE_BLOBHASH: int GAS_OPCODE_JUMP: int GAS_OPCODE_JUMPI: int GAS_OPCODE_CALLDATALOAD: int GAS_OPCODE_CALLDATACOPY: int GAS_OPCODE_CODECOPY: int - GAS_OPCODE_RETURNDATACOPY: int GAS_OPCODE_MLOAD: int GAS_OPCODE_MSTORE: int GAS_OPCODE_MSTORE8: int - GAS_OPCODE_MCOPY: int GAS_OPCODE_PUSH_N: int GAS_OPCODE_DUP_N: int GAS_OPCODE_SWAP_N: int + + # Defined post-Frontier + GAS_OPCODE_SHL: int = 0 + GAS_OPCODE_SHR: int = 0 + GAS_OPCODE_SAR: int = 0 + GAS_OPCODE_RETURNDATACOPY: int = 0 + GAS_OPCODE_BLOBHASH: int = 0 + GAS_OPCODE_MCOPY: int = 0 + GAS_OPCODE_CLZ: int = 0 From 76d62017d1b5ee9676217d809db98ff8db14158c Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 9 Mar 2026 23:26:18 -0400 Subject: [PATCH 05/61] refactor: added gas tiers for the test code --- .../execution_testing/forks/forks/forks.py | 64 +++++++++---------- .../src/execution_testing/forks/gas_costs.py | 6 ++ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index cd400395496..a966ec193f2 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -165,38 +165,38 @@ def gas_costs(cls) -> GasCosts: GAS_PRECOMPILE_P256VERIFY=0, GAS_BLOCK_ACCESS_LIST_ITEM=0, # Opcode specific gas constants for repricing - GAS_OPCODE_ADD=3, - GAS_OPCODE_SUB=3, - GAS_OPCODE_MUL=5, - GAS_OPCODE_DIV=5, - GAS_OPCODE_SDIV=5, - GAS_OPCODE_MOD=5, - GAS_OPCODE_SMOD=5, - GAS_OPCODE_ADDMOD=8, - GAS_OPCODE_MULMOD=8, - GAS_OPCODE_SIGNEXTEND=5, - GAS_OPCODE_LT=3, - GAS_OPCODE_GT=3, - GAS_OPCODE_SLT=3, - GAS_OPCODE_SGT=3, - GAS_OPCODE_EQ=3, - GAS_OPCODE_ISZERO=3, - GAS_OPCODE_AND=3, - GAS_OPCODE_OR=3, - GAS_OPCODE_XOR=3, - GAS_OPCODE_NOT=3, - GAS_OPCODE_BYTE=3, - GAS_OPCODE_JUMP=8, - GAS_OPCODE_JUMPI=10, - GAS_OPCODE_CALLDATALOAD=3, - GAS_OPCODE_CALLDATACOPY=3, - GAS_OPCODE_CODECOPY=3, - GAS_OPCODE_MLOAD=3, - GAS_OPCODE_MSTORE=3, - GAS_OPCODE_MSTORE8=3, - GAS_OPCODE_PUSH_N=3, - GAS_OPCODE_DUP_N=3, - GAS_OPCODE_SWAP_N=3, + GAS_OPCODE_ADD=GAS_VERY_LOW, + GAS_OPCODE_SUB=GAS_VERY_LOW, + GAS_OPCODE_MUL=GAS_LOW, + GAS_OPCODE_DIV=GAS_LOW, + GAS_OPCODE_SDIV=GAS_LOW, + GAS_OPCODE_MOD=GAS_LOW, + GAS_OPCODE_SMOD=GAS_LOW, + GAS_OPCODE_ADDMOD=GAS_MID, + GAS_OPCODE_MULMOD=GAS_MID, + GAS_OPCODE_SIGNEXTEND=GAS_LOW, + GAS_OPCODE_LT=GAS_VERY_LOW, + GAS_OPCODE_GT=GAS_VERY_LOW, + GAS_OPCODE_SLT=GAS_VERY_LOW, + GAS_OPCODE_SGT=GAS_VERY_LOW, + GAS_OPCODE_EQ=GAS_VERY_LOW, + GAS_OPCODE_ISZERO=GAS_VERY_LOW, + GAS_OPCODE_AND=GAS_VERY_LOW, + GAS_OPCODE_OR=GAS_VERY_LOW, + GAS_OPCODE_XOR=GAS_VERY_LOW, + GAS_OPCODE_NOT=GAS_VERY_LOW, + GAS_OPCODE_BYTE=GAS_VERY_LOW, + GAS_OPCODE_JUMP=GAS_MID, + GAS_OPCODE_JUMPI=GAS_HIGH, + GAS_OPCODE_CALLDATALOAD=GAS_VERY_LOW, + GAS_OPCODE_CALLDATACOPY=GAS_VERY_LOW, + GAS_OPCODE_CODECOPY=GAS_VERY_LOW, + GAS_OPCODE_MLOAD=GAS_VERY_LOW, + GAS_OPCODE_MSTORE=GAS_VERY_LOW, + GAS_OPCODE_MSTORE8=GAS_VERY_LOW, + GAS_OPCODE_PUSH_N=GAS_VERY_LOW, + GAS_OPCODE_DUP_N=GAS_VERY_LOW, + GAS_OPCODE_SWAP_N=GAS_VERY_LOW, ) @classmethod diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 58407c09935..fe206fdc84d 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -2,6 +2,12 @@ from dataclasses import dataclass +# Common Gas Cost Tiers +GAS_VERY_LOW = 3 +GAS_LOW = 5 +GAS_MID = 8 +GAS_HIGH = 10 + @dataclass(kw_only=True, frozen=True) class GasCosts: From 9adbb1a96c74ee233c9db0524c0e9f4b77aa2360 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 10 Mar 2026 00:58:18 -0400 Subject: [PATCH 06/61] refactor: use gas module refs for opcode constants --- .../amsterdam/vm/instructions/arithmetic.py | 32 +++++++------------ .../amsterdam/vm/instructions/bitwise.py | 29 ++++++----------- .../amsterdam/vm/instructions/comparison.py | 20 ++++-------- .../amsterdam/vm/instructions/control_flow.py | 7 ++-- .../amsterdam/vm/instructions/environment.py | 14 +++----- .../forks/amsterdam/vm/instructions/memory.py | 14 +++----- .../forks/amsterdam/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../arrow_glacier/vm/instructions/bitwise.py | 26 ++++++--------- .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 14 +++----- .../arrow_glacier/vm/instructions/memory.py | 11 +++---- .../arrow_glacier/vm/instructions/stack.py | 11 +++---- .../berlin/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/berlin/vm/instructions/bitwise.py | 26 ++++++--------- .../berlin/vm/instructions/comparison.py | 20 ++++-------- .../berlin/vm/instructions/control_flow.py | 7 ++-- .../berlin/vm/instructions/environment.py | 14 +++----- .../forks/berlin/vm/instructions/memory.py | 11 +++---- .../forks/berlin/vm/instructions/stack.py | 11 +++---- .../forks/bpo1/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/bpo1/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/bpo1/vm/instructions/comparison.py | 20 ++++-------- .../bpo1/vm/instructions/control_flow.py | 7 ++-- .../forks/bpo1/vm/instructions/environment.py | 14 +++----- .../forks/bpo1/vm/instructions/memory.py | 14 +++----- .../forks/bpo1/vm/instructions/stack.py | 11 +++---- .../forks/bpo2/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/bpo2/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/bpo2/vm/instructions/comparison.py | 20 ++++-------- .../bpo2/vm/instructions/control_flow.py | 7 ++-- .../forks/bpo2/vm/instructions/environment.py | 14 +++----- .../forks/bpo2/vm/instructions/memory.py | 14 +++----- .../forks/bpo2/vm/instructions/stack.py | 11 +++---- .../forks/bpo3/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/bpo3/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/bpo3/vm/instructions/comparison.py | 20 ++++-------- .../bpo3/vm/instructions/control_flow.py | 7 ++-- .../forks/bpo3/vm/instructions/environment.py | 14 +++----- .../forks/bpo3/vm/instructions/memory.py | 14 +++----- .../forks/bpo3/vm/instructions/stack.py | 11 +++---- .../forks/bpo4/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/bpo4/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/bpo4/vm/instructions/comparison.py | 20 ++++-------- .../bpo4/vm/instructions/control_flow.py | 7 ++-- .../forks/bpo4/vm/instructions/environment.py | 14 +++----- .../forks/bpo4/vm/instructions/memory.py | 14 +++----- .../forks/bpo4/vm/instructions/stack.py | 11 +++---- .../forks/bpo5/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/bpo5/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/bpo5/vm/instructions/comparison.py | 20 ++++-------- .../bpo5/vm/instructions/control_flow.py | 7 ++-- .../forks/bpo5/vm/instructions/environment.py | 14 +++----- .../forks/bpo5/vm/instructions/memory.py | 14 +++----- .../forks/bpo5/vm/instructions/stack.py | 11 +++---- .../byzantium/vm/instructions/arithmetic.py | 32 +++++++------------ .../byzantium/vm/instructions/bitwise.py | 17 ++++------ .../byzantium/vm/instructions/comparison.py | 20 ++++-------- .../byzantium/vm/instructions/control_flow.py | 7 ++-- .../byzantium/vm/instructions/environment.py | 14 +++----- .../forks/byzantium/vm/instructions/memory.py | 11 +++---- .../forks/byzantium/vm/instructions/stack.py | 11 +++---- .../cancun/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/cancun/vm/instructions/bitwise.py | 26 ++++++--------- .../cancun/vm/instructions/comparison.py | 20 ++++-------- .../cancun/vm/instructions/control_flow.py | 7 ++-- .../cancun/vm/instructions/environment.py | 14 +++----- .../forks/cancun/vm/instructions/memory.py | 14 +++----- .../forks/cancun/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../constantinople/vm/instructions/bitwise.py | 26 ++++++--------- .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 14 +++----- .../constantinople/vm/instructions/memory.py | 11 +++---- .../constantinople/vm/instructions/stack.py | 11 +++---- .../dao_fork/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/dao_fork/vm/instructions/bitwise.py | 17 ++++------ .../dao_fork/vm/instructions/comparison.py | 20 ++++-------- .../dao_fork/vm/instructions/control_flow.py | 7 ++-- .../dao_fork/vm/instructions/environment.py | 11 +++---- .../forks/dao_fork/vm/instructions/memory.py | 11 +++---- .../forks/dao_fork/vm/instructions/stack.py | 11 +++---- .../frontier/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/frontier/vm/instructions/bitwise.py | 17 ++++------ .../frontier/vm/instructions/comparison.py | 20 ++++-------- .../frontier/vm/instructions/control_flow.py | 7 ++-- .../frontier/vm/instructions/environment.py | 11 +++---- .../forks/frontier/vm/instructions/memory.py | 11 +++---- .../forks/frontier/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../gray_glacier/vm/instructions/bitwise.py | 26 ++++++--------- .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 14 +++----- .../gray_glacier/vm/instructions/memory.py | 11 +++---- .../gray_glacier/vm/instructions/stack.py | 11 +++---- .../homestead/vm/instructions/arithmetic.py | 32 +++++++------------ .../homestead/vm/instructions/bitwise.py | 17 ++++------ .../homestead/vm/instructions/comparison.py | 20 ++++-------- .../homestead/vm/instructions/control_flow.py | 7 ++-- .../homestead/vm/instructions/environment.py | 11 +++---- .../forks/homestead/vm/instructions/memory.py | 11 +++---- .../forks/homestead/vm/instructions/stack.py | 11 +++---- .../istanbul/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/istanbul/vm/instructions/bitwise.py | 26 ++++++--------- .../istanbul/vm/instructions/comparison.py | 20 ++++-------- .../istanbul/vm/instructions/control_flow.py | 7 ++-- .../istanbul/vm/instructions/environment.py | 14 +++----- .../forks/istanbul/vm/instructions/memory.py | 11 +++---- .../forks/istanbul/vm/instructions/stack.py | 11 +++---- .../london/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/london/vm/instructions/bitwise.py | 26 ++++++--------- .../london/vm/instructions/comparison.py | 20 ++++-------- .../london/vm/instructions/control_flow.py | 7 ++-- .../london/vm/instructions/environment.py | 14 +++----- .../forks/london/vm/instructions/memory.py | 11 +++---- .../forks/london/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../muir_glacier/vm/instructions/bitwise.py | 26 ++++++--------- .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 14 +++----- .../muir_glacier/vm/instructions/memory.py | 11 +++---- .../muir_glacier/vm/instructions/stack.py | 11 +++---- .../forks/osaka/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/osaka/vm/instructions/bitwise.py | 29 ++++++----------- .../forks/osaka/vm/instructions/comparison.py | 20 ++++-------- .../osaka/vm/instructions/control_flow.py | 7 ++-- .../osaka/vm/instructions/environment.py | 14 +++----- .../forks/osaka/vm/instructions/memory.py | 14 +++----- .../forks/osaka/vm/instructions/stack.py | 11 +++---- .../forks/paris/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/paris/vm/instructions/bitwise.py | 26 ++++++--------- .../forks/paris/vm/instructions/comparison.py | 20 ++++-------- .../paris/vm/instructions/control_flow.py | 7 ++-- .../paris/vm/instructions/environment.py | 14 +++----- .../forks/paris/vm/instructions/memory.py | 11 +++---- .../forks/paris/vm/instructions/stack.py | 11 +++---- .../prague/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/prague/vm/instructions/bitwise.py | 26 ++++++--------- .../prague/vm/instructions/comparison.py | 20 ++++-------- .../prague/vm/instructions/control_flow.py | 7 ++-- .../prague/vm/instructions/environment.py | 14 +++----- .../forks/prague/vm/instructions/memory.py | 14 +++----- .../forks/prague/vm/instructions/stack.py | 11 +++---- .../shanghai/vm/instructions/arithmetic.py | 32 +++++++------------ .../forks/shanghai/vm/instructions/bitwise.py | 26 ++++++--------- .../shanghai/vm/instructions/comparison.py | 20 ++++-------- .../shanghai/vm/instructions/control_flow.py | 7 ++-- .../shanghai/vm/instructions/environment.py | 14 +++----- .../forks/shanghai/vm/instructions/memory.py | 11 +++---- .../forks/shanghai/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../vm/instructions/bitwise.py | 17 ++++------ .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 11 +++---- .../spurious_dragon/vm/instructions/memory.py | 11 +++---- .../spurious_dragon/vm/instructions/stack.py | 11 +++---- .../vm/instructions/arithmetic.py | 32 +++++++------------ .../vm/instructions/bitwise.py | 17 ++++------ .../vm/instructions/comparison.py | 20 ++++-------- .../vm/instructions/control_flow.py | 7 ++-- .../vm/instructions/environment.py | 11 +++---- .../vm/instructions/memory.py | 11 +++---- .../vm/instructions/stack.py | 11 +++---- 168 files changed, 1025 insertions(+), 1858 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index ea48276dd30..3e2a9e053c8 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state_tracker import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -181,7 +177,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -241,7 +237,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -302,7 +298,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -465,7 +461,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index c7018574c29..31b236e66ca 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/berlin/vm/instructions/bitwise.py b/src/ethereum/forks/berlin/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/berlin/vm/instructions/bitwise.py +++ b/src/ethereum/forks/berlin/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/berlin/vm/instructions/comparison.py b/src/ethereum/forks/berlin/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/berlin/vm/instructions/comparison.py +++ b/src/ethereum/forks/berlin/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 8798f5a4b7b..c2770cd8fa4 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo1/vm/instructions/comparison.py b/src/ethereum/forks/bpo1/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo1/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo2/vm/instructions/comparison.py b/src/ethereum/forks/bpo2/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo2/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo3/vm/instructions/comparison.py b/src/ethereum/forks/bpo3/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo3/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo4/vm/instructions/comparison.py b/src/ethereum/forks/bpo4/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo4/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo5/vm/instructions/comparison.py b/src/ethereum/forks/bpo5/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo5/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py +++ b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/byzantium/vm/instructions/comparison.py b/src/ethereum/forks/byzantium/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/comparison.py +++ b/src/ethereum/forks/byzantium/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 2fb6855f846..9221133e41c 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -18,17 +18,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, calculate_gas_extend_memory, charge_gas, @@ -170,7 +166,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -230,7 +226,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -291,7 +287,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -435,7 +431,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/cancun/vm/instructions/bitwise.py b/src/ethereum/forks/cancun/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/cancun/vm/instructions/bitwise.py +++ b/src/ethereum/forks/cancun/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/cancun/vm/instructions/comparison.py b/src/ethereum/forks/cancun/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/cancun/vm/instructions/comparison.py +++ b/src/ethereum/forks/cancun/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py +++ b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/constantinople/vm/instructions/comparison.py b/src/ethereum/forks/constantinople/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/comparison.py +++ b/src/ethereum/forks/constantinople/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index f935b995c17..bcd2195bfdf 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -19,7 +19,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BALANCE, @@ -27,10 +27,6 @@ GAS_CODE_HASH, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, calculate_gas_extend_memory, charge_gas, @@ -172,7 +168,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -232,7 +228,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -293,7 +289,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -437,7 +433,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index f2c91716993..a4cc54062b5 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -18,15 +18,12 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +164,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +285,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/frontier/vm/instructions/bitwise.py b/src/ethereum/forks/frontier/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/frontier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/frontier/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/frontier/vm/instructions/comparison.py b/src/ethereum/forks/frontier/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/frontier/vm/instructions/comparison.py +++ b/src/ethereum/forks/frontier/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index f2c91716993..a4cc54062b5 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -18,15 +18,12 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +164,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +285,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index c7018574c29..31b236e66ca 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/homestead/vm/instructions/bitwise.py b/src/ethereum/forks/homestead/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/homestead/vm/instructions/bitwise.py +++ b/src/ethereum/forks/homestead/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/homestead/vm/instructions/comparison.py b/src/ethereum/forks/homestead/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/homestead/vm/instructions/comparison.py +++ b/src/ethereum/forks/homestead/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index f2c91716993..a4cc54062b5 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -18,15 +18,12 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +164,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +285,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py +++ b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/istanbul/vm/instructions/comparison.py b/src/ethereum/forks/istanbul/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/comparison.py +++ b/src/ethereum/forks/istanbul/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index a77ca394884..9e720ab49c1 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -19,7 +19,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BALANCE, @@ -28,10 +28,6 @@ GAS_COPY, GAS_EXTERNAL, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, calculate_gas_extend_memory, charge_gas, @@ -173,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -233,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -294,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -438,7 +434,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/london/vm/instructions/bitwise.py b/src/ethereum/forks/london/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/london/vm/instructions/bitwise.py +++ b/src/ethereum/forks/london/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/london/vm/instructions/comparison.py b/src/ethereum/forks/london/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/london/vm/instructions/comparison.py +++ b/src/ethereum/forks/london/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index c7018574c29..31b236e66ca 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index a77ca394884..9e720ab49c1 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -19,7 +19,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BALANCE, @@ -28,10 +28,6 @@ GAS_COPY, GAS_EXTERNAL, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, calculate_gas_extend_memory, charge_gas, @@ -173,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -233,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -294,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -438,7 +434,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/osaka/vm/instructions/bitwise.py b/src/ethereum/forks/osaka/vm/instructions/bitwise.py index 0614ff61fed..3cb188b8579 100644 --- a/src/ethereum/forks/osaka/vm/instructions/bitwise.py +++ b/src/ethereum/forks/osaka/vm/instructions/bitwise.py @@ -13,17 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_CLZ, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -45,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -70,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -95,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -119,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -145,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -180,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -210,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -240,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -273,7 +264,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CLZ) + charge_gas(evm, gas.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/osaka/vm/instructions/comparison.py b/src/ethereum/forks/osaka/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/osaka/vm/instructions/comparison.py +++ b/src/ethereum/forks/osaka/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/paris/vm/instructions/bitwise.py b/src/ethereum/forks/paris/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/paris/vm/instructions/bitwise.py +++ b/src/ethereum/forks/paris/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/paris/vm/instructions/comparison.py b/src/ethereum/forks/paris/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/paris/vm/instructions/comparison.py +++ b/src/ethereum/forks/paris/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 00e43488ea9..54bac51928d 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/prague/vm/instructions/bitwise.py b/src/ethereum/forks/prague/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/prague/vm/instructions/bitwise.py +++ b/src/ethereum/forks/prague/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/prague/vm/instructions/comparison.py b/src/ethereum/forks/prague/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/prague/vm/instructions/comparison.py +++ b/src/ethereum/forks/prague/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 7a2f15c7001..936297a73a6 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -20,7 +20,7 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, @@ -28,10 +28,6 @@ GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_blob_gas_price, @@ -179,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -239,7 +235,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -300,7 +296,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -457,7 +453,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 1e650339074..bccc5fd6f01 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -16,14 +16,10 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, GAS_COPY, - GAS_OPCODE_MCOPY, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -52,7 +48,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -83,7 +79,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -111,7 +107,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -171,7 +167,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py index 4e36a1a7959..4e0a487a749 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py +++ b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py @@ -13,16 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_SAR, - GAS_OPCODE_SHL, - GAS_OPCODE_SHR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -44,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -69,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -94,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -118,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -144,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -179,7 +171,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_SHL) + charge_gas(evm, gas.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -209,7 +201,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SHR) + charge_gas(evm, gas.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -239,7 +231,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SAR) + charge_gas(evm, gas.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/shanghai/vm/instructions/comparison.py b/src/ethereum/forks/shanghai/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/comparison.py +++ b/src/ethereum/forks/shanghai/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 00e43488ea9..54bac51928d 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -19,17 +19,13 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..exceptions import OutOfBoundsRead from ..gas import ( GAS_BASE, GAS_COLD_ACCOUNT_ACCESS, GAS_COPY, GAS_FAST_STEP, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, - GAS_OPCODE_RETURNDATACOPY, GAS_RETURN_DATA_COPY, GAS_WARM_ACCESS, calculate_gas_extend_memory, @@ -176,7 +172,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -236,7 +232,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -297,7 +293,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -454,7 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index a58e1e66e3f..3aaadbf69ab 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -71,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GAS_BASE) else: - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -101,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -133,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index f2c91716993..a4cc54062b5 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -18,15 +18,12 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +164,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +285,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index d74f7425823..e1bf43acdad 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -16,20 +16,10 @@ from ethereum.utils.numeric import get_sign -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_EXPONENTIATION, GAS_EXPONENTIATION_PER_BYTE, - GAS_OPCODE_ADD, - GAS_OPCODE_ADDMOD, - GAS_OPCODE_DIV, - GAS_OPCODE_MOD, - GAS_OPCODE_MUL, - GAS_OPCODE_MULMOD, - GAS_OPCODE_SDIV, - GAS_OPCODE_SIGNEXTEND, - GAS_OPCODE_SMOD, - GAS_OPCODE_SUB, charge_gas, ) from ..stack import pop, push @@ -51,7 +41,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ADD) + charge_gas(evm, gas.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -78,7 +68,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SUB) + charge_gas(evm, gas.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -105,7 +95,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MUL) + charge_gas(evm, gas.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -132,7 +122,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_DIV) + charge_gas(evm, gas.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -165,7 +155,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SDIV) + charge_gas(evm, gas.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -198,7 +188,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_MOD) + charge_gas(evm, gas.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -228,7 +218,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SMOD) + charge_gas(evm, gas.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -259,7 +249,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_ADDMOD) + charge_gas(evm, gas.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -290,7 +280,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_MULMOD) + charge_gas(evm, gas.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -353,7 +343,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py index cb37f6eca7d..476d71d7603 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py @@ -13,13 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_AND, - GAS_OPCODE_BYTE, - GAS_OPCODE_NOT, - GAS_OPCODE_OR, - GAS_OPCODE_XOR, charge_gas, ) from ..stack import pop, push @@ -41,7 +36,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_AND) + charge_gas(evm, gas.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -66,7 +61,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_OR) + charge_gas(evm, gas.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -91,7 +86,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_XOR) + charge_gas(evm, gas.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -115,7 +110,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_NOT) + charge_gas(evm, gas.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -141,7 +136,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_BYTE) + charge_gas(evm, gas.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py index f18a1f221e8..f30d048f94f 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py @@ -13,14 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( - GAS_OPCODE_EQ, - GAS_OPCODE_GT, - GAS_OPCODE_ISZERO, - GAS_OPCODE_LT, - GAS_OPCODE_SGT, - GAS_OPCODE_SLT, charge_gas, ) from ..stack import pop, push @@ -42,7 +36,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_LT) + charge_gas(evm, gas.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -68,7 +62,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SLT) + charge_gas(evm, gas.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -95,7 +89,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_GT) + charge_gas(evm, gas.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -121,7 +115,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GAS_OPCODE_SGT) + charge_gas(evm, gas.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -148,7 +142,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_EQ) + charge_gas(evm, gas.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -174,7 +168,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_ISZERO) + charge_gas(evm, gas.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index 3207f00d738..fabe929c4ce 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -13,11 +13,10 @@ from ethereum_types.numeric import U256, Uint +from ...vm import gas from ...vm.gas import ( GAS_BASE, GAS_JUMPDEST, - GAS_OPCODE_JUMP, - GAS_OPCODE_JUMPI, charge_gas, ) from .. import Evm @@ -63,7 +62,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_OPCODE_JUMP) + charge_gas(evm, gas.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -90,7 +89,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_JUMPI) + charge_gas(evm, gas.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index f2c91716993..a4cc54062b5 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -18,15 +18,12 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BALANCE, GAS_BASE, GAS_COPY, GAS_EXTERNAL, - GAS_OPCODE_CALLDATACOPY, - GAS_OPCODE_CALLDATALOAD, - GAS_OPCODE_CODECOPY, calculate_gas_extend_memory, charge_gas, ) @@ -167,7 +164,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +285,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index 74a9396629a..90b2f06a271 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -14,12 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm +from .. import Evm, gas from ..gas import ( GAS_BASE, - GAS_OPCODE_MLOAD, - GAS_OPCODE_MSTORE, - GAS_OPCODE_MSTORE8, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 4f1b8171e51..e102cc1a2c9 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -15,13 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, stack +from .. import Evm, gas, stack from ..exceptions import StackUnderflowError from ..gas import ( GAS_BASE, - GAS_OPCODE_DUP_N, - GAS_OPCODE_PUSH_N, - GAS_OPCODE_SWAP_N, charge_gas, ) from ..memory import buffer_read @@ -68,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_PUSH_N) + charge_gas(evm, gas.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP_N) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP_N) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( From 14e72c219945c295ad8b6b8b8529b13a45a43642 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 16 Mar 2026 22:39:20 -0400 Subject: [PATCH 07/61] refactor: correct GAS_OPCODE_DUP_N to GAS_OPCODE_DUP --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/stack.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- src/ethereum/forks/arrow_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/stack.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/stack.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/stack.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- src/ethereum/forks/constantinople/vm/instructions/stack.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/instructions/stack.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/instructions/stack.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- src/ethereum/forks/gray_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- src/ethereum/forks/homestead/vm/instructions/stack.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/stack.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/stack.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- src/ethereum/forks/muir_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/stack.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/stack.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/stack.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/stack.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- src/ethereum/forks/spurious_dragon/vm/instructions/stack.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/gas.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py | 2 +- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index a966ec193f2..b0ee4c2d568 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -195,7 +195,7 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_MSTORE=GAS_VERY_LOW, GAS_OPCODE_MSTORE8=GAS_VERY_LOW, GAS_OPCODE_PUSH_N=GAS_VERY_LOW, - GAS_OPCODE_DUP_N=GAS_VERY_LOW, + GAS_OPCODE_DUP=GAS_VERY_LOW, GAS_OPCODE_SWAP_N=GAS_VERY_LOW, ) @@ -436,7 +436,7 @@ def opcode_gas_map( }, # Dup operations (DUP1 through DUP16) **{ - getattr(Opcodes, f"DUP{i}"): gas_costs.GAS_OPCODE_DUP_N + getattr(Opcodes, f"DUP{i}"): gas_costs.GAS_OPCODE_DUP for i in range(1, 17) }, # Swap operations (SWAP1 through SWAP16) diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index fe206fdc84d..0352441e368 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -129,7 +129,7 @@ class GasCosts: GAS_OPCODE_MSTORE: int GAS_OPCODE_MSTORE8: int GAS_OPCODE_PUSH_N: int - GAS_OPCODE_DUP_N: int + GAS_OPCODE_DUP: int GAS_OPCODE_SWAP_N: int # Defined post-Frontier diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index c38ced2595f..6b03db939e2 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -124,7 +124,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 53f88a41363..b6b5c0029df 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -99,7 +99,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 2d54c75993c..2e629167f53 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 94a25483454..b8bd4939163 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index c4ec74aeabe..a55d00d105f 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index c4ec74aeabe..a55d00d105f 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index c4ec74aeabe..a55d00d105f 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index c4ec74aeabe..a55d00d105f 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index a62a1b4f05b..686270adf9a 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -96,7 +96,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index a3004b0eab9..7f653cfac59 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -110,7 +110,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 86aa9f2d4eb..ec1ea2b7af5 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 7ca04137dde..00213df49d6 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -94,7 +94,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 7ca04137dde..00213df49d6 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -94,7 +94,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 53f88a41363..b6b5c0029df 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -99,7 +99,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 7ca04137dde..00213df49d6 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -94,7 +94,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index e577426c407..34fdf447b82 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -102,7 +102,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 53f88a41363..b6b5c0029df 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -99,7 +99,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index e577426c407..34fdf447b82 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -102,7 +102,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 7be8b0ec959..b7482cf8a35 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -121,7 +121,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 53f88a41363..b6b5c0029df 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -99,7 +99,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index d57a2f0abea..17d7585639b 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -117,7 +117,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index c1d4f7408b6..00a2e5c5d52 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index 3aaadbf69ab..05dd6eacae3 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 26f7aa77539..32405056d64 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -94,7 +94,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 7d668fa5b55..5508075d3c5 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -94,7 +94,7 @@ GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP_N = GAS_VERY_LOW +GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP_N = GAS_VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index e102cc1a2c9..f10fa8e1e1f 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP_N) + charge_gas(evm, gas.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] From 26304a7281a1eda2c3702f38860051a4ef492dbe Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 16 Mar 2026 22:44:07 -0400 Subject: [PATCH 08/61] refactor: correct GAS_OPCODE_SWAP_N to GAS_OPCODE_SWAP --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/stack.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- src/ethereum/forks/arrow_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/stack.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/stack.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/stack.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- src/ethereum/forks/constantinople/vm/instructions/stack.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/instructions/stack.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/instructions/stack.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- src/ethereum/forks/gray_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- src/ethereum/forks/homestead/vm/instructions/stack.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/stack.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/stack.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- src/ethereum/forks/muir_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/stack.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/stack.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/stack.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/stack.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- src/ethereum/forks/spurious_dragon/vm/instructions/stack.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/gas.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py | 2 +- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index b0ee4c2d568..6f9e866a5ba 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -196,7 +196,7 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_MSTORE8=GAS_VERY_LOW, GAS_OPCODE_PUSH_N=GAS_VERY_LOW, GAS_OPCODE_DUP=GAS_VERY_LOW, - GAS_OPCODE_SWAP_N=GAS_VERY_LOW, + GAS_OPCODE_SWAP=GAS_VERY_LOW, ) @classmethod @@ -441,7 +441,7 @@ def opcode_gas_map( }, # Swap operations (SWAP1 through SWAP16) **{ - getattr(Opcodes, f"SWAP{i}"): gas_costs.GAS_OPCODE_SWAP_N + getattr(Opcodes, f"SWAP{i}"): gas_costs.GAS_OPCODE_SWAP for i in range(1, 17) }, # Logging operations diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 0352441e368..470a7846c17 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -130,7 +130,7 @@ class GasCosts: GAS_OPCODE_MSTORE8: int GAS_OPCODE_PUSH_N: int GAS_OPCODE_DUP: int - GAS_OPCODE_SWAP_N: int + GAS_OPCODE_SWAP: int # Defined post-Frontier GAS_OPCODE_SHL: int = 0 diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 6b03db939e2..e7c387e1228 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -125,7 +125,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index b6b5c0029df..704fd66ee56 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 2e629167f53..e63a930d561 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -101,7 +101,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index b8bd4939163..b550850c49e 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index a55d00d105f..79a1a915824 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index a55d00d105f..79a1a915824 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index a55d00d105f..79a1a915824 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index a55d00d105f..79a1a915824 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 686270adf9a..873e61f180a 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -97,7 +97,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 7f653cfac59..d8d27dc60e7 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -111,7 +111,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index ec1ea2b7af5..b4a6f4545d9 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -101,7 +101,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 00213df49d6..4a1a8ac9141 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -95,7 +95,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 00213df49d6..4a1a8ac9141 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -95,7 +95,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index b6b5c0029df..704fd66ee56 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 00213df49d6..4a1a8ac9141 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -95,7 +95,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 34fdf447b82..8a8b826083e 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -103,7 +103,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index b6b5c0029df..704fd66ee56 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 34fdf447b82..8a8b826083e 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -103,7 +103,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index b7482cf8a35..01835a9b0d2 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -122,7 +122,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index b6b5c0029df..704fd66ee56 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -100,7 +100,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 17d7585639b..986d95ae1d6 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -118,7 +118,7 @@ GAS_OPCODE_MCOPY = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 00a2e5c5d52..51c94dca9ea 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -101,7 +101,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index 05dd6eacae3..39a1682cb00 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 32405056d64..488341f3d93 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -95,7 +95,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 5508075d3c5..f2804e8e55b 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -95,7 +95,7 @@ GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_PUSH_N = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP_N = GAS_VERY_LOW +GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index f10fa8e1e1f..d875133ccb9 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP_N) + charge_gas(evm, gas.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( From ec3255d3be642786653208ce03102e296b55f356 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 16 Mar 2026 23:25:26 -0400 Subject: [PATCH 09/61] fix: static checks --- .../amsterdam/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/bpo1/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/bpo2/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/bpo3/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/bpo4/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/bpo5/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/cancun/vm/precompiled_contracts/point_evaluation.py | 4 ++-- .../forks/osaka/vm/precompiled_contracts/point_evaluation.py | 4 ++-- src/ethereum/forks/prague/vm/gas.py | 4 ++-- .../forks/prague/vm/precompiled_contracts/point_evaluation.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 986d95ae1d6..bf39df606f5 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -65,8 +65,8 @@ GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH_OPCODE = Uint(3) -GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000) +GAS_BLOBHASH = Uint(3) +GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(786432) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py index ce1d022d049..ce4eed71294 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_PRECOMPILE_POINT_EVALUATION, charge_gas +from ...vm.gas import GAS_POINT_EVALUATION, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_PRECOMPILE_POINT_EVALUATION) + charge_gas(evm, GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError From 82f1bcc4f9406e38be61452b815a5b50a0787ba8 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Thu, 19 Mar 2026 20:58:02 -0400 Subject: [PATCH 10/61] refactor: amsterdam conversion to encapsulate Gas Constants in class --- .../forks/amsterdam/block_access_lists.py | 6 +- src/ethereum/forks/amsterdam/fork.py | 5 +- .../forks/amsterdam/vm/eoa_delegation.py | 6 +- src/ethereum/forks/amsterdam/vm/gas.py | 238 +++++++++--------- .../amsterdam/vm/instructions/arithmetic.py | 29 +-- .../amsterdam/vm/instructions/bitwise.py | 21 +- .../forks/amsterdam/vm/instructions/block.py | 16 +- .../amsterdam/vm/instructions/comparison.py | 15 +- .../amsterdam/vm/instructions/control_flow.py | 14 +- .../amsterdam/vm/instructions/environment.py | 70 +++--- .../forks/amsterdam/vm/instructions/keccak.py | 9 +- .../forks/amsterdam/vm/instructions/log.py | 10 +- .../forks/amsterdam/vm/instructions/memory.py | 17 +- .../forks/amsterdam/vm/instructions/stack.py | 14 +- .../amsterdam/vm/instructions/storage.py | 42 ++-- .../forks/amsterdam/vm/instructions/system.py | 46 ++-- .../forks/amsterdam/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 26 files changed, 314 insertions(+), 309 deletions(-) diff --git a/src/ethereum/forks/amsterdam/block_access_lists.py b/src/ethereum/forks/amsterdam/block_access_lists.py index c6bcf176886..9ab04d492ca 100644 --- a/src/ethereum/forks/amsterdam/block_access_lists.py +++ b/src/ethereum/forks/amsterdam/block_access_lists.py @@ -744,7 +744,7 @@ def validate_block_access_list_gas_limit( The total number of items (addresses + unique storage keys) must not exceed ``block_gas_limit // GAS_BLOCK_ACCESS_LIST_ITEM``. """ - from .vm.gas import GAS_BLOCK_ACCESS_LIST_ITEM + from .vm.gas import GasCosts bal_items = Uint(0) for account in block_access_list: @@ -762,9 +762,9 @@ def validate_block_access_list_gas_limit( # Count each unique storage key as one item bal_items += Uint(len(unique_slots)) - if bal_items > block_gas_limit // GAS_BLOCK_ACCESS_LIST_ITEM: + if bal_items > block_gas_limit // GasCosts.GAS_BLOCK_ACCESS_LIST_ITEM: raise BlockAccessListGasLimitExceededError( f"Block access list exceeds gas limit, {bal_items} items " f"exceeds limit of " - f"{block_gas_limit // GAS_BLOCK_ACCESS_LIST_ITEM}." + f"{block_gas_limit // GasCosts.GAS_BLOCK_ACCESS_LIST_ITEM}." ) diff --git a/src/ethereum/forks/amsterdam/fork.py b/src/ethereum/forks/amsterdam/fork.py index c5dbc499c23..798ea7ddcf4 100644 --- a/src/ethereum/forks/amsterdam/fork.py +++ b/src/ethereum/forks/amsterdam/fork.py @@ -95,8 +95,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -114,7 +113,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" GWEI_TO_WEI = U256(10**9) diff --git a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py index 602afef3c1f..6c133b55a1e 100644 --- a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py +++ b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py @@ -21,7 +21,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -149,9 +149,9 @@ def calculate_delegation_cost( delegated_address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if delegated_address in evm.accessed_addresses: - delegation_gas_cost = GAS_WARM_ACCESS + delegation_gas_cost = GasCosts.GAS_WARM_ACCESS else: - delegation_gas_cost = GAS_COLD_ACCOUNT_ACCESS + delegation_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS return True, delegated_address, delegation_gas_cost diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index e7c387e1228..206d4fbe446 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -25,107 +25,115 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(14) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(21) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Amsterdam fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(14) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(21) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -216,7 +224,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -271,7 +279,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -343,7 +351,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas( @@ -376,21 +386,23 @@ def calculate_excess_blob_gas( base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -409,7 +421,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -430,9 +442,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py index 3cb188b8579..0e1612fed49 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/block.py b/src/ethereum/forks/amsterdam/vm/instructions/block.py index e563a2e96e8..04472d3c18d 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/block.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 3e2a9e053c8..780d406ed03 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state_tracker import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,7 +69,11 @@ def balance(evm: Evm) -> None: # GAS is_cold_access = address not in evm.accessed_addresses - gas_cost = GAS_COLD_ACCOUNT_ACCESS if is_cold_access else GAS_WARM_ACCESS + gas_cost = ( + GasCosts.GAS_COLD_ACCOUNT_ACCESS + if is_cold_access + else GasCosts.GAS_WARM_ACCESS + ) if is_cold_access: evm.accessed_addresses.add(address) @@ -107,7 +105,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -130,7 +128,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -153,7 +151,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -177,7 +175,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -202,7 +200,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -231,13 +229,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -263,7 +261,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -292,13 +290,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -324,7 +322,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -349,7 +347,9 @@ def extcodesize(evm: Evm) -> None: # GAS is_cold_access = address not in evm.accessed_addresses access_gas_cost = ( - GAS_COLD_ACCOUNT_ACCESS if is_cold_access else GAS_WARM_ACCESS + GasCosts.GAS_COLD_ACCOUNT_ACCESS + if is_cold_access + else GasCosts.GAS_WARM_ACCESS ) if is_cold_access: evm.accessed_addresses.add(address) @@ -386,14 +386,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) is_cold_access = address not in evm.accessed_addresses access_gas_cost = ( - GAS_COLD_ACCOUNT_ACCESS if is_cold_access else GAS_WARM_ACCESS + GasCosts.GAS_COLD_ACCOUNT_ACCESS + if is_cold_access + else GasCosts.GAS_WARM_ACCESS ) total_gas_cost = access_gas_cost + copy_gas_cost + extend_memory.cost @@ -429,7 +431,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -455,13 +457,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -492,7 +496,9 @@ def extcodehash(evm: Evm) -> None: # GAS is_cold_access = address not in evm.accessed_addresses access_gas_cost = ( - GAS_COLD_ACCOUNT_ACCESS if is_cold_access else GAS_WARM_ACCESS + GasCosts.GAS_COLD_ACCOUNT_ACCESS + if is_cold_access + else GasCosts.GAS_WARM_ACCESS ) if is_cold_access: evm.accessed_addresses.add(address) @@ -528,7 +534,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -556,7 +562,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -579,7 +585,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -606,7 +612,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/amsterdam/vm/instructions/log.py b/src/ethereum/forks/amsterdam/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/log.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/amsterdam/vm/instructions/storage.py b/src/ethereum/forks/amsterdam/vm/instructions/storage.py index 176b0d9a1c8..72632144772 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/storage.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, check_gas, ) @@ -51,10 +46,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION tx_state = evm.message.tx_env.state @@ -84,7 +79,7 @@ def sstore(evm: Evm) -> None: new_value = pop(evm.stack) # check we have at least the stipend gas - check_gas(evm, GAS_CALL_STIPEND + Uint(1)) + check_gas(evm, GasCosts.GAS_CALL_STIPEND + Uint(1)) tx_state = evm.message.tx_env.state original_value = get_storage_original( @@ -96,37 +91,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -151,7 +151,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -181,7 +181,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) set_transient_storage( evm.message.tx_env.state, evm.message.current_target, diff --git a/src/ethereum/forks/amsterdam/vm/instructions/system.py b/src/ethereum/forks/amsterdam/vm/instructions/system.py index 1660394e56d..e963b18259e 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/system.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/system.py @@ -43,15 +43,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -174,7 +166,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -224,8 +216,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -269,7 +261,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -387,11 +379,11 @@ def call(evm: Evm) -> None: is_cold_access = to not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS else: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE # check static gas before state access check_gas( @@ -404,7 +396,7 @@ def call(evm: Evm) -> None: if is_cold_access: evm.accessed_addresses.add(to) - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(tx_state, to): create_gas_cost = Uint(0) @@ -494,11 +486,11 @@ def callcode(evm: Evm) -> None: is_cold_access = code_address not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS else: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE # check static gas before state access check_gas( @@ -584,11 +576,11 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT is_cold_access = beneficiary not in evm.accessed_addresses if is_cold_access: - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS # check access gas cost before state access check_gas(evm, gas_cost) @@ -602,7 +594,7 @@ def selfdestruct(evm: Evm) -> None: not is_account_alive(tx_state, beneficiary) and get_account(tx_state, evm.message.current_target).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) @@ -656,9 +648,9 @@ def delegatecall(evm: Evm) -> None: is_cold_access = code_address not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS else: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS # check static gas before state access check_gas(evm, access_gas_cost + extend_memory.cost) @@ -746,9 +738,9 @@ def staticcall(evm: Evm) -> None: is_cold_access = to not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS else: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS # check static gas before state access check_gas(evm, access_gas_cost + extend_memory.cost) diff --git a/src/ethereum/forks/amsterdam/vm/interpreter.py b/src/ethereum/forks/amsterdam/vm/interpreter.py index c22f9eef143..bc7dce16baf 100644 --- a/src/ethereum/forks/amsterdam/vm/interpreter.py +++ b/src/ethereum/forks/amsterdam/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -201,7 +201,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 4e205e55a1e8b255414e07bc7ead854bbedefba4 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Thu, 19 Mar 2026 22:17:24 -0400 Subject: [PATCH 11/61] refactor: frontier conversion to encapsulate Gas Constants in class --- src/ethereum/forks/frontier/vm/gas.py | 163 +++++++++--------- .../frontier/vm/instructions/arithmetic.py | 29 ++-- .../forks/frontier/vm/instructions/bitwise.py | 13 +- .../forks/frontier/vm/instructions/block.py | 14 +- .../frontier/vm/instructions/comparison.py | 15 +- .../frontier/vm/instructions/control_flow.py | 14 +- .../frontier/vm/instructions/environment.py | 39 ++--- .../forks/frontier/vm/instructions/keccak.py | 9 +- .../forks/frontier/vm/instructions/log.py | 10 +- .../forks/frontier/vm/instructions/memory.py | 12 +- .../forks/frontier/vm/instructions/stack.py | 12 +- .../forks/frontier/vm/instructions/storage.py | 13 +- .../forks/frontier/vm/instructions/system.py | 12 +- src/ethereum/forks/frontier/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 18 files changed, 191 insertions(+), 193 deletions(-) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 4a1a8ac9141..399b15df309 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -24,78 +24,85 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(50) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(10) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(20) -GAS_BALANCE = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(40) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -REFUND_SELF_DESTRUCT = Uint(24000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Frontier fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(50) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(10) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(20) + GAS_BALANCE = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(40) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + REFUND_SELF_DESTRUCT = Uint(24000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -169,7 +176,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -240,8 +247,10 @@ def calculate_message_call_gas( message_call_gas: `MessageCallGas` """ - create_gas_cost = Uint(0) if account_exists(state, to) else GAS_NEW_ACCOUNT - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE - cost = GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GAS_CALL_STIPEND + gas + create_gas_cost = ( + Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + ) + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/frontier/vm/instructions/bitwise.py b/src/ethereum/forks/frontier/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/frontier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/frontier/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/frontier/vm/instructions/block.py b/src/ethereum/forks/frontier/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/frontier/vm/instructions/block.py +++ b/src/ethereum/forks/frontier/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/frontier/vm/instructions/comparison.py b/src/ethereum/forks/frontier/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/frontier/vm/instructions/comparison.py +++ b/src/ethereum/forks/frontier/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index a4cc54062b5..561f20f5479 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -18,12 +18,9 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -44,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -94,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -117,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -140,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -164,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -189,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -218,13 +215,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -250,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -279,13 +276,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -311,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -334,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -365,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/keccak.py b/src/ethereum/forks/frontier/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/frontier/vm/instructions/keccak.py +++ b/src/ethereum/forks/frontier/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/log.py b/src/ethereum/forks/frontier/vm/instructions/log.py index 76c02e737a4..703f0befa99 100644 --- a/src/ethereum/forks/frontier/vm/instructions/log.py +++ b/src/ethereum/forks/frontier/vm/instructions/log.py @@ -18,9 +18,7 @@ from ...blocks import Log from .. import Evm from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -58,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/frontier/vm/instructions/storage.py b/src/ethereum/forks/frontier/vm/instructions/storage.py index 154b4fd47bb..a69e1093b9a 100644 --- a/src/ethereum/forks/frontier/vm/instructions/storage.py +++ b/src/ethereum/forks/frontier/vm/instructions/storage.py @@ -16,10 +16,7 @@ from ...state import get_storage, set_storage from .. import Evm from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -40,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -71,12 +68,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/frontier/vm/instructions/system.py b/src/ethereum/forks/frontier/vm/instructions/system.py index 41c3b22d3e2..4e5d6ed1c6f 100644 --- a/src/ethereum/forks/frontier/vm/instructions/system.py +++ b/src/ethereum/forks/frontier/vm/instructions/system.py @@ -32,9 +32,7 @@ incorporate_child_on_success, ) from ..gas import ( - GAS_CREATE, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -67,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -155,7 +153,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -362,7 +360,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_ZERO + gas_cost = GasCosts.GAS_ZERO originator = evm.message.current_target @@ -373,7 +371,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += int(REFUND_SELF_DESTRUCT) + evm.refund_counter += int(GasCosts.REFUND_SELF_DESTRUCT) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/frontier/vm/interpreter.py b/src/ethereum/forks/frontier/vm/interpreter.py index 842207405fa..c4ebe520fbd 100644 --- a/src/ethereum/forks/frontier/vm/interpreter.py +++ b/src/ethereum/forks/frontier/vm/interpreter.py @@ -42,7 +42,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 49af68994dd610e29066b9ab46e53562d0215eef Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 00:01:05 -0400 Subject: [PATCH 12/61] refactor: berlin conversion to encapsulate Gas Constants in class --- src/ethereum/forks/berlin/vm/gas.py | 171 +++++++++--------- .../berlin/vm/instructions/arithmetic.py | 29 +-- .../forks/berlin/vm/instructions/bitwise.py | 19 +- .../forks/berlin/vm/instructions/block.py | 16 +- .../berlin/vm/instructions/comparison.py | 15 +- .../berlin/vm/instructions/control_flow.py | 14 +- .../berlin/vm/instructions/environment.py | 61 +++---- .../forks/berlin/vm/instructions/keccak.py | 10 +- .../forks/berlin/vm/instructions/log.py | 10 +- .../forks/berlin/vm/instructions/memory.py | 12 +- .../forks/berlin/vm/instructions/stack.py | 12 +- .../forks/berlin/vm/instructions/storage.py | 38 ++-- .../forks/berlin/vm/instructions/system.py | 49 ++--- src/ethereum/forks/berlin/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../berlin/vm/precompiled_contracts/sha256.py | 7 +- 19 files changed, 241 insertions(+), 248 deletions(-) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index e63a930d561..3185e4b20cb 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -22,86 +22,93 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Belrin fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -175,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -230,7 +237,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/berlin/vm/instructions/bitwise.py b/src/ethereum/forks/berlin/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/berlin/vm/instructions/bitwise.py +++ b/src/ethereum/forks/berlin/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/berlin/vm/instructions/block.py b/src/ethereum/forks/berlin/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/berlin/vm/instructions/block.py +++ b/src/ethereum/forks/berlin/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/berlin/vm/instructions/comparison.py b/src/ethereum/forks/berlin/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/berlin/vm/instructions/comparison.py +++ b/src/ethereum/forks/berlin/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index c2770cd8fa4..0295b509e23 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/berlin/vm/instructions/keccak.py b/src/ethereum/forks/berlin/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/berlin/vm/instructions/keccak.py +++ b/src/ethereum/forks/berlin/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/berlin/vm/instructions/log.py b/src/ethereum/forks/berlin/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/berlin/vm/instructions/log.py +++ b/src/ethereum/forks/berlin/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/berlin/vm/instructions/storage.py b/src/ethereum/forks/berlin/vm/instructions/storage.py index d99ad70f93b..95441af81fb 100644 --- a/src/ethereum/forks/berlin/vm/instructions/storage.py +++ b/src/ethereum/forks/berlin/vm/instructions/storage.py @@ -17,12 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -44,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +81,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/berlin/vm/instructions/system.py b/src/ethereum/forks/berlin/vm/instructions/system.py index 4320315d945..e3016bd084b 100644 --- a/src/ethereum/forks/berlin/vm/instructions/system.py +++ b/src/ethereum/forks/berlin/vm/instructions/system.py @@ -40,16 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -158,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -203,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -243,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -354,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -434,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -492,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -504,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -515,7 +506,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -582,10 +573,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -641,10 +632,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/berlin/vm/interpreter.py b/src/ethereum/forks/berlin/vm/interpreter.py index 6edd4cae8ca..bfea01bfc0b 100644 --- a/src/ethereum/forks/berlin/vm/interpreter.py +++ b/src/ethereum/forks/berlin/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From a6fc2333911e9e4b257a08b0be7e8ab95b76a0a9 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 00:06:30 -0400 Subject: [PATCH 13/61] refactor: byzantium conversion to encapsulate Gas Constants in class --- src/ethereum/forks/byzantium/vm/gas.py | 163 +++++++++--------- .../byzantium/vm/instructions/arithmetic.py | 29 ++-- .../byzantium/vm/instructions/bitwise.py | 13 +- .../forks/byzantium/vm/instructions/block.py | 14 +- .../byzantium/vm/instructions/comparison.py | 15 +- .../byzantium/vm/instructions/control_flow.py | 14 +- .../byzantium/vm/instructions/environment.py | 48 +++--- .../forks/byzantium/vm/instructions/keccak.py | 9 +- .../forks/byzantium/vm/instructions/log.py | 10 +- .../forks/byzantium/vm/instructions/memory.py | 12 +- .../forks/byzantium/vm/instructions/stack.py | 12 +- .../byzantium/vm/instructions/storage.py | 13 +- .../forks/byzantium/vm/instructions/system.py | 33 ++-- .../forks/byzantium/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 10 +- .../vm/precompiled_contracts/ripemd160.py | 10 +- .../vm/precompiled_contracts/sha256.py | 10 +- 18 files changed, 203 insertions(+), 220 deletions(-) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 873e61f180a..83da270810d 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -22,82 +22,89 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(200) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(400) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Byzantium fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(200) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(400) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -171,7 +178,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -226,7 +233,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py +++ b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/byzantium/vm/instructions/block.py b/src/ethereum/forks/byzantium/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/block.py +++ b/src/ethereum/forks/byzantium/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/byzantium/vm/instructions/comparison.py b/src/ethereum/forks/byzantium/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/comparison.py +++ b/src/ethereum/forks/byzantium/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 9221133e41c..ca0ec381a30 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -18,14 +18,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, - GAS_RETURN_DATA_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,7 +42,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,7 +65,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -96,7 +92,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -119,7 +115,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -142,7 +138,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -166,7 +162,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -191,7 +187,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -220,13 +216,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -252,7 +248,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -281,13 +277,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -313,7 +309,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -336,7 +332,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -367,11 +363,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -399,7 +395,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -425,13 +421,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/byzantium/vm/instructions/keccak.py b/src/ethereum/forks/byzantium/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/keccak.py +++ b/src/ethereum/forks/byzantium/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/log.py b/src/ethereum/forks/byzantium/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/log.py +++ b/src/ethereum/forks/byzantium/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/byzantium/vm/instructions/storage.py b/src/ethereum/forks/byzantium/vm/instructions/storage.py index e1c4e4e0958..3681791a28e 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/storage.py +++ b/src/ethereum/forks/byzantium/vm/instructions/storage.py @@ -17,10 +17,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -72,12 +69,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/byzantium/vm/instructions/system.py b/src/ethereum/forks/byzantium/vm/instructions/system.py index 9a4a7ce52ae..7529e3e3f9d 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/system.py +++ b/src/ethereum/forks/byzantium/vm/instructions/system.py @@ -35,14 +35,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -76,7 +69,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -170,7 +163,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -280,16 +273,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -351,13 +344,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -404,7 +397,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -412,7 +405,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -423,7 +416,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -488,7 +481,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -547,7 +540,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL, + GasCosts.GAS_CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/byzantium/vm/interpreter.py b/src/ethereum/forks/byzantium/vm/interpreter.py index 2cb1ccc3335..d6a84291844 100644 --- a/src/ethereum/forks/byzantium/vm/interpreter.py +++ b/src/ethereum/forks/byzantium/vm/interpreter.py @@ -44,7 +44,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py index 133a4832bf8..7dd737fa598 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py @@ -16,11 +16,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def identity(evm: Evm) -> None: @@ -39,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..321f1995757 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py @@ -19,11 +19,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def ripemd160(evm: Evm) -> None: @@ -42,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py index 04dfef6730d..a80c1b81972 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py @@ -18,11 +18,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def sha256(evm: Evm) -> None: @@ -41,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 0721da361a506f3726e4d099cba2777e83497ac6 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 12:47:58 -0400 Subject: [PATCH 14/61] refactor: cancun conversion to encapsulate Gas Constants in class --- src/ethereum/forks/cancun/vm/gas.py | 201 +++++++++--------- .../cancun/vm/instructions/arithmetic.py | 29 +-- .../forks/cancun/vm/instructions/bitwise.py | 19 +- .../forks/cancun/vm/instructions/block.py | 16 +- .../cancun/vm/instructions/comparison.py | 15 +- .../cancun/vm/instructions/control_flow.py | 14 +- .../cancun/vm/instructions/environment.py | 68 +++--- .../forks/cancun/vm/instructions/keccak.py | 10 +- .../forks/cancun/vm/instructions/log.py | 10 +- .../forks/cancun/vm/instructions/memory.py | 17 +- .../forks/cancun/vm/instructions/stack.py | 14 +- .../forks/cancun/vm/instructions/storage.py | 42 ++-- .../forks/cancun/vm/instructions/system.py | 46 ++-- src/ethereum/forks/cancun/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 10 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 10 +- .../cancun/vm/precompiled_contracts/sha256.py | 10 +- 20 files changed, 266 insertions(+), 281 deletions(-) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index d8d27dc60e7..0d8717dab2d 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -24,94 +24,101 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_TARGET_GAS_PER_BLOCK = U64(393216) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Cancun fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_TARGET_GAS_PER_BLOCK = U64(393216) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -185,7 +192,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -240,7 +247,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -312,7 +319,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -341,10 +350,10 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: blob_gas_used = parent_header.blob_gas_used parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -363,7 +372,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -384,9 +393,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/cancun/vm/instructions/bitwise.py b/src/ethereum/forks/cancun/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/cancun/vm/instructions/bitwise.py +++ b/src/ethereum/forks/cancun/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/cancun/vm/instructions/block.py b/src/ethereum/forks/cancun/vm/instructions/block.py index 4f971a9dbf4..a87cbbfb558 100644 --- a/src/ethereum/forks/cancun/vm/instructions/block.py +++ b/src/ethereum/forks/cancun/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/cancun/vm/instructions/comparison.py b/src/ethereum/forks/cancun/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/cancun/vm/instructions/comparison.py +++ b/src/ethereum/forks/cancun/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/cancun/vm/instructions/keccak.py b/src/ethereum/forks/cancun/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/cancun/vm/instructions/keccak.py +++ b/src/ethereum/forks/cancun/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/cancun/vm/instructions/log.py b/src/ethereum/forks/cancun/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/cancun/vm/instructions/log.py +++ b/src/ethereum/forks/cancun/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/cancun/vm/instructions/storage.py b/src/ethereum/forks/cancun/vm/instructions/storage.py index fd5bf4572ff..202917b6072 100644 --- a/src/ethereum/forks/cancun/vm/instructions/storage.py +++ b/src/ethereum/forks/cancun/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +149,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +176,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/cancun/vm/instructions/system.py b/src/ethereum/forks/cancun/vm/instructions/system.py index db725606a08..08921e03c95 100644 --- a/src/ethereum/forks/cancun/vm/instructions/system.py +++ b/src/ethereum/forks/cancun/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -165,7 +157,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -215,8 +207,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -260,7 +252,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -371,17 +363,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -451,12 +443,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -509,10 +501,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -521,7 +513,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -582,10 +574,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -641,10 +633,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/cancun/vm/interpreter.py b/src/ethereum/forks/cancun/vm/interpreter.py index 7f4bed0129c..a59f559ec07 100644 --- a/src/ethereum/forks/cancun/vm/interpreter.py +++ b/src/ethereum/forks/cancun/vm/interpreter.py @@ -43,7 +43,7 @@ set_code, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -171,7 +171,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py index 133a4832bf8..7dd737fa598 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py @@ -16,11 +16,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def identity(evm: Evm) -> None: @@ -39,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..321f1995757 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py @@ -19,11 +19,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def ripemd160(evm: Evm) -> None: @@ -42,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py index 04dfef6730d..a80c1b81972 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py @@ -18,11 +18,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def sha256(evm: Evm) -> None: @@ -41,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 5ed355d1c789d5281e345da07a8d04f3d0fdc499 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 21:55:04 -0400 Subject: [PATCH 15/61] refactor: constantinople conversion to encapsulate Gas Constants in class --- src/ethereum/forks/constantinople/vm/gas.py | 171 +++++++++--------- .../vm/instructions/arithmetic.py | 29 +-- .../constantinople/vm/instructions/bitwise.py | 19 +- .../constantinople/vm/instructions/block.py | 14 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 51 +++--- .../constantinople/vm/instructions/keccak.py | 9 +- .../constantinople/vm/instructions/log.py | 10 +- .../constantinople/vm/instructions/memory.py | 12 +- .../constantinople/vm/instructions/stack.py | 12 +- .../constantinople/vm/instructions/storage.py | 13 +- .../constantinople/vm/instructions/system.py | 38 ++-- .../forks/constantinople/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 18 files changed, 213 insertions(+), 223 deletions(-) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index b4a6f4545d9..28d89226d02 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -22,86 +22,93 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(200) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(400) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_CODE_HASH = Uint(400) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Constantinople fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(200) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(400) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_CODE_HASH = Uint(400) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -175,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -230,7 +237,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py +++ b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/constantinople/vm/instructions/block.py b/src/ethereum/forks/constantinople/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/block.py +++ b/src/ethereum/forks/constantinople/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/constantinople/vm/instructions/comparison.py b/src/ethereum/forks/constantinople/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/comparison.py +++ b/src/ethereum/forks/constantinople/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index bcd2195bfdf..d029d19b7fd 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_CODE_HASH, - GAS_COPY, - GAS_EXTERNAL, - GAS_RETURN_DATA_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -71,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -98,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -121,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -144,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -168,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -193,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -222,13 +217,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -254,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -283,13 +278,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -315,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -369,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -401,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -427,13 +422,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -462,7 +459,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_CODE_HASH) + charge_gas(evm, GasCosts.GAS_CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) diff --git a/src/ethereum/forks/constantinople/vm/instructions/keccak.py b/src/ethereum/forks/constantinople/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/keccak.py +++ b/src/ethereum/forks/constantinople/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/log.py b/src/ethereum/forks/constantinople/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/log.py +++ b/src/ethereum/forks/constantinople/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/constantinople/vm/instructions/storage.py b/src/ethereum/forks/constantinople/vm/instructions/storage.py index e1c4e4e0958..3681791a28e 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/storage.py +++ b/src/ethereum/forks/constantinople/vm/instructions/storage.py @@ -17,10 +17,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -72,12 +69,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index c251e65574d..800ab4afc7b 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -352,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -423,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -476,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -484,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -495,7 +487,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -561,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -620,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL, + GasCosts.GAS_CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/constantinople/vm/interpreter.py b/src/ethereum/forks/constantinople/vm/interpreter.py index b26937492a9..47e33b3498b 100644 --- a/src/ethereum/forks/constantinople/vm/interpreter.py +++ b/src/ethereum/forks/constantinople/vm/interpreter.py @@ -44,7 +44,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From e93dea37a1da3c4da93d93529a816686583911e2 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 22:27:47 -0400 Subject: [PATCH 16/61] refactor: fix bad spelling of Belrin (Berlin) --- src/ethereum/forks/berlin/vm/gas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 3185e4b20cb..b752d9b0bf2 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Belrin fork of the EVM. + Constant gas values for the Berlin fork of the EVM. These values may be patched at runtime by a future gas repricing utility """ From 4ba55451542b6cd1c5dfa08ab39aee862dd168c2 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 22:37:11 -0400 Subject: [PATCH 17/61] refactor: homestead and dao conversion to encapsulate Gas Constants in class --- src/ethereum/forks/dao_fork/vm/gas.py | 163 +++++++++--------- .../dao_fork/vm/instructions/arithmetic.py | 29 ++-- .../forks/dao_fork/vm/instructions/bitwise.py | 13 +- .../forks/dao_fork/vm/instructions/block.py | 14 +- .../dao_fork/vm/instructions/comparison.py | 15 +- .../dao_fork/vm/instructions/control_flow.py | 14 +- .../dao_fork/vm/instructions/environment.py | 39 ++--- .../forks/dao_fork/vm/instructions/keccak.py | 9 +- .../forks/dao_fork/vm/instructions/log.py | 10 +- .../forks/dao_fork/vm/instructions/memory.py | 12 +- .../forks/dao_fork/vm/instructions/stack.py | 12 +- .../forks/dao_fork/vm/instructions/storage.py | 13 +- .../forks/dao_fork/vm/instructions/system.py | 15 +- src/ethereum/forks/dao_fork/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- src/ethereum/forks/homestead/vm/gas.py | 163 +++++++++--------- .../homestead/vm/instructions/arithmetic.py | 29 ++-- .../homestead/vm/instructions/bitwise.py | 13 +- .../forks/homestead/vm/instructions/block.py | 14 +- .../homestead/vm/instructions/comparison.py | 15 +- .../homestead/vm/instructions/control_flow.py | 14 +- .../homestead/vm/instructions/environment.py | 39 ++--- .../forks/homestead/vm/instructions/keccak.py | 9 +- .../forks/homestead/vm/instructions/log.py | 10 +- .../forks/homestead/vm/instructions/memory.py | 12 +- .../forks/homestead/vm/instructions/stack.py | 12 +- .../homestead/vm/instructions/storage.py | 13 +- .../forks/homestead/vm/instructions/system.py | 15 +- .../forks/homestead/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 36 files changed, 384 insertions(+), 390 deletions(-) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 4a1a8ac9141..859f75b0b62 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -24,78 +24,85 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(50) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(10) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(20) -GAS_BALANCE = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(40) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -REFUND_SELF_DESTRUCT = Uint(24000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the DAO fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(50) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(10) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(20) + GAS_BALANCE = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(40) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + REFUND_SELF_DESTRUCT = Uint(24000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -169,7 +176,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -240,8 +247,10 @@ def calculate_message_call_gas( message_call_gas: `MessageCallGas` """ - create_gas_cost = Uint(0) if account_exists(state, to) else GAS_NEW_ACCOUNT - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE - cost = GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GAS_CALL_STIPEND + gas + create_gas_cost = ( + Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + ) + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/block.py b/src/ethereum/forks/dao_fork/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/block.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index a4cc54062b5..561f20f5479 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -18,12 +18,9 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -44,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -94,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -117,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -140,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -164,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -189,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -218,13 +215,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -250,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -279,13 +276,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -311,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -334,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -365,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/log.py b/src/ethereum/forks/dao_fork/vm/instructions/log.py index 76c02e737a4..703f0befa99 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/log.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/log.py @@ -18,9 +18,7 @@ from ...blocks import Log from .. import Evm from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -58,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/dao_fork/vm/instructions/storage.py b/src/ethereum/forks/dao_fork/vm/instructions/storage.py index 154b4fd47bb..a69e1093b9a 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/storage.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/storage.py @@ -16,10 +16,7 @@ from ...state import get_storage, set_storage from .. import Evm from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -40,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -71,12 +68,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/system.py b/src/ethereum/forks/dao_fork/vm/instructions/system.py index 75226650693..7c8138dd6c1 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/system.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/system.py @@ -32,10 +32,7 @@ incorporate_child_on_success, ) from ..gas import ( - GAS_CALL, - GAS_CREATE, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -68,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -157,7 +154,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -368,7 +365,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_ZERO + gas_cost = GasCosts.GAS_ZERO originator = evm.message.current_target @@ -379,7 +376,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += int(REFUND_SELF_DESTRUCT) + evm.refund_counter += int(GasCosts.REFUND_SELF_DESTRUCT) charge_gas(evm, gas_cost) @@ -438,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GAS_CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CALL + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/interpreter.py b/src/ethereum/forks/dao_fork/vm/interpreter.py index 4d26439da49..f4477057e12 100644 --- a/src/ethereum/forks/dao_fork/vm/interpreter.py +++ b/src/ethereum/forks/dao_fork/vm/interpreter.py @@ -42,7 +42,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 4a1a8ac9141..51adbf8d77b 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -24,78 +24,85 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(50) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(10) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(20) -GAS_BALANCE = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(40) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -REFUND_SELF_DESTRUCT = Uint(24000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Homestead fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(50) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(10) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(20) + GAS_BALANCE = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(40) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + REFUND_SELF_DESTRUCT = Uint(24000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -169,7 +176,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -240,8 +247,10 @@ def calculate_message_call_gas( message_call_gas: `MessageCallGas` """ - create_gas_cost = Uint(0) if account_exists(state, to) else GAS_NEW_ACCOUNT - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE - cost = GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GAS_CALL_STIPEND + gas + create_gas_cost = ( + Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + ) + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/homestead/vm/instructions/bitwise.py b/src/ethereum/forks/homestead/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/homestead/vm/instructions/bitwise.py +++ b/src/ethereum/forks/homestead/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/homestead/vm/instructions/block.py b/src/ethereum/forks/homestead/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/homestead/vm/instructions/block.py +++ b/src/ethereum/forks/homestead/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/homestead/vm/instructions/comparison.py b/src/ethereum/forks/homestead/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/homestead/vm/instructions/comparison.py +++ b/src/ethereum/forks/homestead/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index a4cc54062b5..561f20f5479 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -18,12 +18,9 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -44,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -94,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -117,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -140,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -164,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -189,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -218,13 +215,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -250,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -279,13 +276,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -311,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -334,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -365,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/keccak.py b/src/ethereum/forks/homestead/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/homestead/vm/instructions/keccak.py +++ b/src/ethereum/forks/homestead/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/log.py b/src/ethereum/forks/homestead/vm/instructions/log.py index 76c02e737a4..703f0befa99 100644 --- a/src/ethereum/forks/homestead/vm/instructions/log.py +++ b/src/ethereum/forks/homestead/vm/instructions/log.py @@ -18,9 +18,7 @@ from ...blocks import Log from .. import Evm from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -58,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/homestead/vm/instructions/storage.py b/src/ethereum/forks/homestead/vm/instructions/storage.py index 154b4fd47bb..a69e1093b9a 100644 --- a/src/ethereum/forks/homestead/vm/instructions/storage.py +++ b/src/ethereum/forks/homestead/vm/instructions/storage.py @@ -16,10 +16,7 @@ from ...state import get_storage, set_storage from .. import Evm from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -40,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -71,12 +68,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/homestead/vm/instructions/system.py b/src/ethereum/forks/homestead/vm/instructions/system.py index 75226650693..7c8138dd6c1 100644 --- a/src/ethereum/forks/homestead/vm/instructions/system.py +++ b/src/ethereum/forks/homestead/vm/instructions/system.py @@ -32,10 +32,7 @@ incorporate_child_on_success, ) from ..gas import ( - GAS_CALL, - GAS_CREATE, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -68,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -157,7 +154,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -368,7 +365,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_ZERO + gas_cost = GasCosts.GAS_ZERO originator = evm.message.current_target @@ -379,7 +376,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += int(REFUND_SELF_DESTRUCT) + evm.refund_counter += int(GasCosts.REFUND_SELF_DESTRUCT) charge_gas(evm, gas_cost) @@ -438,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GAS_CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CALL + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/interpreter.py b/src/ethereum/forks/homestead/vm/interpreter.py index 47530fcf783..fddc1d03c66 100644 --- a/src/ethereum/forks/homestead/vm/interpreter.py +++ b/src/ethereum/forks/homestead/vm/interpreter.py @@ -42,7 +42,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 7a4f16b7779fb5bfb8408e1bb82d6abb99ad7b29 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 22:53:32 -0400 Subject: [PATCH 18/61] refactor: tangerine_whistle conversion to encapsulate Gas Constants in class --- .../forks/tangerine_whistle/vm/gas.py | 159 +++++++++--------- .../vm/instructions/arithmetic.py | 29 ++-- .../vm/instructions/bitwise.py | 13 +- .../vm/instructions/block.py | 14 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 39 ++--- .../vm/instructions/keccak.py | 9 +- .../tangerine_whistle/vm/instructions/log.py | 10 +- .../vm/instructions/memory.py | 12 +- .../vm/instructions/stack.py | 12 +- .../vm/instructions/storage.py | 13 +- .../vm/instructions/system.py | 31 ++-- .../forks/tangerine_whistle/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 18 files changed, 195 insertions(+), 204 deletions(-) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index f2804e8e55b..a7dbe8ae9ad 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -22,80 +22,87 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(200) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(10) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(400) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Tangerine Whistle fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(200) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(10) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(400) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -169,7 +176,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -224,7 +231,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index a4cc54062b5..561f20f5479 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -18,12 +18,9 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -44,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -94,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -117,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -140,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -164,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -189,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -218,13 +215,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -250,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -279,13 +276,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -311,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -334,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -365,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py index 76c02e737a4..703f0befa99 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py @@ -18,9 +18,7 @@ from ...blocks import Log from .. import Evm from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -58,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py index 154b4fd47bb..a69e1093b9a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py @@ -16,10 +16,7 @@ from ...state import get_storage, set_storage from .. import Evm from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -40,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -71,12 +68,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py index 50a359402b1..4a9801fcb43 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py @@ -33,14 +33,7 @@ incorporate_child_on_success, ) from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -74,7 +67,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -163,7 +156,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -268,14 +261,14 @@ def call(evm: Evm) -> None: code_address = to _account_exists = account_exists(evm.message.block_env.state, to) - create_gas_cost = Uint(0) if _account_exists else GAS_NEW_ACCOUNT - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + create_gas_cost = Uint(0) if _account_exists else GasCosts.GAS_NEW_ACCOUNT + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -335,13 +328,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -386,9 +379,9 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if not account_exists(evm.message.block_env.state, beneficiary): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -399,7 +392,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) @@ -459,7 +452,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py index e6e7c7729c4..a8ace8b373a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py +++ b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py @@ -42,7 +42,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From f47f46fb75996ccbf6b26dba85c245dbb44546ff Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 22:55:54 -0400 Subject: [PATCH 19/61] refactor: spurious_dragon conversion to encapsulate Gas Constants in class --- src/ethereum/forks/spurious_dragon/vm/gas.py | 159 +++++++++--------- .../vm/instructions/arithmetic.py | 29 ++-- .../vm/instructions/bitwise.py | 13 +- .../spurious_dragon/vm/instructions/block.py | 14 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 39 ++--- .../spurious_dragon/vm/instructions/keccak.py | 9 +- .../spurious_dragon/vm/instructions/log.py | 10 +- .../spurious_dragon/vm/instructions/memory.py | 12 +- .../spurious_dragon/vm/instructions/stack.py | 12 +- .../vm/instructions/storage.py | 13 +- .../spurious_dragon/vm/instructions/system.py | 31 ++-- .../forks/spurious_dragon/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 18 files changed, 195 insertions(+), 204 deletions(-) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 488341f3d93..fb83683f41f 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -22,80 +22,87 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(200) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(400) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Spurious Dragon fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(200) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(400) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -169,7 +176,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -224,7 +231,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py index 476d71d7603..963889d27ea 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py index 0edcbf000d1..ba253fb16dc 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index a4cc54062b5..561f20f5479 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -18,12 +18,9 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_COPY, - GAS_EXTERNAL, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -44,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -94,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -117,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -140,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -164,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -189,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -218,13 +215,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -250,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -279,13 +276,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -311,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -334,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -365,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py index 76c02e737a4..703f0befa99 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py @@ -18,9 +18,7 @@ from ...blocks import Log from .. import Evm from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -58,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py b/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py index 154b4fd47bb..a69e1093b9a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py @@ -16,10 +16,7 @@ from ...state import get_storage, set_storage from .. import Evm from ..gas import ( - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -40,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -71,12 +68,12 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py index e35d7a5a7c7..fdc828dc94d 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py @@ -34,14 +34,7 @@ incorporate_child_on_success, ) from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -75,7 +68,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -164,7 +157,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -268,16 +261,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -337,13 +330,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -388,7 +381,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -396,7 +389,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -407,7 +400,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) @@ -470,7 +463,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/spurious_dragon/vm/interpreter.py b/src/ethereum/forks/spurious_dragon/vm/interpreter.py index e65ffc2020a..e7509cd215c 100644 --- a/src/ethereum/forks/spurious_dragon/vm/interpreter.py +++ b/src/ethereum/forks/spurious_dragon/vm/interpreter.py @@ -44,7 +44,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -173,7 +173,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From f0bb6963465dfce640df001add443e31054a8d03 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 23:03:42 -0400 Subject: [PATCH 20/61] refactor: istanbul and muir glacier conversion to encapsulate Gas Constants in class --- src/ethereum/forks/istanbul/vm/gas.py | 175 +++++++++--------- .../istanbul/vm/instructions/arithmetic.py | 29 +-- .../forks/istanbul/vm/instructions/bitwise.py | 19 +- .../forks/istanbul/vm/instructions/block.py | 16 +- .../istanbul/vm/instructions/comparison.py | 15 +- .../istanbul/vm/instructions/control_flow.py | 14 +- .../istanbul/vm/instructions/environment.py | 54 +++--- .../forks/istanbul/vm/instructions/keccak.py | 10 +- .../forks/istanbul/vm/instructions/log.py | 10 +- .../forks/istanbul/vm/instructions/memory.py | 12 +- .../forks/istanbul/vm/instructions/stack.py | 12 +- .../forks/istanbul/vm/instructions/storage.py | 28 +-- .../forks/istanbul/vm/instructions/system.py | 38 ++-- src/ethereum/forks/istanbul/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- src/ethereum/forks/muir_glacier/vm/gas.py | 175 +++++++++--------- .../vm/instructions/arithmetic.py | 29 +-- .../muir_glacier/vm/instructions/bitwise.py | 19 +- .../muir_glacier/vm/instructions/block.py | 16 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 54 +++--- .../muir_glacier/vm/instructions/keccak.py | 9 +- .../forks/muir_glacier/vm/instructions/log.py | 10 +- .../muir_glacier/vm/instructions/memory.py | 12 +- .../muir_glacier/vm/instructions/stack.py | 12 +- .../muir_glacier/vm/instructions/storage.py | 28 +-- .../muir_glacier/vm/instructions/system.py | 38 ++-- .../forks/muir_glacier/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- 38 files changed, 457 insertions(+), 472 deletions(-) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 8a8b826083e..7fd65c90e57 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -22,88 +22,95 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(800) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(700) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_CODE_HASH = Uint(700) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Istanbul fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(800) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(700) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_CODE_HASH = Uint(700) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -177,7 +184,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -232,7 +239,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py +++ b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/istanbul/vm/instructions/block.py b/src/ethereum/forks/istanbul/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/block.py +++ b/src/ethereum/forks/istanbul/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/istanbul/vm/instructions/comparison.py b/src/ethereum/forks/istanbul/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/comparison.py +++ b/src/ethereum/forks/istanbul/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 9e720ab49c1..92ac93dad4b 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -19,16 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_CODE_HASH, - GAS_COPY, - GAS_EXTERNAL, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -169,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -194,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,13 +217,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -255,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,13 +278,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -316,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -339,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -370,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -402,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -428,13 +422,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -463,7 +459,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_CODE_HASH) + charge_gas(evm, GasCosts.GAS_CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -493,7 +489,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/istanbul/vm/instructions/keccak.py b/src/ethereum/forks/istanbul/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/keccak.py +++ b/src/ethereum/forks/istanbul/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/instructions/log.py b/src/ethereum/forks/istanbul/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/log.py +++ b/src/ethereum/forks/istanbul/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/istanbul/vm/instructions/storage.py b/src/ethereum/forks/istanbul/vm/instructions/storage.py index 99beae61e52..e2ca9719c0d 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/storage.py +++ b/src/ethereum/forks/istanbul/vm/instructions/storage.py @@ -17,11 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -42,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -68,7 +64,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -79,30 +75,34 @@ def sstore(evm: Evm) -> None: if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE else: - gas_cost = GAS_SLOAD + gas_cost = GasCosts.GAS_SLOAD # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_SLOAD) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_SLOAD + ) else: # Slot was originally non-empty and was UPDATED earlier - evm.refund_counter += int(GAS_COLD_STORAGE_WRITE - GAS_SLOAD) + evm.refund_counter += int( + GasCosts.GAS_COLD_STORAGE_WRITE - GasCosts.GAS_SLOAD + ) charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index a0b00f24d1e..5573c65cd4c 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -352,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -423,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -476,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -484,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -495,7 +487,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -561,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -620,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL, + GasCosts.GAS_CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/istanbul/vm/interpreter.py b/src/ethereum/forks/istanbul/vm/interpreter.py index 7a92f7471f3..549b340dfa9 100644 --- a/src/ethereum/forks/istanbul/vm/interpreter.py +++ b/src/ethereum/forks/istanbul/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 8a8b826083e..db810c00e94 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -22,88 +22,95 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_SLOAD = Uint(800) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 15000 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_EXTERNAL = Uint(700) -GAS_BALANCE = Uint(700) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_CALL = Uint(700) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -REFUND_SELF_DESTRUCT = 24000 -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_CODE_HASH = Uint(700) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Muir Glacier fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_SLOAD = Uint(800) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 15000 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_EXTERNAL = Uint(700) + GAS_BALANCE = Uint(700) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_CALL = Uint(700) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + REFUND_SELF_DESTRUCT = 24000 + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_CODE_HASH = Uint(700) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -177,7 +184,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -232,7 +239,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/block.py b/src/ethereum/forks/muir_glacier/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 9e720ab49c1..92ac93dad4b 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -19,16 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BALANCE, - GAS_BASE, - GAS_CODE_HASH, - GAS_COPY, - GAS_EXTERNAL, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -49,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BALANCE) + charge_gas(evm, GasCosts.GAS_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -169,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -194,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,13 +217,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -255,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,13 +278,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -316,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -339,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_EXTERNAL) + charge_gas(evm, GasCosts.GAS_EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -370,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -402,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -428,13 +422,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -463,7 +459,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GAS_CODE_HASH) + charge_gas(evm, GasCosts.GAS_CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -493,7 +489,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py index 8661c5d62f5..d863b8ebc74 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/log.py b/src/ethereum/forks/muir_glacier/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/storage.py b/src/ethereum/forks/muir_glacier/vm/instructions/storage.py index 99beae61e52..e2ca9719c0d 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/storage.py @@ -17,11 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_WRITE, - GAS_SLOAD, - GAS_STORAGE_SET, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -42,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_SLOAD) + charge_gas(evm, GasCosts.GAS_SLOAD) # OPERATION value = get_storage( @@ -68,7 +64,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -79,30 +75,34 @@ def sstore(evm: Evm) -> None: if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost = GAS_STORAGE_SET + gas_cost = GasCosts.GAS_STORAGE_SET else: - gas_cost = GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE else: - gas_cost = GAS_SLOAD + gas_cost = GasCosts.GAS_SLOAD # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_SLOAD) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_SLOAD + ) else: # Slot was originally non-empty and was UPDATED earlier - evm.refund_counter += int(GAS_COLD_STORAGE_WRITE - GAS_SLOAD) + evm.refund_counter += int( + GasCosts.GAS_COLD_STORAGE_WRITE - GasCosts.GAS_SLOAD + ) charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index a0b00f24d1e..5573c65cd4c 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL, - GAS_CALL_VALUE, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_ZERO, - REFUND_SELF_DESTRUCT, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -352,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -423,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL + transfer_gas_cost, + GasCosts.GAS_CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -476,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -484,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -495,7 +487,7 @@ def selfdestruct(evm: Evm) -> None: parent_evm = parent_evm.message.parent_evm if originator not in refunded_accounts: - evm.refund_counter += REFUND_SELF_DESTRUCT + evm.refund_counter += GasCosts.REFUND_SELF_DESTRUCT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -561,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -620,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GAS_CALL, + GasCosts.GAS_CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/muir_glacier/vm/interpreter.py b/src/ethereum/forks/muir_glacier/vm/interpreter.py index e4f53153ce9..12d010dd3c1 100644 --- a/src/ethereum/forks/muir_glacier/vm/interpreter.py +++ b/src/ethereum/forks/muir_glacier/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 7f29c077b4274fca19fb283b9217d79ff777a357 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 20 Mar 2026 23:25:22 -0400 Subject: [PATCH 21/61] refactor: london, arrow glacier, and muir glacier conversion to encapsulate Gas Constants in class --- src/ethereum/forks/arrow_glacier/vm/gas.py | 173 +++++++++--------- .../vm/instructions/arithmetic.py | 29 +-- .../arrow_glacier/vm/instructions/bitwise.py | 19 +- .../arrow_glacier/vm/instructions/block.py | 16 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 63 +++---- .../arrow_glacier/vm/instructions/keccak.py | 10 +- .../arrow_glacier/vm/instructions/log.py | 10 +- .../arrow_glacier/vm/instructions/memory.py | 12 +- .../arrow_glacier/vm/instructions/stack.py | 12 +- .../arrow_glacier/vm/instructions/storage.py | 38 ++-- .../arrow_glacier/vm/instructions/system.py | 52 +++--- .../forks/arrow_glacier/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 7 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- src/ethereum/forks/gray_glacier/vm/gas.py | 169 +++++++++-------- .../vm/instructions/arithmetic.py | 29 +-- .../gray_glacier/vm/instructions/bitwise.py | 19 +- .../gray_glacier/vm/instructions/block.py | 16 +- .../vm/instructions/comparison.py | 15 +- .../vm/instructions/control_flow.py | 14 +- .../vm/instructions/environment.py | 63 +++---- .../gray_glacier/vm/instructions/keccak.py | 10 +- .../forks/gray_glacier/vm/instructions/log.py | 10 +- .../gray_glacier/vm/instructions/memory.py | 12 +- .../gray_glacier/vm/instructions/stack.py | 12 +- .../gray_glacier/vm/instructions/storage.py | 38 ++-- .../gray_glacier/vm/instructions/system.py | 46 ++--- .../forks/gray_glacier/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../vm/precompiled_contracts/sha256.py | 7 +- src/ethereum/forks/london/vm/gas.py | 169 +++++++++-------- .../london/vm/instructions/arithmetic.py | 29 +-- .../forks/london/vm/instructions/bitwise.py | 19 +- .../forks/london/vm/instructions/block.py | 16 +- .../london/vm/instructions/comparison.py | 15 +- .../london/vm/instructions/control_flow.py | 14 +- .../london/vm/instructions/environment.py | 63 +++---- .../forks/london/vm/instructions/keccak.py | 10 +- .../forks/london/vm/instructions/log.py | 10 +- .../forks/london/vm/instructions/memory.py | 12 +- .../forks/london/vm/instructions/stack.py | 12 +- .../forks/london/vm/instructions/storage.py | 38 ++-- .../forks/london/vm/instructions/system.py | 46 ++--- src/ethereum/forks/london/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../london/vm/precompiled_contracts/sha256.py | 7 +- 57 files changed, 730 insertions(+), 741 deletions(-) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 704fd66ee56..d0dbf109b4b 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -22,85 +22,92 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Arrow Glacier fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -121,8 +128,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes @@ -174,7 +181,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -229,7 +236,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 31b236e66ca..d80dada24b4 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -543,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py b/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py index d99ad70f93b..95441af81fb 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py @@ -17,12 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -44,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +81,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py index b48d2498ac3..e7531eb1753 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -353,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -433,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -491,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -503,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -570,13 +562,17 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + access_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -629,10 +625,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/arrow_glacier/vm/interpreter.py b/src/ethereum/forks/arrow_glacier/vm/interpreter.py index 20d8c31f1e3..2ea4800c076 100644 --- a/src/ethereum/forks/arrow_glacier/vm/interpreter.py +++ b/src/ethereum/forks/arrow_glacier/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..d7b8c44cb62 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,10 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas( + evm, + GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds, + ) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 704fd66ee56..b4fdd58ea2a 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -22,85 +22,92 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Gray Glacier fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -174,7 +181,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -229,7 +236,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/block.py b/src/ethereum/forks/gray_glacier/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 31b236e66ca..d80dada24b4 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -543,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/log.py b/src/ethereum/forks/gray_glacier/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/storage.py b/src/ethereum/forks/gray_glacier/vm/instructions/storage.py index d99ad70f93b..95441af81fb 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/storage.py @@ -17,12 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -44,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +81,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/system.py b/src/ethereum/forks/gray_glacier/vm/instructions/system.py index b48d2498ac3..e55660ac978 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -353,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -433,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -491,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -503,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -570,10 +562,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -629,10 +621,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/gray_glacier/vm/interpreter.py b/src/ethereum/forks/gray_glacier/vm/interpreter.py index 1135be95939..544b5bb142c 100644 --- a/src/ethereum/forks/gray_glacier/vm/interpreter.py +++ b/src/ethereum/forks/gray_glacier/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 704fd66ee56..73b65ebe639 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -22,85 +22,92 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the London fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -174,7 +181,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -229,7 +236,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/london/vm/instructions/bitwise.py b/src/ethereum/forks/london/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/london/vm/instructions/bitwise.py +++ b/src/ethereum/forks/london/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/london/vm/instructions/block.py b/src/ethereum/forks/london/vm/instructions/block.py index bbf01739ff2..516fcd7a727 100644 --- a/src/ethereum/forks/london/vm/instructions/block.py +++ b/src/ethereum/forks/london/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/london/vm/instructions/comparison.py b/src/ethereum/forks/london/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/london/vm/instructions/comparison.py +++ b/src/ethereum/forks/london/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 31b236e66ca..d80dada24b4 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -543,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/london/vm/instructions/keccak.py b/src/ethereum/forks/london/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/london/vm/instructions/keccak.py +++ b/src/ethereum/forks/london/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/london/vm/instructions/log.py b/src/ethereum/forks/london/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/london/vm/instructions/log.py +++ b/src/ethereum/forks/london/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/london/vm/instructions/storage.py b/src/ethereum/forks/london/vm/instructions/storage.py index d99ad70f93b..95441af81fb 100644 --- a/src/ethereum/forks/london/vm/instructions/storage.py +++ b/src/ethereum/forks/london/vm/instructions/storage.py @@ -17,12 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -44,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +81,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/london/vm/instructions/system.py b/src/ethereum/forks/london/vm/instructions/system.py index b48d2498ac3..e55660ac978 100644 --- a/src/ethereum/forks/london/vm/instructions/system.py +++ b/src/ethereum/forks/london/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -157,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -202,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -242,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -353,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -433,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -491,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -503,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -570,10 +562,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -629,10 +621,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/london/vm/interpreter.py b/src/ethereum/forks/london/vm/interpreter.py index b49ca7be07f..0262ba5c3de 100644 --- a/src/ethereum/forks/london/vm/interpreter.py +++ b/src/ethereum/forks/london/vm/interpreter.py @@ -45,7 +45,7 @@ touch_account, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 77228d2ed0dd735de96cf5606832bd30029a33ac Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:22:14 -0400 Subject: [PATCH 22/61] refactor: paris conversion to encapsulate Gas Constants in class --- src/ethereum/forks/paris/vm/gas.py | 169 +++++++++--------- .../forks/paris/vm/instructions/arithmetic.py | 29 +-- .../forks/paris/vm/instructions/bitwise.py | 19 +- .../forks/paris/vm/instructions/block.py | 16 +- .../forks/paris/vm/instructions/comparison.py | 15 +- .../paris/vm/instructions/control_flow.py | 14 +- .../paris/vm/instructions/environment.py | 63 ++++--- .../forks/paris/vm/instructions/keccak.py | 10 +- .../forks/paris/vm/instructions/log.py | 10 +- .../forks/paris/vm/instructions/memory.py | 12 +- .../forks/paris/vm/instructions/stack.py | 12 +- .../forks/paris/vm/instructions/storage.py | 38 ++-- .../forks/paris/vm/instructions/system.py | 46 ++--- src/ethereum/forks/paris/vm/interpreter.py | 4 +- .../paris/vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../paris/vm/precompiled_contracts/sha256.py | 7 +- 19 files changed, 240 insertions(+), 246 deletions(-) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 704fd66ee56..86a0ee92ca1 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -22,85 +22,92 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Paris fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -174,7 +181,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -229,7 +236,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/paris/vm/instructions/bitwise.py b/src/ethereum/forks/paris/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/paris/vm/instructions/bitwise.py +++ b/src/ethereum/forks/paris/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/paris/vm/instructions/block.py b/src/ethereum/forks/paris/vm/instructions/block.py index 3aa1fb2f6b6..88f0b3a55a7 100644 --- a/src/ethereum/forks/paris/vm/instructions/block.py +++ b/src/ethereum/forks/paris/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/paris/vm/instructions/comparison.py b/src/ethereum/forks/paris/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/paris/vm/instructions/comparison.py +++ b/src/ethereum/forks/paris/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 54bac51928d..972e1f87098 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -543,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/paris/vm/instructions/keccak.py b/src/ethereum/forks/paris/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/paris/vm/instructions/keccak.py +++ b/src/ethereum/forks/paris/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/paris/vm/instructions/log.py b/src/ethereum/forks/paris/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/paris/vm/instructions/log.py +++ b/src/ethereum/forks/paris/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index d875133ccb9..98a9816abc3 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/paris/vm/instructions/storage.py b/src/ethereum/forks/paris/vm/instructions/storage.py index d99ad70f93b..95441af81fb 100644 --- a/src/ethereum/forks/paris/vm/instructions/storage.py +++ b/src/ethereum/forks/paris/vm/instructions/storage.py @@ -17,12 +17,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -44,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +81,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/paris/vm/instructions/system.py b/src/ethereum/forks/paris/vm/instructions/system.py index 2e9a8766a1e..a4e1d9365a6 100644 --- a/src/ethereum/forks/paris/vm/instructions/system.py +++ b/src/ethereum/forks/paris/vm/instructions/system.py @@ -39,15 +39,7 @@ ) from ..exceptions import Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -156,7 +148,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -201,8 +193,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -241,7 +233,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -352,17 +344,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -432,12 +424,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -490,10 +482,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -502,7 +494,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -565,10 +557,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -624,10 +616,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/paris/vm/interpreter.py b/src/ethereum/forks/paris/vm/interpreter.py index 92af867690a..8b3d9c4c35f 100644 --- a/src/ethereum/forks/paris/vm/interpreter.py +++ b/src/ethereum/forks/paris/vm/interpreter.py @@ -43,7 +43,7 @@ set_code, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -167,7 +167,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From e82d4aea60373aa4de3e8f66af28540abadff369 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:27:07 -0400 Subject: [PATCH 23/61] refactor: shanghai conversion to encapsulate Gas Constants in class --- src/ethereum/forks/shanghai/vm/gas.py | 175 +++++++++--------- .../shanghai/vm/instructions/arithmetic.py | 32 ++-- .../forks/shanghai/vm/instructions/bitwise.py | 22 +-- .../forks/shanghai/vm/instructions/block.py | 16 +- .../shanghai/vm/instructions/comparison.py | 18 +- .../shanghai/vm/instructions/control_flow.py | 17 +- .../shanghai/vm/instructions/environment.py | 63 +++---- .../forks/shanghai/vm/instructions/keccak.py | 10 +- .../forks/shanghai/vm/instructions/log.py | 10 +- .../forks/shanghai/vm/instructions/memory.py | 12 +- .../forks/shanghai/vm/instructions/stack.py | 17 +- .../forks/shanghai/vm/instructions/storage.py | 41 ++-- .../forks/shanghai/vm/instructions/system.py | 46 ++--- src/ethereum/forks/shanghai/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 10 +- .../vm/precompiled_contracts/ripemd160.py | 10 +- .../vm/precompiled_contracts/sha256.py | 10 +- 19 files changed, 245 insertions(+), 276 deletions(-) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 51c94dca9ea..4920941ede3 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -22,86 +22,93 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Shanghai fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -175,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -230,7 +237,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -302,4 +309,6 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index e1bf43acdad..460b7f3a677 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -16,12 +16,8 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas -from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -41,7 +37,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +64,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +91,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +118,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +151,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +184,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +214,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +245,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +276,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +311,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +341,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py index 4e0a487a749..64d9397fde4 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py +++ b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/shanghai/vm/instructions/block.py b/src/ethereum/forks/shanghai/vm/instructions/block.py index de2569869bd..c537805bc37 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/block.py +++ b/src/ethereum/forks/shanghai/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/comparison.py b/src/ethereum/forks/shanghai/vm/instructions/comparison.py index f30d048f94f..74bfefbd6bf 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/comparison.py +++ b/src/ethereum/forks/shanghai/vm/instructions/comparison.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index fabe929c4ce..bfcf3904a33 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -13,12 +13,7 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas -from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -62,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 54bac51928d..972e1f87098 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -19,15 +19,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -72,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -102,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -125,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -148,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -172,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -197,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -226,13 +221,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -258,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -287,13 +282,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -319,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -343,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -379,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -418,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,13 +439,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -480,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -515,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -543,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/keccak.py b/src/ethereum/forks/shanghai/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/keccak.py +++ b/src/ethereum/forks/shanghai/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/shanghai/vm/instructions/log.py b/src/ethereum/forks/shanghai/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/log.py +++ b/src/ethereum/forks/shanghai/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index 90b2f06a271..f99bfbf53fd 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -14,9 +14,9 @@ from ethereum_types.bytes import Bytes from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index 39a1682cb00..cda862303c8 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -15,12 +15,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import ( - GAS_BASE, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..memory import buffer_read @@ -38,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +63,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/shanghai/vm/instructions/storage.py b/src/ethereum/forks/shanghai/vm/instructions/storage.py index d99ad70f93b..098d5f0676f 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/storage.py +++ b/src/ethereum/forks/shanghai/vm/instructions/storage.py @@ -16,15 +16,7 @@ from ...state import get_storage, get_storage_original, set_storage from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext -from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -44,10 +36,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -73,7 +65,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -86,37 +78,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/shanghai/vm/instructions/system.py b/src/ethereum/forks/shanghai/vm/instructions/system.py index e5abcae2236..93d21967cb5 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/system.py +++ b/src/ethereum/forks/shanghai/vm/instructions/system.py @@ -39,15 +39,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -164,7 +156,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -214,8 +206,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -259,7 +251,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -370,17 +362,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -450,12 +442,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -508,10 +500,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -520,7 +512,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -583,10 +575,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -642,10 +634,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/shanghai/vm/interpreter.py b/src/ethereum/forks/shanghai/vm/interpreter.py index 6485ebe11f2..2c4634f314b 100644 --- a/src/ethereum/forks/shanghai/vm/interpreter.py +++ b/src/ethereum/forks/shanghai/vm/interpreter.py @@ -43,7 +43,7 @@ set_code, ) from ..vm import Message -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -168,7 +168,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py index 133a4832bf8..7dd737fa598 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py @@ -16,11 +16,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def identity(evm: Evm) -> None: @@ -39,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..321f1995757 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py @@ -19,11 +19,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def ripemd160(evm: Evm) -> None: @@ -42,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py index 04dfef6730d..a80c1b81972 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py @@ -18,11 +18,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def sha256(evm: Evm) -> None: @@ -41,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From bc48f631ff75d80f29e6e32a00a22896415e5b90 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:31:39 -0400 Subject: [PATCH 24/61] refactor: prague conversion to encapsulate Gas Constants in class --- .../forks/prague/vm/eoa_delegation.py | 6 +- src/ethereum/forks/prague/vm/gas.py | 215 +++++++++--------- .../prague/vm/instructions/arithmetic.py | 29 +-- .../forks/prague/vm/instructions/bitwise.py | 19 +- .../forks/prague/vm/instructions/block.py | 16 +- .../prague/vm/instructions/comparison.py | 15 +- .../prague/vm/instructions/control_flow.py | 14 +- .../prague/vm/instructions/environment.py | 68 +++--- .../forks/prague/vm/instructions/keccak.py | 10 +- .../forks/prague/vm/instructions/log.py | 10 +- .../forks/prague/vm/instructions/memory.py | 17 +- .../forks/prague/vm/instructions/stack.py | 14 +- .../forks/prague/vm/instructions/storage.py | 42 ++-- .../forks/prague/vm/instructions/system.py | 46 ++-- src/ethereum/forks/prague/vm/interpreter.py | 4 +- .../vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../prague/vm/precompiled_contracts/sha256.py | 7 +- 23 files changed, 288 insertions(+), 294 deletions(-) diff --git a/src/ethereum/forks/prague/vm/eoa_delegation.py b/src/ethereum/forks/prague/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/prague/vm/eoa_delegation.py +++ b/src/ethereum/forks/prague/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index bf39df606f5..d16faa05d6f 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -24,101 +24,108 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_TARGET_GAS_PER_BLOCK = U64(786432) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Prague fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_TARGET_GAS_PER_BLOCK = U64(786432) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -192,7 +199,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -247,7 +254,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -319,7 +326,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -348,10 +357,10 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: blob_gas_used = parent_header.blob_gas_used parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -370,7 +379,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -391,9 +400,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/prague/vm/instructions/bitwise.py b/src/ethereum/forks/prague/vm/instructions/bitwise.py index 4e0a487a749..c01bf41e74a 100644 --- a/src/ethereum/forks/prague/vm/instructions/bitwise.py +++ b/src/ethereum/forks/prague/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/prague/vm/instructions/block.py b/src/ethereum/forks/prague/vm/instructions/block.py index b3bfb500a09..dfa4020c47f 100644 --- a/src/ethereum/forks/prague/vm/instructions/block.py +++ b/src/ethereum/forks/prague/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/prague/vm/instructions/comparison.py b/src/ethereum/forks/prague/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/prague/vm/instructions/comparison.py +++ b/src/ethereum/forks/prague/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/prague/vm/instructions/keccak.py b/src/ethereum/forks/prague/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/prague/vm/instructions/keccak.py +++ b/src/ethereum/forks/prague/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/prague/vm/instructions/log.py b/src/ethereum/forks/prague/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/prague/vm/instructions/log.py +++ b/src/ethereum/forks/prague/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/prague/vm/instructions/storage.py b/src/ethereum/forks/prague/vm/instructions/storage.py index fd5bf4572ff..202917b6072 100644 --- a/src/ethereum/forks/prague/vm/instructions/storage.py +++ b/src/ethereum/forks/prague/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +149,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +176,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/prague/vm/instructions/system.py b/src/ethereum/forks/prague/vm/instructions/system.py index 29c3fe9e6e2..d1c9c4254d3 100644 --- a/src/ethereum/forks/prague/vm/instructions/system.py +++ b/src/ethereum/forks/prague/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/prague/vm/interpreter.py b/src/ethereum/forks/prague/vm/interpreter.py index 290f2831710..c8a18c89c87 100644 --- a/src/ethereum/forks/prague/vm/interpreter.py +++ b/src/ethereum/forks/prague/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 59d72432aa635653d8291c2a453b64860896787f Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:34:21 -0400 Subject: [PATCH 25/61] refactor: osaka conversion to encapsulate Gas Constants in class --- src/ethereum/forks/osaka/fork.py | 5 +- src/ethereum/forks/osaka/vm/eoa_delegation.py | 6 +- src/ethereum/forks/osaka/vm/gas.py | 234 +++++++++--------- .../forks/osaka/vm/instructions/arithmetic.py | 29 +-- .../forks/osaka/vm/instructions/bitwise.py | 21 +- .../forks/osaka/vm/instructions/block.py | 16 +- .../forks/osaka/vm/instructions/comparison.py | 15 +- .../osaka/vm/instructions/control_flow.py | 14 +- .../osaka/vm/instructions/environment.py | 68 +++-- .../forks/osaka/vm/instructions/keccak.py | 10 +- .../forks/osaka/vm/instructions/log.py | 10 +- .../forks/osaka/vm/instructions/memory.py | 17 +- .../forks/osaka/vm/instructions/stack.py | 14 +- .../forks/osaka/vm/instructions/storage.py | 47 ++-- .../forks/osaka/vm/instructions/system.py | 61 ++--- src/ethereum/forks/osaka/vm/interpreter.py | 4 +- .../osaka/vm/precompiled_contracts/blake2f.py | 7 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../osaka/vm/precompiled_contracts/sha256.py | 7 +- 25 files changed, 319 insertions(+), 316 deletions(-) diff --git a/src/ethereum/forks/osaka/fork.py b/src/ethereum/forks/osaka/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/osaka/fork.py +++ b/src/ethereum/forks/osaka/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/osaka/vm/eoa_delegation.py b/src/ethereum/forks/osaka/vm/eoa_delegation.py index ff4aca94087..bb6144b51c8 100644 --- a/src/ethereum/forks/osaka/vm/eoa_delegation.py +++ b/src/ethereum/forks/osaka/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -148,10 +148,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 01835a9b0d2..f9988f71914 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(6) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(9) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the Osaka fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(6) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(9) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/osaka/vm/instructions/bitwise.py b/src/ethereum/forks/osaka/vm/instructions/bitwise.py index 3cb188b8579..0e1612fed49 100644 --- a/src/ethereum/forks/osaka/vm/instructions/bitwise.py +++ b/src/ethereum/forks/osaka/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/osaka/vm/instructions/block.py b/src/ethereum/forks/osaka/vm/instructions/block.py index 43be9e58e23..e8e4fabc79d 100644 --- a/src/ethereum/forks/osaka/vm/instructions/block.py +++ b/src/ethereum/forks/osaka/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/osaka/vm/instructions/comparison.py b/src/ethereum/forks/osaka/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/osaka/vm/instructions/comparison.py +++ b/src/ethereum/forks/osaka/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/osaka/vm/instructions/keccak.py b/src/ethereum/forks/osaka/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/osaka/vm/instructions/keccak.py +++ b/src/ethereum/forks/osaka/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/osaka/vm/instructions/log.py b/src/ethereum/forks/osaka/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/osaka/vm/instructions/log.py +++ b/src/ethereum/forks/osaka/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/osaka/vm/instructions/storage.py b/src/ethereum/forks/osaka/vm/instructions/storage.py index fd5bf4572ff..92db4d9ea2a 100644 --- a/src/ethereum/forks/osaka/vm/instructions/storage.py +++ b/src/ethereum/forks/osaka/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,37 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: - # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: - # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: - # Storage slot being restored to its original value if original_value == 0: - # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: - # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +144,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +171,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/osaka/vm/instructions/system.py b/src/ethereum/forks/osaka/vm/instructions/system.py index 29c3fe9e6e2..a4815b4487b 100644 --- a/src/ethereum/forks/osaka/vm/instructions/system.py +++ b/src/ethereum/forks/osaka/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,10 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, + GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -489,7 +484,8 @@ def callcode(evm: Evm) -> None: # OPERATION evm.memory += b"\x00" * extend_memory.expand_by sender_balance = get_account( - evm.message.block_env.state, evm.message.current_target + evm.message.block_env.state, + evm.message.current_target, ).balance if sender_balance < value: push(evm.stack, U256(0)) @@ -531,19 +527,20 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( - evm.message.block_env.state, evm.message.current_target + evm.message.block_env.state, + evm.message.current_target, ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +601,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -618,7 +615,11 @@ def delegatecall(evm: Evm) -> None: access_gas_cost += delegated_access_gas_cost message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + access_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -673,10 +674,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/osaka/vm/interpreter.py b/src/ethereum/forks/osaka/vm/interpreter.py index bdbf6520cc7..5802d508142 100644 --- a/src/ethereum/forks/osaka/vm/interpreter.py +++ b/src/ethereum/forks/osaka/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..d7b8c44cb62 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,10 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas( + evm, + GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds, + ) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 19ef467af8d289e5efa208e6f34a21fe6985eae0 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:37:13 -0400 Subject: [PATCH 26/61] refactor: BPO1 conversion to encapsulate Gas Constants in class --- src/ethereum/forks/bpo1/fork.py | 5 +- src/ethereum/forks/bpo1/vm/eoa_delegation.py | 6 +- src/ethereum/forks/bpo1/vm/gas.py | 234 +++++++++--------- .../forks/bpo1/vm/instructions/arithmetic.py | 29 +-- .../forks/bpo1/vm/instructions/bitwise.py | 21 +- .../forks/bpo1/vm/instructions/block.py | 16 +- .../forks/bpo1/vm/instructions/comparison.py | 15 +- .../bpo1/vm/instructions/control_flow.py | 14 +- .../forks/bpo1/vm/instructions/environment.py | 68 +++-- .../forks/bpo1/vm/instructions/keccak.py | 10 +- .../forks/bpo1/vm/instructions/log.py | 10 +- .../forks/bpo1/vm/instructions/memory.py | 17 +- .../forks/bpo1/vm/instructions/stack.py | 14 +- .../forks/bpo1/vm/instructions/storage.py | 42 ++-- .../forks/bpo1/vm/instructions/system.py | 49 ++-- src/ethereum/forks/bpo1/vm/interpreter.py | 4 +- .../bpo1/vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../bpo1/vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../bpo1/vm/precompiled_contracts/sha256.py | 7 +- 25 files changed, 307 insertions(+), 308 deletions(-) diff --git a/src/ethereum/forks/bpo1/fork.py b/src/ethereum/forks/bpo1/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/bpo1/fork.py +++ b/src/ethereum/forks/bpo1/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo1/vm/eoa_delegation.py b/src/ethereum/forks/bpo1/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/bpo1/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo1/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index b550850c49e..0dab658f265 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(10) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(15) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(8346193) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the BPO (Blob Parameter Only) 1 fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(10) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(15) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(8346193) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py index 3cb188b8579..0e1612fed49 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo1/vm/instructions/block.py b/src/ethereum/forks/bpo1/vm/instructions/block.py index 75810aacd39..2ff879de431 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/block.py +++ b/src/ethereum/forks/bpo1/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo1/vm/instructions/comparison.py b/src/ethereum/forks/bpo1/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo1/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo1/vm/instructions/keccak.py b/src/ethereum/forks/bpo1/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo1/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo1/vm/instructions/log.py b/src/ethereum/forks/bpo1/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/log.py +++ b/src/ethereum/forks/bpo1/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo1/vm/instructions/storage.py b/src/ethereum/forks/bpo1/vm/instructions/storage.py index fd5bf4572ff..202917b6072 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo1/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +149,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +176,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo1/vm/instructions/system.py b/src/ethereum/forks/bpo1/vm/instructions/system.py index 29c3fe9e6e2..5087e180f3b 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/system.py +++ b/src/ethereum/forks/bpo1/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,10 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, + GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo1/vm/interpreter.py b/src/ethereum/forks/bpo1/vm/interpreter.py index 9c05883b7dc..ce5209bb811 100644 --- a/src/ethereum/forks/bpo1/vm/interpreter.py +++ b/src/ethereum/forks/bpo1/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..913638a6d0a 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G1ADD) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G1MAP) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..687dfbe168c 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G2ADD) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G2MAP) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 4c145058686e2e8474bf9487bae03a845fd7efa7 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:38:46 -0400 Subject: [PATCH 27/61] refactor: BPO2 conversion to encapsulate Gas Constants in class --- src/ethereum/forks/bpo2/fork.py | 5 +- src/ethereum/forks/bpo2/vm/eoa_delegation.py | 6 +- src/ethereum/forks/bpo2/vm/gas.py | 234 +++++++++--------- .../forks/bpo2/vm/instructions/arithmetic.py | 29 +-- .../forks/bpo2/vm/instructions/bitwise.py | 24 +- .../forks/bpo2/vm/instructions/block.py | 16 +- .../forks/bpo2/vm/instructions/comparison.py | 18 +- .../bpo2/vm/instructions/control_flow.py | 17 +- .../forks/bpo2/vm/instructions/environment.py | 68 +++-- .../forks/bpo2/vm/instructions/keccak.py | 10 +- .../forks/bpo2/vm/instructions/log.py | 10 +- .../forks/bpo2/vm/instructions/memory.py | 17 +- .../forks/bpo2/vm/instructions/stack.py | 17 +- .../forks/bpo2/vm/instructions/storage.py | 45 ++-- .../forks/bpo2/vm/instructions/system.py | 46 ++-- src/ethereum/forks/bpo2/vm/interpreter.py | 4 +- .../bpo2/vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 15 +- .../bls12_381/bls12_381_g2.py | 15 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../bpo2/vm/precompiled_contracts/identity.py | 10 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 10 +- .../bpo2/vm/precompiled_contracts/sha256.py | 10 +- 25 files changed, 304 insertions(+), 338 deletions(-) diff --git a/src/ethereum/forks/bpo2/fork.py b/src/ethereum/forks/bpo2/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/bpo2/fork.py +++ b/src/ethereum/forks/bpo2/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo2/vm/eoa_delegation.py b/src/ethereum/forks/bpo2/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/bpo2/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo2/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 79a1a915824..9a484e7ca43 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(14) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(21) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the BPO (Blob Parameter Only) 2 fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(14) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(21) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py index 3cb188b8579..29551c2c2a9 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +262,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo2/vm/instructions/block.py b/src/ethereum/forks/bpo2/vm/instructions/block.py index 9923433c7b6..07a3fcdb320 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/block.py +++ b/src/ethereum/forks/bpo2/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo2/vm/instructions/comparison.py b/src/ethereum/forks/bpo2/vm/instructions/comparison.py index f30d048f94f..74bfefbd6bf 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo2/vm/instructions/comparison.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index fabe929c4ce..bfcf3904a33 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -13,12 +13,7 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas -from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -62,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo2/vm/instructions/keccak.py b/src/ethereum/forks/bpo2/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo2/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo2/vm/instructions/log.py b/src/ethereum/forks/bpo2/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/log.py +++ b/src/ethereum/forks/bpo2/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index 39a1682cb00..cda862303c8 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -15,12 +15,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import ( - GAS_BASE, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..memory import buffer_read @@ -38,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +63,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo2/vm/instructions/storage.py b/src/ethereum/forks/bpo2/vm/instructions/storage.py index fd5bf4572ff..08884b40394 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo2/vm/instructions/storage.py @@ -22,15 +22,7 @@ ) from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext -from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -50,10 +42,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +71,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +84,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +146,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +173,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo2/vm/instructions/system.py b/src/ethereum/forks/bpo2/vm/instructions/system.py index 29c3fe9e6e2..d1c9c4254d3 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/system.py +++ b/src/ethereum/forks/bpo2/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo2/vm/interpreter.py b/src/ethereum/forks/bpo2/vm/interpreter.py index a7b27243123..e18354f75a9 100644 --- a/src/ethereum/forks/bpo2/vm/interpreter.py +++ b/src/ethereum/forks/bpo2/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..df60c23fb22 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -20,12 +20,7 @@ ) from ....vm import Evm -from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, - charge_gas, -) +from ....vm.gas import GasCosts, charge_gas from ....vm.memory import buffer_read from ...exceptions import InvalidParameter from . import ( @@ -60,7 +55,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +96,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +137,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..355e5399800 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -20,12 +20,7 @@ ) from ....vm import Evm -from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, - charge_gas, -) +from ....vm.gas import GasCosts, charge_gas from ....vm.memory import buffer_read from ...exceptions import InvalidParameter from . import ( @@ -61,7 +56,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +97,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +138,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py index 133a4832bf8..7dd737fa598 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py @@ -16,11 +16,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def identity(evm: Evm) -> None: @@ -39,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..321f1995757 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py @@ -19,11 +19,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def ripemd160(evm: Evm) -> None: @@ -42,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py index 04dfef6730d..a80c1b81972 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py @@ -18,11 +18,7 @@ from ethereum.utils.numeric import ceil32 from ...vm import Evm -from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas def sha256(evm: Evm) -> None: @@ -41,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 98a576408ed89277b145a28bdcc81a5a7425b011 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:57:46 -0400 Subject: [PATCH 28/61] refactor: BPO3 conversion to encapsulate Gas Constants in class --- src/ethereum/forks/bpo3/fork.py | 5 +- src/ethereum/forks/bpo3/vm/eoa_delegation.py | 6 +- src/ethereum/forks/bpo3/vm/gas.py | 234 +++++++++--------- .../forks/bpo3/vm/instructions/arithmetic.py | 29 +-- .../forks/bpo3/vm/instructions/bitwise.py | 24 +- .../forks/bpo3/vm/instructions/block.py | 16 +- .../forks/bpo3/vm/instructions/comparison.py | 18 +- .../bpo3/vm/instructions/control_flow.py | 17 +- .../forks/bpo3/vm/instructions/environment.py | 68 +++-- .../forks/bpo3/vm/instructions/keccak.py | 10 +- .../forks/bpo3/vm/instructions/log.py | 10 +- .../forks/bpo3/vm/instructions/memory.py | 17 +- .../forks/bpo3/vm/instructions/stack.py | 17 +- .../forks/bpo3/vm/instructions/storage.py | 45 ++-- .../forks/bpo3/vm/instructions/system.py | 46 ++-- src/ethereum/forks/bpo3/vm/interpreter.py | 4 +- .../bpo3/vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../bpo3/vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../bpo3/vm/precompiled_contracts/sha256.py | 7 +- 25 files changed, 304 insertions(+), 323 deletions(-) diff --git a/src/ethereum/forks/bpo3/fork.py b/src/ethereum/forks/bpo3/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/bpo3/fork.py +++ b/src/ethereum/forks/bpo3/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo3/vm/eoa_delegation.py b/src/ethereum/forks/bpo3/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/bpo3/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo3/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 79a1a915824..f704e4dab07 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(14) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(21) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the BPO (Blob Parameter Only) 3 fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(14) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(21) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py index 3cb188b8579..29551c2c2a9 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +262,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo3/vm/instructions/block.py b/src/ethereum/forks/bpo3/vm/instructions/block.py index 10fcbdbdb57..937ec58ca20 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/block.py +++ b/src/ethereum/forks/bpo3/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo3/vm/instructions/comparison.py b/src/ethereum/forks/bpo3/vm/instructions/comparison.py index f30d048f94f..74bfefbd6bf 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo3/vm/instructions/comparison.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas -from ..gas import ( - charge_gas, -) +from .. import Evm +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -36,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index fabe929c4ce..bfcf3904a33 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -13,12 +13,7 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas -from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, - charge_gas, -) +from ...vm.gas import GasCosts, charge_gas from .. import Evm from ..exceptions import InvalidJumpDestError from ..stack import pop, push @@ -62,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo3/vm/instructions/keccak.py b/src/ethereum/forks/bpo3/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo3/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo3/vm/instructions/log.py b/src/ethereum/forks/bpo3/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/log.py +++ b/src/ethereum/forks/bpo3/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index 39a1682cb00..cda862303c8 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -15,12 +15,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError -from ..gas import ( - GAS_BASE, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..memory import buffer_read @@ -38,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +63,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo3/vm/instructions/storage.py b/src/ethereum/forks/bpo3/vm/instructions/storage.py index fd5bf4572ff..08884b40394 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo3/vm/instructions/storage.py @@ -22,15 +22,7 @@ ) from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext -from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, - charge_gas, -) +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -50,10 +42,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +71,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +84,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +146,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +173,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo3/vm/instructions/system.py b/src/ethereum/forks/bpo3/vm/instructions/system.py index 29c3fe9e6e2..d1c9c4254d3 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/system.py +++ b/src/ethereum/forks/bpo3/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo3/vm/interpreter.py b/src/ethereum/forks/bpo3/vm/interpreter.py index 4111d5b4c78..7a9b1e15f41 100644 --- a/src/ethereum/forks/bpo3/vm/interpreter.py +++ b/src/ethereum/forks/bpo3/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 84314aad370c476f20ed934358bdeaa0cba72464 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 00:59:54 -0400 Subject: [PATCH 29/61] refactor: BPO4 conversion to encapsulate Gas Constants in class --- src/ethereum/forks/bpo4/fork.py | 5 +- src/ethereum/forks/bpo4/vm/eoa_delegation.py | 6 +- src/ethereum/forks/bpo4/vm/gas.py | 234 +++++++++--------- .../forks/bpo4/vm/instructions/arithmetic.py | 29 +-- .../forks/bpo4/vm/instructions/bitwise.py | 21 +- .../forks/bpo4/vm/instructions/block.py | 16 +- .../forks/bpo4/vm/instructions/comparison.py | 15 +- .../bpo4/vm/instructions/control_flow.py | 14 +- .../forks/bpo4/vm/instructions/environment.py | 68 +++-- .../forks/bpo4/vm/instructions/keccak.py | 10 +- .../forks/bpo4/vm/instructions/log.py | 10 +- .../forks/bpo4/vm/instructions/memory.py | 17 +- .../forks/bpo4/vm/instructions/stack.py | 14 +- .../forks/bpo4/vm/instructions/storage.py | 42 ++-- .../forks/bpo4/vm/instructions/system.py | 49 ++-- src/ethereum/forks/bpo4/vm/interpreter.py | 4 +- .../bpo4/vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../bpo4/vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../bpo4/vm/precompiled_contracts/sha256.py | 7 +- 25 files changed, 307 insertions(+), 308 deletions(-) diff --git a/src/ethereum/forks/bpo4/fork.py b/src/ethereum/forks/bpo4/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/bpo4/fork.py +++ b/src/ethereum/forks/bpo4/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo4/vm/eoa_delegation.py b/src/ethereum/forks/bpo4/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/bpo4/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo4/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 79a1a915824..318db550cc5 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(14) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(21) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the BPO (Blob Parameter Only) 4 fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(14) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(21) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py index 3cb188b8579..0e1612fed49 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo4/vm/instructions/block.py b/src/ethereum/forks/bpo4/vm/instructions/block.py index 52145aa9f82..1e80ccccca9 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/block.py +++ b/src/ethereum/forks/bpo4/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo4/vm/instructions/comparison.py b/src/ethereum/forks/bpo4/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo4/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo4/vm/instructions/keccak.py b/src/ethereum/forks/bpo4/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo4/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo4/vm/instructions/log.py b/src/ethereum/forks/bpo4/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/log.py +++ b/src/ethereum/forks/bpo4/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo4/vm/instructions/storage.py b/src/ethereum/forks/bpo4/vm/instructions/storage.py index fd5bf4572ff..202917b6072 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo4/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +149,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +176,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo4/vm/instructions/system.py b/src/ethereum/forks/bpo4/vm/instructions/system.py index 29c3fe9e6e2..5087e180f3b 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/system.py +++ b/src/ethereum/forks/bpo4/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,10 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, + GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo4/vm/interpreter.py b/src/ethereum/forks/bpo4/vm/interpreter.py index 7e789cf4b69..7f3c4154df7 100644 --- a/src/ethereum/forks/bpo4/vm/interpreter.py +++ b/src/ethereum/forks/bpo4/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From eee2e5bd569468fe42838190f4c69752544b6e75 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sat, 21 Mar 2026 01:09:06 -0400 Subject: [PATCH 30/61] refactor: BPO5 conversion to encapsulate Gas Constants in class --- src/ethereum/forks/bpo5/fork.py | 5 +- src/ethereum/forks/bpo5/vm/eoa_delegation.py | 6 +- src/ethereum/forks/bpo5/vm/gas.py | 234 +++++++++--------- .../forks/bpo5/vm/instructions/arithmetic.py | 29 +-- .../forks/bpo5/vm/instructions/bitwise.py | 21 +- .../forks/bpo5/vm/instructions/block.py | 16 +- .../forks/bpo5/vm/instructions/comparison.py | 15 +- .../bpo5/vm/instructions/control_flow.py | 14 +- .../forks/bpo5/vm/instructions/environment.py | 68 +++-- .../forks/bpo5/vm/instructions/keccak.py | 10 +- .../forks/bpo5/vm/instructions/log.py | 10 +- .../forks/bpo5/vm/instructions/memory.py | 17 +- .../forks/bpo5/vm/instructions/stack.py | 14 +- .../forks/bpo5/vm/instructions/storage.py | 42 ++-- .../forks/bpo5/vm/instructions/system.py | 49 ++-- src/ethereum/forks/bpo5/vm/interpreter.py | 4 +- .../bpo5/vm/precompiled_contracts/blake2f.py | 4 +- .../bls12_381/bls12_381_g1.py | 12 +- .../bls12_381/bls12_381_g2.py | 12 +- .../vm/precompiled_contracts/ecrecover.py | 4 +- .../bpo5/vm/precompiled_contracts/identity.py | 7 +- .../vm/precompiled_contracts/p256verify.py | 4 +- .../precompiled_contracts/point_evaluation.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 7 +- .../bpo5/vm/precompiled_contracts/sha256.py | 7 +- 25 files changed, 307 insertions(+), 308 deletions(-) diff --git a/src/ethereum/forks/bpo5/fork.py b/src/ethereum/forks/bpo5/fork.py index 7e6b5ee46de..ff32777abde 100644 --- a/src/ethereum/forks/bpo5/fork.py +++ b/src/ethereum/forks/bpo5/fork.py @@ -81,8 +81,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( - BLOB_SCHEDULE_MAX, - GAS_PER_BLOB, + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -100,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo5/vm/eoa_delegation.py b/src/ethereum/forks/bpo5/vm/eoa_delegation.py index fce580bee4a..acdc91afbdf 100644 --- a/src/ethereum/forks/bpo5/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo5/vm/eoa_delegation.py @@ -22,7 +22,7 @@ set_code, ) from ..utils.hexadecimal import hex_to_address -from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS +from ..vm.gas import GasCosts from . import Evm, Message SET_CODE_TX_MAGIC = b"\x05" @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 79a1a915824..cba2d33cf96 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -24,105 +24,113 @@ from . import Evm from .exceptions import OutOfGasError -GAS_JUMPDEST = Uint(1) -GAS_BASE = Uint(2) -GAS_VERY_LOW = Uint(3) -GAS_STORAGE_SET = Uint(20000) -GAS_COLD_STORAGE_WRITE = Uint(5000) -REFUND_STORAGE_CLEAR = 4800 -GAS_LOW = Uint(5) -GAS_MID = Uint(8) -GAS_HIGH = Uint(10) -GAS_EXPONENTIATION = Uint(10) -GAS_EXPONENTIATION_PER_BYTE = Uint(50) -GAS_MEMORY = Uint(3) -GAS_KECCAK256 = Uint(30) -GAS_KECCAK256_PER_WORD = Uint(6) -GAS_COPY = Uint(3) -GAS_BLOCK_HASH = Uint(20) -GAS_LOG = Uint(375) -GAS_LOG_DATA_PER_BYTE = Uint(8) -GAS_LOG_TOPIC = Uint(375) -GAS_CREATE = Uint(32000) -GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) -GAS_ZERO = Uint(0) -GAS_NEW_ACCOUNT = Uint(25000) -GAS_CALL_VALUE = Uint(9000) -GAS_CALL_STIPEND = Uint(2300) -GAS_SELF_DESTRUCT = Uint(5000) -GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) -GAS_PRECOMPILE_ECRECOVER = Uint(3000) -GAS_PRECOMPILE_P256VERIFY = Uint(6900) -GAS_PRECOMPILE_SHA256_BASE = Uint(60) -GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) -GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) -GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) -GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) -GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) -GAS_RETURN_DATA_COPY = Uint(3) -GAS_FAST_STEP = Uint(5) -GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) -GAS_COLD_STORAGE_ACCESS = Uint(2100) -GAS_COLD_ACCOUNT_ACCESS = Uint(2600) -GAS_WARM_ACCESS = Uint(100) -GAS_CODE_INIT_PER_WORD = Uint(2) -GAS_BLOBHASH = Uint(3) -GAS_POINT_EVALUATION = Uint(50000) - -GAS_PER_BLOB = U64(2**17) -BLOB_SCHEDULE_TARGET = U64(14) -BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET -BLOB_BASE_COST = Uint(2**13) -BLOB_SCHEDULE_MAX = U64(21) -BLOB_MIN_GASPRICE = Uint(1) -BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - -GAS_PRECOMPILE_BLS_G1ADD = Uint(375) -GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) -GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) -GAS_PRECOMPILE_BLS_G2ADD = Uint(600) -GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) -GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - -# Opcode specific vars used for repricing -GAS_OPCODE_ADD = GAS_VERY_LOW -GAS_OPCODE_SUB = GAS_VERY_LOW -GAS_OPCODE_MUL = GAS_LOW -GAS_OPCODE_DIV = GAS_LOW -GAS_OPCODE_SDIV = GAS_LOW -GAS_OPCODE_MOD = GAS_LOW -GAS_OPCODE_SMOD = GAS_LOW -GAS_OPCODE_ADDMOD = GAS_MID -GAS_OPCODE_MULMOD = GAS_MID -GAS_OPCODE_SIGNEXTEND = GAS_LOW -GAS_OPCODE_LT = GAS_VERY_LOW -GAS_OPCODE_GT = GAS_VERY_LOW -GAS_OPCODE_SLT = GAS_VERY_LOW -GAS_OPCODE_SGT = GAS_VERY_LOW -GAS_OPCODE_EQ = GAS_VERY_LOW -GAS_OPCODE_ISZERO = GAS_VERY_LOW -GAS_OPCODE_AND = GAS_VERY_LOW -GAS_OPCODE_OR = GAS_VERY_LOW -GAS_OPCODE_XOR = GAS_VERY_LOW -GAS_OPCODE_NOT = GAS_VERY_LOW -GAS_OPCODE_BYTE = GAS_VERY_LOW -GAS_OPCODE_SHL = GAS_VERY_LOW -GAS_OPCODE_SHR = GAS_VERY_LOW -GAS_OPCODE_SAR = GAS_VERY_LOW -GAS_OPCODE_CLZ = GAS_LOW -GAS_OPCODE_JUMP = GAS_MID -GAS_OPCODE_JUMPI = GAS_HIGH -GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW -GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW -GAS_OPCODE_CODECOPY = GAS_VERY_LOW -GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW -GAS_OPCODE_MLOAD = GAS_VERY_LOW -GAS_OPCODE_MSTORE = GAS_VERY_LOW -GAS_OPCODE_MSTORE8 = GAS_VERY_LOW -GAS_OPCODE_MCOPY = GAS_VERY_LOW -GAS_OPCODE_PUSH_N = GAS_VERY_LOW -GAS_OPCODE_DUP = GAS_VERY_LOW -GAS_OPCODE_SWAP = GAS_VERY_LOW + +class GasCosts: + """ + Constant gas values for the BPO (Blob Parameter Only) 5 fork of the EVM. + + These values may be patched at runtime by a future gas repricing utility + """ + + GAS_JUMPDEST = Uint(1) + GAS_BASE = Uint(2) + GAS_VERY_LOW = Uint(3) + GAS_STORAGE_SET = Uint(20000) + GAS_COLD_STORAGE_WRITE = Uint(5000) + REFUND_STORAGE_CLEAR = 4800 + GAS_LOW = Uint(5) + GAS_MID = Uint(8) + GAS_HIGH = Uint(10) + GAS_EXPONENTIATION = Uint(10) + GAS_EXPONENTIATION_PER_BYTE = Uint(50) + GAS_MEMORY = Uint(3) + GAS_KECCAK256 = Uint(30) + GAS_KECCAK256_PER_WORD = Uint(6) + GAS_COPY = Uint(3) + GAS_BLOCK_HASH = Uint(20) + GAS_LOG = Uint(375) + GAS_LOG_DATA_PER_BYTE = Uint(8) + GAS_LOG_TOPIC = Uint(375) + GAS_CREATE = Uint(32000) + GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) + GAS_ZERO = Uint(0) + GAS_NEW_ACCOUNT = Uint(25000) + GAS_CALL_VALUE = Uint(9000) + GAS_CALL_STIPEND = Uint(2300) + GAS_SELF_DESTRUCT = Uint(5000) + GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + GAS_PRECOMPILE_ECRECOVER = Uint(3000) + GAS_PRECOMPILE_P256VERIFY = Uint(6900) + GAS_PRECOMPILE_SHA256_BASE = Uint(60) + GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) + GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) + GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) + GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + GAS_RETURN_DATA_COPY = Uint(3) + GAS_FAST_STEP = Uint(5) + GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + GAS_COLD_STORAGE_ACCESS = Uint(2100) + GAS_COLD_ACCOUNT_ACCESS = Uint(2600) + GAS_WARM_ACCESS = Uint(100) + GAS_CODE_INIT_PER_WORD = Uint(2) + GAS_BLOBHASH = Uint(3) + GAS_POINT_EVALUATION = Uint(50000) + + GAS_PER_BLOB = U64(2**17) + BLOB_SCHEDULE_TARGET = U64(14) + BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_BASE_COST = Uint(2**13) + BLOB_SCHEDULE_MAX = U64(21) + BLOB_MIN_GASPRICE = Uint(1) + BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) + + GAS_PRECOMPILE_BLS_G1ADD = Uint(375) + GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) + GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) + GAS_PRECOMPILE_BLS_G2ADD = Uint(600) + GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) + GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Opcode specific vars used for repricing + GAS_OPCODE_ADD = GAS_VERY_LOW + GAS_OPCODE_SUB = GAS_VERY_LOW + GAS_OPCODE_MUL = GAS_LOW + GAS_OPCODE_DIV = GAS_LOW + GAS_OPCODE_SDIV = GAS_LOW + GAS_OPCODE_MOD = GAS_LOW + GAS_OPCODE_SMOD = GAS_LOW + GAS_OPCODE_ADDMOD = GAS_MID + GAS_OPCODE_MULMOD = GAS_MID + GAS_OPCODE_SIGNEXTEND = GAS_LOW + GAS_OPCODE_LT = GAS_VERY_LOW + GAS_OPCODE_GT = GAS_VERY_LOW + GAS_OPCODE_SLT = GAS_VERY_LOW + GAS_OPCODE_SGT = GAS_VERY_LOW + GAS_OPCODE_EQ = GAS_VERY_LOW + GAS_OPCODE_ISZERO = GAS_VERY_LOW + GAS_OPCODE_AND = GAS_VERY_LOW + GAS_OPCODE_OR = GAS_VERY_LOW + GAS_OPCODE_XOR = GAS_VERY_LOW + GAS_OPCODE_NOT = GAS_VERY_LOW + GAS_OPCODE_BYTE = GAS_VERY_LOW + GAS_OPCODE_SHL = GAS_VERY_LOW + GAS_OPCODE_SHR = GAS_VERY_LOW + GAS_OPCODE_SAR = GAS_VERY_LOW + GAS_OPCODE_CLZ = GAS_LOW + GAS_OPCODE_JUMP = GAS_MID + GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW + GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW + GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_MLOAD = GAS_VERY_LOW + GAS_OPCODE_MSTORE = GAS_VERY_LOW + GAS_OPCODE_MSTORE8 = GAS_VERY_LOW + GAS_OPCODE_MCOPY = GAS_VERY_LOW + GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_DUP = GAS_VERY_LOW + GAS_OPCODE_SWAP = GAS_VERY_LOW @dataclass @@ -196,7 +204,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GAS_MEMORY + linear_cost = size_in_words * GasCosts.GAS_MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -251,7 +259,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -323,7 +331,9 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + return ( + GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) + ) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -354,21 +364,23 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: base_fee_per_gas = parent_header.base_fee_per_gas parent_blob_gas = excess_blob_gas + blob_gas_used - if parent_blob_gas < BLOB_TARGET_GAS_PER_BLOCK: + if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) - base_blob_tx_price = BLOB_BASE_COST * base_fee_per_gas + base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas if base_blob_tx_price > target_blob_gas_price: - blob_schedule_delta = BLOB_SCHEDULE_MAX - BLOB_SCHEDULE_TARGET + blob_schedule_delta = ( + GasCosts.BLOB_SCHEDULE_MAX - GasCosts.BLOB_SCHEDULE_TARGET + ) return ( excess_blob_gas - + blob_gas_used * blob_schedule_delta // BLOB_SCHEDULE_MAX + + blob_gas_used * blob_schedule_delta // GasCosts.BLOB_SCHEDULE_MAX ) - return parent_blob_gas - BLOB_TARGET_GAS_PER_BLOCK + return parent_blob_gas - GasCosts.BLOB_TARGET_GAS_PER_BLOCK def calculate_total_blob_gas(tx: Transaction) -> U64: @@ -387,7 +399,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) @@ -408,9 +420,9 @@ def calculate_blob_gas_price(excess_blob_gas: U64) -> Uint: """ return taylor_exponential( - BLOB_MIN_GASPRICE, + GasCosts.BLOB_MIN_GASPRICE, Uint(excess_blob_gas), - BLOB_BASE_FEE_UPDATE_FRACTION, + GasCosts.BLOB_BASE_FEE_UPDATE_FRACTION, ) diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index e1bf43acdad..6add253f46e 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import get_sign -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_EXPONENTIATION, - GAS_EXPONENTIATION_PER_BYTE, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -41,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -68,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.GAS_OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -95,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.GAS_OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -122,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.GAS_OPCODE_DIV) # OPERATION if divisor == 0: @@ -155,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) # OPERATION if divisor == 0: @@ -188,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MOD) # OPERATION if y == 0: @@ -218,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) # OPERATION if y == 0: @@ -249,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) # OPERATION if z == 0: @@ -280,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) # OPERATION if z == 0: @@ -315,7 +314,9 @@ def exp(evm: Evm) -> None: exponent_bits = exponent.bit_length() exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( - evm, GAS_EXPONENTIATION + GAS_EXPONENTIATION_PER_BYTE * exponent_bytes + evm, + GasCosts.GAS_EXPONENTIATION + + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION @@ -343,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py index 3cb188b8579..0e1612fed49 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.GAS_OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -61,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.GAS_OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -86,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.GAS_OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -110,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.GAS_OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -136,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -171,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.GAS_OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -201,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.GAS_OPCODE_SHR) # OPERATION if shift < U256(256): @@ -231,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.GAS_OPCODE_SAR) # OPERATION if shift < 256: @@ -264,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo5/vm/instructions/block.py b/src/ethereum/forks/bpo5/vm/instructions/block.py index 84930244d4c..5d4054bf508 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/block.py +++ b/src/ethereum/forks/bpo5/vm/instructions/block.py @@ -14,7 +14,7 @@ from ethereum_types.numeric import U256, Uint from .. import Evm -from ..gas import GAS_BASE, GAS_BLOCK_HASH, charge_gas +from ..gas import GasCosts, charge_gas from ..stack import pop, push @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_BLOCK_HASH) # OPERATION max_block_number = block_number + Uint(256) @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo5/vm/instructions/comparison.py b/src/ethereum/forks/bpo5/vm/instructions/comparison.py index f30d048f94f..ab71ab44f9d 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo5/vm/instructions/comparison.py @@ -13,8 +13,9 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas +from .. import Evm from ..gas import ( + GasCosts, charge_gas, ) from ..stack import pop, push @@ -36,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.GAS_OPCODE_LT) # OPERATION result = U256(left < right) @@ -62,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.GAS_OPCODE_SLT) # OPERATION result = U256(left < right) @@ -89,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.GAS_OPCODE_GT) # OPERATION result = U256(left > right) @@ -115,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, gas.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.GAS_OPCODE_SGT) # OPERATION result = U256(left > right) @@ -142,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.GAS_OPCODE_EQ) # OPERATION result = U256(left == right) @@ -168,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index fabe929c4ce..eb346c393dc 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -13,10 +13,8 @@ from ethereum_types.numeric import U256, Uint -from ...vm import gas from ...vm.gas import ( - GAS_BASE, - GAS_JUMPDEST, + GasCosts, charge_gas, ) from .. import Evm @@ -62,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -89,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -118,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -142,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) @@ -167,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 936297a73a6..edbb980db38 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -20,16 +20,10 @@ from ...state import get_account, get_code from ...utils.address import to_address_masked from ...vm.memory import buffer_read, memory_write -from .. import Evm, gas +from .. import Evm from ..exceptions import OutOfBoundsRead from ..gas import ( - GAS_BASE, - GAS_BLOBHASH, - GAS_COLD_ACCOUNT_ACCESS, - GAS_COPY, - GAS_FAST_STEP, - GAS_RETURN_DATA_COPY, - GAS_WARM_ACCESS, + GasCosts, calculate_blob_gas_price, calculate_gas_extend_memory, charge_gas, @@ -51,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -75,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -105,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -128,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -151,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, evm.message.value) @@ -175,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, gas.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -200,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -229,13 +223,13 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -261,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -290,13 +284,13 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -322,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -346,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -382,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -421,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -447,13 +441,15 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - gas.GAS_OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_RETURNDATACOPY + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -483,10 +479,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -518,7 +514,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_FAST_STEP) + charge_gas(evm, GasCosts.GAS_FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -546,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -569,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): @@ -596,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo5/vm/instructions/keccak.py b/src/ethereum/forks/bpo5/vm/instructions/keccak.py index 8661c5d62f5..5173dd59f67 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo5/vm/instructions/keccak.py @@ -18,8 +18,7 @@ from .. import Evm from ..gas import ( - GAS_KECCAK256, - GAS_KECCAK256_PER_WORD, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -46,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GAS_KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo5/vm/instructions/log.py b/src/ethereum/forks/bpo5/vm/instructions/log.py index abc297df6fa..715be004c55 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/log.py +++ b/src/ethereum/forks/bpo5/vm/instructions/log.py @@ -19,9 +19,7 @@ from .. import Evm from ..exceptions import WriteInStaticContext from ..gas import ( - GAS_LOG, - GAS_LOG_DATA_PER_BYTE, - GAS_LOG_TOPIC, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -59,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GAS_LOG - + GAS_LOG_DATA_PER_BYTE * Uint(size) - + GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.GAS_LOG + + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index bccc5fd6f01..2ec99f27cac 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -16,10 +16,9 @@ from ethereum.utils.numeric import ceil32 -from .. import Evm, gas +from .. import Evm from ..gas import ( - GAS_BASE, - GAS_COPY, + GasCosts, calculate_gas_extend_memory, charge_gas, ) @@ -48,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -79,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, gas.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -107,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, gas.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -134,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -160,14 +159,14 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GAS_COPY * words + copy_gas_cost = GasCosts.GAS_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] ) charge_gas( evm, - gas.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index 39a1682cb00..ec10bfb8aee 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -15,10 +15,10 @@ from ethereum_types.numeric import U256, Uint -from .. import Evm, gas, stack +from .. import Evm, stack from ..exceptions import StackUnderflowError from ..gas import ( - GAS_BASE, + GasCosts, charge_gas, ) from ..memory import buffer_read @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) # OPERATION pass @@ -66,9 +66,9 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GAS_BASE) + charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, gas.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.GAS_OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, gas.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo5/vm/instructions/storage.py b/src/ethereum/forks/bpo5/vm/instructions/storage.py index fd5bf4572ff..202917b6072 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo5/vm/instructions/storage.py @@ -23,12 +23,7 @@ from .. import Evm from ..exceptions import OutOfGasError, WriteInStaticContext from ..gas import ( - GAS_CALL_STIPEND, - GAS_COLD_STORAGE_ACCESS, - GAS_COLD_STORAGE_WRITE, - GAS_STORAGE_SET, - GAS_WARM_ACCESS, - REFUND_STORAGE_CLEAR, + GasCosts, charge_gas, ) from ..stack import pop, push @@ -50,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -79,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -92,37 +87,42 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GAS_STORAGE_SET + gas_cost += GasCosts.GAS_STORAGE_SET else: - gas_cost += GAS_COLD_STORAGE_WRITE - GAS_COLD_STORAGE_ACCESS + gas_cost += ( + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + ) else: - gas_cost += GAS_WARM_ACCESS + gas_cost += GasCosts.GAS_WARM_ACCESS # Refund Counter Calculation if current_value != new_value: if original_value != 0 and current_value != 0 and new_value == 0: # Storage is cleared for the first time in the transaction - evm.refund_counter += REFUND_STORAGE_CLEAR + evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR if original_value != 0 and current_value == 0: # Gas refund issued earlier to be reversed - evm.refund_counter -= REFUND_STORAGE_CLEAR + evm.refund_counter -= GasCosts.REFUND_STORAGE_CLEAR if original_value == new_value: # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - evm.refund_counter += int(GAS_STORAGE_SET - GAS_WARM_ACCESS) + evm.refund_counter += int( + GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GAS_COLD_STORAGE_WRITE - - GAS_COLD_STORAGE_ACCESS - - GAS_WARM_ACCESS + GasCosts.GAS_COLD_STORAGE_WRITE + - GasCosts.GAS_COLD_STORAGE_ACCESS + - GasCosts.GAS_WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +149,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +176,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo5/vm/instructions/system.py b/src/ethereum/forks/bpo5/vm/instructions/system.py index 29c3fe9e6e2..5087e180f3b 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/system.py +++ b/src/ethereum/forks/bpo5/vm/instructions/system.py @@ -40,15 +40,7 @@ ) from ..exceptions import OutOfGasError, Revert, WriteInStaticContext from ..gas import ( - GAS_CALL_VALUE, - GAS_COLD_ACCOUNT_ACCESS, - GAS_CREATE, - GAS_KECCAK256_PER_WORD, - GAS_NEW_ACCOUNT, - GAS_SELF_DESTRUCT, - GAS_SELF_DESTRUCT_NEW_ACCOUNT, - GAS_WARM_ACCESS, - GAS_ZERO, + GasCosts, calculate_gas_extend_memory, calculate_message_call_gas, charge_gas, @@ -166,7 +158,10 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, + GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GAS_CREATE - + GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.GAS_CREATE + + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -374,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( @@ -388,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.GAS_NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -463,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -476,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -531,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GAS_SELF_DESTRUCT + gas_cost = GasCosts.GAS_SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -543,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -604,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -673,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GAS_WARM_ACCESS + access_gas_cost = GasCosts.GAS_WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo5/vm/interpreter.py b/src/ethereum/forks/bpo5/vm/interpreter.py index d0eda4ef22d..bcf50e9a159 100644 --- a/src/ethereum/forks/bpo5/vm/interpreter.py +++ b/src/ethereum/forks/bpo5/vm/interpreter.py @@ -46,7 +46,7 @@ ) from ..vm import Message from ..vm.eoa_delegation import get_delegated_code_address, set_delegation -from ..vm.gas import GAS_CODE_DEPOSIT_PER_BYTE, charge_gas +from ..vm.gas import GasCosts, charge_gas from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS from . import Evm from .exceptions import ( @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE + Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py index c5eaff7d62a..2e80c49f6e4 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py @@ -14,7 +14,7 @@ from ethereum.crypto.blake2 import Blake2b from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_BLAKE2F_PER_ROUND, charge_gas +from ...vm.gas import GasCosts, charge_gas from ..exceptions import InvalidParameter @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 9c03c820465..f239ac2c7fd 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G1ADD, - GAS_PRECOMPILE_BLS_G1MAP, - GAS_PRECOMPILE_BLS_G1MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -60,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -101,7 +99,9 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +140,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 7a80d78b10c..c47b6689b07 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -21,9 +21,7 @@ from ....vm import Evm from ....vm.gas import ( - GAS_PRECOMPILE_BLS_G2ADD, - GAS_PRECOMPILE_BLS_G2MAP, - GAS_PRECOMPILE_BLS_G2MUL, + GasCosts, charge_gas, ) from ....vm.memory import buffer_read @@ -61,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -102,7 +100,9 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = Uint(k) * GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + gas_cost = ( + Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER + ) charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +141,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py index b6d23a58a89..049e6f13577 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py @@ -19,7 +19,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_ECRECOVER, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py index 133a4832bf8..07804e9174f 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py @@ -17,8 +17,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_IDENTITY_BASE, - GAS_PRECOMPILE_IDENTITY_PER_WORD, + GasCosts, charge_gas, ) @@ -39,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_IDENTITY_BASE - + GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_IDENTITY_BASE + + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py index e35ea1bb4ec..99b3c722940 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py @@ -24,7 +24,7 @@ from ethereum.utils.byte import left_pad_zero_bytes from ...vm import Evm -from ...vm.gas import GAS_PRECOMPILE_P256VERIFY, charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py index ce4eed71294..ca60b8daee5 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py @@ -22,7 +22,7 @@ from ...vm import Evm from ...vm.exceptions import KZGProofError -from ...vm.gas import GAS_POINT_EVALUATION, charge_gas +from ...vm.gas import GasCosts, charge_gas FIELD_ELEMENTS_PER_BLOB = 4096 BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513 # noqa: E501 @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..b3ee3aab9b1 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py @@ -20,8 +20,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_RIPEMD160_BASE, - GAS_PRECOMPILE_RIPEMD160_PER_WORD, + GasCosts, charge_gas, ) @@ -42,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_RIPEMD160_BASE - + GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE + + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py index 04dfef6730d..5482b20221d 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py @@ -19,8 +19,7 @@ from ...vm import Evm from ...vm.gas import ( - GAS_PRECOMPILE_SHA256_BASE, - GAS_PRECOMPILE_SHA256_PER_WORD, + GasCosts, charge_gas, ) @@ -41,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GAS_PRECOMPILE_SHA256_BASE - + GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.GAS_PRECOMPILE_SHA256_BASE + + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION From 07ff662e45e22310bc55a6b74375140bf6f0cf45 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 25 Mar 2026 13:42:18 -0400 Subject: [PATCH 31/61] refactor: GAS_OPCODE_PUSH_N -> GAS_OPCODE_PUSH --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/stack.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- src/ethereum/forks/arrow_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/stack.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/stack.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/stack.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- src/ethereum/forks/constantinople/vm/instructions/stack.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/instructions/stack.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/instructions/stack.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- src/ethereum/forks/gray_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- src/ethereum/forks/homestead/vm/instructions/stack.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/stack.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/stack.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- src/ethereum/forks/muir_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/stack.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/stack.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/stack.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/stack.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- src/ethereum/forks/spurious_dragon/vm/instructions/stack.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/gas.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py | 2 +- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 6f9e866a5ba..1859570e856 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -194,7 +194,7 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_MLOAD=GAS_VERY_LOW, GAS_OPCODE_MSTORE=GAS_VERY_LOW, GAS_OPCODE_MSTORE8=GAS_VERY_LOW, - GAS_OPCODE_PUSH_N=GAS_VERY_LOW, + GAS_OPCODE_PUSH=GAS_VERY_LOW, GAS_OPCODE_DUP=GAS_VERY_LOW, GAS_OPCODE_SWAP=GAS_VERY_LOW, ) @@ -431,7 +431,7 @@ def opcode_gas_map( Opcodes.JUMPDEST: gas_costs.GAS_JUMPDEST, # Push operations (PUSH1 through PUSH32) **{ - getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_OPCODE_PUSH_N + getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_OPCODE_PUSH for i in range(1, 33) }, # Dup operations (DUP1 through DUP16) diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 470a7846c17..54e1103c5a5 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MLOAD: int GAS_OPCODE_MSTORE: int GAS_OPCODE_MSTORE8: int - GAS_OPCODE_PUSH_N: int + GAS_OPCODE_PUSH: int GAS_OPCODE_DUP: int GAS_OPCODE_SWAP: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 206d4fbe446..8bf8396d8db 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -131,7 +131,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index d0dbf109b4b..c67885fa7cc 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -105,7 +105,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index b752d9b0bf2..b451dcec643 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -106,7 +106,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 0dab658f265..52c8e8a1e3f 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 9a484e7ca43..eb1cc912eba 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index cda862303c8..465df9da7d2 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index f704e4dab07..cb28c979f80 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index cda862303c8..465df9da7d2 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 318db550cc5..56c55aa2836 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index cba2d33cf96..08f6bedf370 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 83da270810d..cd237c9fd24 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -102,7 +102,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 0d8717dab2d..df179b4aed6 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -116,7 +116,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 28d89226d02..b2ab9d8f20a 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -106,7 +106,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 859f75b0b62..39f141b7d66 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -100,7 +100,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 399b15df309..ad9e72181ea 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -100,7 +100,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index b4fdd58ea2a..cb8593f3d17 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -105,7 +105,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 51adbf8d77b..5bf5245d155 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -100,7 +100,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 7fd65c90e57..0d2a1db7683 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -108,7 +108,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 73b65ebe639..74d500de65a 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -105,7 +105,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index db810c00e94..982bf3bd60e 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -108,7 +108,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index f9988f71914..c837e1dde0c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -128,7 +128,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 86a0ee92ca1..d4ea713283e 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -105,7 +105,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index d16faa05d6f..db9a89fd025 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -123,7 +123,7 @@ class GasCosts: GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index ec10bfb8aee..f3825c561b5 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 4920941ede3..43ad962a97a 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -106,7 +106,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index cda862303c8..465df9da7d2 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index fb83683f41f..c1a683dfa74 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -100,7 +100,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index a7dbe8ae9ad..b8db2b1044c 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -100,7 +100,7 @@ class GasCosts: GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH_N = GAS_VERY_LOW + GAS_OPCODE_PUSH = GAS_VERY_LOW GAS_OPCODE_DUP = GAS_VERY_LOW GAS_OPCODE_SWAP = GAS_VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 98a9816abc3..2acc1af3d26 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH_N) + charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( From 290aa203560bd9246b1ed20446d638ebd4ad60c3 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 25 Mar 2026 14:31:14 -0400 Subject: [PATCH 32/61] feat: add COINBASE opcode gas constant --- src/ethereum/forks/amsterdam/vm/gas.py | 1 + src/ethereum/forks/arrow_glacier/vm/gas.py | 1 + src/ethereum/forks/berlin/vm/gas.py | 1 + src/ethereum/forks/bpo1/vm/gas.py | 1 + src/ethereum/forks/bpo2/vm/gas.py | 1 + src/ethereum/forks/bpo3/vm/gas.py | 1 + src/ethereum/forks/bpo4/vm/gas.py | 1 + src/ethereum/forks/bpo5/vm/gas.py | 1 + src/ethereum/forks/byzantium/vm/gas.py | 1 + src/ethereum/forks/cancun/vm/gas.py | 1 + src/ethereum/forks/constantinople/vm/gas.py | 1 + src/ethereum/forks/dao_fork/vm/gas.py | 1 + src/ethereum/forks/frontier/vm/gas.py | 1 + src/ethereum/forks/gray_glacier/vm/gas.py | 1 + src/ethereum/forks/homestead/vm/gas.py | 1 + src/ethereum/forks/istanbul/vm/gas.py | 1 + src/ethereum/forks/london/vm/gas.py | 1 + src/ethereum/forks/muir_glacier/vm/gas.py | 1 + src/ethereum/forks/osaka/vm/gas.py | 1 + src/ethereum/forks/paris/vm/gas.py | 1 + src/ethereum/forks/prague/vm/gas.py | 1 + src/ethereum/forks/shanghai/vm/gas.py | 1 + src/ethereum/forks/spurious_dragon/vm/gas.py | 1 + src/ethereum/forks/tangerine_whistle/vm/gas.py | 1 + 24 files changed, 24 insertions(+) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 8bf8396d8db..36b651db372 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -127,6 +127,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index c67885fa7cc..1e346c86b42 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index b451dcec643..75f8f5f4e83 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 52c8e8a1e3f..35d9f617012 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index eb1cc912eba..8a58a248bf8 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index cb28c979f80..d2db631b691 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 56c55aa2836..cdfd23b7e7f 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 08f6bedf370..0fa7503989e 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index cd237c9fd24..18e823cb15b 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -99,6 +99,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index df179b4aed6..e73bd373bb7 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -112,6 +112,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index b2ab9d8f20a..c359ae978e5 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 39f141b7d66..6a4a9460639 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -97,6 +97,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index ad9e72181ea..8dda106ffdf 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -97,6 +97,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index cb8593f3d17..7cf72b42e50 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 5bf5245d155..078df4ebf6e 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -97,6 +97,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 0d2a1db7683..13721b3a9ce 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -105,6 +105,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 74d500de65a..78ddd796260 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 982bf3bd60e..50178f04c93 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -105,6 +105,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index c837e1dde0c..1edae16bcc5 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -124,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index d4ea713283e..26f12bcaad2 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index db9a89fd025..d4791e4706d 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -119,6 +119,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 43ad962a97a..4b4b8be74e6 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index c1a683dfa74..a4327628691 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -97,6 +97,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index b8db2b1044c..e25efaa67d2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -97,6 +97,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW From 5f77a69579a8b9b64b99e766d03efa229f6eaf3e Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 25 Mar 2026 19:56:30 -0400 Subject: [PATCH 33/61] refactor: align formatting of a docstring --- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++-- src/ethereum/forks/berlin/vm/gas.py | 4 ++-- src/ethereum/forks/bpo1/vm/gas.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 4 ++-- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- src/ethereum/forks/cancun/vm/gas.py | 4 ++-- src/ethereum/forks/constantinople/vm/gas.py | 4 ++-- src/ethereum/forks/dao_fork/vm/gas.py | 4 ++-- src/ethereum/forks/frontier/vm/gas.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/homestead/vm/gas.py | 4 ++-- src/ethereum/forks/istanbul/vm/gas.py | 4 ++-- src/ethereum/forks/london/vm/gas.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/osaka/vm/gas.py | 4 ++-- src/ethereum/forks/paris/vm/gas.py | 4 ++-- src/ethereum/forks/prague/vm/gas.py | 4 ++-- src/ethereum/forks/shanghai/vm/gas.py | 4 ++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 4 ++-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 4 ++-- 23 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 36b651db372..c12614abb3e 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -155,8 +155,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 75f8f5f4e83..e449188b41c 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -130,8 +130,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 35d9f617012..1b91f4a6d3d 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 8a58a248bf8..9a5979a1e9f 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index d2db631b691..08910d4a006 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index cdfd23b7e7f..663675ee294 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 0fa7503989e..e0ff71ebdf6 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 18e823cb15b..59241e424b5 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -126,8 +126,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index e73bd373bb7..d137db966ae 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -140,8 +140,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index c359ae978e5..beefbef6b2f 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -130,8 +130,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 6a4a9460639..65f0769d57d 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -124,8 +124,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 8dda106ffdf..6cc74f6d68e 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -124,8 +124,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 7cf72b42e50..e3a63b81860 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -129,8 +129,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 078df4ebf6e..a3e1fb07601 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -124,8 +124,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 13721b3a9ce..409c748426b 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -132,8 +132,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 78ddd796260..f4be793cc50 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -129,8 +129,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 50178f04c93..a6a5e79fe5f 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -132,8 +132,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 1edae16bcc5..3ce9d2c495a 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -152,8 +152,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 26f12bcaad2..cdfa23e7eba 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -129,8 +129,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index d4791e4706d..cd972edfa78 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -147,8 +147,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 4b4b8be74e6..0f34ed018b8 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -130,8 +130,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index a4327628691..6bfc1fa13a0 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -124,8 +124,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index e25efaa67d2..ba92c543a3e 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -124,8 +124,8 @@ class ExtendMemory: @dataclass class MessageCallGas: """ - Define the gas cost and gas given to the sub-call for - executing the call opcodes. + Define the gas cost and gas given to the sub-call for executing the call + opcodes. `cost`: `ethereum.base_types.Uint` The gas required to execute the call opcode, excludes From 17da94627818f95fb92182b44b3867504fc76213 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Fri, 27 Mar 2026 14:50:07 -0400 Subject: [PATCH 34/61] fix: code review comments --- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- .../amsterdam/vm/instructions/environment.py | 52 +++++++------------ .../forks/amsterdam/vm/interpreter.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- .../forks/arrow_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/interpreter.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/interpreter.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/interpreter.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/interpreter.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/interpreter.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/interpreter.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- .../forks/byzantium/vm/interpreter.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/interpreter.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- .../forks/constantinople/vm/interpreter.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/interpreter.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/interpreter.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- .../forks/gray_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- .../forks/homestead/vm/interpreter.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/interpreter.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/interpreter.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- .../forks/muir_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/interpreter.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/interpreter.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/interpreter.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/interpreter.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- .../forks/spurious_dragon/vm/interpreter.py | 2 +- .../forks/tangerine_whistle/vm/gas.py | 2 +- .../forks/tangerine_whistle/vm/interpreter.py | 2 +- 49 files changed, 66 insertions(+), 82 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index c12614abb3e..360fa6c7876 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -28,7 +28,7 @@ class GasCosts: """ - Constant gas values for the Amsterdam fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 780d406ed03..44f73343af5 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -68,16 +68,11 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - is_cold_access = address not in evm.accessed_addresses - gas_cost = ( - GasCosts.GAS_COLD_ACCOUNT_ACCESS - if is_cold_access - else GasCosts.GAS_WARM_ACCESS - ) - if is_cold_access: + if address in evm.accessed_addresses: + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + else: evm.accessed_addresses.add(address) - - charge_gas(evm, gas_cost) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -345,16 +340,11 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - is_cold_access = address not in evm.accessed_addresses - access_gas_cost = ( - GasCosts.GAS_COLD_ACCOUNT_ACCESS - if is_cold_access - else GasCosts.GAS_WARM_ACCESS - ) - if is_cold_access: + if address in evm.accessed_addresses: + charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + else: evm.accessed_addresses.add(address) - - charge_gas(evm, access_gas_cost) + charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) # OPERATION tx_state = evm.message.tx_env.state @@ -391,16 +381,13 @@ def extcodecopy(evm: Evm) -> None: evm.memory, [(memory_start_index, size)] ) - is_cold_access = address not in evm.accessed_addresses - access_gas_cost = ( - GasCosts.GAS_COLD_ACCOUNT_ACCESS - if is_cold_access - else GasCosts.GAS_WARM_ACCESS - ) - total_gas_cost = access_gas_cost + copy_gas_cost + extend_memory.cost - - if is_cold_access: + if address in evm.accessed_addresses: + access_gas_cost = GasCosts.GAS_WARM_ACCESS + else: evm.accessed_addresses.add(address) + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + + total_gas_cost = access_gas_cost + copy_gas_cost + extend_memory.cost charge_gas(evm, total_gas_cost) @@ -494,14 +481,11 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - is_cold_access = address not in evm.accessed_addresses - access_gas_cost = ( - GasCosts.GAS_COLD_ACCOUNT_ACCESS - if is_cold_access - else GasCosts.GAS_WARM_ACCESS - ) - if is_cold_access: + if address in evm.accessed_addresses: + access_gas_cost = GasCosts.GAS_WARM_ACCESS + else: evm.accessed_addresses.add(address) + access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) diff --git a/src/ethereum/forks/amsterdam/vm/interpreter.py b/src/ethereum/forks/amsterdam/vm/interpreter.py index bc7dce16baf..f24694ae00d 100644 --- a/src/ethereum/forks/amsterdam/vm/interpreter.py +++ b/src/ethereum/forks/amsterdam/vm/interpreter.py @@ -201,7 +201,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 1e346c86b42..40182987378 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Arrow Glacier fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/arrow_glacier/vm/interpreter.py b/src/ethereum/forks/arrow_glacier/vm/interpreter.py index 2ea4800c076..ae35e4f84fe 100644 --- a/src/ethereum/forks/arrow_glacier/vm/interpreter.py +++ b/src/ethereum/forks/arrow_glacier/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index e449188b41c..b268a513b57 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Berlin fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/berlin/vm/interpreter.py b/src/ethereum/forks/berlin/vm/interpreter.py index bfea01bfc0b..5bf644862bc 100644 --- a/src/ethereum/forks/berlin/vm/interpreter.py +++ b/src/ethereum/forks/berlin/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 1b91f4a6d3d..554a7e54847 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the BPO (Blob Parameter Only) 1 fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/bpo1/vm/interpreter.py b/src/ethereum/forks/bpo1/vm/interpreter.py index ce5209bb811..0e1e167b257 100644 --- a/src/ethereum/forks/bpo1/vm/interpreter.py +++ b/src/ethereum/forks/bpo1/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 9a5979a1e9f..56b02e3d041 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the BPO (Blob Parameter Only) 2 fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/bpo2/vm/interpreter.py b/src/ethereum/forks/bpo2/vm/interpreter.py index e18354f75a9..c6e3953339d 100644 --- a/src/ethereum/forks/bpo2/vm/interpreter.py +++ b/src/ethereum/forks/bpo2/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 08910d4a006..56b02e3d041 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the BPO (Blob Parameter Only) 3 fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/bpo3/vm/interpreter.py b/src/ethereum/forks/bpo3/vm/interpreter.py index 7a9b1e15f41..81ddbf448a6 100644 --- a/src/ethereum/forks/bpo3/vm/interpreter.py +++ b/src/ethereum/forks/bpo3/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 663675ee294..56b02e3d041 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the BPO (Blob Parameter Only) 4 fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/bpo4/vm/interpreter.py b/src/ethereum/forks/bpo4/vm/interpreter.py index 7f3c4154df7..7d38f5d59b9 100644 --- a/src/ethereum/forks/bpo4/vm/interpreter.py +++ b/src/ethereum/forks/bpo4/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index e0ff71ebdf6..56b02e3d041 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the BPO (Blob Parameter Only) 5 fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/bpo5/vm/interpreter.py b/src/ethereum/forks/bpo5/vm/interpreter.py index bcf50e9a159..c2d287eb655 100644 --- a/src/ethereum/forks/bpo5/vm/interpreter.py +++ b/src/ethereum/forks/bpo5/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 59241e424b5..43b9d592da6 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Byzantium fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/byzantium/vm/interpreter.py b/src/ethereum/forks/byzantium/vm/interpreter.py index d6a84291844..c8047c020bf 100644 --- a/src/ethereum/forks/byzantium/vm/interpreter.py +++ b/src/ethereum/forks/byzantium/vm/interpreter.py @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index d137db966ae..6d0c905eea0 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the Cancun fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/cancun/vm/interpreter.py b/src/ethereum/forks/cancun/vm/interpreter.py index a59f559ec07..b0cfdcbcad9 100644 --- a/src/ethereum/forks/cancun/vm/interpreter.py +++ b/src/ethereum/forks/cancun/vm/interpreter.py @@ -171,7 +171,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index beefbef6b2f..ef9c518fe49 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Constantinople fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/constantinople/vm/interpreter.py b/src/ethereum/forks/constantinople/vm/interpreter.py index 47e33b3498b..6264ddc194f 100644 --- a/src/ethereum/forks/constantinople/vm/interpreter.py +++ b/src/ethereum/forks/constantinople/vm/interpreter.py @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 65f0769d57d..4b6c626b717 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the DAO fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/dao_fork/vm/interpreter.py b/src/ethereum/forks/dao_fork/vm/interpreter.py index f4477057e12..32ed648b2d3 100644 --- a/src/ethereum/forks/dao_fork/vm/interpreter.py +++ b/src/ethereum/forks/dao_fork/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 6cc74f6d68e..4b6c626b717 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the Frontier fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/frontier/vm/interpreter.py b/src/ethereum/forks/frontier/vm/interpreter.py index c4ebe520fbd..3f1917a2202 100644 --- a/src/ethereum/forks/frontier/vm/interpreter.py +++ b/src/ethereum/forks/frontier/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index e3a63b81860..40182987378 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Gray Glacier fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/gray_glacier/vm/interpreter.py b/src/ethereum/forks/gray_glacier/vm/interpreter.py index 544b5bb142c..978633c4896 100644 --- a/src/ethereum/forks/gray_glacier/vm/interpreter.py +++ b/src/ethereum/forks/gray_glacier/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index a3e1fb07601..4b6c626b717 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the Homestead fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/homestead/vm/interpreter.py b/src/ethereum/forks/homestead/vm/interpreter.py index fddc1d03c66..299022576d9 100644 --- a/src/ethereum/forks/homestead/vm/interpreter.py +++ b/src/ethereum/forks/homestead/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 409c748426b..50b51841221 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Istanbul fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/istanbul/vm/interpreter.py b/src/ethereum/forks/istanbul/vm/interpreter.py index 549b340dfa9..5f21440ba63 100644 --- a/src/ethereum/forks/istanbul/vm/interpreter.py +++ b/src/ethereum/forks/istanbul/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index f4be793cc50..40182987378 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the London fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/london/vm/interpreter.py b/src/ethereum/forks/london/vm/interpreter.py index 0262ba5c3de..01abdaba107 100644 --- a/src/ethereum/forks/london/vm/interpreter.py +++ b/src/ethereum/forks/london/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index a6a5e79fe5f..50b51841221 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Muir Glacier fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/muir_glacier/vm/interpreter.py b/src/ethereum/forks/muir_glacier/vm/interpreter.py index 12d010dd3c1..2479183621d 100644 --- a/src/ethereum/forks/muir_glacier/vm/interpreter.py +++ b/src/ethereum/forks/muir_glacier/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 3ce9d2c495a..355887b5699 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the Osaka fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/osaka/vm/interpreter.py b/src/ethereum/forks/osaka/vm/interpreter.py index 5802d508142..8477afbe071 100644 --- a/src/ethereum/forks/osaka/vm/interpreter.py +++ b/src/ethereum/forks/osaka/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index cdfa23e7eba..40182987378 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Paris fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/paris/vm/interpreter.py b/src/ethereum/forks/paris/vm/interpreter.py index 8b3d9c4c35f..29577922e6c 100644 --- a/src/ethereum/forks/paris/vm/interpreter.py +++ b/src/ethereum/forks/paris/vm/interpreter.py @@ -167,7 +167,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index cd972edfa78..db7cb9a21f7 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -27,7 +27,7 @@ class GasCosts: """ - Constant gas values for the Prague fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/prague/vm/interpreter.py b/src/ethereum/forks/prague/vm/interpreter.py index c8a18c89c87..8c0b3b394b1 100644 --- a/src/ethereum/forks/prague/vm/interpreter.py +++ b/src/ethereum/forks/prague/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 0f34ed018b8..aeb2597c3a0 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Shanghai fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/shanghai/vm/interpreter.py b/src/ethereum/forks/shanghai/vm/interpreter.py index 2c4634f314b..95c8f9ca897 100644 --- a/src/ethereum/forks/shanghai/vm/interpreter.py +++ b/src/ethereum/forks/shanghai/vm/interpreter.py @@ -168,7 +168,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 6bfc1fa13a0..9274d71f834 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Spurious Dragon fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/spurious_dragon/vm/interpreter.py b/src/ethereum/forks/spurious_dragon/vm/interpreter.py index e7509cd215c..6a306d79c8a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/interpreter.py +++ b/src/ethereum/forks/spurious_dragon/vm/interpreter.py @@ -173,7 +173,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index ba92c543a3e..65ccf5ee7b1 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -25,7 +25,7 @@ class GasCosts: """ - Constant gas values for the Tangerine Whistle fork of the EVM. + Constant gas values for the EVM. These values may be patched at runtime by a future gas repricing utility """ diff --git a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py index a8ace8b373a..e35f2c4b04a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py +++ b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - Uint(len(contract_code)) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) From 246f14a1f22a4ea1b515ab929d4bb234b51591a3 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 30 Mar 2026 13:21:30 -0400 Subject: [PATCH 35/61] refactor:GAS_BLOCK_HASH => GAS_OPCODE_BLOCKHASH --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/block.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- src/ethereum/forks/arrow_glacier/vm/instructions/block.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/block.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/block.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/block.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/block.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/block.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/block.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/block.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/block.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- src/ethereum/forks/constantinople/vm/instructions/block.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/instructions/block.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/instructions/block.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- src/ethereum/forks/gray_glacier/vm/instructions/block.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- src/ethereum/forks/homestead/vm/instructions/block.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/block.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/block.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- src/ethereum/forks/muir_glacier/vm/instructions/block.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/block.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/block.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/block.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/block.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- src/ethereum/forks/spurious_dragon/vm/instructions/block.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/gas.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/instructions/block.py | 2 +- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 1859570e856..f8865443aaa 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -133,7 +133,6 @@ def gas_costs(cls) -> GasCosts: GAS_KECCAK256=30, GAS_KECCAK256_PER_WORD=6, GAS_COPY=3, - GAS_BLOCK_HASH=20, GAS_PRECOMPILE_ECRECOVER=3_000, GAS_PRECOMPILE_SHA256_BASE=60, GAS_PRECOMPILE_SHA256_PER_WORD=12, @@ -191,6 +190,7 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_CALLDATALOAD=GAS_VERY_LOW, GAS_OPCODE_CALLDATACOPY=GAS_VERY_LOW, GAS_OPCODE_CODECOPY=GAS_VERY_LOW, + GAS_OPCODE_BLOCKHASH=20, GAS_OPCODE_MLOAD=GAS_VERY_LOW, GAS_OPCODE_MSTORE=GAS_VERY_LOW, GAS_OPCODE_MSTORE8=GAS_VERY_LOW, @@ -395,7 +395,7 @@ def opcode_gas_map( memory_expansion_calculator, ), # Block information - Opcodes.BLOCKHASH: gas_costs.GAS_BLOCK_HASH, + Opcodes.BLOCKHASH: gas_costs.GAS_OPCODE_BLOCKHASH, Opcodes.COINBASE: gas_costs.GAS_BASE, Opcodes.TIMESTAMP: gas_costs.GAS_BASE, Opcodes.NUMBER: gas_costs.GAS_BASE, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 54e1103c5a5..2a34eb338d8 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -58,7 +58,6 @@ class GasCosts: GAS_KECCAK256_PER_WORD: int GAS_COPY: int - GAS_BLOCK_HASH: int GAS_AUTH_PER_EMPTY_ACCOUNT: int @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD: int GAS_OPCODE_CALLDATACOPY: int GAS_OPCODE_CODECOPY: int + GAS_OPCODE_BLOCKHASH: int GAS_OPCODE_MLOAD: int GAS_OPCODE_MSTORE: int GAS_OPCODE_MSTORE8: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 360fa6c7876..98e27795323 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -48,7 +48,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -127,6 +126,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/block.py b/src/ethereum/forks/amsterdam/vm/instructions/block.py index 04472d3c18d..65a537e6657 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/block.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 40182987378..55b01b58f17 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -102,6 +101,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index b268a513b57..f6fec42f893 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -103,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/block.py b/src/ethereum/forks/berlin/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/berlin/vm/instructions/block.py +++ b/src/ethereum/forks/berlin/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 554a7e54847..8daa5162f6d 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/block.py b/src/ethereum/forks/bpo1/vm/instructions/block.py index 2ff879de431..1d405801688 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/block.py +++ b/src/ethereum/forks/bpo1/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 56b02e3d041..1901b8237a7 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/block.py b/src/ethereum/forks/bpo2/vm/instructions/block.py index 07a3fcdb320..acb15f411d7 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/block.py +++ b/src/ethereum/forks/bpo2/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 56b02e3d041..1901b8237a7 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/block.py b/src/ethereum/forks/bpo3/vm/instructions/block.py index 937ec58ca20..15844f6a783 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/block.py +++ b/src/ethereum/forks/bpo3/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 56b02e3d041..1901b8237a7 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/block.py b/src/ethereum/forks/bpo4/vm/instructions/block.py index 1e80ccccca9..434e674df32 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/block.py +++ b/src/ethereum/forks/bpo4/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 56b02e3d041..1901b8237a7 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/block.py b/src/ethereum/forks/bpo5/vm/instructions/block.py index 5d4054bf508..d14e8c66a5c 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/block.py +++ b/src/ethereum/forks/bpo5/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 43b9d592da6..05c37c8af51 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(400) GAS_LOG = Uint(375) @@ -99,6 +98,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/block.py b/src/ethereum/forks/byzantium/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/block.py +++ b/src/ethereum/forks/byzantium/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 6d0c905eea0..9aa7801588b 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -112,6 +111,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/block.py b/src/ethereum/forks/cancun/vm/instructions/block.py index a87cbbfb558..d0b3fb5aa82 100644 --- a/src/ethereum/forks/cancun/vm/instructions/block.py +++ b/src/ethereum/forks/cancun/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index ef9c518fe49..9205fa1722a 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(400) GAS_LOG = Uint(375) @@ -103,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/block.py b/src/ethereum/forks/constantinople/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/block.py +++ b/src/ethereum/forks/constantinople/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 4b6c626b717..bd93e361bf8 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -48,7 +48,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(20) GAS_BALANCE = Uint(20) GAS_LOG = Uint(375) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/instructions/block.py b/src/ethereum/forks/dao_fork/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/block.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 4b6c626b717..bd93e361bf8 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -48,7 +48,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(20) GAS_BALANCE = Uint(20) GAS_LOG = Uint(375) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/instructions/block.py b/src/ethereum/forks/frontier/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/frontier/vm/instructions/block.py +++ b/src/ethereum/forks/frontier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 40182987378..55b01b58f17 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -102,6 +101,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/block.py b/src/ethereum/forks/gray_glacier/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 4b6c626b717..bd93e361bf8 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -48,7 +48,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(20) GAS_BALANCE = Uint(20) GAS_LOG = Uint(375) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/instructions/block.py b/src/ethereum/forks/homestead/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/homestead/vm/instructions/block.py +++ b/src/ethereum/forks/homestead/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 50b51841221..33c786f407c 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(700) GAS_LOG = Uint(375) @@ -105,6 +104,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/block.py b/src/ethereum/forks/istanbul/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/block.py +++ b/src/ethereum/forks/istanbul/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 40182987378..55b01b58f17 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -102,6 +101,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/block.py b/src/ethereum/forks/london/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/london/vm/instructions/block.py +++ b/src/ethereum/forks/london/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 50b51841221..33c786f407c 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(700) GAS_LOG = Uint(375) @@ -105,6 +104,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/block.py b/src/ethereum/forks/muir_glacier/vm/instructions/block.py index 516fcd7a727..b22b2b0ffa0 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 355887b5699..392b068c528 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -124,6 +123,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/block.py b/src/ethereum/forks/osaka/vm/instructions/block.py index e8e4fabc79d..c856418c191 100644 --- a/src/ethereum/forks/osaka/vm/instructions/block.py +++ b/src/ethereum/forks/osaka/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 40182987378..55b01b58f17 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -102,6 +101,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/block.py b/src/ethereum/forks/paris/vm/instructions/block.py index 88f0b3a55a7..f009e2d58a2 100644 --- a/src/ethereum/forks/paris/vm/instructions/block.py +++ b/src/ethereum/forks/paris/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index db7cb9a21f7..08deb4400ee 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -47,7 +47,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/block.py b/src/ethereum/forks/prague/vm/instructions/block.py index dfa4020c47f..c53a9cddbbf 100644 --- a/src/ethereum/forks/prague/vm/instructions/block.py +++ b/src/ethereum/forks/prague/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index aeb2597c3a0..d7407bc1d5d 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -45,7 +45,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_LOG = Uint(375) GAS_LOG_DATA_PER_BYTE = Uint(8) GAS_LOG_TOPIC = Uint(375) @@ -103,6 +102,7 @@ class GasCosts: GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/block.py b/src/ethereum/forks/shanghai/vm/instructions/block.py index c537805bc37..aec457e3eef 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/block.py +++ b/src/ethereum/forks/shanghai/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 9274d71f834..14a5e188ff3 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(400) GAS_LOG = Uint(375) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 65ccf5ee7b1..be9c4e69e71 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -46,7 +46,6 @@ class GasCosts: GAS_KECCAK256 = Uint(30) GAS_KECCAK256_PER_WORD = Uint(6) GAS_COPY = Uint(3) - GAS_BLOCK_HASH = Uint(20) GAS_EXTERNAL = Uint(700) GAS_BALANCE = Uint(400) GAS_LOG = Uint(375) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW + GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py index ba253fb16dc..abde61719df 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BLOCK_HASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) From af420fa68fdba9b5bf98fe913f2b191cb9e9b394 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 30 Mar 2026 13:39:48 -0400 Subject: [PATCH 36/61] refactor:GAS_JUMPDEST => GAS_OPCODE_JUMPDEST --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- .../testing/src/execution_testing/tools/utility/generators.py | 4 ++-- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- .../forks/arrow_glacier/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- .../forks/constantinople/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- src/ethereum/forks/dao_fork/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 2 +- src/ethereum/forks/frontier/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- .../forks/gray_glacier/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 2 +- src/ethereum/forks/homestead/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- .../forks/muir_glacier/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- .../forks/spurious_dragon/vm/instructions/control_flow.py | 2 +- src/ethereum/forks/tangerine_whistle/vm/gas.py | 2 +- .../forks/tangerine_whistle/vm/instructions/control_flow.py | 2 +- 51 files changed, 53 insertions(+), 53 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index f8865443aaa..80d6f4f8128 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -97,7 +97,6 @@ def gas_costs(cls) -> GasCosts: Return dataclass with the defined gas costs constants for genesis. """ return GasCosts( - GAS_JUMPDEST=1, GAS_BASE=2, GAS_VERY_LOW=3, GAS_LOW=5, @@ -187,6 +186,7 @@ def gas_costs(cls) -> GasCosts: GAS_OPCODE_BYTE=GAS_VERY_LOW, GAS_OPCODE_JUMP=GAS_MID, GAS_OPCODE_JUMPI=GAS_HIGH, + GAS_OPCODE_JUMPDEST=1, GAS_OPCODE_CALLDATALOAD=GAS_VERY_LOW, GAS_OPCODE_CALLDATACOPY=GAS_VERY_LOW, GAS_OPCODE_CODECOPY=GAS_VERY_LOW, @@ -428,7 +428,7 @@ def opcode_gas_map( Opcodes.PC: gas_costs.GAS_BASE, Opcodes.MSIZE: gas_costs.GAS_BASE, Opcodes.GAS: gas_costs.GAS_BASE, - Opcodes.JUMPDEST: gas_costs.GAS_JUMPDEST, + Opcodes.JUMPDEST: gas_costs.GAS_OPCODE_JUMPDEST, # Push operations (PUSH1 through PUSH32) **{ getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_OPCODE_PUSH diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 2a34eb338d8..67980347f06 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -13,7 +13,6 @@ class GasCosts: """Class that contains the gas cost constants for any fork.""" - GAS_JUMPDEST: int GAS_BASE: int GAS_VERY_LOW: int GAS_LOW: int @@ -121,6 +120,7 @@ class GasCosts: GAS_OPCODE_BYTE: int GAS_OPCODE_JUMP: int GAS_OPCODE_JUMPI: int + GAS_OPCODE_JUMPDEST: int GAS_OPCODE_CALLDATALOAD: int GAS_OPCODE_CALLDATACOPY: int GAS_OPCODE_CODECOPY: int diff --git a/packages/testing/src/execution_testing/tools/utility/generators.py b/packages/testing/src/execution_testing/tools/utility/generators.py index f2e725e1dc9..26d790165aa 100644 --- a/packages/testing/src/execution_testing/tools/utility/generators.py +++ b/packages/testing/src/execution_testing/tools/utility/generators.py @@ -369,9 +369,9 @@ def wrapper( # If the gas limit is not divisible by the gas used per # storage, we need to add some NO-OP (JUMPDEST) to the code # that each consume 1 gas. - assert gas_costs.GAS_JUMPDEST == 1, ( + assert gas_costs.GAS_OPCODE_JUMPDEST == 1, ( "JUMPDEST gas cost should be 1, but got " - f"{gas_costs.GAS_JUMPDEST}. Generator " + f"{gas_costs.GAS_OPCODE_JUMPDEST}. Generator " "`generate_system_contract_error_test` needs updating." ) modified_system_contract_code += sum( diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 98e27795323..51fd46e7e06 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -33,7 +33,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -122,6 +121,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 55b01b58f17..2e9027f665e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index f6fec42f893..7ae48a6f84a 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -98,6 +97,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 8daa5162f6d..77a45fa958e 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 1901b8237a7..845aef469c2 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index bfcf3904a33..72487f9dcf9 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 1901b8237a7..845aef469c2 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index bfcf3904a33..72487f9dcf9 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 1901b8237a7..845aef469c2 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 1901b8237a7..845aef469c2 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 05c37c8af51..75990ccd3bf 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) @@ -94,6 +93,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 9aa7801588b..43da16903e1 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -107,6 +106,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 9205fa1722a..be1f3497bd0 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) @@ -98,6 +97,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index bd93e361bf8..f41b7f85512 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) @@ -93,6 +92,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index bd93e361bf8..f41b7f85512 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) @@ -93,6 +92,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 55b01b58f17..2e9027f665e 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index bd93e361bf8..f41b7f85512 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) @@ -93,6 +92,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 33c786f407c..542973760fd 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(800) @@ -100,6 +99,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 55b01b58f17..2e9027f665e 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 33c786f407c..542973760fd 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(800) @@ -100,6 +99,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 392b068c528..7990b540301 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -119,6 +118,7 @@ class GasCosts: GAS_OPCODE_CLZ = GAS_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 55b01b58f17..2e9027f665e 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -97,6 +96,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 08deb4400ee..ee400e49729 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -32,7 +32,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -114,6 +113,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index d7407bc1d5d..29d5235fafd 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) @@ -98,6 +97,7 @@ class GasCosts: GAS_OPCODE_SAR = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index bfcf3904a33..72487f9dcf9 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 14a5e188ff3..38ffddb2dc8 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) @@ -93,6 +92,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index be9c4e69e71..bc6e9d5e010 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -30,7 +30,6 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - GAS_JUMPDEST = Uint(1) GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) @@ -93,6 +92,7 @@ class GasCosts: GAS_OPCODE_BYTE = GAS_VERY_LOW GAS_OPCODE_JUMP = GAS_MID GAS_OPCODE_JUMPI = GAS_HIGH + GAS_OPCODE_JUMPDEST = Uint(1) GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW GAS_OPCODE_CODECOPY = GAS_VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index eb346c393dc..8582c0e45d2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_JUMPDEST) + charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) # OPERATION pass From 96357250edf66f6ee0f13b002b5f3c721eabb564 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 30 Mar 2026 14:25:43 -0400 Subject: [PATCH 37/61] refactor:GAS_BLOBHASH => GAS_OPCODE_BLOBHASH --- src/ethereum/forks/amsterdam/vm/gas.py | 2 +- src/ethereum/forks/amsterdam/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/environment.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/environment.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/environment.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/environment.py | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 51fd46e7e06..441d6533a21 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -73,7 +73,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -128,6 +127,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 44f73343af5..af8feeedde7 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -569,7 +569,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 77a45fa958e..0124cc2ea20 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 845aef469c2..070d0f96ff0 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 845aef469c2..070d0f96ff0 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 845aef469c2..070d0f96ff0 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 845aef469c2..070d0f96ff0 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 43da16903e1..8cd00cebfd7 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -71,7 +71,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -113,6 +112,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 7990b540301..d0011858fbb 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -72,7 +72,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -125,6 +124,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index ee400e49729..54bd8dfcb2d 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -71,7 +71,6 @@ class GasCosts: GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_BLOBHASH = Uint(3) GAS_POINT_EVALUATION = Uint(50000) GAS_PER_BLOB = U64(2**17) @@ -120,6 +119,7 @@ class GasCosts: GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW GAS_OPCODE_BLOCKHASH = Uint(20) GAS_OPCODE_COINBASE = GAS_BASE + GAS_OPCODE_BLOBHASH = Uint(3) GAS_OPCODE_MLOAD = GAS_VERY_LOW GAS_OPCODE_MSTORE = GAS_VERY_LOW GAS_OPCODE_MSTORE8 = GAS_VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index edbb980db38..440a4b10f8b 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -565,7 +565,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BLOBHASH) + charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): From 13445c38a3d29fb561a949a79dceb95710c2f716 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 30 Mar 2026 14:41:05 -0400 Subject: [PATCH 38/61] refactor:GAS_OPCODE => OPCODE --- .../execution_testing/forks/forks/forks.py | 138 +++++++++--------- .../src/execution_testing/forks/gas_costs.py | 82 +++++------ .../tools/utility/generators.py | 4 +- src/ethereum/forks/amsterdam/vm/gas.py | 84 +++++------ .../amsterdam/vm/instructions/arithmetic.py | 20 +-- .../amsterdam/vm/instructions/bitwise.py | 18 +-- .../forks/amsterdam/vm/instructions/block.py | 2 +- .../amsterdam/vm/instructions/comparison.py | 12 +- .../amsterdam/vm/instructions/control_flow.py | 6 +- .../amsterdam/vm/instructions/environment.py | 12 +- .../forks/amsterdam/vm/instructions/memory.py | 8 +- .../forks/amsterdam/vm/instructions/stack.py | 6 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 78 +++++----- .../vm/instructions/arithmetic.py | 20 +-- .../arrow_glacier/vm/instructions/bitwise.py | 16 +- .../arrow_glacier/vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 10 +- .../arrow_glacier/vm/instructions/memory.py | 6 +- .../arrow_glacier/vm/instructions/stack.py | 6 +- src/ethereum/forks/berlin/vm/gas.py | 78 +++++----- .../berlin/vm/instructions/arithmetic.py | 20 +-- .../forks/berlin/vm/instructions/bitwise.py | 16 +- .../forks/berlin/vm/instructions/block.py | 2 +- .../berlin/vm/instructions/comparison.py | 12 +- .../berlin/vm/instructions/control_flow.py | 6 +- .../berlin/vm/instructions/environment.py | 10 +- .../forks/berlin/vm/instructions/memory.py | 6 +- .../forks/berlin/vm/instructions/stack.py | 6 +- src/ethereum/forks/bpo1/vm/gas.py | 84 +++++------ .../forks/bpo1/vm/instructions/arithmetic.py | 20 +-- .../forks/bpo1/vm/instructions/bitwise.py | 18 +-- .../forks/bpo1/vm/instructions/block.py | 2 +- .../forks/bpo1/vm/instructions/comparison.py | 12 +- .../bpo1/vm/instructions/control_flow.py | 6 +- .../forks/bpo1/vm/instructions/environment.py | 12 +- .../forks/bpo1/vm/instructions/memory.py | 8 +- .../forks/bpo1/vm/instructions/stack.py | 6 +- src/ethereum/forks/bpo2/vm/gas.py | 84 +++++------ .../forks/bpo2/vm/instructions/arithmetic.py | 20 +-- .../forks/bpo2/vm/instructions/bitwise.py | 18 +-- .../forks/bpo2/vm/instructions/block.py | 2 +- .../forks/bpo2/vm/instructions/comparison.py | 12 +- .../bpo2/vm/instructions/control_flow.py | 6 +- .../forks/bpo2/vm/instructions/environment.py | 12 +- .../forks/bpo2/vm/instructions/memory.py | 8 +- .../forks/bpo2/vm/instructions/stack.py | 6 +- src/ethereum/forks/bpo3/vm/gas.py | 84 +++++------ .../forks/bpo3/vm/instructions/arithmetic.py | 20 +-- .../forks/bpo3/vm/instructions/bitwise.py | 18 +-- .../forks/bpo3/vm/instructions/block.py | 2 +- .../forks/bpo3/vm/instructions/comparison.py | 12 +- .../bpo3/vm/instructions/control_flow.py | 6 +- .../forks/bpo3/vm/instructions/environment.py | 12 +- .../forks/bpo3/vm/instructions/memory.py | 8 +- .../forks/bpo3/vm/instructions/stack.py | 6 +- src/ethereum/forks/bpo4/vm/gas.py | 84 +++++------ .../forks/bpo4/vm/instructions/arithmetic.py | 20 +-- .../forks/bpo4/vm/instructions/bitwise.py | 18 +-- .../forks/bpo4/vm/instructions/block.py | 2 +- .../forks/bpo4/vm/instructions/comparison.py | 12 +- .../bpo4/vm/instructions/control_flow.py | 6 +- .../forks/bpo4/vm/instructions/environment.py | 12 +- .../forks/bpo4/vm/instructions/memory.py | 8 +- .../forks/bpo4/vm/instructions/stack.py | 6 +- src/ethereum/forks/bpo5/vm/gas.py | 84 +++++------ .../forks/bpo5/vm/instructions/arithmetic.py | 20 +-- .../forks/bpo5/vm/instructions/bitwise.py | 18 +-- .../forks/bpo5/vm/instructions/block.py | 2 +- .../forks/bpo5/vm/instructions/comparison.py | 12 +- .../bpo5/vm/instructions/control_flow.py | 6 +- .../forks/bpo5/vm/instructions/environment.py | 12 +- .../forks/bpo5/vm/instructions/memory.py | 8 +- .../forks/bpo5/vm/instructions/stack.py | 6 +- src/ethereum/forks/byzantium/vm/gas.py | 72 ++++----- .../byzantium/vm/instructions/arithmetic.py | 20 +-- .../byzantium/vm/instructions/bitwise.py | 10 +- .../forks/byzantium/vm/instructions/block.py | 2 +- .../byzantium/vm/instructions/comparison.py | 12 +- .../byzantium/vm/instructions/control_flow.py | 6 +- .../byzantium/vm/instructions/environment.py | 10 +- .../forks/byzantium/vm/instructions/memory.py | 6 +- .../forks/byzantium/vm/instructions/stack.py | 6 +- src/ethereum/forks/cancun/vm/gas.py | 82 +++++------ .../cancun/vm/instructions/arithmetic.py | 20 +-- .../forks/cancun/vm/instructions/bitwise.py | 16 +- .../forks/cancun/vm/instructions/block.py | 2 +- .../cancun/vm/instructions/comparison.py | 12 +- .../cancun/vm/instructions/control_flow.py | 6 +- .../cancun/vm/instructions/environment.py | 12 +- .../forks/cancun/vm/instructions/memory.py | 8 +- .../forks/cancun/vm/instructions/stack.py | 6 +- src/ethereum/forks/constantinople/vm/gas.py | 78 +++++----- .../vm/instructions/arithmetic.py | 20 +-- .../constantinople/vm/instructions/bitwise.py | 16 +- .../constantinople/vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 10 +- .../constantinople/vm/instructions/memory.py | 6 +- .../constantinople/vm/instructions/stack.py | 6 +- src/ethereum/forks/dao_fork/vm/gas.py | 70 ++++----- .../dao_fork/vm/instructions/arithmetic.py | 20 +-- .../forks/dao_fork/vm/instructions/bitwise.py | 10 +- .../forks/dao_fork/vm/instructions/block.py | 2 +- .../dao_fork/vm/instructions/comparison.py | 12 +- .../dao_fork/vm/instructions/control_flow.py | 6 +- .../dao_fork/vm/instructions/environment.py | 6 +- .../forks/dao_fork/vm/instructions/memory.py | 6 +- .../forks/dao_fork/vm/instructions/stack.py | 6 +- src/ethereum/forks/frontier/vm/gas.py | 70 ++++----- .../frontier/vm/instructions/arithmetic.py | 20 +-- .../forks/frontier/vm/instructions/bitwise.py | 10 +- .../forks/frontier/vm/instructions/block.py | 2 +- .../frontier/vm/instructions/comparison.py | 12 +- .../frontier/vm/instructions/control_flow.py | 6 +- .../frontier/vm/instructions/environment.py | 6 +- .../forks/frontier/vm/instructions/memory.py | 6 +- .../forks/frontier/vm/instructions/stack.py | 6 +- src/ethereum/forks/gray_glacier/vm/gas.py | 78 +++++----- .../vm/instructions/arithmetic.py | 20 +-- .../gray_glacier/vm/instructions/bitwise.py | 16 +- .../gray_glacier/vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 10 +- .../gray_glacier/vm/instructions/memory.py | 6 +- .../gray_glacier/vm/instructions/stack.py | 6 +- src/ethereum/forks/homestead/vm/gas.py | 70 ++++----- .../homestead/vm/instructions/arithmetic.py | 20 +-- .../homestead/vm/instructions/bitwise.py | 10 +- .../forks/homestead/vm/instructions/block.py | 2 +- .../homestead/vm/instructions/comparison.py | 12 +- .../homestead/vm/instructions/control_flow.py | 6 +- .../homestead/vm/instructions/environment.py | 6 +- .../forks/homestead/vm/instructions/memory.py | 6 +- .../forks/homestead/vm/instructions/stack.py | 6 +- src/ethereum/forks/istanbul/vm/gas.py | 78 +++++----- .../istanbul/vm/instructions/arithmetic.py | 20 +-- .../forks/istanbul/vm/instructions/bitwise.py | 16 +- .../forks/istanbul/vm/instructions/block.py | 2 +- .../istanbul/vm/instructions/comparison.py | 12 +- .../istanbul/vm/instructions/control_flow.py | 6 +- .../istanbul/vm/instructions/environment.py | 10 +- .../forks/istanbul/vm/instructions/memory.py | 6 +- .../forks/istanbul/vm/instructions/stack.py | 6 +- src/ethereum/forks/london/vm/gas.py | 78 +++++----- .../london/vm/instructions/arithmetic.py | 20 +-- .../forks/london/vm/instructions/bitwise.py | 16 +- .../forks/london/vm/instructions/block.py | 2 +- .../london/vm/instructions/comparison.py | 12 +- .../london/vm/instructions/control_flow.py | 6 +- .../london/vm/instructions/environment.py | 10 +- .../forks/london/vm/instructions/memory.py | 6 +- .../forks/london/vm/instructions/stack.py | 6 +- src/ethereum/forks/muir_glacier/vm/gas.py | 78 +++++----- .../vm/instructions/arithmetic.py | 20 +-- .../muir_glacier/vm/instructions/bitwise.py | 16 +- .../muir_glacier/vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 10 +- .../muir_glacier/vm/instructions/memory.py | 6 +- .../muir_glacier/vm/instructions/stack.py | 6 +- src/ethereum/forks/osaka/vm/gas.py | 84 +++++------ .../forks/osaka/vm/instructions/arithmetic.py | 20 +-- .../forks/osaka/vm/instructions/bitwise.py | 18 +-- .../forks/osaka/vm/instructions/block.py | 2 +- .../forks/osaka/vm/instructions/comparison.py | 12 +- .../osaka/vm/instructions/control_flow.py | 6 +- .../osaka/vm/instructions/environment.py | 12 +- .../forks/osaka/vm/instructions/memory.py | 8 +- .../forks/osaka/vm/instructions/stack.py | 6 +- src/ethereum/forks/paris/vm/gas.py | 78 +++++----- .../forks/paris/vm/instructions/arithmetic.py | 20 +-- .../forks/paris/vm/instructions/bitwise.py | 16 +- .../forks/paris/vm/instructions/block.py | 2 +- .../forks/paris/vm/instructions/comparison.py | 12 +- .../paris/vm/instructions/control_flow.py | 6 +- .../paris/vm/instructions/environment.py | 10 +- .../forks/paris/vm/instructions/memory.py | 6 +- .../forks/paris/vm/instructions/stack.py | 6 +- src/ethereum/forks/prague/vm/gas.py | 82 +++++------ .../prague/vm/instructions/arithmetic.py | 20 +-- .../forks/prague/vm/instructions/bitwise.py | 16 +- .../forks/prague/vm/instructions/block.py | 2 +- .../prague/vm/instructions/comparison.py | 12 +- .../prague/vm/instructions/control_flow.py | 6 +- .../prague/vm/instructions/environment.py | 12 +- .../forks/prague/vm/instructions/memory.py | 8 +- .../forks/prague/vm/instructions/stack.py | 6 +- src/ethereum/forks/shanghai/vm/gas.py | 78 +++++----- .../shanghai/vm/instructions/arithmetic.py | 20 +-- .../forks/shanghai/vm/instructions/bitwise.py | 16 +- .../forks/shanghai/vm/instructions/block.py | 2 +- .../shanghai/vm/instructions/comparison.py | 12 +- .../shanghai/vm/instructions/control_flow.py | 6 +- .../shanghai/vm/instructions/environment.py | 10 +- .../forks/shanghai/vm/instructions/memory.py | 6 +- .../forks/shanghai/vm/instructions/stack.py | 6 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 70 ++++----- .../vm/instructions/arithmetic.py | 20 +-- .../vm/instructions/bitwise.py | 10 +- .../spurious_dragon/vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 6 +- .../spurious_dragon/vm/instructions/memory.py | 6 +- .../spurious_dragon/vm/instructions/stack.py | 6 +- .../forks/tangerine_whistle/vm/gas.py | 70 ++++----- .../vm/instructions/arithmetic.py | 20 +-- .../vm/instructions/bitwise.py | 10 +- .../vm/instructions/block.py | 2 +- .../vm/instructions/comparison.py | 12 +- .../vm/instructions/control_flow.py | 6 +- .../vm/instructions/environment.py | 6 +- .../vm/instructions/memory.py | 6 +- .../vm/instructions/stack.py | 6 +- 219 files changed, 1963 insertions(+), 2003 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 80d6f4f8128..55af7e3c08d 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -163,40 +163,40 @@ def gas_costs(cls) -> GasCosts: GAS_PRECOMPILE_P256VERIFY=0, GAS_BLOCK_ACCESS_LIST_ITEM=0, # Opcode specific gas constants for repricing - GAS_OPCODE_ADD=GAS_VERY_LOW, - GAS_OPCODE_SUB=GAS_VERY_LOW, - GAS_OPCODE_MUL=GAS_LOW, - GAS_OPCODE_DIV=GAS_LOW, - GAS_OPCODE_SDIV=GAS_LOW, - GAS_OPCODE_MOD=GAS_LOW, - GAS_OPCODE_SMOD=GAS_LOW, - GAS_OPCODE_ADDMOD=GAS_MID, - GAS_OPCODE_MULMOD=GAS_MID, - GAS_OPCODE_SIGNEXTEND=GAS_LOW, - GAS_OPCODE_LT=GAS_VERY_LOW, - GAS_OPCODE_GT=GAS_VERY_LOW, - GAS_OPCODE_SLT=GAS_VERY_LOW, - GAS_OPCODE_SGT=GAS_VERY_LOW, - GAS_OPCODE_EQ=GAS_VERY_LOW, - GAS_OPCODE_ISZERO=GAS_VERY_LOW, - GAS_OPCODE_AND=GAS_VERY_LOW, - GAS_OPCODE_OR=GAS_VERY_LOW, - GAS_OPCODE_XOR=GAS_VERY_LOW, - GAS_OPCODE_NOT=GAS_VERY_LOW, - GAS_OPCODE_BYTE=GAS_VERY_LOW, - GAS_OPCODE_JUMP=GAS_MID, - GAS_OPCODE_JUMPI=GAS_HIGH, - GAS_OPCODE_JUMPDEST=1, - GAS_OPCODE_CALLDATALOAD=GAS_VERY_LOW, - GAS_OPCODE_CALLDATACOPY=GAS_VERY_LOW, - GAS_OPCODE_CODECOPY=GAS_VERY_LOW, - GAS_OPCODE_BLOCKHASH=20, - GAS_OPCODE_MLOAD=GAS_VERY_LOW, - GAS_OPCODE_MSTORE=GAS_VERY_LOW, - GAS_OPCODE_MSTORE8=GAS_VERY_LOW, - GAS_OPCODE_PUSH=GAS_VERY_LOW, - GAS_OPCODE_DUP=GAS_VERY_LOW, - GAS_OPCODE_SWAP=GAS_VERY_LOW, + OPCODE_ADD=GAS_VERY_LOW, + OPCODE_SUB=GAS_VERY_LOW, + OPCODE_MUL=GAS_LOW, + OPCODE_DIV=GAS_LOW, + OPCODE_SDIV=GAS_LOW, + OPCODE_MOD=GAS_LOW, + OPCODE_SMOD=GAS_LOW, + OPCODE_ADDMOD=GAS_MID, + OPCODE_MULMOD=GAS_MID, + OPCODE_SIGNEXTEND=GAS_LOW, + OPCODE_LT=GAS_VERY_LOW, + OPCODE_GT=GAS_VERY_LOW, + OPCODE_SLT=GAS_VERY_LOW, + OPCODE_SGT=GAS_VERY_LOW, + OPCODE_EQ=GAS_VERY_LOW, + OPCODE_ISZERO=GAS_VERY_LOW, + OPCODE_AND=GAS_VERY_LOW, + OPCODE_OR=GAS_VERY_LOW, + OPCODE_XOR=GAS_VERY_LOW, + OPCODE_NOT=GAS_VERY_LOW, + OPCODE_BYTE=GAS_VERY_LOW, + OPCODE_JUMP=GAS_MID, + OPCODE_JUMPI=GAS_HIGH, + OPCODE_JUMPDEST=1, + OPCODE_CALLDATALOAD=GAS_VERY_LOW, + OPCODE_CALLDATACOPY=GAS_VERY_LOW, + OPCODE_CODECOPY=GAS_VERY_LOW, + OPCODE_BLOCKHASH=20, + OPCODE_MLOAD=GAS_VERY_LOW, + OPCODE_MSTORE=GAS_VERY_LOW, + OPCODE_MSTORE8=GAS_VERY_LOW, + OPCODE_PUSH=GAS_VERY_LOW, + OPCODE_DUP=GAS_VERY_LOW, + OPCODE_SWAP=GAS_VERY_LOW, ) @classmethod @@ -330,33 +330,33 @@ def opcode_gas_map( return { # Stop and arithmetic operations Opcodes.STOP: 0, - Opcodes.ADD: gas_costs.GAS_OPCODE_ADD, - Opcodes.MUL: gas_costs.GAS_OPCODE_MUL, - Opcodes.SUB: gas_costs.GAS_OPCODE_SUB, - Opcodes.DIV: gas_costs.GAS_OPCODE_DIV, - Opcodes.SDIV: gas_costs.GAS_OPCODE_SDIV, - Opcodes.MOD: gas_costs.GAS_OPCODE_MOD, - Opcodes.SMOD: gas_costs.GAS_OPCODE_SMOD, - Opcodes.ADDMOD: gas_costs.GAS_OPCODE_ADDMOD, - Opcodes.MULMOD: gas_costs.GAS_OPCODE_MULMOD, + Opcodes.ADD: gas_costs.OPCODE_ADD, + Opcodes.MUL: gas_costs.OPCODE_MUL, + Opcodes.SUB: gas_costs.OPCODE_SUB, + Opcodes.DIV: gas_costs.OPCODE_DIV, + Opcodes.SDIV: gas_costs.OPCODE_SDIV, + Opcodes.MOD: gas_costs.OPCODE_MOD, + Opcodes.SMOD: gas_costs.OPCODE_SMOD, + Opcodes.ADDMOD: gas_costs.OPCODE_ADDMOD, + Opcodes.MULMOD: gas_costs.OPCODE_MULMOD, Opcodes.EXP: lambda op: ( gas_costs.GAS_EXPONENTIATION + gas_costs.GAS_EXPONENTIATION_PER_BYTE * ((op.metadata["exponent"].bit_length() + 7) // 8) ), - Opcodes.SIGNEXTEND: gas_costs.GAS_OPCODE_SIGNEXTEND, + Opcodes.SIGNEXTEND: gas_costs.OPCODE_SIGNEXTEND, # Comparison & bitwise logic operations - Opcodes.LT: gas_costs.GAS_OPCODE_LT, - Opcodes.GT: gas_costs.GAS_OPCODE_GT, - Opcodes.SLT: gas_costs.GAS_OPCODE_SLT, - Opcodes.SGT: gas_costs.GAS_OPCODE_SGT, - Opcodes.EQ: gas_costs.GAS_OPCODE_EQ, - Opcodes.ISZERO: gas_costs.GAS_OPCODE_ISZERO, - Opcodes.AND: gas_costs.GAS_OPCODE_AND, - Opcodes.OR: gas_costs.GAS_OPCODE_OR, - Opcodes.XOR: gas_costs.GAS_OPCODE_XOR, - Opcodes.NOT: gas_costs.GAS_OPCODE_NOT, - Opcodes.BYTE: gas_costs.GAS_OPCODE_BYTE, + Opcodes.LT: gas_costs.OPCODE_LT, + Opcodes.GT: gas_costs.OPCODE_GT, + Opcodes.SLT: gas_costs.OPCODE_SLT, + Opcodes.SGT: gas_costs.OPCODE_SGT, + Opcodes.EQ: gas_costs.OPCODE_EQ, + Opcodes.ISZERO: gas_costs.OPCODE_ISZERO, + Opcodes.AND: gas_costs.OPCODE_AND, + Opcodes.OR: gas_costs.OPCODE_OR, + Opcodes.XOR: gas_costs.OPCODE_XOR, + Opcodes.NOT: gas_costs.OPCODE_NOT, + Opcodes.BYTE: gas_costs.OPCODE_BYTE, # SHA3 Opcodes.SHA3: cls._with_memory_expansion( lambda op: ( @@ -372,17 +372,15 @@ def opcode_gas_map( Opcodes.ORIGIN: gas_costs.GAS_BASE, Opcodes.CALLER: gas_costs.GAS_BASE, Opcodes.CALLVALUE: gas_costs.GAS_BASE, - Opcodes.CALLDATALOAD: gas_costs.GAS_OPCODE_CALLDATALOAD, + Opcodes.CALLDATALOAD: gas_costs.OPCODE_CALLDATALOAD, Opcodes.CALLDATASIZE: gas_costs.GAS_BASE, Opcodes.CALLDATACOPY: cls._with_memory_expansion( - cls._with_data_copy( - gas_costs.GAS_OPCODE_CALLDATACOPY, gas_costs - ), + cls._with_data_copy(gas_costs.OPCODE_CALLDATACOPY, gas_costs), memory_expansion_calculator, ), Opcodes.CODESIZE: gas_costs.GAS_BASE, Opcodes.CODECOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.GAS_OPCODE_CODECOPY, gas_costs), + cls._with_data_copy(gas_costs.OPCODE_CODECOPY, gas_costs), memory_expansion_calculator, ), Opcodes.GASPRICE: gas_costs.GAS_BASE, @@ -395,7 +393,7 @@ def opcode_gas_map( memory_expansion_calculator, ), # Block information - Opcodes.BLOCKHASH: gas_costs.GAS_OPCODE_BLOCKHASH, + Opcodes.BLOCKHASH: gas_costs.OPCODE_BLOCKHASH, Opcodes.COINBASE: gas_costs.GAS_BASE, Opcodes.TIMESTAMP: gas_costs.GAS_BASE, Opcodes.NUMBER: gas_costs.GAS_BASE, @@ -404,15 +402,15 @@ def opcode_gas_map( # Stack, memory, storage and flow operations Opcodes.POP: gas_costs.GAS_BASE, Opcodes.MLOAD: cls._with_memory_expansion( - gas_costs.GAS_OPCODE_MLOAD, + gas_costs.OPCODE_MLOAD, memory_expansion_calculator, ), Opcodes.MSTORE: cls._with_memory_expansion( - gas_costs.GAS_OPCODE_MSTORE, + gas_costs.OPCODE_MSTORE, memory_expansion_calculator, ), Opcodes.MSTORE8: cls._with_memory_expansion( - gas_costs.GAS_OPCODE_MSTORE8, + gas_costs.OPCODE_MSTORE8, memory_expansion_calculator, ), Opcodes.SLOAD: lambda op: ( @@ -423,25 +421,25 @@ def opcode_gas_map( Opcodes.SSTORE: lambda op: cls._calculate_sstore_gas( op, gas_costs ), - Opcodes.JUMP: gas_costs.GAS_OPCODE_JUMP, - Opcodes.JUMPI: gas_costs.GAS_OPCODE_JUMPI, + Opcodes.JUMP: gas_costs.OPCODE_JUMP, + Opcodes.JUMPI: gas_costs.OPCODE_JUMPI, Opcodes.PC: gas_costs.GAS_BASE, Opcodes.MSIZE: gas_costs.GAS_BASE, Opcodes.GAS: gas_costs.GAS_BASE, - Opcodes.JUMPDEST: gas_costs.GAS_OPCODE_JUMPDEST, + Opcodes.JUMPDEST: gas_costs.OPCODE_JUMPDEST, # Push operations (PUSH1 through PUSH32) **{ - getattr(Opcodes, f"PUSH{i}"): gas_costs.GAS_OPCODE_PUSH + getattr(Opcodes, f"PUSH{i}"): gas_costs.OPCODE_PUSH for i in range(1, 33) }, # Dup operations (DUP1 through DUP16) **{ - getattr(Opcodes, f"DUP{i}"): gas_costs.GAS_OPCODE_DUP + getattr(Opcodes, f"DUP{i}"): gas_costs.OPCODE_DUP for i in range(1, 17) }, # Swap operations (SWAP1 through SWAP16) **{ - getattr(Opcodes, f"SWAP{i}"): gas_costs.GAS_OPCODE_SWAP + getattr(Opcodes, f"SWAP{i}"): gas_costs.OPCODE_SWAP for i in range(1, 17) }, # Logging operations diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 67980347f06..3813279991d 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -97,46 +97,46 @@ class GasCosts: GAS_BLOCK_ACCESS_LIST_ITEM: int # Opcode specific gas constants for repricing - GAS_OPCODE_ADD: int - GAS_OPCODE_SUB: int - GAS_OPCODE_MUL: int - GAS_OPCODE_DIV: int - GAS_OPCODE_SDIV: int - GAS_OPCODE_MOD: int - GAS_OPCODE_SMOD: int - GAS_OPCODE_ADDMOD: int - GAS_OPCODE_MULMOD: int - GAS_OPCODE_SIGNEXTEND: int - GAS_OPCODE_LT: int - GAS_OPCODE_GT: int - GAS_OPCODE_SLT: int - GAS_OPCODE_SGT: int - GAS_OPCODE_EQ: int - GAS_OPCODE_ISZERO: int - GAS_OPCODE_AND: int - GAS_OPCODE_OR: int - GAS_OPCODE_XOR: int - GAS_OPCODE_NOT: int - GAS_OPCODE_BYTE: int - GAS_OPCODE_JUMP: int - GAS_OPCODE_JUMPI: int - GAS_OPCODE_JUMPDEST: int - GAS_OPCODE_CALLDATALOAD: int - GAS_OPCODE_CALLDATACOPY: int - GAS_OPCODE_CODECOPY: int - GAS_OPCODE_BLOCKHASH: int - GAS_OPCODE_MLOAD: int - GAS_OPCODE_MSTORE: int - GAS_OPCODE_MSTORE8: int - GAS_OPCODE_PUSH: int - GAS_OPCODE_DUP: int - GAS_OPCODE_SWAP: int + OPCODE_ADD: int + OPCODE_SUB: int + OPCODE_MUL: int + OPCODE_DIV: int + OPCODE_SDIV: int + OPCODE_MOD: int + OPCODE_SMOD: int + OPCODE_ADDMOD: int + OPCODE_MULMOD: int + OPCODE_SIGNEXTEND: int + OPCODE_LT: int + OPCODE_GT: int + OPCODE_SLT: int + OPCODE_SGT: int + OPCODE_EQ: int + OPCODE_ISZERO: int + OPCODE_AND: int + OPCODE_OR: int + OPCODE_XOR: int + OPCODE_NOT: int + OPCODE_BYTE: int + OPCODE_JUMP: int + OPCODE_JUMPI: int + OPCODE_JUMPDEST: int + OPCODE_CALLDATALOAD: int + OPCODE_CALLDATACOPY: int + OPCODE_CODECOPY: int + OPCODE_BLOCKHASH: int + OPCODE_MLOAD: int + OPCODE_MSTORE: int + OPCODE_MSTORE8: int + OPCODE_PUSH: int + OPCODE_DUP: int + OPCODE_SWAP: int # Defined post-Frontier - GAS_OPCODE_SHL: int = 0 - GAS_OPCODE_SHR: int = 0 - GAS_OPCODE_SAR: int = 0 - GAS_OPCODE_RETURNDATACOPY: int = 0 - GAS_OPCODE_BLOBHASH: int = 0 - GAS_OPCODE_MCOPY: int = 0 - GAS_OPCODE_CLZ: int = 0 + OPCODE_SHL: int = 0 + OPCODE_SHR: int = 0 + OPCODE_SAR: int = 0 + OPCODE_RETURNDATACOPY: int = 0 + OPCODE_BLOBHASH: int = 0 + OPCODE_MCOPY: int = 0 + OPCODE_CLZ: int = 0 diff --git a/packages/testing/src/execution_testing/tools/utility/generators.py b/packages/testing/src/execution_testing/tools/utility/generators.py index 26d790165aa..56dcfcda034 100644 --- a/packages/testing/src/execution_testing/tools/utility/generators.py +++ b/packages/testing/src/execution_testing/tools/utility/generators.py @@ -369,9 +369,9 @@ def wrapper( # If the gas limit is not divisible by the gas used per # storage, we need to add some NO-OP (JUMPDEST) to the code # that each consume 1 gas. - assert gas_costs.GAS_OPCODE_JUMPDEST == 1, ( + assert gas_costs.OPCODE_JUMPDEST == 1, ( "JUMPDEST gas cost should be 1, but got " - f"{gas_costs.GAS_OPCODE_JUMPDEST}. Generator " + f"{gas_costs.OPCODE_JUMPDEST}. Generator " "`generate_system_contract_error_test` needs updating." ) modified_system_contract_code += sum( diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 441d6533a21..3862b0341be 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -93,48 +93,48 @@ class GasCosts: GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py index 0e1612fed49..7674d3c720f 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -265,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/block.py b/src/ethereum/forks/amsterdam/vm/instructions/block.py index 65a537e6657..8eb11ca119b 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/block.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/comparison.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index af8feeedde7..f521b356b55 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -170,7 +170,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -230,7 +230,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -291,7 +291,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -450,9 +450,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -569,7 +567,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 2e9027f665e..09e41f0835e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -70,45 +70,45 @@ class GasCosts: GAS_WARM_ACCESS = Uint(100) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index d80dada24b4..7bb7fa72462 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 7ae48a6f84a..ee55bb3f10e 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -71,45 +71,45 @@ class GasCosts: GAS_WARM_ACCESS = Uint(100) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/berlin/vm/instructions/bitwise.py b/src/ethereum/forks/berlin/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/berlin/vm/instructions/bitwise.py +++ b/src/ethereum/forks/berlin/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/berlin/vm/instructions/block.py b/src/ethereum/forks/berlin/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/berlin/vm/instructions/block.py +++ b/src/ethereum/forks/berlin/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/berlin/vm/instructions/comparison.py b/src/ethereum/forks/berlin/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/berlin/vm/instructions/comparison.py +++ b/src/ethereum/forks/berlin/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 0295b509e23..f4b5f91b245 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 0124cc2ea20..b12d00ab85b 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py index 0e1612fed49..7674d3c720f 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo1/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -265,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo1/vm/instructions/block.py b/src/ethereum/forks/bpo1/vm/instructions/block.py index 1d405801688..81f3bed52c2 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/block.py +++ b/src/ethereum/forks/bpo1/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo1/vm/instructions/comparison.py b/src/ethereum/forks/bpo1/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo1/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 070d0f96ff0..37d039100a3 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py index 29551c2c2a9..8b41a55d2b2 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo2/vm/instructions/bitwise.py @@ -34,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +262,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo2/vm/instructions/block.py b/src/ethereum/forks/bpo2/vm/instructions/block.py index acb15f411d7..5ff36ccf385 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/block.py +++ b/src/ethereum/forks/bpo2/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo2/vm/instructions/comparison.py b/src/ethereum/forks/bpo2/vm/instructions/comparison.py index 74bfefbd6bf..ee5c881ef0d 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo2/vm/instructions/comparison.py @@ -34,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index 72487f9dcf9..2604040cb28 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -57,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index 465df9da7d2..c404c9d39ba 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 070d0f96ff0..37d039100a3 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py index 29551c2c2a9..8b41a55d2b2 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo3/vm/instructions/bitwise.py @@ -34,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -262,7 +262,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo3/vm/instructions/block.py b/src/ethereum/forks/bpo3/vm/instructions/block.py index 15844f6a783..39e16bc2035 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/block.py +++ b/src/ethereum/forks/bpo3/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo3/vm/instructions/comparison.py b/src/ethereum/forks/bpo3/vm/instructions/comparison.py index 74bfefbd6bf..ee5c881ef0d 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo3/vm/instructions/comparison.py @@ -34,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index 72487f9dcf9..2604040cb28 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -57,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index 465df9da7d2..c404c9d39ba 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 070d0f96ff0..37d039100a3 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py index 0e1612fed49..7674d3c720f 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo4/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -265,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo4/vm/instructions/block.py b/src/ethereum/forks/bpo4/vm/instructions/block.py index 434e674df32..23494f47615 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/block.py +++ b/src/ethereum/forks/bpo4/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo4/vm/instructions/comparison.py b/src/ethereum/forks/bpo4/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo4/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 070d0f96ff0..37d039100a3 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py index 0e1612fed49..7674d3c720f 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/bitwise.py +++ b/src/ethereum/forks/bpo5/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -265,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/bpo5/vm/instructions/block.py b/src/ethereum/forks/bpo5/vm/instructions/block.py index d14e8c66a5c..e23987d2fe0 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/block.py +++ b/src/ethereum/forks/bpo5/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/bpo5/vm/instructions/comparison.py b/src/ethereum/forks/bpo5/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/comparison.py +++ b/src/ethereum/forks/bpo5/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 75990ccd3bf..d9f5bc2f344 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -70,42 +70,42 @@ class GasCosts: GAS_RETURN_DATA_COPY = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/bitwise.py +++ b/src/ethereum/forks/byzantium/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/byzantium/vm/instructions/block.py b/src/ethereum/forks/byzantium/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/block.py +++ b/src/ethereum/forks/byzantium/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/byzantium/vm/instructions/comparison.py b/src/ethereum/forks/byzantium/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/comparison.py +++ b/src/ethereum/forks/byzantium/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index ca0ec381a30..619523ad0fd 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -162,7 +162,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -222,7 +222,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -283,7 +283,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -427,9 +427,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 8cd00cebfd7..d43b53ad69b 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -79,47 +79,47 @@ class GasCosts: BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/cancun/vm/instructions/bitwise.py b/src/ethereum/forks/cancun/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/cancun/vm/instructions/bitwise.py +++ b/src/ethereum/forks/cancun/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/cancun/vm/instructions/block.py b/src/ethereum/forks/cancun/vm/instructions/block.py index d0b3fb5aa82..d08f153b6f8 100644 --- a/src/ethereum/forks/cancun/vm/instructions/block.py +++ b/src/ethereum/forks/cancun/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/cancun/vm/instructions/comparison.py b/src/ethereum/forks/cancun/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/cancun/vm/instructions/comparison.py +++ b/src/ethereum/forks/cancun/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index be1f3497bd0..054aef29b37 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -71,45 +71,45 @@ class GasCosts: GAS_CODE_HASH = Uint(400) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/bitwise.py +++ b/src/ethereum/forks/constantinople/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/constantinople/vm/instructions/block.py b/src/ethereum/forks/constantinople/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/block.py +++ b/src/ethereum/forks/constantinople/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/constantinople/vm/instructions/comparison.py b/src/ethereum/forks/constantinople/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/comparison.py +++ b/src/ethereum/forks/constantinople/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index d029d19b7fd..2832ba44042 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -163,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -428,9 +428,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index f41b7f85512..cf8b4cd2743 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -69,41 +69,41 @@ class GasCosts: GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/dao_fork/vm/instructions/block.py b/src/ethereum/forks/dao_fork/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/block.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/comparison.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 561f20f5479..5baf8effdc3 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -161,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index f41b7f85512..cf8b4cd2743 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -69,41 +69,41 @@ class GasCosts: GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/frontier/vm/instructions/bitwise.py b/src/ethereum/forks/frontier/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/frontier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/frontier/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/frontier/vm/instructions/block.py b/src/ethereum/forks/frontier/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/frontier/vm/instructions/block.py +++ b/src/ethereum/forks/frontier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/frontier/vm/instructions/comparison.py b/src/ethereum/forks/frontier/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/frontier/vm/instructions/comparison.py +++ b/src/ethereum/forks/frontier/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 561f20f5479..5baf8effdc3 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -161,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 2e9027f665e..09e41f0835e 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -70,45 +70,45 @@ class GasCosts: GAS_WARM_ACCESS = Uint(100) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/block.py b/src/ethereum/forks/gray_glacier/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index d80dada24b4..7bb7fa72462 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index f41b7f85512..cf8b4cd2743 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -69,41 +69,41 @@ class GasCosts: GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/homestead/vm/instructions/bitwise.py b/src/ethereum/forks/homestead/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/homestead/vm/instructions/bitwise.py +++ b/src/ethereum/forks/homestead/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/homestead/vm/instructions/block.py b/src/ethereum/forks/homestead/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/homestead/vm/instructions/block.py +++ b/src/ethereum/forks/homestead/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/homestead/vm/instructions/comparison.py b/src/ethereum/forks/homestead/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/homestead/vm/instructions/comparison.py +++ b/src/ethereum/forks/homestead/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 561f20f5479..5baf8effdc3 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -161,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 542973760fd..3e88c11596b 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -73,45 +73,45 @@ class GasCosts: GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/bitwise.py +++ b/src/ethereum/forks/istanbul/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/istanbul/vm/instructions/block.py b/src/ethereum/forks/istanbul/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/block.py +++ b/src/ethereum/forks/istanbul/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/istanbul/vm/instructions/comparison.py b/src/ethereum/forks/istanbul/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/comparison.py +++ b/src/ethereum/forks/istanbul/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 92ac93dad4b..73fc5cc49a5 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -163,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -428,9 +428,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 2e9027f665e..09e41f0835e 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -70,45 +70,45 @@ class GasCosts: GAS_WARM_ACCESS = Uint(100) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/london/vm/instructions/bitwise.py b/src/ethereum/forks/london/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/london/vm/instructions/bitwise.py +++ b/src/ethereum/forks/london/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/london/vm/instructions/block.py b/src/ethereum/forks/london/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/london/vm/instructions/block.py +++ b/src/ethereum/forks/london/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/london/vm/instructions/comparison.py b/src/ethereum/forks/london/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/london/vm/instructions/comparison.py +++ b/src/ethereum/forks/london/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index d80dada24b4..7bb7fa72462 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 542973760fd..3e88c11596b 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -73,45 +73,45 @@ class GasCosts: GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/block.py b/src/ethereum/forks/muir_glacier/vm/instructions/block.py index b22b2b0ffa0..cb186f9f6a8 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 92ac93dad4b..73fc5cc49a5 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -163,7 +163,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -428,9 +428,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index d0011858fbb..89e34fdfd22 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -90,48 +90,48 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_CLZ = GAS_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_CLZ = GAS_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/osaka/vm/instructions/bitwise.py b/src/ethereum/forks/osaka/vm/instructions/bitwise.py index 0e1612fed49..7674d3c720f 100644 --- a/src/ethereum/forks/osaka/vm/instructions/bitwise.py +++ b/src/ethereum/forks/osaka/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: @@ -265,7 +265,7 @@ def count_leading_zeros(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CLZ) + charge_gas(evm, GasCosts.OPCODE_CLZ) # OPERATION bit_length = U256(x.bit_length()) diff --git a/src/ethereum/forks/osaka/vm/instructions/block.py b/src/ethereum/forks/osaka/vm/instructions/block.py index c856418c191..9c24310914f 100644 --- a/src/ethereum/forks/osaka/vm/instructions/block.py +++ b/src/ethereum/forks/osaka/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/osaka/vm/instructions/comparison.py b/src/ethereum/forks/osaka/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/osaka/vm/instructions/comparison.py +++ b/src/ethereum/forks/osaka/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 2e9027f665e..09e41f0835e 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -70,45 +70,45 @@ class GasCosts: GAS_WARM_ACCESS = Uint(100) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/paris/vm/instructions/bitwise.py b/src/ethereum/forks/paris/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/paris/vm/instructions/bitwise.py +++ b/src/ethereum/forks/paris/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/paris/vm/instructions/block.py b/src/ethereum/forks/paris/vm/instructions/block.py index f009e2d58a2..3b4ac3a0257 100644 --- a/src/ethereum/forks/paris/vm/instructions/block.py +++ b/src/ethereum/forks/paris/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/paris/vm/instructions/comparison.py b/src/ethereum/forks/paris/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/paris/vm/instructions/comparison.py +++ b/src/ethereum/forks/paris/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 972e1f87098..b30b69d8210 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 54bd8dfcb2d..5ce701eb209 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -86,47 +86,47 @@ class GasCosts: GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_BLOBHASH = Uint(3) - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_MCOPY = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_BLOBHASH = Uint(3) + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_MCOPY = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/prague/vm/instructions/bitwise.py b/src/ethereum/forks/prague/vm/instructions/bitwise.py index c01bf41e74a..1de6c615931 100644 --- a/src/ethereum/forks/prague/vm/instructions/bitwise.py +++ b/src/ethereum/forks/prague/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -172,7 +172,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -202,7 +202,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -232,7 +232,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/prague/vm/instructions/block.py b/src/ethereum/forks/prague/vm/instructions/block.py index c53a9cddbbf..5236fb303a8 100644 --- a/src/ethereum/forks/prague/vm/instructions/block.py +++ b/src/ethereum/forks/prague/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/prague/vm/instructions/comparison.py b/src/ethereum/forks/prague/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/prague/vm/instructions/comparison.py +++ b/src/ethereum/forks/prague/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 440a4b10f8b..a56f117e095 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -169,7 +169,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -447,9 +447,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -565,7 +563,7 @@ def blob_hash(evm: Evm) -> None: index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOBHASH) + charge_gas(evm, GasCosts.OPCODE_BLOBHASH) # OPERATION if int(index) < len(evm.message.tx_env.blob_versioned_hashes): diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 2ec99f27cac..f8141229434 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index f3825c561b5..d80df54321d 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -68,7 +68,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -98,7 +98,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -130,7 +130,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 29d5235fafd..73efbabd9a9 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -71,45 +71,45 @@ class GasCosts: GAS_CODE_INIT_PER_WORD = Uint(2) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_SHL = GAS_VERY_LOW - GAS_OPCODE_SHR = GAS_VERY_LOW - GAS_OPCODE_SAR = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_RETURNDATACOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_SHL = GAS_VERY_LOW + OPCODE_SHR = GAS_VERY_LOW + OPCODE_SAR = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index 460b7f3a677..dfe38cd80bf 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -37,7 +37,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -64,7 +64,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -91,7 +91,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -118,7 +118,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -151,7 +151,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -184,7 +184,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -214,7 +214,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -245,7 +245,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -276,7 +276,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -341,7 +341,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py index 64d9397fde4..99b62433076 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/bitwise.py +++ b/src/ethereum/forks/shanghai/vm/instructions/bitwise.py @@ -34,7 +34,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -59,7 +59,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -84,7 +84,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -108,7 +108,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -134,7 +134,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): @@ -169,7 +169,7 @@ def bitwise_shl(evm: Evm) -> None: value = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHL) + charge_gas(evm, GasCosts.OPCODE_SHL) # OPERATION if shift < Uint(256): @@ -199,7 +199,7 @@ def bitwise_shr(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SHR) + charge_gas(evm, GasCosts.OPCODE_SHR) # OPERATION if shift < U256(256): @@ -229,7 +229,7 @@ def bitwise_sar(evm: Evm) -> None: signed_value = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SAR) + charge_gas(evm, GasCosts.OPCODE_SAR) # OPERATION if shift < 256: diff --git a/src/ethereum/forks/shanghai/vm/instructions/block.py b/src/ethereum/forks/shanghai/vm/instructions/block.py index aec457e3eef..eb7c7792186 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/block.py +++ b/src/ethereum/forks/shanghai/vm/instructions/block.py @@ -40,7 +40,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/shanghai/vm/instructions/comparison.py b/src/ethereum/forks/shanghai/vm/instructions/comparison.py index 74bfefbd6bf..ee5c881ef0d 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/comparison.py +++ b/src/ethereum/forks/shanghai/vm/instructions/comparison.py @@ -34,7 +34,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -60,7 +60,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -87,7 +87,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -113,7 +113,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -140,7 +140,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -166,7 +166,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index 72487f9dcf9..2604040cb28 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -57,7 +57,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -84,7 +84,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -162,7 +162,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 972e1f87098..b30b69d8210 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -167,7 +167,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -445,9 +445,7 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_RETURNDATACOPY - + copy_gas_cost - + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index 465df9da7d2..c404c9d39ba 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: if num_bytes == 0: charge_gas(evm, GasCosts.GAS_BASE) else: - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 38ffddb2dc8..53dc119a041 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -69,41 +69,41 @@ class GasCosts: GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 561f20f5479..5baf8effdc3 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -161,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index bc6e9d5e010..70c777c8bef 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -69,41 +69,41 @@ class GasCosts: GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcode specific vars used for repricing - GAS_OPCODE_ADD = GAS_VERY_LOW - GAS_OPCODE_SUB = GAS_VERY_LOW - GAS_OPCODE_MUL = GAS_LOW - GAS_OPCODE_DIV = GAS_LOW - GAS_OPCODE_SDIV = GAS_LOW - GAS_OPCODE_MOD = GAS_LOW - GAS_OPCODE_SMOD = GAS_LOW - GAS_OPCODE_ADDMOD = GAS_MID - GAS_OPCODE_MULMOD = GAS_MID - GAS_OPCODE_SIGNEXTEND = GAS_LOW - GAS_OPCODE_LT = GAS_VERY_LOW - GAS_OPCODE_GT = GAS_VERY_LOW - GAS_OPCODE_SLT = GAS_VERY_LOW - GAS_OPCODE_SGT = GAS_VERY_LOW - GAS_OPCODE_EQ = GAS_VERY_LOW - GAS_OPCODE_ISZERO = GAS_VERY_LOW - GAS_OPCODE_AND = GAS_VERY_LOW - GAS_OPCODE_OR = GAS_VERY_LOW - GAS_OPCODE_XOR = GAS_VERY_LOW - GAS_OPCODE_NOT = GAS_VERY_LOW - GAS_OPCODE_BYTE = GAS_VERY_LOW - GAS_OPCODE_JUMP = GAS_MID - GAS_OPCODE_JUMPI = GAS_HIGH - GAS_OPCODE_JUMPDEST = Uint(1) - GAS_OPCODE_CALLDATALOAD = GAS_VERY_LOW - GAS_OPCODE_CALLDATACOPY = GAS_VERY_LOW - GAS_OPCODE_CODECOPY = GAS_VERY_LOW - GAS_OPCODE_BLOCKHASH = Uint(20) - GAS_OPCODE_COINBASE = GAS_BASE - GAS_OPCODE_MLOAD = GAS_VERY_LOW - GAS_OPCODE_MSTORE = GAS_VERY_LOW - GAS_OPCODE_MSTORE8 = GAS_VERY_LOW - GAS_OPCODE_PUSH = GAS_VERY_LOW - GAS_OPCODE_DUP = GAS_VERY_LOW - GAS_OPCODE_SWAP = GAS_VERY_LOW + OPCODE_ADD = GAS_VERY_LOW + OPCODE_SUB = GAS_VERY_LOW + OPCODE_MUL = GAS_LOW + OPCODE_DIV = GAS_LOW + OPCODE_SDIV = GAS_LOW + OPCODE_MOD = GAS_LOW + OPCODE_SMOD = GAS_LOW + OPCODE_ADDMOD = GAS_MID + OPCODE_MULMOD = GAS_MID + OPCODE_SIGNEXTEND = GAS_LOW + OPCODE_LT = GAS_VERY_LOW + OPCODE_GT = GAS_VERY_LOW + OPCODE_SLT = GAS_VERY_LOW + OPCODE_SGT = GAS_VERY_LOW + OPCODE_EQ = GAS_VERY_LOW + OPCODE_ISZERO = GAS_VERY_LOW + OPCODE_AND = GAS_VERY_LOW + OPCODE_OR = GAS_VERY_LOW + OPCODE_XOR = GAS_VERY_LOW + OPCODE_NOT = GAS_VERY_LOW + OPCODE_BYTE = GAS_VERY_LOW + OPCODE_JUMP = GAS_MID + OPCODE_JUMPI = GAS_HIGH + OPCODE_JUMPDEST = Uint(1) + OPCODE_CALLDATALOAD = GAS_VERY_LOW + OPCODE_CALLDATACOPY = GAS_VERY_LOW + OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_BLOCKHASH = Uint(20) + OPCODE_COINBASE = GAS_BASE + OPCODE_MLOAD = GAS_VERY_LOW + OPCODE_MSTORE = GAS_VERY_LOW + OPCODE_MSTORE8 = GAS_VERY_LOW + OPCODE_PUSH = GAS_VERY_LOW + OPCODE_DUP = GAS_VERY_LOW + OPCODE_SWAP = GAS_VERY_LOW @dataclass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index 6add253f46e..92e49121ba5 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -40,7 +40,7 @@ def add(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADD) + charge_gas(evm, GasCosts.OPCODE_ADD) # OPERATION result = x.wrapping_add(y) @@ -67,7 +67,7 @@ def sub(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SUB) + charge_gas(evm, GasCosts.OPCODE_SUB) # OPERATION result = x.wrapping_sub(y) @@ -94,7 +94,7 @@ def mul(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MUL) + charge_gas(evm, GasCosts.OPCODE_MUL) # OPERATION result = x.wrapping_mul(y) @@ -121,7 +121,7 @@ def div(evm: Evm) -> None: divisor = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DIV) + charge_gas(evm, GasCosts.OPCODE_DIV) # OPERATION if divisor == 0: @@ -154,7 +154,7 @@ def sdiv(evm: Evm) -> None: divisor = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SDIV) + charge_gas(evm, GasCosts.OPCODE_SDIV) # OPERATION if divisor == 0: @@ -187,7 +187,7 @@ def mod(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MOD) + charge_gas(evm, GasCosts.OPCODE_MOD) # OPERATION if y == 0: @@ -217,7 +217,7 @@ def smod(evm: Evm) -> None: y = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SMOD) + charge_gas(evm, GasCosts.OPCODE_SMOD) # OPERATION if y == 0: @@ -248,7 +248,7 @@ def addmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ADDMOD) + charge_gas(evm, GasCosts.OPCODE_ADDMOD) # OPERATION if z == 0: @@ -279,7 +279,7 @@ def mulmod(evm: Evm) -> None: z = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_MULMOD) + charge_gas(evm, GasCosts.OPCODE_MULMOD) # OPERATION if z == 0: @@ -344,7 +344,7 @@ def signextend(evm: Evm) -> None: value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SIGNEXTEND) + charge_gas(evm, GasCosts.OPCODE_SIGNEXTEND) # OPERATION if byte_num > U256(31): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py index 963889d27ea..62da98041ad 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/bitwise.py @@ -37,7 +37,7 @@ def bitwise_and(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_AND) + charge_gas(evm, GasCosts.OPCODE_AND) # OPERATION push(evm.stack, x & y) @@ -62,7 +62,7 @@ def bitwise_or(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_OR) + charge_gas(evm, GasCosts.OPCODE_OR) # OPERATION push(evm.stack, x | y) @@ -87,7 +87,7 @@ def bitwise_xor(evm: Evm) -> None: y = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_XOR) + charge_gas(evm, GasCosts.OPCODE_XOR) # OPERATION push(evm.stack, x ^ y) @@ -111,7 +111,7 @@ def bitwise_not(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_NOT) + charge_gas(evm, GasCosts.OPCODE_NOT) # OPERATION push(evm.stack, ~x) @@ -137,7 +137,7 @@ def get_byte(evm: Evm) -> None: word = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BYTE) + charge_gas(evm, GasCosts.OPCODE_BYTE) # OPERATION if byte_index >= U256(32): diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py index abde61719df..904a1e71771 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py @@ -33,7 +33,7 @@ def block_hash(evm: Evm) -> None: block_number = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_BLOCKHASH) + charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) # OPERATION max_block_number = block_number + Uint(256) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py index ab71ab44f9d..22d3d8916b1 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/comparison.py @@ -37,7 +37,7 @@ def less_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_LT) + charge_gas(evm, GasCosts.OPCODE_LT) # OPERATION result = U256(left < right) @@ -63,7 +63,7 @@ def signed_less_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SLT) + charge_gas(evm, GasCosts.OPCODE_SLT) # OPERATION result = U256(left < right) @@ -90,7 +90,7 @@ def greater_than(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_GT) + charge_gas(evm, GasCosts.OPCODE_GT) # OPERATION result = U256(left > right) @@ -116,7 +116,7 @@ def signed_greater_than(evm: Evm) -> None: right = pop(evm.stack).to_signed() # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SGT) + charge_gas(evm, GasCosts.OPCODE_SGT) # OPERATION result = U256(left > right) @@ -143,7 +143,7 @@ def equal(evm: Evm) -> None: right = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_EQ) + charge_gas(evm, GasCosts.OPCODE_EQ) # OPERATION result = U256(left == right) @@ -169,7 +169,7 @@ def is_zero(evm: Evm) -> None: x = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_ISZERO) + charge_gas(evm, GasCosts.OPCODE_ISZERO) # OPERATION result = U256(x == 0) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index 8582c0e45d2..12a18a10ab2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -60,7 +60,7 @@ def jump(evm: Evm) -> None: jump_dest = Uint(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMP) + charge_gas(evm, GasCosts.OPCODE_JUMP) # OPERATION if jump_dest not in evm.valid_jump_destinations: @@ -87,7 +87,7 @@ def jumpi(evm: Evm) -> None: conditional_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPI) + charge_gas(evm, GasCosts.OPCODE_JUMPI) # OPERATION if conditional_value == 0: @@ -165,7 +165,7 @@ def jumpdest(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_JUMPDEST) + charge_gas(evm, GasCosts.OPCODE_JUMPDEST) # OPERATION pass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 561f20f5479..5baf8effdc3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -161,7 +161,7 @@ def calldataload(evm: Evm) -> None: start_index = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_CALLDATALOAD) + charge_gas(evm, GasCosts.OPCODE_CALLDATALOAD) # OPERATION value = buffer_read(evm.message.data, start_index, U256(32)) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.GAS_OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index f99bfbf53fd..deec5941342 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.GAS_OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 2acc1af3d26..97123b5f2e2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -65,7 +65,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_PUSH) + charge_gas(evm, GasCosts.OPCODE_PUSH) # OPERATION data_to_push = U256.from_be_bytes( @@ -95,7 +95,7 @@ def dup_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_DUP) + charge_gas(evm, GasCosts.OPCODE_DUP) if item_number >= len(evm.stack): raise StackUnderflowError data_to_duplicate = evm.stack[len(evm.stack) - 1 - item_number] @@ -127,7 +127,7 @@ def swap_n(evm: Evm, item_number: int) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_OPCODE_SWAP) + charge_gas(evm, GasCosts.OPCODE_SWAP) if item_number >= len(evm.stack): raise StackUnderflowError evm.stack[-1], evm.stack[-1 - item_number] = ( From 5eb0f829f8779297d8f88f60901a8feb2c6bf565 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 31 Mar 2026 12:55:28 -0400 Subject: [PATCH 39/61] refactor: drop GAS_ prefix for opcode, precompile, and refund consts --- .../execution_testing/forks/forks/forks.py | 46 +++++++-------- .../src/execution_testing/forks/gas_costs.py | 56 +++++++++---------- src/ethereum/forks/amsterdam/vm/gas.py | 42 ++++++++------ .../vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/berlin/vm/gas.py | 27 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../berlin/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/bpo1/vm/gas.py | 41 ++++++++------ .../bpo1/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../bpo1/vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../bpo1/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/bpo2/vm/gas.py | 41 ++++++++------ .../bpo2/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../bpo2/vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../bpo2/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/bpo3/vm/gas.py | 41 ++++++++------ .../bpo3/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../bpo3/vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../bpo3/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/bpo4/vm/gas.py | 41 ++++++++------ .../bpo4/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../bpo4/vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../bpo4/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/bpo5/vm/gas.py | 41 ++++++++------ .../bpo5/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../bpo5/vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../bpo5/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/byzantium/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/cancun/vm/gas.py | 26 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../cancun/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/constantinople/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/dao_fork/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/frontier/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/gray_glacier/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/homestead/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/istanbul/vm/gas.py | 27 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/london/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../london/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/muir_glacier/vm/gas.py | 27 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/osaka/vm/gas.py | 41 ++++++++------ .../osaka/vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/p256verify.py | 2 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../osaka/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/paris/vm/gas.py | 25 +++++---- .../paris/vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../paris/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/prague/vm/gas.py | 39 +++++++------ .../vm/precompiled_contracts/blake2f.py | 2 +- .../bls12_381/bls12_381_g1.py | 8 +-- .../bls12_381/bls12_381_g2.py | 8 +-- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../prague/vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/shanghai/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/blake2f.py | 2 +- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- .../forks/tangerine_whistle/vm/gas.py | 25 +++++---- .../vm/precompiled_contracts/ecrecover.py | 2 +- .../vm/precompiled_contracts/identity.py | 4 +- .../vm/precompiled_contracts/ripemd160.py | 4 +- .../vm/precompiled_contracts/sha256.py | 4 +- .../compute/precompile/test_alt_bn128.py | 8 +-- .../compute/precompile/test_identity.py | 4 +- .../compute/precompile/test_ripemd160.py | 4 +- .../compute/precompile/test_sha256.py | 4 +- tests/byzantium/eip196_ec_add_mul/conftest.py | 4 +- tests/byzantium/eip197_ec_pairing/conftest.py | 4 +- .../test_point_evaluation_precompile.py | 10 ++-- .../test_point_evaluation_precompile_gas.py | 6 +- .../conftest.py | 2 +- .../test_p256verify.py | 6 +- .../test_p256verify_before_fork.py | 2 +- .../eip2537_bls_12_381_precompiles/spec.py | 16 +++--- 174 files changed, 753 insertions(+), 665 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 55af7e3c08d..198730c82bd 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -132,35 +132,35 @@ def gas_costs(cls) -> GasCosts: GAS_KECCAK256=30, GAS_KECCAK256_PER_WORD=6, GAS_COPY=3, - GAS_PRECOMPILE_ECRECOVER=3_000, - GAS_PRECOMPILE_SHA256_BASE=60, - GAS_PRECOMPILE_SHA256_PER_WORD=12, - GAS_PRECOMPILE_RIPEMD160_BASE=600, - GAS_PRECOMPILE_RIPEMD160_PER_WORD=120, - GAS_PRECOMPILE_IDENTITY_BASE=15, - GAS_PRECOMPILE_IDENTITY_PER_WORD=3, + PRECOMPILE_ECRECOVER=3_000, + PRECOMPILE_SHA256_BASE=60, + PRECOMPILE_SHA256_PER_WORD=12, + PRECOMPILE_RIPEMD160_BASE=600, + PRECOMPILE_RIPEMD160_PER_WORD=120, + PRECOMPILE_IDENTITY_BASE=15, + PRECOMPILE_IDENTITY_PER_WORD=3, # Zero-initialized: introduced in later forks, set via # replace() in the fork that activates them. GAS_TX_DATA_TOKEN_STANDARD=0, GAS_TX_DATA_TOKEN_FLOOR=0, GAS_AUTH_PER_EMPTY_ACCOUNT=0, REFUND_AUTH_PER_EXISTING_ACCOUNT=0, - GAS_PRECOMPILE_ECADD=0, - GAS_PRECOMPILE_ECMUL=0, - GAS_PRECOMPILE_ECPAIRING_BASE=0, - GAS_PRECOMPILE_ECPAIRING_PER_POINT=0, - GAS_PRECOMPILE_BLAKE2F_BASE=0, - GAS_PRECOMPILE_BLAKE2F_PER_ROUND=0, - GAS_PRECOMPILE_POINT_EVALUATION=0, - GAS_PRECOMPILE_BLS_G1ADD=0, - GAS_PRECOMPILE_BLS_G1MUL=0, - GAS_PRECOMPILE_BLS_G1MAP=0, - GAS_PRECOMPILE_BLS_G2ADD=0, - GAS_PRECOMPILE_BLS_G2MUL=0, - GAS_PRECOMPILE_BLS_G2MAP=0, - GAS_PRECOMPILE_BLS_PAIRING_BASE=0, - GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR=0, - GAS_PRECOMPILE_P256VERIFY=0, + PRECOMPILE_ECADD=0, + PRECOMPILE_ECMUL=0, + PRECOMPILE_ECPAIRING_BASE=0, + PRECOMPILE_ECPAIRING_PER_POINT=0, + PRECOMPILE_BLAKE2F_BASE=0, + PRECOMPILE_BLAKE2F_PER_ROUND=0, + PRECOMPILE_POINT_EVALUATION=0, + PRECOMPILE_BLS_G1ADD=0, + PRECOMPILE_BLS_G1MUL=0, + PRECOMPILE_BLS_G1MAP=0, + PRECOMPILE_BLS_G2ADD=0, + PRECOMPILE_BLS_G2MUL=0, + PRECOMPILE_BLS_G2MAP=0, + PRECOMPILE_BLS_PAIRING_BASE=0, + PRECOMPILE_BLS_PAIRING_PER_PAIR=0, + PRECOMPILE_P256VERIFY=0, GAS_BLOCK_ACCESS_LIST_ITEM=0, # Opcode specific gas constants for repricing OPCODE_ADD=GAS_VERY_LOW, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 3813279991d..777b44a8a8d 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -61,34 +61,34 @@ class GasCosts: GAS_AUTH_PER_EMPTY_ACCOUNT: int # Precompiled contract gas constants - GAS_PRECOMPILE_ECRECOVER: int - GAS_PRECOMPILE_SHA256_BASE: int - GAS_PRECOMPILE_SHA256_PER_WORD: int - GAS_PRECOMPILE_RIPEMD160_BASE: int - GAS_PRECOMPILE_RIPEMD160_PER_WORD: int - GAS_PRECOMPILE_IDENTITY_BASE: int - GAS_PRECOMPILE_IDENTITY_PER_WORD: int - - GAS_PRECOMPILE_ECADD: int - GAS_PRECOMPILE_ECMUL: int - GAS_PRECOMPILE_ECPAIRING_BASE: int - GAS_PRECOMPILE_ECPAIRING_PER_POINT: int - - GAS_PRECOMPILE_BLAKE2F_BASE: int - GAS_PRECOMPILE_BLAKE2F_PER_ROUND: int - - GAS_PRECOMPILE_POINT_EVALUATION: int - - GAS_PRECOMPILE_BLS_G1ADD: int - GAS_PRECOMPILE_BLS_G1MUL: int - GAS_PRECOMPILE_BLS_G1MAP: int - GAS_PRECOMPILE_BLS_G2ADD: int - GAS_PRECOMPILE_BLS_G2MUL: int - GAS_PRECOMPILE_BLS_G2MAP: int - GAS_PRECOMPILE_BLS_PAIRING_BASE: int - GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR: int - - GAS_PRECOMPILE_P256VERIFY: int + PRECOMPILE_ECRECOVER: int + PRECOMPILE_SHA256_BASE: int + PRECOMPILE_SHA256_PER_WORD: int + PRECOMPILE_RIPEMD160_BASE: int + PRECOMPILE_RIPEMD160_PER_WORD: int + PRECOMPILE_IDENTITY_BASE: int + PRECOMPILE_IDENTITY_PER_WORD: int + + PRECOMPILE_ECADD: int + PRECOMPILE_ECMUL: int + PRECOMPILE_ECPAIRING_BASE: int + PRECOMPILE_ECPAIRING_PER_POINT: int + + PRECOMPILE_BLAKE2F_BASE: int + PRECOMPILE_BLAKE2F_PER_ROUND: int + + PRECOMPILE_POINT_EVALUATION: int + + PRECOMPILE_BLS_G1ADD: int + PRECOMPILE_BLS_G1MUL: int + PRECOMPILE_BLS_G1MAP: int + PRECOMPILE_BLS_G2ADD: int + PRECOMPILE_BLS_G2MUL: int + PRECOMPILE_BLS_G2MAP: int + PRECOMPILE_BLS_PAIRING_BASE: int + PRECOMPILE_BLS_PAIRING_PER_PAIR: int + + PRECOMPILE_P256VERIFY: int # Refund constants REFUND_STORAGE_CLEAR: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 3862b0341be..cf2164d0d34 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -33,11 +33,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -58,23 +58,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -83,16 +95,10 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - + # Block Access Lists GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 09e41f0835e..efd942e4706 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,21 +55,26 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py index d7b8c44cb62..9d8c71b806d 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/blake2f.py @@ -37,7 +37,7 @@ def blake2f(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds, + GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds, ) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index ee55bb3f10e..0025350043b 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,22 +55,27 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 15000 + REFUND_SELF_DESTRUCT = 24000 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index b12d00ab85b..07e2d5f91d3 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(10) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(8346193) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index 913638a6d0a..d1f63224a0c 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G1ADD) + charge_gas(evm, GasCosts.PRECOMPILE_BLS_G1ADD) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G1MAP) + charge_gas(evm, GasCosts.PRECOMPILE_BLS_G1MAP) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 687dfbe168c..2fd32313f89 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G2ADD) + charge_gas(evm, GasCosts.PRECOMPILE_BLS_G2ADD) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLS_G2MAP) + charge_gas(evm, GasCosts.PRECOMPILE_BLS_G2MAP) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 37d039100a3..7eadc2c2074 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index df60c23fb22..f77ff60a32c 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -55,7 +55,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -96,9 +96,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -137,7 +135,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index 355e5399800..b49ec065e7c 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -56,7 +56,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -97,9 +97,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -138,7 +136,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py index 7dd737fa598..2b4929fb8d2 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py @@ -35,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py index 321f1995757..04d0e2ff594 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py @@ -38,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py index a80c1b81972..f5346f1529c 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py @@ -37,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 37d039100a3..7eadc2c2074 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 37d039100a3..7eadc2c2074 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 37d039100a3..7eadc2c2074 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index d9f5bc2f344..6480d0717a4 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,17 +59,22 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 15000 + REFUND_SELF_DESTRUCT = 24000 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py index 7dd737fa598..2b4929fb8d2 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py @@ -35,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py index 321f1995757..04d0e2ff594 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py @@ -38,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py index a80c1b81972..f5346f1529c 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py @@ -37,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index d43b53ad69b..05690295141 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,28 +57,34 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(393216) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py index 7dd737fa598..2b4929fb8d2 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py @@ -35,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py index 321f1995757..04d0e2ff594 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py @@ -38,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py index a80c1b81972..f5346f1529c 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py @@ -37,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 054aef29b37..8ee4de9527b 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,18 +59,23 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_CODE_HASH = Uint(400) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 15000 + REFUND_SELF_DESTRUCT = 24000 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index cf8b4cd2743..9c5a4cb1ddf 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -32,12 +32,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,16 +59,21 @@ class GasCosts: GAS_NEW_ACCOUNT = Uint(25000) GAS_CALL_VALUE = Uint(9000) GAS_CALL_STIPEND = Uint(2300) + + # Refunds + REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = Uint(24000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - # Opcode specific vars used for repricing + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index cf8b4cd2743..9c5a4cb1ddf 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -32,12 +32,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,16 +59,21 @@ class GasCosts: GAS_NEW_ACCOUNT = Uint(25000) GAS_CALL_VALUE = Uint(9000) GAS_CALL_STIPEND = Uint(2300) + + # Refunds + REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = Uint(24000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - # Opcode specific vars used for repricing + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 09e41f0835e..efd942e4706 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,21 +55,26 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index cf8b4cd2743..9c5a4cb1ddf 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -32,12 +32,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(50) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,16 +59,21 @@ class GasCosts: GAS_NEW_ACCOUNT = Uint(25000) GAS_CALL_VALUE = Uint(9000) GAS_CALL_STIPEND = Uint(2300) + + # Refunds + REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = Uint(24000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - # Opcode specific vars used for repricing + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 3e88c11596b..db120355d24 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(800) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,20 +59,25 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_CODE_HASH = Uint(700) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 15000 + REFUND_SELF_DESTRUCT = 24000 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 09e41f0835e..efd942e4706 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,21 +55,26 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 3e88c11596b..db120355d24 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(800) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,20 +59,25 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_CODE_HASH = Uint(700) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 15000 + REFUND_SELF_DESTRUCT = 24000 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 89e34fdfd22..815c8f92723 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,23 +57,35 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_P256VERIFY = Uint(6900) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_P256VERIFY = Uint(6900) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(6) BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET @@ -82,14 +94,7 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py index d7b8c44cb62..9d8c71b806d 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/blake2f.py @@ -37,7 +37,7 @@ def blake2f(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds, + GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds, ) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py index 99b3c722940..29c2e91e0f0 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/p256verify.py @@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY) + charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY) if len(data) != 160: return diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 09e41f0835e..efd942e4706 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,21 +55,26 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 5ce701eb209..8c08a456baa 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -32,11 +32,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -57,35 +57,40 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) GAS_POINT_EVALUATION = Uint(50000) + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_BLS_G1ADD = Uint(375) + PRECOMPILE_BLS_G1MUL = Uint(12000) + PRECOMPILE_BLS_G1MAP = Uint(5500) + PRECOMPILE_BLS_G2ADD = Uint(600) + PRECOMPILE_BLS_G2MUL = Uint(22500) + PRECOMPILE_BLS_G2MAP = Uint(23800) + + # Blobs GAS_PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(786432) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - GAS_PRECOMPILE_BLS_G1ADD = Uint(375) - GAS_PRECOMPILE_BLS_G1MUL = Uint(12000) - GAS_PRECOMPILE_BLS_G1MAP = Uint(5500) - GAS_PRECOMPILE_BLS_G2ADD = Uint(600) - GAS_PRECOMPILE_BLS_G2MUL = Uint(22500) - GAS_PRECOMPILE_BLS_G2MAP = Uint(23800) - - # Opcode specific vars used for repricing + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py index f239ac2c7fd..fa0d3ec4c2d 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g1.py @@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD)) # OPERATION p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128))) @@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None: else: discount = Uint(G1_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP)) # OPERATION fp = int.from_bytes(data, "big") diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py index c47b6689b07..a5b2be04018 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/bls12_381/bls12_381_g2.py @@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD)) # OPERATION p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256))) @@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None: else: discount = Uint(G2_MAX_DISCOUNT) - gas_cost = ( - Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER - ) + gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER charge_gas(evm, gas_cost) # OPERATION @@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None: raise InvalidParameter("Invalid Input Length") # GAS - charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP)) + charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP)) # OPERATION field_element = bytes_to_fq2(data) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 73efbabd9a9..5e89ac62596 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -30,11 +30,11 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 4800 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -55,22 +55,27 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) GAS_RETURN_DATA_COPY = Uint(3) GAS_FAST_STEP = Uint(5) - GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) GAS_COLD_STORAGE_ACCESS = Uint(2100) GAS_COLD_ACCOUNT_ACCESS = Uint(2600) GAS_WARM_ACCESS = Uint(100) GAS_CODE_INIT_PER_WORD = Uint(2) - # Opcode specific vars used for repricing + # Refunds + REFUND_STORAGE_CLEAR = 4800 + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py index 2e80c49f6e4..ae53b1ab4b5 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/blake2f.py @@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None: blake2b = Blake2b() rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data) - charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds) + charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds) if f not in [0, 1]: raise InvalidParameter diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py index 7dd737fa598..2b4929fb8d2 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py @@ -35,8 +35,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py index 321f1995757..04d0e2ff594 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py @@ -38,8 +38,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py index a80c1b81972..f5346f1529c 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py @@ -37,8 +37,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 53dc119a041..7490477f06b 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,16 +59,21 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + + # Refunds + REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - # Opcode specific vars used for repricing + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 70c777c8bef..d7d8e01bb4b 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -30,12 +30,12 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ + # General GAS_BASE = Uint(2) GAS_VERY_LOW = Uint(3) GAS_SLOAD = Uint(200) GAS_STORAGE_SET = Uint(20000) GAS_COLD_STORAGE_WRITE = Uint(5000) - REFUND_STORAGE_CLEAR = 15000 GAS_LOW = Uint(5) GAS_MID = Uint(8) GAS_HIGH = Uint(10) @@ -59,16 +59,21 @@ class GasCosts: GAS_CALL_STIPEND = Uint(2300) GAS_SELF_DESTRUCT = Uint(5000) GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + + # Refunds + REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = 24000 - GAS_PRECOMPILE_ECRECOVER = Uint(3000) - GAS_PRECOMPILE_SHA256_BASE = Uint(60) - GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12) - GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600) - GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) - GAS_PRECOMPILE_IDENTITY_BASE = Uint(15) - GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - - # Opcode specific vars used for repricing + + # Precompiles + PRECOMPILE_ECRECOVER = Uint(3000) + PRECOMPILE_SHA256_BASE = Uint(60) + PRECOMPILE_SHA256_PER_WORD = Uint(12) + PRECOMPILE_RIPEMD160_BASE = Uint(600) + PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) + PRECOMPILE_IDENTITY_BASE = Uint(15) + PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + + # Opcodes OPCODE_ADD = GAS_VERY_LOW OPCODE_SUB = GAS_VERY_LOW OPCODE_MUL = GAS_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py index 049e6f13577..17a0174f6ed 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ecrecover.py @@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER) + charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER) # OPERATION message_hash_bytes = buffer_read(data, U256(0), U256(32)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py index 07804e9174f..cdbd61f5b0d 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py @@ -38,8 +38,8 @@ def identity(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_IDENTITY_BASE - + GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count, + GasCosts.PRECOMPILE_IDENTITY_BASE + + GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py index b3ee3aab9b1..eafdf08c365 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py @@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE - + GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count, + GasCosts.PRECOMPILE_RIPEMD160_BASE + + GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py index 5482b20221d..0a9f67e8441 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py @@ -40,8 +40,8 @@ def sha256(evm: Evm) -> None: word_count = ceil32(Uint(len(data))) // Uint(32) charge_gas( evm, - GasCosts.GAS_PRECOMPILE_SHA256_BASE - + GasCosts.GAS_PRECOMPILE_SHA256_PER_WORD * word_count, + GasCosts.PRECOMPILE_SHA256_BASE + + GasCosts.PRECOMPILE_SHA256_PER_WORD * word_count, ) # OPERATION diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index 6466f554e7e..7d406990681 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -457,8 +457,8 @@ def test_bn128_pairings_amortized( size_per_pairing = 192 gsc = fork.gas_costs() - base_cost = gsc.GAS_PRECOMPILE_ECPAIRING_BASE - pairing_cost = gsc.GAS_PRECOMPILE_ECPAIRING_PER_POINT + base_cost = gsc.PRECOMPILE_ECPAIRING_BASE + pairing_cost = gsc.PRECOMPILE_ECPAIRING_PER_POINT intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator() mem_exp_gas_calculator = fork.memory_expansion_gas_calculator() warm_account_access_cost = Op.STATICCALL( @@ -571,8 +571,8 @@ def test_ec_pairing( intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator() mem_exp = fork.memory_expansion_gas_calculator() precompile_cost = ( - gsc.GAS_PRECOMPILE_ECPAIRING_BASE - + gsc.GAS_PRECOMPILE_ECPAIRING_PER_POINT * num_pairs + gsc.PRECOMPILE_ECPAIRING_BASE + + gsc.PRECOMPILE_ECPAIRING_PER_POINT * num_pairs ) # Each iteration: STATICCALL ecpairing at advancing calldata offset, diff --git a/tests/benchmark/compute/precompile/test_identity.py b/tests/benchmark/compute/precompile/test_identity.py index 56198ef1e14..206e813cf79 100644 --- a/tests/benchmark/compute/precompile/test_identity.py +++ b/tests/benchmark/compute/precompile/test_identity.py @@ -24,8 +24,8 @@ def test_identity( optimal_input_length = calculate_optimal_input_length( available_gas=gas_available, fork=fork, - static_cost=gas_costs.GAS_PRECOMPILE_IDENTITY_BASE, - per_word_dynamic_cost=gas_costs.GAS_PRECOMPILE_IDENTITY_PER_WORD, + static_cost=gas_costs.PRECOMPILE_IDENTITY_BASE, + per_word_dynamic_cost=gas_costs.PRECOMPILE_IDENTITY_PER_WORD, bytes_per_unit_of_work=1, ) diff --git a/tests/benchmark/compute/precompile/test_ripemd160.py b/tests/benchmark/compute/precompile/test_ripemd160.py index 75aef42266a..af415839082 100644 --- a/tests/benchmark/compute/precompile/test_ripemd160.py +++ b/tests/benchmark/compute/precompile/test_ripemd160.py @@ -24,8 +24,8 @@ def test_ripemd160( optimal_input_length = calculate_optimal_input_length( available_gas=gas_available, fork=fork, - static_cost=gas_costs.GAS_PRECOMPILE_RIPEMD160_BASE, - per_word_dynamic_cost=gas_costs.GAS_PRECOMPILE_RIPEMD160_PER_WORD, + static_cost=gas_costs.PRECOMPILE_RIPEMD160_BASE, + per_word_dynamic_cost=gas_costs.PRECOMPILE_RIPEMD160_PER_WORD, bytes_per_unit_of_work=64, ) diff --git a/tests/benchmark/compute/precompile/test_sha256.py b/tests/benchmark/compute/precompile/test_sha256.py index def1d35bdae..9cc8a4bec29 100644 --- a/tests/benchmark/compute/precompile/test_sha256.py +++ b/tests/benchmark/compute/precompile/test_sha256.py @@ -24,8 +24,8 @@ def test_sha256( optimal_input_length = calculate_optimal_input_length( available_gas=gas_available, fork=fork, - static_cost=gas_costs.GAS_PRECOMPILE_SHA256_BASE, - per_word_dynamic_cost=gas_costs.GAS_PRECOMPILE_SHA256_PER_WORD, + static_cost=gas_costs.PRECOMPILE_SHA256_BASE, + per_word_dynamic_cost=gas_costs.PRECOMPILE_SHA256_PER_WORD, bytes_per_unit_of_work=64, ) diff --git a/tests/byzantium/eip196_ec_add_mul/conftest.py b/tests/byzantium/eip196_ec_add_mul/conftest.py index 6fc5cae214d..42e0d29776f 100644 --- a/tests/byzantium/eip196_ec_add_mul/conftest.py +++ b/tests/byzantium/eip196_ec_add_mul/conftest.py @@ -27,9 +27,9 @@ def precompile_gas(precompile_address: Address, fork: Fork) -> int: gas_costs = fork.gas_costs() match precompile_address: case Spec.ECADD: - return gas_costs.GAS_PRECOMPILE_ECADD + return gas_costs.PRECOMPILE_ECADD case Spec.ECMUL: - return gas_costs.GAS_PRECOMPILE_ECMUL + return gas_costs.PRECOMPILE_ECMUL case _: raise ValueError( f"Unexpected precompile address: {precompile_address}" diff --git a/tests/byzantium/eip197_ec_pairing/conftest.py b/tests/byzantium/eip197_ec_pairing/conftest.py index 01bc4552191..8f3164caadf 100644 --- a/tests/byzantium/eip197_ec_pairing/conftest.py +++ b/tests/byzantium/eip197_ec_pairing/conftest.py @@ -23,6 +23,6 @@ def precompile_gas(input_data: bytes, fork: Fork) -> int: gas_costs = fork.gas_costs() k = len(input_data) // 192 return ( - gas_costs.GAS_PRECOMPILE_ECPAIRING_BASE - + gas_costs.GAS_PRECOMPILE_ECPAIRING_PER_POINT * k + gas_costs.PRECOMPILE_ECPAIRING_BASE + + gas_costs.PRECOMPILE_ECPAIRING_PER_POINT * k ) diff --git a/tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py b/tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py index 5e8e2cf1b54..952b41069ea 100644 --- a/tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py +++ b/tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py @@ -113,7 +113,7 @@ def call_gas(fork: Fork) -> int: Defaults to the point evaluation precompile gas cost, but can be parametrized to test different amounts. """ - return fork.gas_costs().GAS_PRECOMPILE_POINT_EVALUATION + return fork.gas_costs().PRECOMPILE_POINT_EVALUATION precompile_caller_storage_keys = count() @@ -202,9 +202,7 @@ def tx( sender=sender, data=precompile_input, to=precompile_caller_address, - gas_limit=fork.transitions_to() - .gas_costs() - .GAS_PRECOMPILE_POINT_EVALUATION + gas_limit=fork.transitions_to().gas_costs().PRECOMPILE_POINT_EVALUATION * 100, ) @@ -589,7 +587,7 @@ def test_tx_entry_point( # Consumed gas will only be the precompile gas if the proof is correct and # the call gas is sufficient. # Otherwise, the call gas will be consumed in full. - precompile_gas = fork.gas_costs().GAS_PRECOMPILE_POINT_EVALUATION + precompile_gas = fork.gas_costs().PRECOMPILE_POINT_EVALUATION consumed_gas = ( precompile_gas if call_gas >= precompile_gas and proof_correct @@ -714,7 +712,7 @@ def test_precompile_during_fork( Test calling the Point Evaluation Precompile during the appropriate fork. """ precompile_gas = ( - fork.transitions_to().gas_costs().GAS_PRECOMPILE_POINT_EVALUATION + fork.transitions_to().gas_costs().PRECOMPILE_POINT_EVALUATION ) # Blocks before fork blocks = [ diff --git a/tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py b/tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py index 1f313594db4..231f084a7f9 100644 --- a/tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py +++ b/tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py @@ -66,7 +66,7 @@ def call_gas(fork: Fork) -> int: Defaults to the point evaluation precompile gas cost, but can be parametrized to test different amounts. """ - return fork.gas_costs().GAS_PRECOMPILE_POINT_EVALUATION + return fork.gas_costs().PRECOMPILE_POINT_EVALUATION def copy_opcode_cost(fork: Fork, length: int) -> int: @@ -157,7 +157,7 @@ def tx( data=precompile_input, to=precompile_caller_address, value=0, - gas_limit=fork.gas_costs().GAS_PRECOMPILE_POINT_EVALUATION * 20, + gas_limit=fork.gas_costs().PRECOMPILE_POINT_EVALUATION * 20, ) @@ -172,7 +172,7 @@ def post( Prepare expected post for each test, depending on the success or failure of the precompile call and the gas usage. """ - precompile_gas = fork.gas_costs().GAS_PRECOMPILE_POINT_EVALUATION + precompile_gas = fork.gas_costs().PRECOMPILE_POINT_EVALUATION if proof == "correct": expected_gas_usage = ( call_gas if call_gas < precompile_gas else precompile_gas diff --git a/tests/osaka/eip7951_p256verify_precompiles/conftest.py b/tests/osaka/eip7951_p256verify_precompiles/conftest.py index 2c313fda41b..af45811a5ba 100644 --- a/tests/osaka/eip7951_p256verify_precompiles/conftest.py +++ b/tests/osaka/eip7951_p256verify_precompiles/conftest.py @@ -33,7 +33,7 @@ def vector_gas_value() -> int | None: @pytest.fixture def precompile_gas(vector_gas_value: int | None, fork: Fork) -> int: """Gas cost for the precompile.""" - gas = fork.gas_costs().GAS_PRECOMPILE_P256VERIFY + gas = fork.gas_costs().PRECOMPILE_P256VERIFY if vector_gas_value is not None: assert vector_gas_value == gas, ( f"Calculated gas {vector_gas_value} != Vector gas {gas}" diff --git a/tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py b/tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py index b826fcd7389..183ba71686c 100644 --- a/tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py +++ b/tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py @@ -1101,7 +1101,7 @@ def test_precompile_will_return_success_with_tx_value( call_256verify_bytecode = ( Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE()) + Op.CALL( - gas=fork.gas_costs().GAS_PRECOMPILE_P256VERIFY, + gas=fork.gas_costs().PRECOMPILE_P256VERIFY, address=Spec.P256VERIFY, value=Op.CALLVALUE(), args_offset=0, @@ -1244,7 +1244,7 @@ def test_contract_creation_transaction( contract_bytecode = ( Op.CODECOPY(0, Op.SUB(Op.CODESIZE, len(input_data)), len(input_data)) + Op.CALL( - gas=fork.gas_costs().GAS_PRECOMPILE_P256VERIFY, + gas=fork.gas_costs().PRECOMPILE_P256VERIFY, address=Spec.P256VERIFY, value=0, args_offset=0, @@ -1311,7 +1311,7 @@ def test_contract_initcode( call_256verify_bytecode = ( Op.CODECOPY(0, Op.SUB(Op.CODESIZE, len(input_data)), len(input_data)) + Op.CALL( - gas=fork.gas_costs().GAS_PRECOMPILE_P256VERIFY, + gas=fork.gas_costs().PRECOMPILE_P256VERIFY, address=Spec.P256VERIFY, value=0, args_offset=0, diff --git a/tests/osaka/eip7951_p256verify_precompiles/test_p256verify_before_fork.py b/tests/osaka/eip7951_p256verify_precompiles/test_p256verify_before_fork.py index 9bcca0ac450..1c8b5f141b8 100644 --- a/tests/osaka/eip7951_p256verify_precompiles/test_p256verify_before_fork.py +++ b/tests/osaka/eip7951_p256verify_precompiles/test_p256verify_before_fork.py @@ -29,7 +29,7 @@ @pytest.fixture def precompile_gas(vector_gas_value: int | None, fork: TransitionFork) -> int: """Gas cost for the precompile.""" - gas = fork.transitions_to().gas_costs().GAS_PRECOMPILE_P256VERIFY + gas = fork.transitions_to().gas_costs().PRECOMPILE_P256VERIFY if vector_gas_value is not None: assert vector_gas_value == gas, ( f"Calculated gas {vector_gas_value} != Vector gas {gas}" diff --git a/tests/prague/eip2537_bls_12_381_precompiles/spec.py b/tests/prague/eip2537_bls_12_381_precompiles/spec.py index 053b4ad743e..a8bb7a3431c 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/spec.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/spec.py @@ -299,8 +299,8 @@ def _pairing_gas_from_costs( def calc(input_length: int) -> int: k = input_length // Spec.LEN_PER_PAIR return ( - gas_costs.GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR * k - + gas_costs.GAS_PRECOMPILE_BLS_PAIRING_BASE + gas_costs.PRECOMPILE_BLS_PAIRING_PER_PAIR * k + + gas_costs.PRECOMPILE_BLS_PAIRING_BASE ) return calc @@ -311,19 +311,19 @@ def build_gas_calculation_function_map( ) -> Dict[int, Callable[[int], int]]: """Build a gas calculation function map from fork gas costs.""" return { - Spec.G1ADD: lambda _: gas_costs.GAS_PRECOMPILE_BLS_G1ADD, + Spec.G1ADD: lambda _: gas_costs.PRECOMPILE_BLS_G1ADD, Spec.G1MSM: msm_gas_func_gen( BLS12Group.G1, len(PointG1() + Scalar()), - gas_costs.GAS_PRECOMPILE_BLS_G1MUL, + gas_costs.PRECOMPILE_BLS_G1MUL, ), - Spec.G2ADD: lambda _: gas_costs.GAS_PRECOMPILE_BLS_G2ADD, + Spec.G2ADD: lambda _: gas_costs.PRECOMPILE_BLS_G2ADD, Spec.G2MSM: msm_gas_func_gen( BLS12Group.G2, len(PointG2() + Scalar()), - gas_costs.GAS_PRECOMPILE_BLS_G2MUL, + gas_costs.PRECOMPILE_BLS_G2MUL, ), Spec.PAIRING: _pairing_gas_from_costs(gas_costs), - Spec.MAP_FP_TO_G1: lambda _: gas_costs.GAS_PRECOMPILE_BLS_G1MAP, - Spec.MAP_FP2_TO_G2: lambda _: gas_costs.GAS_PRECOMPILE_BLS_G2MAP, + Spec.MAP_FP_TO_G1: lambda _: gas_costs.PRECOMPILE_BLS_G1MAP, + Spec.MAP_FP2_TO_G2: lambda _: gas_costs.PRECOMPILE_BLS_G2MAP, } From 5a81fc1ec351e4e47ef1281e1891a7675e1daaa1 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 31 Mar 2026 16:50:31 -0400 Subject: [PATCH 40/61] refactor: remove GAS_ prefix from remaining non-module-level constants --- .../forks/amsterdam/block_access_lists.py | 4 +- src/ethereum/forks/amsterdam/fork.py | 2 +- .../forks/amsterdam/vm/eoa_delegation.py | 4 +- src/ethereum/forks/amsterdam/vm/gas.py | 158 +++++++++--------- .../amsterdam/vm/instructions/arithmetic.py | 4 +- .../forks/amsterdam/vm/instructions/block.py | 12 +- .../amsterdam/vm/instructions/control_flow.py | 4 +- .../amsterdam/vm/instructions/environment.py | 46 ++--- .../forks/amsterdam/vm/instructions/keccak.py | 6 +- .../forks/amsterdam/vm/instructions/log.py | 6 +- .../forks/amsterdam/vm/instructions/memory.py | 4 +- .../forks/amsterdam/vm/instructions/stack.py | 4 +- .../amsterdam/vm/instructions/storage.py | 27 ++- .../forks/amsterdam/vm/instructions/system.py | 36 ++-- .../forks/amsterdam/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 136 +++++++-------- .../vm/instructions/arithmetic.py | 4 +- .../arrow_glacier/vm/instructions/block.py | 12 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 44 ++--- .../arrow_glacier/vm/instructions/keccak.py | 4 +- .../arrow_glacier/vm/instructions/log.py | 6 +- .../arrow_glacier/vm/instructions/memory.py | 2 +- .../arrow_glacier/vm/instructions/stack.py | 2 +- .../arrow_glacier/vm/instructions/storage.py | 23 ++- .../arrow_glacier/vm/instructions/system.py | 36 ++-- .../forks/arrow_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 136 +++++++-------- .../berlin/vm/instructions/arithmetic.py | 4 +- .../forks/berlin/vm/instructions/block.py | 12 +- .../berlin/vm/instructions/control_flow.py | 4 +- .../berlin/vm/instructions/environment.py | 42 ++--- .../forks/berlin/vm/instructions/keccak.py | 4 +- .../forks/berlin/vm/instructions/log.py | 6 +- .../forks/berlin/vm/instructions/memory.py | 2 +- .../forks/berlin/vm/instructions/stack.py | 2 +- .../forks/berlin/vm/instructions/storage.py | 23 ++- .../forks/berlin/vm/instructions/system.py | 36 ++-- src/ethereum/forks/berlin/vm/interpreter.py | 2 +- src/ethereum/forks/bpo1/fork.py | 2 +- src/ethereum/forks/bpo1/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo1/vm/gas.py | 156 +++++++++-------- .../forks/bpo1/vm/instructions/arithmetic.py | 4 +- .../forks/bpo1/vm/instructions/block.py | 12 +- .../bpo1/vm/instructions/control_flow.py | 4 +- .../forks/bpo1/vm/instructions/environment.py | 46 ++--- .../forks/bpo1/vm/instructions/keccak.py | 4 +- .../forks/bpo1/vm/instructions/log.py | 6 +- .../forks/bpo1/vm/instructions/memory.py | 4 +- .../forks/bpo1/vm/instructions/stack.py | 4 +- .../forks/bpo1/vm/instructions/storage.py | 27 ++- .../forks/bpo1/vm/instructions/system.py | 36 ++-- src/ethereum/forks/bpo1/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo2/fork.py | 2 +- src/ethereum/forks/bpo2/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo2/vm/gas.py | 156 +++++++++-------- .../forks/bpo2/vm/instructions/arithmetic.py | 4 +- .../forks/bpo2/vm/instructions/block.py | 12 +- .../bpo2/vm/instructions/control_flow.py | 4 +- .../forks/bpo2/vm/instructions/environment.py | 46 ++--- .../forks/bpo2/vm/instructions/keccak.py | 4 +- .../forks/bpo2/vm/instructions/log.py | 6 +- .../forks/bpo2/vm/instructions/memory.py | 4 +- .../forks/bpo2/vm/instructions/stack.py | 4 +- .../forks/bpo2/vm/instructions/storage.py | 27 ++- .../forks/bpo2/vm/instructions/system.py | 36 ++-- src/ethereum/forks/bpo2/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo3/fork.py | 2 +- src/ethereum/forks/bpo3/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo3/vm/gas.py | 156 +++++++++-------- .../forks/bpo3/vm/instructions/arithmetic.py | 4 +- .../forks/bpo3/vm/instructions/block.py | 12 +- .../bpo3/vm/instructions/control_flow.py | 4 +- .../forks/bpo3/vm/instructions/environment.py | 46 ++--- .../forks/bpo3/vm/instructions/keccak.py | 4 +- .../forks/bpo3/vm/instructions/log.py | 6 +- .../forks/bpo3/vm/instructions/memory.py | 4 +- .../forks/bpo3/vm/instructions/stack.py | 4 +- .../forks/bpo3/vm/instructions/storage.py | 27 ++- .../forks/bpo3/vm/instructions/system.py | 36 ++-- src/ethereum/forks/bpo3/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo4/fork.py | 2 +- src/ethereum/forks/bpo4/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo4/vm/gas.py | 156 +++++++++-------- .../forks/bpo4/vm/instructions/arithmetic.py | 4 +- .../forks/bpo4/vm/instructions/block.py | 12 +- .../bpo4/vm/instructions/control_flow.py | 4 +- .../forks/bpo4/vm/instructions/environment.py | 46 ++--- .../forks/bpo4/vm/instructions/keccak.py | 4 +- .../forks/bpo4/vm/instructions/log.py | 6 +- .../forks/bpo4/vm/instructions/memory.py | 4 +- .../forks/bpo4/vm/instructions/stack.py | 4 +- .../forks/bpo4/vm/instructions/storage.py | 27 ++- .../forks/bpo4/vm/instructions/system.py | 36 ++-- src/ethereum/forks/bpo4/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo5/fork.py | 2 +- src/ethereum/forks/bpo5/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo5/vm/gas.py | 156 +++++++++-------- .../forks/bpo5/vm/instructions/arithmetic.py | 4 +- .../forks/bpo5/vm/instructions/block.py | 12 +- .../bpo5/vm/instructions/control_flow.py | 4 +- .../forks/bpo5/vm/instructions/environment.py | 46 ++--- .../forks/bpo5/vm/instructions/keccak.py | 4 +- .../forks/bpo5/vm/instructions/log.py | 6 +- .../forks/bpo5/vm/instructions/memory.py | 4 +- .../forks/bpo5/vm/instructions/stack.py | 4 +- .../forks/bpo5/vm/instructions/storage.py | 27 ++- .../forks/bpo5/vm/instructions/system.py | 36 ++-- src/ethereum/forks/bpo5/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 130 +++++++------- .../byzantium/vm/instructions/arithmetic.py | 4 +- .../forks/byzantium/vm/instructions/block.py | 10 +- .../byzantium/vm/instructions/control_flow.py | 4 +- .../byzantium/vm/instructions/environment.py | 30 ++-- .../forks/byzantium/vm/instructions/keccak.py | 6 +- .../forks/byzantium/vm/instructions/log.py | 6 +- .../forks/byzantium/vm/instructions/memory.py | 2 +- .../forks/byzantium/vm/instructions/stack.py | 2 +- .../byzantium/vm/instructions/storage.py | 6 +- .../forks/byzantium/vm/instructions/system.py | 22 +-- .../forks/byzantium/vm/interpreter.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 150 ++++++++--------- .../cancun/vm/instructions/arithmetic.py | 4 +- .../forks/cancun/vm/instructions/block.py | 12 +- .../cancun/vm/instructions/control_flow.py | 4 +- .../cancun/vm/instructions/environment.py | 46 ++--- .../forks/cancun/vm/instructions/keccak.py | 4 +- .../forks/cancun/vm/instructions/log.py | 6 +- .../forks/cancun/vm/instructions/memory.py | 4 +- .../forks/cancun/vm/instructions/stack.py | 4 +- .../forks/cancun/vm/instructions/storage.py | 27 ++- .../forks/cancun/vm/instructions/system.py | 36 ++-- src/ethereum/forks/cancun/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 138 +++++++-------- .../vm/instructions/arithmetic.py | 4 +- .../constantinople/vm/instructions/block.py | 10 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 32 ++-- .../constantinople/vm/instructions/keccak.py | 6 +- .../constantinople/vm/instructions/log.py | 6 +- .../constantinople/vm/instructions/memory.py | 2 +- .../constantinople/vm/instructions/stack.py | 2 +- .../constantinople/vm/instructions/storage.py | 6 +- .../constantinople/vm/instructions/system.py | 26 +-- .../forks/constantinople/vm/interpreter.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 128 +++++++------- .../dao_fork/vm/instructions/arithmetic.py | 4 +- .../forks/dao_fork/vm/instructions/block.py | 10 +- .../dao_fork/vm/instructions/control_flow.py | 4 +- .../dao_fork/vm/instructions/environment.py | 26 +-- .../forks/dao_fork/vm/instructions/keccak.py | 6 +- .../forks/dao_fork/vm/instructions/log.py | 6 +- .../forks/dao_fork/vm/instructions/memory.py | 2 +- .../forks/dao_fork/vm/instructions/stack.py | 2 +- .../forks/dao_fork/vm/instructions/storage.py | 6 +- .../forks/dao_fork/vm/instructions/system.py | 8 +- src/ethereum/forks/dao_fork/vm/interpreter.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 128 +++++++------- .../frontier/vm/instructions/arithmetic.py | 4 +- .../forks/frontier/vm/instructions/block.py | 10 +- .../frontier/vm/instructions/control_flow.py | 4 +- .../frontier/vm/instructions/environment.py | 26 +-- .../forks/frontier/vm/instructions/keccak.py | 6 +- .../forks/frontier/vm/instructions/log.py | 6 +- .../forks/frontier/vm/instructions/memory.py | 2 +- .../forks/frontier/vm/instructions/stack.py | 2 +- .../forks/frontier/vm/instructions/storage.py | 6 +- .../forks/frontier/vm/instructions/system.py | 6 +- src/ethereum/forks/frontier/vm/interpreter.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 136 +++++++-------- .../vm/instructions/arithmetic.py | 4 +- .../gray_glacier/vm/instructions/block.py | 12 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 44 ++--- .../gray_glacier/vm/instructions/keccak.py | 4 +- .../forks/gray_glacier/vm/instructions/log.py | 6 +- .../gray_glacier/vm/instructions/memory.py | 2 +- .../gray_glacier/vm/instructions/stack.py | 2 +- .../gray_glacier/vm/instructions/storage.py | 23 ++- .../gray_glacier/vm/instructions/system.py | 36 ++-- .../forks/gray_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 128 +++++++------- .../homestead/vm/instructions/arithmetic.py | 4 +- .../forks/homestead/vm/instructions/block.py | 10 +- .../homestead/vm/instructions/control_flow.py | 4 +- .../homestead/vm/instructions/environment.py | 26 +-- .../forks/homestead/vm/instructions/keccak.py | 6 +- .../forks/homestead/vm/instructions/log.py | 6 +- .../forks/homestead/vm/instructions/memory.py | 2 +- .../forks/homestead/vm/instructions/stack.py | 2 +- .../homestead/vm/instructions/storage.py | 6 +- .../forks/homestead/vm/instructions/system.py | 8 +- .../forks/homestead/vm/interpreter.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 140 ++++++++-------- .../istanbul/vm/instructions/arithmetic.py | 4 +- .../forks/istanbul/vm/instructions/block.py | 12 +- .../istanbul/vm/instructions/control_flow.py | 4 +- .../istanbul/vm/instructions/environment.py | 34 ++-- .../forks/istanbul/vm/instructions/keccak.py | 4 +- .../forks/istanbul/vm/instructions/log.py | 6 +- .../forks/istanbul/vm/instructions/memory.py | 2 +- .../forks/istanbul/vm/instructions/stack.py | 2 +- .../forks/istanbul/vm/instructions/storage.py | 14 +- .../forks/istanbul/vm/instructions/system.py | 26 +-- src/ethereum/forks/istanbul/vm/interpreter.py | 2 +- src/ethereum/forks/london/vm/gas.py | 136 +++++++-------- .../london/vm/instructions/arithmetic.py | 4 +- .../forks/london/vm/instructions/block.py | 12 +- .../london/vm/instructions/control_flow.py | 4 +- .../london/vm/instructions/environment.py | 44 ++--- .../forks/london/vm/instructions/keccak.py | 4 +- .../forks/london/vm/instructions/log.py | 6 +- .../forks/london/vm/instructions/memory.py | 2 +- .../forks/london/vm/instructions/stack.py | 2 +- .../forks/london/vm/instructions/storage.py | 23 ++- .../forks/london/vm/instructions/system.py | 36 ++-- src/ethereum/forks/london/vm/interpreter.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 140 ++++++++-------- .../vm/instructions/arithmetic.py | 4 +- .../muir_glacier/vm/instructions/block.py | 12 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 34 ++-- .../muir_glacier/vm/instructions/keccak.py | 6 +- .../forks/muir_glacier/vm/instructions/log.py | 6 +- .../muir_glacier/vm/instructions/memory.py | 2 +- .../muir_glacier/vm/instructions/stack.py | 2 +- .../muir_glacier/vm/instructions/storage.py | 14 +- .../muir_glacier/vm/instructions/system.py | 26 +-- .../forks/muir_glacier/vm/interpreter.py | 2 +- src/ethereum/forks/osaka/fork.py | 2 +- src/ethereum/forks/osaka/vm/eoa_delegation.py | 4 +- src/ethereum/forks/osaka/vm/gas.py | 156 +++++++++-------- .../forks/osaka/vm/instructions/arithmetic.py | 4 +- .../forks/osaka/vm/instructions/block.py | 12 +- .../osaka/vm/instructions/control_flow.py | 4 +- .../osaka/vm/instructions/environment.py | 46 ++--- .../forks/osaka/vm/instructions/keccak.py | 4 +- .../forks/osaka/vm/instructions/log.py | 6 +- .../forks/osaka/vm/instructions/memory.py | 4 +- .../forks/osaka/vm/instructions/stack.py | 4 +- .../forks/osaka/vm/instructions/storage.py | 27 ++- .../forks/osaka/vm/instructions/system.py | 36 ++-- src/ethereum/forks/osaka/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 136 +++++++-------- .../forks/paris/vm/instructions/arithmetic.py | 4 +- .../forks/paris/vm/instructions/block.py | 12 +- .../paris/vm/instructions/control_flow.py | 4 +- .../paris/vm/instructions/environment.py | 44 ++--- .../forks/paris/vm/instructions/keccak.py | 4 +- .../forks/paris/vm/instructions/log.py | 6 +- .../forks/paris/vm/instructions/memory.py | 2 +- .../forks/paris/vm/instructions/stack.py | 2 +- .../forks/paris/vm/instructions/storage.py | 23 ++- .../forks/paris/vm/instructions/system.py | 36 ++-- src/ethereum/forks/paris/vm/interpreter.py | 2 +- .../forks/prague/vm/eoa_delegation.py | 4 +- src/ethereum/forks/prague/vm/gas.py | 150 ++++++++--------- .../prague/vm/instructions/arithmetic.py | 4 +- .../forks/prague/vm/instructions/block.py | 12 +- .../prague/vm/instructions/control_flow.py | 4 +- .../prague/vm/instructions/environment.py | 46 ++--- .../forks/prague/vm/instructions/keccak.py | 4 +- .../forks/prague/vm/instructions/log.py | 6 +- .../forks/prague/vm/instructions/memory.py | 4 +- .../forks/prague/vm/instructions/stack.py | 4 +- .../forks/prague/vm/instructions/storage.py | 27 ++- .../forks/prague/vm/instructions/system.py | 36 ++-- src/ethereum/forks/prague/vm/interpreter.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 142 ++++++++-------- .../shanghai/vm/instructions/arithmetic.py | 4 +- .../forks/shanghai/vm/instructions/block.py | 12 +- .../shanghai/vm/instructions/control_flow.py | 4 +- .../shanghai/vm/instructions/environment.py | 44 ++--- .../forks/shanghai/vm/instructions/keccak.py | 4 +- .../forks/shanghai/vm/instructions/log.py | 6 +- .../forks/shanghai/vm/instructions/memory.py | 2 +- .../forks/shanghai/vm/instructions/stack.py | 4 +- .../forks/shanghai/vm/instructions/storage.py | 23 ++- .../forks/shanghai/vm/instructions/system.py | 36 ++-- src/ethereum/forks/shanghai/vm/interpreter.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 126 +++++++------- .../vm/instructions/arithmetic.py | 4 +- .../spurious_dragon/vm/instructions/block.py | 10 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 26 +-- .../spurious_dragon/vm/instructions/keccak.py | 6 +- .../spurious_dragon/vm/instructions/log.py | 6 +- .../spurious_dragon/vm/instructions/memory.py | 2 +- .../spurious_dragon/vm/instructions/stack.py | 2 +- .../vm/instructions/storage.py | 6 +- .../spurious_dragon/vm/instructions/system.py | 20 +-- .../forks/spurious_dragon/vm/interpreter.py | 2 +- .../forks/tangerine_whistle/vm/gas.py | 126 +++++++------- .../vm/instructions/arithmetic.py | 4 +- .../vm/instructions/block.py | 10 +- .../vm/instructions/control_flow.py | 4 +- .../vm/instructions/environment.py | 26 +-- .../vm/instructions/keccak.py | 6 +- .../tangerine_whistle/vm/instructions/log.py | 6 +- .../vm/instructions/memory.py | 2 +- .../vm/instructions/stack.py | 2 +- .../vm/instructions/storage.py | 6 +- .../vm/instructions/system.py | 20 +-- .../forks/tangerine_whistle/vm/interpreter.py | 2 +- 313 files changed, 3205 insertions(+), 3258 deletions(-) diff --git a/src/ethereum/forks/amsterdam/block_access_lists.py b/src/ethereum/forks/amsterdam/block_access_lists.py index 9ab04d492ca..261b992e503 100644 --- a/src/ethereum/forks/amsterdam/block_access_lists.py +++ b/src/ethereum/forks/amsterdam/block_access_lists.py @@ -762,9 +762,9 @@ def validate_block_access_list_gas_limit( # Count each unique storage key as one item bal_items += Uint(len(unique_slots)) - if bal_items > block_gas_limit // GasCosts.GAS_BLOCK_ACCESS_LIST_ITEM: + if bal_items > block_gas_limit // GasCosts.BLOCK_ACCESS_LIST_ITEM: raise BlockAccessListGasLimitExceededError( f"Block access list exceeds gas limit, {bal_items} items " f"exceeds limit of " - f"{block_gas_limit // GasCosts.GAS_BLOCK_ACCESS_LIST_ITEM}." + f"{block_gas_limit // GasCosts.BLOCK_ACCESS_LIST_ITEM}." ) diff --git a/src/ethereum/forks/amsterdam/fork.py b/src/ethereum/forks/amsterdam/fork.py index 798ea7ddcf4..0d4c69d2b34 100644 --- a/src/ethereum/forks/amsterdam/fork.py +++ b/src/ethereum/forks/amsterdam/fork.py @@ -113,7 +113,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" GWEI_TO_WEI = U256(10**9) diff --git a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py index 6c133b55a1e..cf8ddb73807 100644 --- a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py +++ b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py @@ -149,9 +149,9 @@ def calculate_delegation_cost( delegated_address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if delegated_address in evm.accessed_addresses: - delegation_gas_cost = GasCosts.GAS_WARM_ACCESS + delegation_gas_cost = GasCosts.WARM_ACCESS else: - delegation_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + delegation_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS return True, delegated_address, delegation_gas_cost diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index cf2164d0d34..59f80867038 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -34,37 +34,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -87,60 +87,60 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(21) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) # Block Access Lists - GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000) + BLOCK_ACCESS_LIST_ITEM = Uint(2000) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -231,7 +231,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -286,7 +286,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -358,9 +358,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas( @@ -396,7 +394,7 @@ def calculate_excess_blob_gas( if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -428,7 +426,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/instructions/block.py b/src/ethereum/forks/amsterdam/vm/instructions/block.py index 8eb11ca119b..0fc62deba97 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/block.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index f521b356b55..ee695e331cf 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -100,7 +100,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -123,7 +123,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -146,7 +146,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -195,7 +195,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -224,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -256,7 +256,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -285,7 +285,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -317,7 +317,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -341,10 +341,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION tx_state = evm.message.tx_env.state @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS total_gas_cost = access_gas_cost + copy_gas_cost + extend_memory.cost @@ -418,7 +418,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -444,7 +444,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -480,10 +480,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -516,7 +516,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -544,7 +544,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -594,7 +594,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/amsterdam/vm/instructions/log.py b/src/ethereum/forks/amsterdam/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/log.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/storage.py b/src/ethereum/forks/amsterdam/vm/instructions/storage.py index 72632144772..56e1ed28d06 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/storage.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/storage.py @@ -46,10 +46,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION tx_state = evm.message.tx_env.state @@ -79,7 +79,7 @@ def sstore(evm: Evm) -> None: new_value = pop(evm.stack) # check we have at least the stipend gas - check_gas(evm, GasCosts.GAS_CALL_STIPEND + Uint(1)) + check_gas(evm, GasCosts.CALL_STIPEND + Uint(1)) tx_state = evm.message.tx_env.state original_value = get_storage_original( @@ -91,18 +91,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -119,14 +118,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -151,7 +150,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -181,7 +180,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) set_transient_storage( evm.message.tx_env.state, evm.message.current_target, diff --git a/src/ethereum/forks/amsterdam/vm/instructions/system.py b/src/ethereum/forks/amsterdam/vm/instructions/system.py index e963b18259e..d309023903c 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/system.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/system.py @@ -166,7 +166,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,8 +216,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -261,7 +261,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -379,11 +379,11 @@ def call(evm: Evm) -> None: is_cold_access = to not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS else: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE # check static gas before state access check_gas( @@ -396,7 +396,7 @@ def call(evm: Evm) -> None: if is_cold_access: evm.accessed_addresses.add(to) - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(tx_state, to): create_gas_cost = Uint(0) @@ -486,11 +486,11 @@ def callcode(evm: Evm) -> None: is_cold_access = code_address not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS else: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE # check static gas before state access check_gas( @@ -576,11 +576,11 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT is_cold_access = beneficiary not in evm.accessed_addresses if is_cold_access: - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS # check access gas cost before state access check_gas(evm, gas_cost) @@ -594,7 +594,7 @@ def selfdestruct(evm: Evm) -> None: not is_account_alive(tx_state, beneficiary) and get_account(tx_state, evm.message.current_target).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) @@ -648,9 +648,9 @@ def delegatecall(evm: Evm) -> None: is_cold_access = code_address not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS else: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS # check static gas before state access check_gas(evm, access_gas_cost + extend_memory.cost) @@ -738,9 +738,9 @@ def staticcall(evm: Evm) -> None: is_cold_access = to not in evm.accessed_addresses if is_cold_access: - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS else: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS # check static gas before state access check_gas(evm, access_gas_cost + extend_memory.cost) diff --git a/src/ethereum/forks/amsterdam/vm/interpreter.py b/src/ethereum/forks/amsterdam/vm/interpreter.py index f24694ae00d..80b30bd7ab2 100644 --- a/src/ethereum/forks/amsterdam/vm/interpreter.py +++ b/src/ethereum/forks/amsterdam/vm/interpreter.py @@ -201,7 +201,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index efd942e4706..74d2c68446a 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -75,45 +75,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -187,7 +187,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -242,7 +242,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 7bb7fa72462..76784f10948 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -538,7 +538,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py b/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py index 95441af81fb..287544f353b 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/storage.py @@ -39,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -68,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -81,18 +81,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -109,14 +108,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py index e7531eb1753..d2ff1afe683 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -345,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -425,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -483,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -562,10 +562,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), @@ -625,10 +625,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/arrow_glacier/vm/interpreter.py b/src/ethereum/forks/arrow_glacier/vm/interpreter.py index ae35e4f84fe..f2262c47175 100644 --- a/src/ethereum/forks/arrow_glacier/vm/interpreter.py +++ b/src/ethereum/forks/arrow_glacier/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 0025350043b..e2db19c3fc0 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -76,45 +76,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -188,7 +188,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -243,7 +243,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/instructions/block.py b/src/ethereum/forks/berlin/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/berlin/vm/instructions/block.py +++ b/src/ethereum/forks/berlin/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index f4b5f91b245..a7eb88e2e70 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/berlin/vm/instructions/keccak.py b/src/ethereum/forks/berlin/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/berlin/vm/instructions/keccak.py +++ b/src/ethereum/forks/berlin/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/instructions/log.py b/src/ethereum/forks/berlin/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/berlin/vm/instructions/log.py +++ b/src/ethereum/forks/berlin/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/berlin/vm/instructions/storage.py b/src/ethereum/forks/berlin/vm/instructions/storage.py index 95441af81fb..287544f353b 100644 --- a/src/ethereum/forks/berlin/vm/instructions/storage.py +++ b/src/ethereum/forks/berlin/vm/instructions/storage.py @@ -39,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -68,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -81,18 +81,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -109,14 +108,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/berlin/vm/instructions/system.py b/src/ethereum/forks/berlin/vm/instructions/system.py index e3016bd084b..6fef8addff6 100644 --- a/src/ethereum/forks/berlin/vm/instructions/system.py +++ b/src/ethereum/forks/berlin/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -345,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -425,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -483,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -573,10 +573,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -632,10 +632,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/berlin/vm/interpreter.py b/src/ethereum/forks/berlin/vm/interpreter.py index 5bf644862bc..1f482d07cea 100644 --- a/src/ethereum/forks/berlin/vm/interpreter.py +++ b/src/ethereum/forks/berlin/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/bpo1/fork.py b/src/ethereum/forks/bpo1/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/bpo1/fork.py +++ b/src/ethereum/forks/bpo1/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo1/vm/eoa_delegation.py b/src/ethereum/forks/bpo1/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/bpo1/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo1/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 07e2d5f91d3..0d8c798d88c 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(10) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(15) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(8346193) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/block.py b/src/ethereum/forks/bpo1/vm/instructions/block.py index 81f3bed52c2..82e4a4c502c 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/block.py +++ b/src/ethereum/forks/bpo1/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo1/vm/instructions/keccak.py b/src/ethereum/forks/bpo1/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo1/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/log.py b/src/ethereum/forks/bpo1/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/log.py +++ b/src/ethereum/forks/bpo1/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo1/vm/instructions/storage.py b/src/ethereum/forks/bpo1/vm/instructions/storage.py index 202917b6072..5aa3cc6746f 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo1/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -115,14 +114,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +148,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +175,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo1/vm/instructions/system.py b/src/ethereum/forks/bpo1/vm/instructions/system.py index 5087e180f3b..50d4e74c341 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/system.py +++ b/src/ethereum/forks/bpo1/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + GasCosts.CREATE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -256,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -369,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -383,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -458,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -471,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -526,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -599,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -668,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo1/vm/interpreter.py b/src/ethereum/forks/bpo1/vm/interpreter.py index 0e1e167b257..b79580a6429 100644 --- a/src/ethereum/forks/bpo1/vm/interpreter.py +++ b/src/ethereum/forks/bpo1/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo2/fork.py b/src/ethereum/forks/bpo2/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/bpo2/fork.py +++ b/src/ethereum/forks/bpo2/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo2/vm/eoa_delegation.py b/src/ethereum/forks/bpo2/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/bpo2/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo2/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 7eadc2c2074..9cc2ae84b07 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(21) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/block.py b/src/ethereum/forks/bpo2/vm/instructions/block.py index 5ff36ccf385..046ddc3b6d7 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/block.py +++ b/src/ethereum/forks/bpo2/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index 2604040cb28..76948ae4796 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo2/vm/instructions/keccak.py b/src/ethereum/forks/bpo2/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo2/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/log.py b/src/ethereum/forks/bpo2/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/log.py +++ b/src/ethereum/forks/bpo2/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index c404c9d39ba..dec0bc81afe 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo2/vm/instructions/storage.py b/src/ethereum/forks/bpo2/vm/instructions/storage.py index 08884b40394..dbbd8db40ca 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo2/vm/instructions/storage.py @@ -42,10 +42,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -71,7 +71,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -84,18 +84,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -112,14 +111,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -146,7 +145,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -173,7 +172,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo2/vm/instructions/system.py b/src/ethereum/forks/bpo2/vm/instructions/system.py index d1c9c4254d3..e9952c58e97 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/system.py +++ b/src/ethereum/forks/bpo2/vm/instructions/system.py @@ -158,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -253,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -366,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -380,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -455,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -468,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -523,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -535,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -596,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -665,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo2/vm/interpreter.py b/src/ethereum/forks/bpo2/vm/interpreter.py index c6e3953339d..31e07e2d968 100644 --- a/src/ethereum/forks/bpo2/vm/interpreter.py +++ b/src/ethereum/forks/bpo2/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo3/fork.py b/src/ethereum/forks/bpo3/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/bpo3/fork.py +++ b/src/ethereum/forks/bpo3/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo3/vm/eoa_delegation.py b/src/ethereum/forks/bpo3/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/bpo3/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo3/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 7eadc2c2074..9cc2ae84b07 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(21) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/block.py b/src/ethereum/forks/bpo3/vm/instructions/block.py index 39e16bc2035..ace26d66c3d 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/block.py +++ b/src/ethereum/forks/bpo3/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index 2604040cb28..76948ae4796 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo3/vm/instructions/keccak.py b/src/ethereum/forks/bpo3/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo3/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/log.py b/src/ethereum/forks/bpo3/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/log.py +++ b/src/ethereum/forks/bpo3/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index c404c9d39ba..dec0bc81afe 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo3/vm/instructions/storage.py b/src/ethereum/forks/bpo3/vm/instructions/storage.py index 08884b40394..dbbd8db40ca 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo3/vm/instructions/storage.py @@ -42,10 +42,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -71,7 +71,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -84,18 +84,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -112,14 +111,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -146,7 +145,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -173,7 +172,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo3/vm/instructions/system.py b/src/ethereum/forks/bpo3/vm/instructions/system.py index d1c9c4254d3..e9952c58e97 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/system.py +++ b/src/ethereum/forks/bpo3/vm/instructions/system.py @@ -158,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -253,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -366,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -380,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -455,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -468,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -523,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -535,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -596,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -665,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo3/vm/interpreter.py b/src/ethereum/forks/bpo3/vm/interpreter.py index 81ddbf448a6..d3c301fc708 100644 --- a/src/ethereum/forks/bpo3/vm/interpreter.py +++ b/src/ethereum/forks/bpo3/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo4/fork.py b/src/ethereum/forks/bpo4/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/bpo4/fork.py +++ b/src/ethereum/forks/bpo4/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo4/vm/eoa_delegation.py b/src/ethereum/forks/bpo4/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/bpo4/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo4/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 7eadc2c2074..9cc2ae84b07 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(21) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/block.py b/src/ethereum/forks/bpo4/vm/instructions/block.py index 23494f47615..aaf58be49f4 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/block.py +++ b/src/ethereum/forks/bpo4/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo4/vm/instructions/keccak.py b/src/ethereum/forks/bpo4/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo4/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/log.py b/src/ethereum/forks/bpo4/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/log.py +++ b/src/ethereum/forks/bpo4/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo4/vm/instructions/storage.py b/src/ethereum/forks/bpo4/vm/instructions/storage.py index 202917b6072..5aa3cc6746f 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo4/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -115,14 +114,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +148,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +175,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo4/vm/instructions/system.py b/src/ethereum/forks/bpo4/vm/instructions/system.py index 5087e180f3b..50d4e74c341 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/system.py +++ b/src/ethereum/forks/bpo4/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + GasCosts.CREATE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -256,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -369,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -383,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -458,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -471,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -526,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -599,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -668,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo4/vm/interpreter.py b/src/ethereum/forks/bpo4/vm/interpreter.py index 7d38f5d59b9..de598138081 100644 --- a/src/ethereum/forks/bpo4/vm/interpreter.py +++ b/src/ethereum/forks/bpo4/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo5/fork.py b/src/ethereum/forks/bpo5/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/bpo5/fork.py +++ b/src/ethereum/forks/bpo5/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/bpo5/vm/eoa_delegation.py b/src/ethereum/forks/bpo5/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/bpo5/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo5/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 7eadc2c2074..9cc2ae84b07 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(14) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(21) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/block.py b/src/ethereum/forks/bpo5/vm/instructions/block.py index e23987d2fe0..09e8d711af0 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/block.py +++ b/src/ethereum/forks/bpo5/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo5/vm/instructions/keccak.py b/src/ethereum/forks/bpo5/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo5/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/log.py b/src/ethereum/forks/bpo5/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/log.py +++ b/src/ethereum/forks/bpo5/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo5/vm/instructions/storage.py b/src/ethereum/forks/bpo5/vm/instructions/storage.py index 202917b6072..5aa3cc6746f 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/storage.py +++ b/src/ethereum/forks/bpo5/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -115,14 +114,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +148,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +175,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/bpo5/vm/instructions/system.py b/src/ethereum/forks/bpo5/vm/instructions/system.py index 5087e180f3b..50d4e74c341 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/system.py +++ b/src/ethereum/forks/bpo5/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + GasCosts.CREATE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -256,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -369,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -383,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -458,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -471,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -526,10 +526,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -599,10 +599,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -668,10 +668,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/bpo5/vm/interpreter.py b/src/ethereum/forks/bpo5/vm/interpreter.py index c2d287eb655..138131315c5 100644 --- a/src/ethereum/forks/bpo5/vm/interpreter.py +++ b/src/ethereum/forks/bpo5/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 6480d0717a4..df5283e28d0 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(200) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(400) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -75,42 +75,42 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -184,7 +184,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -239,7 +239,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/instructions/block.py b/src/ethereum/forks/byzantium/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/block.py +++ b/src/ethereum/forks/byzantium/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 619523ad0fd..4fa99946626 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -42,7 +42,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -65,7 +65,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -92,7 +92,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -115,7 +115,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -138,7 +138,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -187,7 +187,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -216,7 +216,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -248,7 +248,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -277,7 +277,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -309,7 +309,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -332,7 +332,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -363,11 +363,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -395,7 +395,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -421,7 +421,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/byzantium/vm/instructions/keccak.py b/src/ethereum/forks/byzantium/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/keccak.py +++ b/src/ethereum/forks/byzantium/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/log.py b/src/ethereum/forks/byzantium/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/log.py +++ b/src/ethereum/forks/byzantium/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/byzantium/vm/instructions/storage.py b/src/ethereum/forks/byzantium/vm/instructions/storage.py index 3681791a28e..0e5aae6031d 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/storage.py +++ b/src/ethereum/forks/byzantium/vm/instructions/storage.py @@ -38,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -69,9 +69,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/byzantium/vm/instructions/system.py b/src/ethereum/forks/byzantium/vm/instructions/system.py index 7529e3e3f9d..e99e2a66766 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/system.py +++ b/src/ethereum/forks/byzantium/vm/instructions/system.py @@ -69,7 +69,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -163,7 +163,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -273,16 +273,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -344,13 +344,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -397,7 +397,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -405,7 +405,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -481,7 +481,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -540,7 +540,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL, + GasCosts.CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/byzantium/vm/interpreter.py b/src/ethereum/forks/byzantium/vm/interpreter.py index c8047c020bf..a5a72762dbd 100644 --- a/src/ethereum/forks/byzantium/vm/interpreter.py +++ b/src/ethereum/forks/byzantium/vm/interpreter.py @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 05690295141..394c271557e 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -79,53 +79,53 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(393216) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -199,7 +199,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -254,7 +254,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -326,9 +326,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -379,7 +377,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/block.py b/src/ethereum/forks/cancun/vm/instructions/block.py index d08f153b6f8..d5c0aa656d8 100644 --- a/src/ethereum/forks/cancun/vm/instructions/block.py +++ b/src/ethereum/forks/cancun/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/cancun/vm/instructions/keccak.py b/src/ethereum/forks/cancun/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/cancun/vm/instructions/keccak.py +++ b/src/ethereum/forks/cancun/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/log.py b/src/ethereum/forks/cancun/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/cancun/vm/instructions/log.py +++ b/src/ethereum/forks/cancun/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/cancun/vm/instructions/storage.py b/src/ethereum/forks/cancun/vm/instructions/storage.py index 202917b6072..5aa3cc6746f 100644 --- a/src/ethereum/forks/cancun/vm/instructions/storage.py +++ b/src/ethereum/forks/cancun/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -115,14 +114,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +148,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +175,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/cancun/vm/instructions/system.py b/src/ethereum/forks/cancun/vm/instructions/system.py index 08921e03c95..64cd5b2cac7 100644 --- a/src/ethereum/forks/cancun/vm/instructions/system.py +++ b/src/ethereum/forks/cancun/vm/instructions/system.py @@ -157,7 +157,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -207,8 +207,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -252,7 +252,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -363,17 +363,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -443,12 +443,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -501,10 +501,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -513,7 +513,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -574,10 +574,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -633,10 +633,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/cancun/vm/interpreter.py b/src/ethereum/forks/cancun/vm/interpreter.py index b0cfdcbcad9..05d14c7aebe 100644 --- a/src/ethereum/forks/cancun/vm/interpreter.py +++ b/src/ethereum/forks/cancun/vm/interpreter.py @@ -171,7 +171,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 8ee4de9527b..35f2d45e8ee 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -31,36 +31,36 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(200) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(400) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_CODE_HASH = Uint(400) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + CODE_HASH = Uint(400) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -76,45 +76,45 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -188,7 +188,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -243,7 +243,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/instructions/block.py b/src/ethereum/forks/constantinople/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/block.py +++ b/src/ethereum/forks/constantinople/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index 2832ba44042..f4492840724 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -364,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -396,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -422,7 +422,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -457,7 +457,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_CODE_HASH) + charge_gas(evm, GasCosts.CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) diff --git a/src/ethereum/forks/constantinople/vm/instructions/keccak.py b/src/ethereum/forks/constantinople/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/keccak.py +++ b/src/ethereum/forks/constantinople/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/log.py b/src/ethereum/forks/constantinople/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/log.py +++ b/src/ethereum/forks/constantinople/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/constantinople/vm/instructions/storage.py b/src/ethereum/forks/constantinople/vm/instructions/storage.py index 3681791a28e..0e5aae6031d 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/storage.py +++ b/src/ethereum/forks/constantinople/vm/instructions/storage.py @@ -38,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -69,9 +69,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index 800ab4afc7b..633bd05e34d 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -344,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -415,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -553,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL, + GasCosts.CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/constantinople/vm/interpreter.py b/src/ethereum/forks/constantinople/vm/interpreter.py index 6264ddc194f..ffd3e29a5b7 100644 --- a/src/ethereum/forks/constantinople/vm/interpreter.py +++ b/src/ethereum/forks/constantinople/vm/interpreter.py @@ -174,7 +174,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 9c5a4cb1ddf..c3cb8a26959 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -33,32 +33,32 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(50) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(10) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(20) - GAS_BALANCE = Uint(20) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(40) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(40) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -74,41 +74,41 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -182,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -254,9 +254,9 @@ def calculate_message_call_gas( """ create_gas_cost = ( - Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE - cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE + cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/instructions/block.py b/src/ethereum/forks/dao_fork/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/block.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 5baf8effdc3..0981b35f615 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -362,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/log.py b/src/ethereum/forks/dao_fork/vm/instructions/log.py index 703f0befa99..7b1fed7c967 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/log.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/storage.py b/src/ethereum/forks/dao_fork/vm/instructions/storage.py index a69e1093b9a..0b2a1cce8aa 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/storage.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/storage.py @@ -37,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -68,9 +68,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/dao_fork/vm/instructions/system.py b/src/ethereum/forks/dao_fork/vm/instructions/system.py index 7c8138dd6c1..53daba51cee 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/system.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -154,7 +154,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -365,7 +365,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_ZERO + gas_cost = GasCosts.ZERO originator = evm.message.current_target @@ -435,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GasCosts.GAS_CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.CALL + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/interpreter.py b/src/ethereum/forks/dao_fork/vm/interpreter.py index 32ed648b2d3..40bdffcc071 100644 --- a/src/ethereum/forks/dao_fork/vm/interpreter.py +++ b/src/ethereum/forks/dao_fork/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 9c5a4cb1ddf..c3cb8a26959 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -33,32 +33,32 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(50) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(10) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(20) - GAS_BALANCE = Uint(20) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(40) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(40) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -74,41 +74,41 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -182,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -254,9 +254,9 @@ def calculate_message_call_gas( """ create_gas_cost = ( - Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE - cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE + cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/instructions/block.py b/src/ethereum/forks/frontier/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/frontier/vm/instructions/block.py +++ b/src/ethereum/forks/frontier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 5baf8effdc3..0981b35f615 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -362,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/keccak.py b/src/ethereum/forks/frontier/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/frontier/vm/instructions/keccak.py +++ b/src/ethereum/forks/frontier/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/instructions/log.py b/src/ethereum/forks/frontier/vm/instructions/log.py index 703f0befa99..7b1fed7c967 100644 --- a/src/ethereum/forks/frontier/vm/instructions/log.py +++ b/src/ethereum/forks/frontier/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/frontier/vm/instructions/storage.py b/src/ethereum/forks/frontier/vm/instructions/storage.py index a69e1093b9a..0b2a1cce8aa 100644 --- a/src/ethereum/forks/frontier/vm/instructions/storage.py +++ b/src/ethereum/forks/frontier/vm/instructions/storage.py @@ -37,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -68,9 +68,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/frontier/vm/instructions/system.py b/src/ethereum/forks/frontier/vm/instructions/system.py index 4e5d6ed1c6f..3b614b76344 100644 --- a/src/ethereum/forks/frontier/vm/instructions/system.py +++ b/src/ethereum/forks/frontier/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -153,7 +153,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -360,7 +360,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_ZERO + gas_cost = GasCosts.ZERO originator = evm.message.current_target diff --git a/src/ethereum/forks/frontier/vm/interpreter.py b/src/ethereum/forks/frontier/vm/interpreter.py index 3f1917a2202..90e59a193f0 100644 --- a/src/ethereum/forks/frontier/vm/interpreter.py +++ b/src/ethereum/forks/frontier/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index efd942e4706..74d2c68446a 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -75,45 +75,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -187,7 +187,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -242,7 +242,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/block.py b/src/ethereum/forks/gray_glacier/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 7bb7fa72462..76784f10948 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -538,7 +538,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/log.py b/src/ethereum/forks/gray_glacier/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/storage.py b/src/ethereum/forks/gray_glacier/vm/instructions/storage.py index 95441af81fb..287544f353b 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/storage.py @@ -39,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -68,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -81,18 +81,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -109,14 +108,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/system.py b/src/ethereum/forks/gray_glacier/vm/instructions/system.py index e55660ac978..da80d3c7122 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -345,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -425,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -483,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -562,10 +562,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -621,10 +621,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/gray_glacier/vm/interpreter.py b/src/ethereum/forks/gray_glacier/vm/interpreter.py index 978633c4896..434147299b0 100644 --- a/src/ethereum/forks/gray_glacier/vm/interpreter.py +++ b/src/ethereum/forks/gray_glacier/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 9c5a4cb1ddf..c3cb8a26959 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -33,32 +33,32 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(50) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(10) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(20) - GAS_BALANCE = Uint(20) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(40) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(40) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -74,41 +74,41 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -182,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -254,9 +254,9 @@ def calculate_message_call_gas( """ create_gas_cost = ( - Uint(0) if account_exists(state, to) else GasCosts.GAS_NEW_ACCOUNT + Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE - cost = GasCosts.GAS_CALL + gas + create_gas_cost + transfer_gas_cost - stipend = gas if value == 0 else GasCosts.GAS_CALL_STIPEND + gas + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE + cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/instructions/block.py b/src/ethereum/forks/homestead/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/homestead/vm/instructions/block.py +++ b/src/ethereum/forks/homestead/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 5baf8effdc3..0981b35f615 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -362,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/keccak.py b/src/ethereum/forks/homestead/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/homestead/vm/instructions/keccak.py +++ b/src/ethereum/forks/homestead/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/log.py b/src/ethereum/forks/homestead/vm/instructions/log.py index 703f0befa99..7b1fed7c967 100644 --- a/src/ethereum/forks/homestead/vm/instructions/log.py +++ b/src/ethereum/forks/homestead/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/homestead/vm/instructions/storage.py b/src/ethereum/forks/homestead/vm/instructions/storage.py index a69e1093b9a..0b2a1cce8aa 100644 --- a/src/ethereum/forks/homestead/vm/instructions/storage.py +++ b/src/ethereum/forks/homestead/vm/instructions/storage.py @@ -37,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -68,9 +68,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/homestead/vm/instructions/system.py b/src/ethereum/forks/homestead/vm/instructions/system.py index 7c8138dd6c1..53daba51cee 100644 --- a/src/ethereum/forks/homestead/vm/instructions/system.py +++ b/src/ethereum/forks/homestead/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) @@ -154,7 +154,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -365,7 +365,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_ZERO + gas_cost = GasCosts.ZERO originator = evm.message.current_target @@ -435,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GasCosts.GAS_CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.CALL + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/interpreter.py b/src/ethereum/forks/homestead/vm/interpreter.py index 299022576d9..7d12402e037 100644 --- a/src/ethereum/forks/homestead/vm/interpreter.py +++ b/src/ethereum/forks/homestead/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index db120355d24..9c4373bc5ee 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -31,37 +31,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(800) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(700) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_CODE_HASH = Uint(700) - GAS_FAST_STEP = Uint(5) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(800) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(700) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + CODE_HASH = Uint(700) + FAST_STEP = Uint(5) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -78,45 +78,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -190,7 +190,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -245,7 +245,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/instructions/block.py b/src/ethereum/forks/istanbul/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/block.py +++ b/src/ethereum/forks/istanbul/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 73fc5cc49a5..4c3b815e5ef 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -364,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -396,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -422,7 +422,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -457,7 +457,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_CODE_HASH) + charge_gas(evm, GasCosts.CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -487,7 +487,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/istanbul/vm/instructions/keccak.py b/src/ethereum/forks/istanbul/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/keccak.py +++ b/src/ethereum/forks/istanbul/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/instructions/log.py b/src/ethereum/forks/istanbul/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/log.py +++ b/src/ethereum/forks/istanbul/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/istanbul/vm/instructions/storage.py b/src/ethereum/forks/istanbul/vm/instructions/storage.py index e2ca9719c0d..c34e6f31912 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/storage.py +++ b/src/ethereum/forks/istanbul/vm/instructions/storage.py @@ -38,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -64,7 +64,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -75,11 +75,11 @@ def sstore(evm: Evm) -> None: if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE else: - gas_cost = GasCosts.GAS_SLOAD + gas_cost = GasCosts.SLOAD # Refund Counter Calculation if current_value != new_value: @@ -96,12 +96,12 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_SLOAD + GasCosts.STORAGE_SET - GasCosts.SLOAD ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - GasCosts.GAS_SLOAD + GasCosts.COLD_STORAGE_WRITE - GasCosts.SLOAD ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index 5573c65cd4c..adc16d7eb7f 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -344,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -415,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -553,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL, + GasCosts.CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/istanbul/vm/interpreter.py b/src/ethereum/forks/istanbul/vm/interpreter.py index 5f21440ba63..2e3e5d6af2d 100644 --- a/src/ethereum/forks/istanbul/vm/interpreter.py +++ b/src/ethereum/forks/istanbul/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index efd942e4706..74d2c68446a 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -75,45 +75,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -187,7 +187,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -242,7 +242,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/instructions/block.py b/src/ethereum/forks/london/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/london/vm/instructions/block.py +++ b/src/ethereum/forks/london/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 7bb7fa72462..76784f10948 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -538,7 +538,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/london/vm/instructions/keccak.py b/src/ethereum/forks/london/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/london/vm/instructions/keccak.py +++ b/src/ethereum/forks/london/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/instructions/log.py b/src/ethereum/forks/london/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/london/vm/instructions/log.py +++ b/src/ethereum/forks/london/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/london/vm/instructions/storage.py b/src/ethereum/forks/london/vm/instructions/storage.py index 95441af81fb..287544f353b 100644 --- a/src/ethereum/forks/london/vm/instructions/storage.py +++ b/src/ethereum/forks/london/vm/instructions/storage.py @@ -39,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -68,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -81,18 +81,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -109,14 +108,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/london/vm/instructions/system.py b/src/ethereum/forks/london/vm/instructions/system.py index e55660ac978..da80d3c7122 100644 --- a/src/ethereum/forks/london/vm/instructions/system.py +++ b/src/ethereum/forks/london/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -345,17 +345,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -425,12 +425,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -483,10 +483,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -562,10 +562,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -621,10 +621,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/london/vm/interpreter.py b/src/ethereum/forks/london/vm/interpreter.py index 01abdaba107..eb067c2bb4d 100644 --- a/src/ethereum/forks/london/vm/interpreter.py +++ b/src/ethereum/forks/london/vm/interpreter.py @@ -179,7 +179,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index db120355d24..9c4373bc5ee 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -31,37 +31,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(800) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(700) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_CODE_HASH = Uint(700) - GAS_FAST_STEP = Uint(5) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(800) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(700) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + CODE_HASH = Uint(700) + FAST_STEP = Uint(5) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -78,45 +78,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -190,7 +190,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -245,7 +245,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/block.py b/src/ethereum/forks/muir_glacier/vm/instructions/block.py index cb186f9f6a8..7392e5dfa6c 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 73fc5cc49a5..4c3b815e5ef 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -364,11 +364,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -396,7 +396,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -422,7 +422,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -457,7 +457,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_CODE_HASH) + charge_gas(evm, GasCosts.CODE_HASH) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -487,7 +487,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/log.py b/src/ethereum/forks/muir_glacier/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/storage.py b/src/ethereum/forks/muir_glacier/vm/instructions/storage.py index e2ca9719c0d..c34e6f31912 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/storage.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/storage.py @@ -38,7 +38,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -64,7 +64,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -75,11 +75,11 @@ def sstore(evm: Evm) -> None: if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE else: - gas_cost = GasCosts.GAS_SLOAD + gas_cost = GasCosts.SLOAD # Refund Counter Calculation if current_value != new_value: @@ -96,12 +96,12 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_SLOAD + GasCosts.STORAGE_SET - GasCosts.SLOAD ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - GasCosts.GAS_SLOAD + GasCosts.COLD_STORAGE_WRITE - GasCosts.SLOAD ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index 5573c65cd4c..adc16d7eb7f 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,8 +194,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -234,7 +234,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -344,16 +344,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -415,13 +415,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -553,7 +553,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +612,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL, + GasCosts.CALL, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/muir_glacier/vm/interpreter.py b/src/ethereum/forks/muir_glacier/vm/interpreter.py index 2479183621d..66db7006918 100644 --- a/src/ethereum/forks/muir_glacier/vm/interpreter.py +++ b/src/ethereum/forks/muir_glacier/vm/interpreter.py @@ -178,7 +178,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/osaka/fork.py b/src/ethereum/forks/osaka/fork.py index ff32777abde..6cd7998cfe7 100644 --- a/src/ethereum/forks/osaka/fork.py +++ b/src/ethereum/forks/osaka/fork.py @@ -99,7 +99,7 @@ "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" ) SYSTEM_TRANSACTION_GAS = Uint(30000000) -MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.GAS_PER_BLOB +MAX_BLOB_GAS_PER_BLOCK = GasCosts.BLOB_SCHEDULE_MAX * GasCosts.PER_BLOB VERSIONED_HASH_VERSION_KZG = b"\x01" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address( diff --git a/src/ethereum/forks/osaka/vm/eoa_delegation.py b/src/ethereum/forks/osaka/vm/eoa_delegation.py index bb6144b51c8..d63c540ed47 100644 --- a/src/ethereum/forks/osaka/vm/eoa_delegation.py +++ b/src/ethereum/forks/osaka/vm/eoa_delegation.py @@ -148,10 +148,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 815c8f92723..bdf25956110 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -86,57 +86,57 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_SCHEDULE_TARGET = U64(6) - BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET + BLOB_TARGET_GAS_PER_BLOCK = PER_BLOB * BLOB_SCHEDULE_TARGET BLOB_BASE_COST = Uint(2**13) BLOB_SCHEDULE_MAX = U64(9) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_CLZ = GAS_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_CLZ = LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -210,7 +210,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -265,7 +265,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -337,9 +337,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -373,7 +371,7 @@ def calculate_excess_blob_gas(parent_header: Header) -> U64: if parent_blob_gas < GasCosts.BLOB_TARGET_GAS_PER_BLOCK: return U64(0) - target_blob_gas_price = Uint(GasCosts.GAS_PER_BLOB) + target_blob_gas_price = Uint(GasCosts.PER_BLOB) target_blob_gas_price *= calculate_blob_gas_price(excess_blob_gas) base_blob_tx_price = GasCosts.BLOB_BASE_COST * base_fee_per_gas @@ -405,7 +403,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/block.py b/src/ethereum/forks/osaka/vm/instructions/block.py index 9c24310914f..ce1507800c7 100644 --- a/src/ethereum/forks/osaka/vm/instructions/block.py +++ b/src/ethereum/forks/osaka/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/osaka/vm/instructions/keccak.py b/src/ethereum/forks/osaka/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/osaka/vm/instructions/keccak.py +++ b/src/ethereum/forks/osaka/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/log.py b/src/ethereum/forks/osaka/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/osaka/vm/instructions/log.py +++ b/src/ethereum/forks/osaka/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/osaka/vm/instructions/storage.py b/src/ethereum/forks/osaka/vm/instructions/storage.py index 92db4d9ea2a..a782cd0db25 100644 --- a/src/ethereum/forks/osaka/vm/instructions/storage.py +++ b/src/ethereum/forks/osaka/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -111,13 +110,13 @@ def sstore(evm: Evm) -> None: if original_value == new_value: if original_value == 0: evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -144,7 +143,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -171,7 +170,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/osaka/vm/instructions/system.py b/src/ethereum/forks/osaka/vm/instructions/system.py index a4815b4487b..ecedf2851a1 100644 --- a/src/ethereum/forks/osaka/vm/instructions/system.py +++ b/src/ethereum/forks/osaka/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas, + GasCosts.CREATE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,8 +211,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -256,7 +256,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -369,10 +369,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -383,10 +383,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -458,10 +458,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -471,7 +471,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -527,10 +527,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -540,7 +540,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -601,10 +601,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -674,10 +674,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/osaka/vm/interpreter.py b/src/ethereum/forks/osaka/vm/interpreter.py index 8477afbe071..b956f824d0e 100644 --- a/src/ethereum/forks/osaka/vm/interpreter.py +++ b/src/ethereum/forks/osaka/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index efd942e4706..74d2c68446a 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -31,35 +31,35 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -75,45 +75,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -187,7 +187,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -242,7 +242,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/instructions/block.py b/src/ethereum/forks/paris/vm/instructions/block.py index 3b4ac3a0257..d1b1194b94c 100644 --- a/src/ethereum/forks/paris/vm/instructions/block.py +++ b/src/ethereum/forks/paris/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index b30b69d8210..20c0dd10fa0 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -538,7 +538,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/paris/vm/instructions/keccak.py b/src/ethereum/forks/paris/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/paris/vm/instructions/keccak.py +++ b/src/ethereum/forks/paris/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/instructions/log.py b/src/ethereum/forks/paris/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/paris/vm/instructions/log.py +++ b/src/ethereum/forks/paris/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/paris/vm/instructions/storage.py b/src/ethereum/forks/paris/vm/instructions/storage.py index 95441af81fb..287544f353b 100644 --- a/src/ethereum/forks/paris/vm/instructions/storage.py +++ b/src/ethereum/forks/paris/vm/instructions/storage.py @@ -39,10 +39,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -68,7 +68,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -81,18 +81,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -109,14 +108,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/paris/vm/instructions/system.py b/src/ethereum/forks/paris/vm/instructions/system.py index a4e1d9365a6..1466a9677f5 100644 --- a/src/ethereum/forks/paris/vm/instructions/system.py +++ b/src/ethereum/forks/paris/vm/instructions/system.py @@ -148,7 +148,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -193,8 +193,8 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) @@ -233,7 +233,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -344,17 +344,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -424,12 +424,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -482,10 +482,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -494,7 +494,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -557,10 +557,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -616,10 +616,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/paris/vm/interpreter.py b/src/ethereum/forks/paris/vm/interpreter.py index 29577922e6c..32cb2e3b4de 100644 --- a/src/ethereum/forks/paris/vm/interpreter.py +++ b/src/ethereum/forks/paris/vm/interpreter.py @@ -167,7 +167,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/prague/vm/eoa_delegation.py b/src/ethereum/forks/prague/vm/eoa_delegation.py index acdc91afbdf..d4ff0ff9fb8 100644 --- a/src/ethereum/forks/prague/vm/eoa_delegation.py +++ b/src/ethereum/forks/prague/vm/eoa_delegation.py @@ -147,10 +147,10 @@ def access_delegation( address = Address(code[EOA_DELEGATION_MARKER_LENGTH:]) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code = get_code(state, get_account(state, address).code_hash) return True, address, code, access_gas_cost diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 8c08a456baa..63f9854b2f1 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -33,37 +33,37 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) - GAS_POINT_EVALUATION = Uint(50000) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) + POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -85,53 +85,53 @@ class GasCosts: PRECOMPILE_BLS_G2MAP = Uint(23800) # Blobs - GAS_PER_BLOB = U64(2**17) + PER_BLOB = U64(2**17) BLOB_TARGET_GAS_PER_BLOCK = U64(786432) BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE + OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_MCOPY = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_MCOPY = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -205,7 +205,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -260,7 +260,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -332,9 +332,7 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) def calculate_excess_blob_gas(parent_header: Header) -> U64: @@ -385,7 +383,7 @@ def calculate_total_blob_gas(tx: Transaction) -> U64: """ if isinstance(tx, BlobTransaction): - return GasCosts.GAS_PER_BLOB * U64(len(tx.blob_versioned_hashes)) + return GasCosts.PER_BLOB * U64(len(tx.blob_versioned_hashes)) else: return U64(0) diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/block.py b/src/ethereum/forks/prague/vm/instructions/block.py index 5236fb303a8..555f100c519 100644 --- a/src/ethereum/forks/prague/vm/instructions/block.py +++ b/src/ethereum/forks/prague/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index a56f117e095..a834e81efdc 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -69,10 +69,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -340,10 +340,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -376,16 +376,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -477,10 +477,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -512,7 +512,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -590,7 +590,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/prague/vm/instructions/keccak.py b/src/ethereum/forks/prague/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/prague/vm/instructions/keccak.py +++ b/src/ethereum/forks/prague/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/log.py b/src/ethereum/forks/prague/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/prague/vm/instructions/log.py +++ b/src/ethereum/forks/prague/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index f8141229434..4b03a0386ef 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index d80df54321d..5520ac8303a 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/prague/vm/instructions/storage.py b/src/ethereum/forks/prague/vm/instructions/storage.py index 202917b6072..5aa3cc6746f 100644 --- a/src/ethereum/forks/prague/vm/instructions/storage.py +++ b/src/ethereum/forks/prague/vm/instructions/storage.py @@ -45,10 +45,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -74,7 +74,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -87,18 +87,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -115,14 +114,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) @@ -149,7 +148,7 @@ def tload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) # OPERATION value = get_transient_storage( @@ -176,7 +175,7 @@ def tstore(evm: Evm) -> None: new_value = pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) if evm.message.is_static: raise WriteInStaticContext set_transient_storage( diff --git a/src/ethereum/forks/prague/vm/instructions/system.py b/src/ethereum/forks/prague/vm/instructions/system.py index d1c9c4254d3..e9952c58e97 100644 --- a/src/ethereum/forks/prague/vm/instructions/system.py +++ b/src/ethereum/forks/prague/vm/instructions/system.py @@ -158,7 +158,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,8 +208,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -253,7 +253,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -366,10 +366,10 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( @@ -380,10 +380,10 @@ def call(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -455,10 +455,10 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -468,7 +468,7 @@ def callcode(evm: Evm) -> None: ) = access_delegation(evm, code_address) access_gas_cost += delegated_access_gas_cost - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -523,10 +523,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -535,7 +535,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -596,10 +596,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS ( disable_precompiles, @@ -665,10 +665,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to ( diff --git a/src/ethereum/forks/prague/vm/interpreter.py b/src/ethereum/forks/prague/vm/interpreter.py index 8c0b3b394b1..fd41c59a310 100644 --- a/src/ethereum/forks/prague/vm/interpreter.py +++ b/src/ethereum/forks/prague/vm/interpreter.py @@ -191,7 +191,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py index ca60b8daee5..302abba4cfe 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.GAS_POINT_EVALUATION) + charge_gas(evm, GasCosts.POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 5e89ac62596..471aa27e0f1 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -31,36 +31,36 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - GAS_RETURN_DATA_COPY = Uint(3) - GAS_FAST_STEP = Uint(5) - GAS_COLD_STORAGE_ACCESS = Uint(2100) - GAS_COLD_ACCOUNT_ACCESS = Uint(2600) - GAS_WARM_ACCESS = Uint(100) - GAS_CODE_INIT_PER_WORD = Uint(2) + BASE = Uint(2) + VERY_LOW = Uint(3) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + RETURN_DATA_COPY = Uint(3) + FAST_STEP = Uint(5) + COLD_STORAGE_ACCESS = Uint(2100) + COLD_ACCOUNT_ACCESS = Uint(2600) + WARM_ACCESS = Uint(100) + CODE_INIT_PER_WORD = Uint(2) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -76,45 +76,45 @@ class GasCosts: PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_SHL = GAS_VERY_LOW - OPCODE_SHR = GAS_VERY_LOW - OPCODE_SAR = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_SHL = VERY_LOW + OPCODE_SHR = VERY_LOW + OPCODE_SAR = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW - OPCODE_RETURNDATACOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -188,7 +188,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -243,7 +243,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) @@ -315,6 +315,4 @@ def init_code_cost(init_code_length: Uint) -> Uint: The gas to be charged for the init code. """ - return ( - GasCosts.GAS_CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) - ) + return GasCosts.CODE_INIT_PER_WORD * ceil32(init_code_length) // Uint(32) diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index dfe38cd80bf..be213222ec6 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -312,8 +312,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/instructions/block.py b/src/ethereum/forks/shanghai/vm/instructions/block.py index eb7c7792186..7d98aa2a41e 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/block.py +++ b/src/ethereum/forks/shanghai/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index 2604040cb28..76948ae4796 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index b30b69d8210..20c0dd10fa0 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -67,10 +67,10 @@ def balance(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_addresses.add(address) - charge_gas(evm, GasCosts.GAS_COLD_ACCOUNT_ACCESS) + charge_gas(evm, GasCosts.COLD_ACCOUNT_ACCESS) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -338,10 +338,10 @@ def extcodesize(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -374,16 +374,16 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.RETURN_DATA_COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -475,10 +475,10 @@ def extcodehash(evm: Evm) -> None: # GAS if address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS charge_gas(evm, access_gas_cost) @@ -510,7 +510,7 @@ def self_balance(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_FAST_STEP) + charge_gas(evm, GasCosts.FAST_STEP) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -538,7 +538,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/keccak.py b/src/ethereum/forks/shanghai/vm/instructions/keccak.py index 5173dd59f67..931cb45d875 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/keccak.py +++ b/src/ethereum/forks/shanghai/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/instructions/log.py b/src/ethereum/forks/shanghai/vm/instructions/log.py index 715be004c55..72877b99176 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/log.py +++ b/src/ethereum/forks/shanghai/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index c404c9d39ba..dec0bc81afe 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/shanghai/vm/instructions/storage.py b/src/ethereum/forks/shanghai/vm/instructions/storage.py index 098d5f0676f..0936a10b1e1 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/storage.py +++ b/src/ethereum/forks/shanghai/vm/instructions/storage.py @@ -36,10 +36,10 @@ def sload(evm: Evm) -> None: # GAS if (evm.message.current_target, key) in evm.accessed_storage_keys: - charge_gas(evm, GasCosts.GAS_WARM_ACCESS) + charge_gas(evm, GasCosts.WARM_ACCESS) else: evm.accessed_storage_keys.add((evm.message.current_target, key)) - charge_gas(evm, GasCosts.GAS_COLD_STORAGE_ACCESS) + charge_gas(evm, GasCosts.COLD_STORAGE_ACCESS) # OPERATION value = get_storage( @@ -65,7 +65,7 @@ def sstore(evm: Evm) -> None: # STACK key = pop(evm.stack).to_be_bytes32() new_value = pop(evm.stack) - if evm.gas_left <= GasCosts.GAS_CALL_STIPEND: + if evm.gas_left <= GasCosts.CALL_STIPEND: raise OutOfGasError state = evm.message.block_env.state @@ -78,18 +78,17 @@ def sstore(evm: Evm) -> None: if (evm.message.current_target, key) not in evm.accessed_storage_keys: evm.accessed_storage_keys.add((evm.message.current_target, key)) - gas_cost += GasCosts.GAS_COLD_STORAGE_ACCESS + gas_cost += GasCosts.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += GasCosts.GAS_STORAGE_SET + gas_cost += GasCosts.STORAGE_SET else: gas_cost += ( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS + GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS ) else: - gas_cost += GasCosts.GAS_WARM_ACCESS + gas_cost += GasCosts.WARM_ACCESS # Refund Counter Calculation if current_value != new_value: @@ -106,14 +105,14 @@ def sstore(evm: Evm) -> None: if original_value == 0: # Slot was originally empty and was SET earlier evm.refund_counter += int( - GasCosts.GAS_STORAGE_SET - GasCosts.GAS_WARM_ACCESS + GasCosts.STORAGE_SET - GasCosts.WARM_ACCESS ) else: # Slot was originally non-empty and was UPDATED earlier evm.refund_counter += int( - GasCosts.GAS_COLD_STORAGE_WRITE - - GasCosts.GAS_COLD_STORAGE_ACCESS - - GasCosts.GAS_WARM_ACCESS + GasCosts.COLD_STORAGE_WRITE + - GasCosts.COLD_STORAGE_ACCESS + - GasCosts.WARM_ACCESS ) charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/shanghai/vm/instructions/system.py b/src/ethereum/forks/shanghai/vm/instructions/system.py index 93d21967cb5..2ac2e1d3b22 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/system.py +++ b/src/ethereum/forks/shanghai/vm/instructions/system.py @@ -156,7 +156,7 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost + init_code_gas) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -206,8 +206,8 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.GAS_CREATE - + GasCosts.GAS_KECCAK256_PER_WORD * call_data_words + GasCosts.CREATE + + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) @@ -251,7 +251,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -362,17 +362,17 @@ def call(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -442,12 +442,12 @@ def callcode(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, @@ -500,10 +500,10 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) - gas_cost += GasCosts.GAS_COLD_ACCOUNT_ACCESS + gas_cost += GasCosts.COLD_ACCOUNT_ACCESS if ( not is_account_alive(evm.message.block_env.state, beneficiary) @@ -512,7 +512,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: @@ -575,10 +575,10 @@ def delegatecall(evm: Evm) -> None: ) if code_address in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(code_address) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS message_call_gas = calculate_message_call_gas( U256(0), gas, Uint(evm.gas_left), extend_memory.cost, access_gas_cost @@ -634,10 +634,10 @@ def staticcall(evm: Evm) -> None: ) if to in evm.accessed_addresses: - access_gas_cost = GasCosts.GAS_WARM_ACCESS + access_gas_cost = GasCosts.WARM_ACCESS else: evm.accessed_addresses.add(to) - access_gas_cost = GasCosts.GAS_COLD_ACCOUNT_ACCESS + access_gas_cost = GasCosts.COLD_ACCOUNT_ACCESS code_address = to diff --git a/src/ethereum/forks/shanghai/vm/interpreter.py b/src/ethereum/forks/shanghai/vm/interpreter.py index 95c8f9ca897..d4ec312b4fa 100644 --- a/src/ethereum/forks/shanghai/vm/interpreter.py +++ b/src/ethereum/forks/shanghai/vm/interpreter.py @@ -168,7 +168,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: if len(contract_code) > 0: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 7490477f06b..49570a15b72 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -31,34 +31,34 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(200) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(50) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(400) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -74,41 +74,41 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -182,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -237,7 +237,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 5baf8effdc3..0981b35f615 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -362,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py index 703f0befa99..7b1fed7c967 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py b/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py index a69e1093b9a..0b2a1cce8aa 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/storage.py @@ -37,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -68,9 +68,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py index fdc828dc94d..00cebb30ea3 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py @@ -68,7 +68,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -157,7 +157,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -261,16 +261,16 @@ def call(evm: Evm) -> None: code_address = to - create_gas_cost = GasCosts.GAS_NEW_ACCOUNT + create_gas_cost = GasCosts.NEW_ACCOUNT if value == 0 or is_account_alive(evm.message.block_env.state, to): create_gas_cost = Uint(0) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -330,13 +330,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -381,7 +381,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -389,7 +389,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -463,7 +463,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/spurious_dragon/vm/interpreter.py b/src/ethereum/forks/spurious_dragon/vm/interpreter.py index 6a306d79c8a..c970cbc1ee4 100644 --- a/src/ethereum/forks/spurious_dragon/vm/interpreter.py +++ b/src/ethereum/forks/spurious_dragon/vm/interpreter.py @@ -173,7 +173,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index d7d8e01bb4b..3521b386ca1 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -31,34 +31,34 @@ class GasCosts: """ # General - GAS_BASE = Uint(2) - GAS_VERY_LOW = Uint(3) - GAS_SLOAD = Uint(200) - GAS_STORAGE_SET = Uint(20000) - GAS_COLD_STORAGE_WRITE = Uint(5000) - GAS_LOW = Uint(5) - GAS_MID = Uint(8) - GAS_HIGH = Uint(10) - GAS_EXPONENTIATION = Uint(10) - GAS_EXPONENTIATION_PER_BYTE = Uint(10) - GAS_MEMORY = Uint(3) - GAS_KECCAK256 = Uint(30) - GAS_KECCAK256_PER_WORD = Uint(6) - GAS_COPY = Uint(3) - GAS_EXTERNAL = Uint(700) - GAS_BALANCE = Uint(400) - GAS_LOG = Uint(375) - GAS_LOG_DATA_PER_BYTE = Uint(8) - GAS_LOG_TOPIC = Uint(375) - GAS_CREATE = Uint(32000) - GAS_CODE_DEPOSIT_PER_BYTE = Uint(200) - GAS_ZERO = Uint(0) - GAS_CALL = Uint(700) - GAS_NEW_ACCOUNT = Uint(25000) - GAS_CALL_VALUE = Uint(9000) - GAS_CALL_STIPEND = Uint(2300) - GAS_SELF_DESTRUCT = Uint(5000) - GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + BASE = Uint(2) + VERY_LOW = Uint(3) + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) + LOW = Uint(5) + MID = Uint(8) + HIGH = Uint(10) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + MEMORY = Uint(3) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + COPY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + CREATE = Uint(32000) + CODE_DEPOSIT_PER_BYTE = Uint(200) + ZERO = Uint(0) + CALL = Uint(700) + NEW_ACCOUNT = Uint(25000) + CALL_VALUE = Uint(9000) + CALL_STIPEND = Uint(2300) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -74,41 +74,41 @@ class GasCosts: PRECOMPILE_IDENTITY_PER_WORD = Uint(3) # Opcodes - OPCODE_ADD = GAS_VERY_LOW - OPCODE_SUB = GAS_VERY_LOW - OPCODE_MUL = GAS_LOW - OPCODE_DIV = GAS_LOW - OPCODE_SDIV = GAS_LOW - OPCODE_MOD = GAS_LOW - OPCODE_SMOD = GAS_LOW - OPCODE_ADDMOD = GAS_MID - OPCODE_MULMOD = GAS_MID - OPCODE_SIGNEXTEND = GAS_LOW - OPCODE_LT = GAS_VERY_LOW - OPCODE_GT = GAS_VERY_LOW - OPCODE_SLT = GAS_VERY_LOW - OPCODE_SGT = GAS_VERY_LOW - OPCODE_EQ = GAS_VERY_LOW - OPCODE_ISZERO = GAS_VERY_LOW - OPCODE_AND = GAS_VERY_LOW - OPCODE_OR = GAS_VERY_LOW - OPCODE_XOR = GAS_VERY_LOW - OPCODE_NOT = GAS_VERY_LOW - OPCODE_BYTE = GAS_VERY_LOW - OPCODE_JUMP = GAS_MID - OPCODE_JUMPI = GAS_HIGH + OPCODE_ADD = VERY_LOW + OPCODE_SUB = VERY_LOW + OPCODE_MUL = LOW + OPCODE_DIV = LOW + OPCODE_SDIV = LOW + OPCODE_MOD = LOW + OPCODE_SMOD = LOW + OPCODE_ADDMOD = MID + OPCODE_MULMOD = MID + OPCODE_SIGNEXTEND = LOW + OPCODE_LT = VERY_LOW + OPCODE_GT = VERY_LOW + OPCODE_SLT = VERY_LOW + OPCODE_SGT = VERY_LOW + OPCODE_EQ = VERY_LOW + OPCODE_ISZERO = VERY_LOW + OPCODE_AND = VERY_LOW + OPCODE_OR = VERY_LOW + OPCODE_XOR = VERY_LOW + OPCODE_NOT = VERY_LOW + OPCODE_BYTE = VERY_LOW + OPCODE_JUMP = MID + OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) - OPCODE_CALLDATALOAD = GAS_VERY_LOW - OPCODE_CALLDATACOPY = GAS_VERY_LOW - OPCODE_CODECOPY = GAS_VERY_LOW + OPCODE_CALLDATALOAD = VERY_LOW + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) - OPCODE_COINBASE = GAS_BASE - OPCODE_MLOAD = GAS_VERY_LOW - OPCODE_MSTORE = GAS_VERY_LOW - OPCODE_MSTORE8 = GAS_VERY_LOW - OPCODE_PUSH = GAS_VERY_LOW - OPCODE_DUP = GAS_VERY_LOW - OPCODE_SWAP = GAS_VERY_LOW + OPCODE_COINBASE = BASE + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_PUSH = VERY_LOW + OPCODE_DUP = VERY_LOW + OPCODE_SWAP = VERY_LOW @dataclass @@ -182,7 +182,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.GAS_MEMORY + linear_cost = size_in_words * GasCosts.MEMORY quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: @@ -237,7 +237,7 @@ def calculate_message_call_gas( gas_left: Uint, memory_cost: Uint, extra_gas: Uint, - call_stipend: Uint = GasCosts.GAS_CALL_STIPEND, + call_stipend: Uint = GasCosts.CALL_STIPEND, ) -> MessageCallGas: """ Calculates the MessageCallGas (cost and gas made available to the sub-call) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index 92e49121ba5..6ce0b105c04 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.GAS_EXPONENTIATION - + GasCosts.GAS_EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.EXPONENTIATION + + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py index 904a1e71771..f8897e35754 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index 12a18a10ab2..9c98154f9aa 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 5baf8effdc3..0981b35f615 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_BALANCE) + charge_gas(evm, GasCosts.BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.GAS_EXTERNAL) + charge_gas(evm, GasCosts.EXTERNAL) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -362,11 +362,11 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.GAS_COPY * words + copy_gas_cost = GasCosts.COPY * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.GAS_EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py index d863b8ebc74..497024b578b 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py @@ -45,13 +45,11 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.GAS_KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.KECCAK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas( - evm, GasCosts.GAS_KECCAK256 + word_gas_cost + extend_memory.cost - ) + charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py index 703f0befa99..7b1fed7c967 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.GAS_LOG - + GasCosts.GAS_LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.GAS_LOG_TOPIC * Uint(num_topics) + GasCosts.LOG + + GasCosts.LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index deec5941342..0b3d4d1de51 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 97123b5f2e2..03049761b31 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.GAS_BASE) + charge_gas(evm, GasCosts.BASE) # OPERATION pass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py index a69e1093b9a..0b2a1cce8aa 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/storage.py @@ -37,7 +37,7 @@ def sload(evm: Evm) -> None: key = pop(evm.stack).to_be_bytes32() # GAS - charge_gas(evm, GasCosts.GAS_SLOAD) + charge_gas(evm, GasCosts.SLOAD) # OPERATION value = get_storage( @@ -68,9 +68,9 @@ def sstore(evm: Evm) -> None: state = evm.message.block_env.state current_value = get_storage(state, evm.message.current_target, key) if new_value != 0 and current_value == 0: - gas_cost = GasCosts.GAS_STORAGE_SET + gas_cost = GasCosts.STORAGE_SET else: - gas_cost = GasCosts.GAS_COLD_STORAGE_WRITE + gas_cost = GasCosts.COLD_STORAGE_WRITE if new_value == 0 and current_value != 0: evm.refund_counter += GasCosts.REFUND_STORAGE_CLEAR diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py index 4a9801fcb43..4b95c5986f3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py @@ -67,7 +67,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.CREATE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas @@ -156,7 +156,7 @@ def return_(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.GAS_ZERO + extend_memory.cost) + charge_gas(evm, GasCosts.ZERO + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -261,14 +261,14 @@ def call(evm: Evm) -> None: code_address = to _account_exists = account_exists(evm.message.block_env.state, to) - create_gas_cost = Uint(0) if _account_exists else GasCosts.GAS_NEW_ACCOUNT - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + create_gas_cost = Uint(0) if _account_exists else GasCosts.NEW_ACCOUNT + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + create_gas_cost + transfer_gas_cost, + GasCosts.CALL + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -328,13 +328,13 @@ def callcode(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - transfer_gas_cost = Uint(0) if value == 0 else GasCosts.GAS_CALL_VALUE + transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE message_call_gas = calculate_message_call_gas( value, gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.GAS_CALL + transfer_gas_cost, + GasCosts.CALL + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -379,9 +379,9 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.GAS_SELF_DESTRUCT + gas_cost = GasCosts.SELF_DESTRUCT if not account_exists(evm.message.block_env.state, beneficiary): - gas_cost += GasCosts.GAS_SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT originator = evm.message.current_target @@ -452,7 +452,7 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.GAS_CALL + U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py index e35f2c4b04a..a687e748de3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py +++ b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py @@ -158,7 +158,7 @@ def process_create_message(message: Message) -> Evm: if not evm.error: contract_code = evm.output contract_code_gas = ( - ulen(contract_code) * GasCosts.GAS_CODE_DEPOSIT_PER_BYTE + ulen(contract_code) * GasCosts.CODE_DEPOSIT_PER_BYTE ) try: charge_gas(evm, contract_code_gas) From cb1dfbd8cb1ca54c13817b631ed95a0c66044ead Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 31 Mar 2026 21:25:13 -0400 Subject: [PATCH 41/61] refactor: group tier gas constants --- src/ethereum/forks/amsterdam/vm/gas.py | 8 +++++--- src/ethereum/forks/arrow_glacier/vm/gas.py | 8 +++++--- src/ethereum/forks/berlin/vm/gas.py | 8 +++++--- src/ethereum/forks/bpo1/vm/gas.py | 8 +++++--- src/ethereum/forks/bpo2/vm/gas.py | 8 +++++--- src/ethereum/forks/bpo3/vm/gas.py | 8 +++++--- src/ethereum/forks/bpo4/vm/gas.py | 8 +++++--- src/ethereum/forks/bpo5/vm/gas.py | 8 +++++--- src/ethereum/forks/byzantium/vm/gas.py | 10 ++++++---- src/ethereum/forks/cancun/vm/gas.py | 8 +++++--- src/ethereum/forks/constantinople/vm/gas.py | 10 ++++++---- src/ethereum/forks/dao_fork/vm/gas.py | 10 ++++++---- src/ethereum/forks/frontier/vm/gas.py | 10 ++++++---- src/ethereum/forks/gray_glacier/vm/gas.py | 8 +++++--- src/ethereum/forks/homestead/vm/gas.py | 10 ++++++---- src/ethereum/forks/istanbul/vm/gas.py | 10 ++++++---- src/ethereum/forks/london/vm/gas.py | 8 +++++--- src/ethereum/forks/muir_glacier/vm/gas.py | 10 ++++++---- src/ethereum/forks/osaka/vm/gas.py | 8 +++++--- src/ethereum/forks/paris/vm/gas.py | 8 +++++--- src/ethereum/forks/prague/vm/gas.py | 8 +++++--- src/ethereum/forks/shanghai/vm/gas.py | 8 +++++--- src/ethereum/forks/spurious_dragon/vm/gas.py | 10 ++++++---- src/ethereum/forks/tangerine_whistle/vm/gas.py | 10 ++++++---- 24 files changed, 129 insertions(+), 81 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 59f80867038..dad1da67c76 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -33,14 +33,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 74d2c68446a..a1c25d967d5 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index e2db19c3fc0..db25ac3a8d9 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 0d8c798d88c..c23c9c29e0f 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 9cc2ae84b07..9229ef704eb 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 9cc2ae84b07..9229ef704eb 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 9cc2ae84b07..9229ef704eb 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 9cc2ae84b07..9229ef704eb 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index df5283e28d0..6f880ad18f9 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(200) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 394c271557e..467c1d902eb 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 35f2d45e8ee..7edaaab6b87 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(200) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index c3cb8a26959..5867cd74d48 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -32,15 +32,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(50) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) MEMORY = Uint(3) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index c3cb8a26959..5867cd74d48 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -32,15 +32,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(50) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) MEMORY = Uint(3) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 74d2c68446a..a1c25d967d5 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index c3cb8a26959..5867cd74d48 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -32,15 +32,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(50) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(50) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) MEMORY = Uint(3) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 9c4373bc5ee..241aa6a9a5b 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(800) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(800) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 74d2c68446a..a1c25d967d5 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 9c4373bc5ee..241aa6a9a5b 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(800) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(800) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index bdf25956110..3d124f3b8a6 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 74d2c68446a..a1c25d967d5 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 63f9854b2f1..1c83b7b98b8 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -32,14 +32,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 471aa27e0f1..36bf312d215 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -30,14 +30,16 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 49570a15b72..e96097141d8 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(200) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) MEMORY = Uint(3) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 3521b386ca1..2a767e41ea2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -30,15 +30,17 @@ class GasCosts: These values may be patched at runtime by a future gas repricing utility """ - # General + # Tiers BASE = Uint(2) VERY_LOW = Uint(3) - SLOAD = Uint(200) - STORAGE_SET = Uint(20000) - COLD_STORAGE_WRITE = Uint(5000) LOW = Uint(5) MID = Uint(8) HIGH = Uint(10) + + # General + SLOAD = Uint(200) + STORAGE_SET = Uint(20000) + COLD_STORAGE_WRITE = Uint(5000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) MEMORY = Uint(3) From a235eb2bfe83c5b0a21f5b330ba354faf6fd1e27 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 1 Apr 2026 01:29:44 -0400 Subject: [PATCH 42/61] refactor: remove GAS_ prefix in all test code + clean up --- .../plugins/execute/pre_alloc.py | 10 +- .../execution_testing/forks/forks/forks.py | 288 +++++++++--------- .../src/execution_testing/forks/gas_costs.py | 140 +++++---- .../forks/tests/test_opcode_gas_costs.py | 193 ++++++------ .../tools/utility/generators.py | 14 +- .../test_block_access_lists.py | 4 +- .../test_block_access_lists_opcodes.py | 8 +- .../compute/instruction/test_system.py | 2 +- .../compute/precompile/test_alt_bn128.py | 4 +- .../scenario/test_transaction_types.py | 18 +- .../stateful/bloatnet/test_multi_opcode.py | 8 +- .../eip2929_gas_cost_increases/test_create.py | 4 +- tests/byzantium/eip196_ec_add_mul/test_gas.py | 4 +- tests/byzantium/eip197_ec_pairing/test_gas.py | 4 +- tests/frontier/opcodes/test_call.py | 10 +- .../test_call_and_callcode_gas_calculation.py | 8 +- .../test_tx_gas_limit.py | 4 +- .../eip7623_increase_calldata_cost/spec.py | 4 +- tests/prague/eip7702_set_code_tx/spec.py | 2 +- tests/prague/eip7702_set_code_tx/test_gas.py | 4 +- .../eip7702_set_code_tx/test_set_code_txs.py | 15 +- .../test_eip150_selfdestruct.py | 38 +-- 22 files changed, 396 insertions(+), 390 deletions(-) diff --git a/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py b/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py index 65d9e100ca6..306b6c143fd 100644 --- a/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py +++ b/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py @@ -348,10 +348,8 @@ def _deterministic_deploy_contract( raise ValueError( f"initcode too large {len(initcode)} > {max_initcode_size}" ) - deploy_gas_limit = gas_costs.GAS_TX_BASE + gas_costs.GAS_TX_CREATE - deploy_gas_limit += ( - len(deploy_code) * gas_costs.GAS_CODE_DEPOSIT_PER_BYTE - ) + deploy_gas_limit = gas_costs.TX_BASE + gas_costs.TX_CREATE + deploy_gas_limit += len(deploy_code) * gas_costs.CODE_DEPOSIT_PER_BYTE deploy_gas_limit += memory_expansion_gas_calculator( new_bytes=len(initcode) ) @@ -445,7 +443,7 @@ def _deploy_contract( initcode_prefix = Bytecode() - deploy_gas_limit = gas_costs.GAS_TX_BASE + gas_costs.GAS_TX_CREATE + deploy_gas_limit = gas_costs.TX_BASE + gas_costs.TX_CREATE if len(storage.root) > 0: initcode_prefix += sum( @@ -462,7 +460,7 @@ def _deploy_contract( if len(code) > max_code_size: raise ValueError(f"code too large: {len(code)} > {max_code_size}") - deploy_gas_limit += len(code) * gas_costs.GAS_CODE_DEPOSIT_PER_BYTE + deploy_gas_limit += len(code) * gas_costs.CODE_DEPOSIT_PER_BYTE prepared_initcode = Initcode( deploy_code=code, initcode_prefix=initcode_prefix diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 198730c82bd..ae0a7ccc528 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -97,41 +97,49 @@ def gas_costs(cls) -> GasCosts: Return dataclass with the defined gas costs constants for genesis. """ return GasCosts( - GAS_BASE=2, - GAS_VERY_LOW=3, - GAS_LOW=5, - GAS_MID=8, - GAS_HIGH=10, - GAS_WARM_ACCESS=100, - GAS_COLD_ACCOUNT_ACCESS=2_600, - GAS_TX_ACCESS_LIST_ADDRESS=2_400, - GAS_TX_ACCESS_LIST_STORAGE_KEY=1_900, - GAS_WARM_SLOAD=100, - GAS_COLD_STORAGE_ACCESS=2_100, - GAS_STORAGE_SET=20_000, - GAS_COLD_STORAGE_WRITE=5_000, - GAS_STORAGE_RESET=2_900, + # Tiers + BASE=BASE, + VERY_LOW=VERY_LOW, + LOW=LOW, + MID=MID, + HIGH=HIGH, + # Access Costs + WARM_ACCESS=100, + COLD_ACCOUNT_ACCESS=2_600, + WARM_SLOAD=100, + COLD_STORAGE_ACCESS=2_100, + # Storage Costs + STORAGE_SET=20_000, + COLD_STORAGE_WRITE=5_000, + STORAGE_RESET=2_900, + # Call Costs + CALL_VALUE=9_000, + CALL_STIPEND=2_300, + NEW_ACCOUNT=25_000, + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE=200, + CODE_INIT_PER_WORD=2, + # Component Costs for Dynamic Opcodes + COPY=3, + CREATE=32_000, + MEMORY=3, + EXPONENTIATION=10, + EXPONENTIATION_PER_BYTE=50, + LOG=375, + LOG_DATA_PER_BYTE=8, + LOG_TOPIC=375, + KECCAK256=30, + KECCAK256_PER_WORD=6, + # Transactions + TX_BASE=21_000, + TX_ACCESS_LIST_ADDRESS=2_400, + TX_ACCESS_LIST_STORAGE_KEY=1_900, + TX_DATA_PER_ZERO=4, + TX_DATA_PER_NON_ZERO=68, + TX_CREATE=32_000, + # Refunds REFUND_STORAGE_CLEAR=4_800, - GAS_SELF_DESTRUCT=5_000, - GAS_CREATE=32_000, - GAS_CODE_DEPOSIT_PER_BYTE=200, - GAS_CODE_INIT_PER_WORD=2, - GAS_CALL_VALUE=9_000, - GAS_CALL_STIPEND=2_300, - GAS_NEW_ACCOUNT=25_000, - GAS_EXPONENTIATION=10, - GAS_EXPONENTIATION_PER_BYTE=50, - GAS_MEMORY=3, - GAS_TX_DATA_PER_ZERO=4, - GAS_TX_DATA_PER_NON_ZERO=68, - GAS_TX_BASE=21_000, - GAS_TX_CREATE=32_000, - GAS_LOG=375, - GAS_LOG_DATA_PER_BYTE=8, - GAS_LOG_TOPIC=375, - GAS_KECCAK256=30, - GAS_KECCAK256_PER_WORD=6, - GAS_COPY=3, + # Precompiles PRECOMPILE_ECRECOVER=3_000, PRECOMPILE_SHA256_BASE=60, PRECOMPILE_SHA256_PER_WORD=12, @@ -139,11 +147,49 @@ def gas_costs(cls) -> GasCosts: PRECOMPILE_RIPEMD160_PER_WORD=120, PRECOMPILE_IDENTITY_BASE=15, PRECOMPILE_IDENTITY_PER_WORD=3, + # Static Opcodes + OPCODE_ADD=VERY_LOW, + OPCODE_SUB=VERY_LOW, + OPCODE_MUL=LOW, + OPCODE_DIV=LOW, + OPCODE_SDIV=LOW, + OPCODE_MOD=LOW, + OPCODE_SMOD=LOW, + OPCODE_ADDMOD=MID, + OPCODE_MULMOD=MID, + OPCODE_SIGNEXTEND=LOW, + OPCODE_LT=VERY_LOW, + OPCODE_GT=VERY_LOW, + OPCODE_SLT=VERY_LOW, + OPCODE_SGT=VERY_LOW, + OPCODE_EQ=VERY_LOW, + OPCODE_ISZERO=VERY_LOW, + OPCODE_AND=VERY_LOW, + OPCODE_OR=VERY_LOW, + OPCODE_XOR=VERY_LOW, + OPCODE_NOT=VERY_LOW, + OPCODE_BYTE=VERY_LOW, + OPCODE_JUMP=MID, + OPCODE_JUMPI=HIGH, + OPCODE_JUMPDEST=1, + OPCODE_CALLDATALOAD=VERY_LOW, + OPCODE_BLOCKHASH=20, + OPCODE_COINBASE=BASE, + OPCODE_PUSH=VERY_LOW, + OPCODE_DUP=VERY_LOW, + OPCODE_SWAP=VERY_LOW, + # Dynamic Opcodes + OPCODE_CALLDATACOPY=VERY_LOW, + OPCODE_CODECOPY=VERY_LOW, + OPCODE_MLOAD=VERY_LOW, + OPCODE_MSTORE=VERY_LOW, + OPCODE_MSTORE8=VERY_LOW, + OPCODE_SELFDESTRUCT=5_000, # Zero-initialized: introduced in later forks, set via # replace() in the fork that activates them. - GAS_TX_DATA_TOKEN_STANDARD=0, - GAS_TX_DATA_TOKEN_FLOOR=0, - GAS_AUTH_PER_EMPTY_ACCOUNT=0, + TX_DATA_TOKEN_STANDARD=0, + TX_DATA_TOKEN_FLOOR=0, + AUTH_PER_EMPTY_ACCOUNT=0, REFUND_AUTH_PER_EXISTING_ACCOUNT=0, PRECOMPILE_ECADD=0, PRECOMPILE_ECMUL=0, @@ -161,42 +207,7 @@ def gas_costs(cls) -> GasCosts: PRECOMPILE_BLS_PAIRING_BASE=0, PRECOMPILE_BLS_PAIRING_PER_PAIR=0, PRECOMPILE_P256VERIFY=0, - GAS_BLOCK_ACCESS_LIST_ITEM=0, - # Opcode specific gas constants for repricing - OPCODE_ADD=GAS_VERY_LOW, - OPCODE_SUB=GAS_VERY_LOW, - OPCODE_MUL=GAS_LOW, - OPCODE_DIV=GAS_LOW, - OPCODE_SDIV=GAS_LOW, - OPCODE_MOD=GAS_LOW, - OPCODE_SMOD=GAS_LOW, - OPCODE_ADDMOD=GAS_MID, - OPCODE_MULMOD=GAS_MID, - OPCODE_SIGNEXTEND=GAS_LOW, - OPCODE_LT=GAS_VERY_LOW, - OPCODE_GT=GAS_VERY_LOW, - OPCODE_SLT=GAS_VERY_LOW, - OPCODE_SGT=GAS_VERY_LOW, - OPCODE_EQ=GAS_VERY_LOW, - OPCODE_ISZERO=GAS_VERY_LOW, - OPCODE_AND=GAS_VERY_LOW, - OPCODE_OR=GAS_VERY_LOW, - OPCODE_XOR=GAS_VERY_LOW, - OPCODE_NOT=GAS_VERY_LOW, - OPCODE_BYTE=GAS_VERY_LOW, - OPCODE_JUMP=GAS_MID, - OPCODE_JUMPI=GAS_HIGH, - OPCODE_JUMPDEST=1, - OPCODE_CALLDATALOAD=GAS_VERY_LOW, - OPCODE_CALLDATACOPY=GAS_VERY_LOW, - OPCODE_CODECOPY=GAS_VERY_LOW, - OPCODE_BLOCKHASH=20, - OPCODE_MLOAD=GAS_VERY_LOW, - OPCODE_MSTORE=GAS_VERY_LOW, - OPCODE_MSTORE8=GAS_VERY_LOW, - OPCODE_PUSH=GAS_VERY_LOW, - OPCODE_DUP=GAS_VERY_LOW, - OPCODE_SWAP=GAS_VERY_LOW, + BLOCK_ACCESS_LIST_ITEM=0, ) @classmethod @@ -265,9 +276,9 @@ def wrapper(opcode: OpcodeBase) -> int: # Add account access cost based on warmth if opcode.metadata["address_warm"]: - access_cost = gas_costs.GAS_WARM_ACCESS + access_cost = gas_costs.WARM_ACCESS else: - access_cost = gas_costs.GAS_COLD_ACCOUNT_ACCESS + access_cost = gas_costs.COLD_ACCOUNT_ACCESS return base_cost + access_cost @@ -285,7 +296,7 @@ def _with_data_copy( Args: base_gas: Either a constant gas cost (int) or a callable that calculates it - gas_costs: The gas costs dataclass for accessing GAS_COPY + gas_costs: The gas costs dataclass for accessing COPY Returns: A callable that calculates base_gas + copy_cost @@ -302,7 +313,7 @@ def wrapper(opcode: OpcodeBase) -> int: # Add copy cost based on data size data_size = opcode.metadata["data_size"] word_count = (data_size + 31) // 32 - copy_cost = gas_costs.GAS_COPY * word_count + copy_cost = gas_costs.COPY * word_count return base_cost + copy_cost @@ -340,8 +351,8 @@ def opcode_gas_map( Opcodes.ADDMOD: gas_costs.OPCODE_ADDMOD, Opcodes.MULMOD: gas_costs.OPCODE_MULMOD, Opcodes.EXP: lambda op: ( - gas_costs.GAS_EXPONENTIATION - + gas_costs.GAS_EXPONENTIATION_PER_BYTE + gas_costs.EXPONENTIATION + + gas_costs.EXPONENTIATION_PER_BYTE * ((op.metadata["exponent"].bit_length() + 7) // 8) ), Opcodes.SIGNEXTEND: gas_costs.OPCODE_SIGNEXTEND, @@ -360,30 +371,30 @@ def opcode_gas_map( # SHA3 Opcodes.SHA3: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_KECCAK256 - + gas_costs.GAS_KECCAK256_PER_WORD + gas_costs.KECCAK256 + + gas_costs.KECCAK256_PER_WORD * ((op.metadata["data_size"] + 31) // 32) ), memory_expansion_calculator, ), # Environmental information - Opcodes.ADDRESS: gas_costs.GAS_BASE, + Opcodes.ADDRESS: gas_costs.BASE, Opcodes.BALANCE: cls._with_account_access(0, gas_costs), - Opcodes.ORIGIN: gas_costs.GAS_BASE, - Opcodes.CALLER: gas_costs.GAS_BASE, - Opcodes.CALLVALUE: gas_costs.GAS_BASE, + Opcodes.ORIGIN: gas_costs.BASE, + Opcodes.CALLER: gas_costs.BASE, + Opcodes.CALLVALUE: gas_costs.BASE, Opcodes.CALLDATALOAD: gas_costs.OPCODE_CALLDATALOAD, - Opcodes.CALLDATASIZE: gas_costs.GAS_BASE, + Opcodes.CALLDATASIZE: gas_costs.BASE, Opcodes.CALLDATACOPY: cls._with_memory_expansion( cls._with_data_copy(gas_costs.OPCODE_CALLDATACOPY, gas_costs), memory_expansion_calculator, ), - Opcodes.CODESIZE: gas_costs.GAS_BASE, + Opcodes.CODESIZE: gas_costs.BASE, Opcodes.CODECOPY: cls._with_memory_expansion( cls._with_data_copy(gas_costs.OPCODE_CODECOPY, gas_costs), memory_expansion_calculator, ), - Opcodes.GASPRICE: gas_costs.GAS_BASE, + Opcodes.GASPRICE: gas_costs.BASE, Opcodes.EXTCODESIZE: cls._with_account_access(0, gas_costs), Opcodes.EXTCODECOPY: cls._with_memory_expansion( cls._with_data_copy( @@ -394,13 +405,13 @@ def opcode_gas_map( ), # Block information Opcodes.BLOCKHASH: gas_costs.OPCODE_BLOCKHASH, - Opcodes.COINBASE: gas_costs.GAS_BASE, - Opcodes.TIMESTAMP: gas_costs.GAS_BASE, - Opcodes.NUMBER: gas_costs.GAS_BASE, - Opcodes.PREVRANDAO: gas_costs.GAS_BASE, - Opcodes.GASLIMIT: gas_costs.GAS_BASE, + Opcodes.COINBASE: gas_costs.OPCODE_COINBASE, + Opcodes.TIMESTAMP: gas_costs.BASE, + Opcodes.NUMBER: gas_costs.BASE, + Opcodes.PREVRANDAO: gas_costs.BASE, + Opcodes.GASLIMIT: gas_costs.BASE, # Stack, memory, storage and flow operations - Opcodes.POP: gas_costs.GAS_BASE, + Opcodes.POP: gas_costs.BASE, Opcodes.MLOAD: cls._with_memory_expansion( gas_costs.OPCODE_MLOAD, memory_expansion_calculator, @@ -414,18 +425,18 @@ def opcode_gas_map( memory_expansion_calculator, ), Opcodes.SLOAD: lambda op: ( - gas_costs.GAS_WARM_SLOAD + gas_costs.WARM_SLOAD if op.metadata["key_warm"] - else gas_costs.GAS_COLD_STORAGE_ACCESS + else gas_costs.COLD_STORAGE_ACCESS ), Opcodes.SSTORE: lambda op: cls._calculate_sstore_gas( op, gas_costs ), Opcodes.JUMP: gas_costs.OPCODE_JUMP, Opcodes.JUMPI: gas_costs.OPCODE_JUMPI, - Opcodes.PC: gas_costs.GAS_BASE, - Opcodes.MSIZE: gas_costs.GAS_BASE, - Opcodes.GAS: gas_costs.GAS_BASE, + Opcodes.PC: gas_costs.BASE, + Opcodes.MSIZE: gas_costs.BASE, + Opcodes.GAS: gas_costs.BASE, Opcodes.JUMPDEST: gas_costs.OPCODE_JUMPDEST, # Push operations (PUSH1 through PUSH32) **{ @@ -445,45 +456,40 @@ def opcode_gas_map( # Logging operations Opcodes.LOG0: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_LOG - + gas_costs.GAS_LOG_DATA_PER_BYTE - * op.metadata["data_size"] + gas_costs.LOG + + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] ), memory_expansion_calculator, ), Opcodes.LOG1: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_LOG - + gas_costs.GAS_LOG_DATA_PER_BYTE - * op.metadata["data_size"] - + gas_costs.GAS_LOG_TOPIC + gas_costs.LOG + + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] + + gas_costs.LOG_TOPIC ), memory_expansion_calculator, ), Opcodes.LOG2: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_LOG - + gas_costs.GAS_LOG_DATA_PER_BYTE - * op.metadata["data_size"] - + gas_costs.GAS_LOG_TOPIC * 2 + gas_costs.LOG + + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] + + gas_costs.LOG_TOPIC * 2 ), memory_expansion_calculator, ), Opcodes.LOG3: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_LOG - + gas_costs.GAS_LOG_DATA_PER_BYTE - * op.metadata["data_size"] - + gas_costs.GAS_LOG_TOPIC * 3 + gas_costs.LOG + + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] + + gas_costs.LOG_TOPIC * 3 ), memory_expansion_calculator, ), Opcodes.LOG4: cls._with_memory_expansion( lambda op: ( - gas_costs.GAS_LOG - + gas_costs.GAS_LOG_DATA_PER_BYTE - * op.metadata["data_size"] - + gas_costs.GAS_LOG_TOPIC * 4 + gas_costs.LOG + + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] + + gas_costs.LOG_TOPIC * 4 ), memory_expansion_calculator, ), @@ -606,15 +612,13 @@ def _calculate_sstore_refund( # Storage slot being restored to its original value if original_value == 0: # Slot was originally empty and was SET earlier - refund += ( - gas_costs.GAS_STORAGE_SET - gas_costs.GAS_WARM_SLOAD - ) + refund += gas_costs.STORAGE_SET - gas_costs.WARM_SLOAD else: # Slot was originally non-empty and was UPDATED earlier refund += ( - gas_costs.GAS_COLD_STORAGE_WRITE - - gas_costs.GAS_COLD_STORAGE_ACCESS - - gas_costs.GAS_WARM_SLOAD + gas_costs.COLD_STORAGE_WRITE + - gas_costs.COLD_STORAGE_ACCESS + - gas_costs.WARM_SLOAD ) return refund @@ -632,20 +636,18 @@ def _calculate_sstore_gas( current_value = original_value new_value = metadata["new_value"] - gas_cost = ( - 0 if metadata["key_warm"] else gas_costs.GAS_COLD_STORAGE_ACCESS - ) + gas_cost = 0 if metadata["key_warm"] else gas_costs.COLD_STORAGE_ACCESS if original_value == current_value and current_value != new_value: if original_value == 0: - gas_cost += gas_costs.GAS_STORAGE_SET + gas_cost += gas_costs.STORAGE_SET else: gas_cost += ( - gas_costs.GAS_COLD_STORAGE_WRITE - - gas_costs.GAS_COLD_STORAGE_ACCESS + gas_costs.COLD_STORAGE_WRITE + - gas_costs.COLD_STORAGE_ACCESS ) else: - gas_cost += gas_costs.GAS_WARM_SLOAD + gas_cost += gas_costs.WARM_SLOAD return gas_cost @@ -660,9 +662,9 @@ def _calculate_call_gas( # Base cost depends on address warmth if metadata["address_warm"]: - base_cost = gas_costs.GAS_WARM_ACCESS + base_cost = gas_costs.WARM_ACCESS else: - base_cost = gas_costs.GAS_COLD_ACCOUNT_ACCESS + base_cost = gas_costs.COLD_ACCOUNT_ACCESS return base_cost @@ -672,7 +674,7 @@ def _calculate_create_gas( ) -> int: """CREATE gas is constant at Frontier.""" del opcode - return gas_costs.GAS_CREATE + return gas_costs.CREATE @classmethod def _calculate_create2_gas( @@ -694,7 +696,7 @@ def _calculate_return_gas( # Code deposit cost when returning from initcode code_deposit_size = metadata["code_deposit_size"] - return gas_costs.GAS_CODE_DEPOSIT_PER_BYTE * code_deposit_size + return gas_costs.CODE_DEPOSIT_PER_BYTE * code_deposit_size @classmethod def _calculate_selfdestruct_gas( @@ -703,15 +705,15 @@ def _calculate_selfdestruct_gas( """Calculate SELFDESTRUCT gas cost based on metadata.""" metadata = opcode.metadata - base_cost = gas_costs.GAS_SELF_DESTRUCT + base_cost = gas_costs.OPCODE_SELFDESTRUCT # Check if the beneficiary is cold if not metadata["address_warm"]: - base_cost += gas_costs.GAS_COLD_ACCOUNT_ACCESS + base_cost += gas_costs.COLD_ACCOUNT_ACCESS # Check if creating a new account if metadata["account_new"]: - base_cost += gas_costs.GAS_NEW_ACCOUNT + base_cost += gas_costs.NEW_ACCOUNT return base_cost @@ -730,7 +732,7 @@ def fn(*, new_bytes: int, previous_bytes: int = 0) -> int: previous_words = ceiling_division(previous_bytes, 32) def c(w: int) -> int: - return (gas_costs.GAS_MEMORY * w) + ((w * w) // 512) + return (gas_costs.MEMORY * w) + ((w * w) // 512) return c(new_words) - c(previous_words) @@ -751,8 +753,8 @@ def fn(*, data: BytesConvertible, floor: bool = False) -> int: num_zeros = raw.count(0) num_non_zeros = len(raw) - num_zeros return ( - num_zeros * gas_costs.GAS_TX_DATA_PER_ZERO - + num_non_zeros * gas_costs.GAS_TX_DATA_PER_NON_ZERO + num_zeros * gas_costs.TX_DATA_PER_ZERO + + num_non_zeros * gas_costs.TX_DATA_PER_NON_ZERO ) return fn @@ -830,11 +832,11 @@ def fn( f"Authorizations are not supported in {cls.name()}" ) - intrinsic_cost: int = gas_costs.GAS_TX_BASE + intrinsic_cost: int = gas_costs.TX_BASE if contract_creation: intrinsic_cost += ( - gas_costs.GAS_CODE_INIT_PER_WORD + gas_costs.CODE_INIT_PER_WORD * ceiling_division(len(Bytes(calldata)), 32) ) diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 777b44a8a8d..5c1c4bdce18 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -3,64 +3,74 @@ from dataclasses import dataclass # Common Gas Cost Tiers -GAS_VERY_LOW = 3 -GAS_LOW = 5 -GAS_MID = 8 -GAS_HIGH = 10 +BASE = 2 +VERY_LOW = 3 +LOW = 5 +MID = 8 +HIGH = 10 @dataclass(kw_only=True, frozen=True) class GasCosts: """Class that contains the gas cost constants for any fork.""" - GAS_BASE: int - GAS_VERY_LOW: int - GAS_LOW: int - GAS_MID: int - GAS_HIGH: int - GAS_WARM_ACCESS: int - GAS_COLD_ACCOUNT_ACCESS: int - GAS_TX_ACCESS_LIST_ADDRESS: int - GAS_TX_ACCESS_LIST_STORAGE_KEY: int - GAS_WARM_SLOAD: int - GAS_COLD_STORAGE_ACCESS: int - GAS_STORAGE_SET: int - GAS_COLD_STORAGE_WRITE: int - GAS_STORAGE_RESET: int - - GAS_SELF_DESTRUCT: int - GAS_CREATE: int - - GAS_CODE_DEPOSIT_PER_BYTE: int - GAS_CODE_INIT_PER_WORD: int - - GAS_CALL_VALUE: int - GAS_CALL_STIPEND: int - GAS_NEW_ACCOUNT: int - - GAS_EXPONENTIATION: int - GAS_EXPONENTIATION_PER_BYTE: int - - GAS_MEMORY: int - GAS_TX_BASE: int - GAS_TX_CREATE: int - GAS_TX_DATA_PER_ZERO: int - GAS_TX_DATA_PER_NON_ZERO: int - GAS_TX_DATA_TOKEN_STANDARD: int - GAS_TX_DATA_TOKEN_FLOOR: int - - GAS_LOG: int - GAS_LOG_DATA_PER_BYTE: int - GAS_LOG_TOPIC: int - - GAS_KECCAK256: int - GAS_KECCAK256_PER_WORD: int - - GAS_COPY: int - - GAS_AUTH_PER_EMPTY_ACCOUNT: int - - # Precompiled contract gas constants + # Tiers + BASE: int + VERY_LOW: int + LOW: int + MID: int + HIGH: int + + # Access Costs + WARM_ACCESS: int + COLD_ACCOUNT_ACCESS: int + WARM_SLOAD: int + COLD_STORAGE_ACCESS: int + + # Storage Costs + STORAGE_SET: int + COLD_STORAGE_WRITE: int + STORAGE_RESET: int + + # Call Costs + CALL_VALUE: int + CALL_STIPEND: int + NEW_ACCOUNT: int + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE: int + CODE_INIT_PER_WORD: int + + # Authorization Costs + AUTH_PER_EMPTY_ACCOUNT: int + + # Component Costs for Dynamic Opcodes + COPY: int + CREATE: int + MEMORY: int + EXPONENTIATION: int + EXPONENTIATION_PER_BYTE: int + LOG: int + LOG_DATA_PER_BYTE: int + LOG_TOPIC: int + KECCAK256: int + KECCAK256_PER_WORD: int + + # Transactions + TX_BASE: int + TX_CREATE: int + TX_DATA_PER_ZERO: int + TX_DATA_PER_NON_ZERO: int + TX_DATA_TOKEN_STANDARD: int + TX_DATA_TOKEN_FLOOR: int + TX_ACCESS_LIST_ADDRESS: int + TX_ACCESS_LIST_STORAGE_KEY: int + + # Refunds + REFUND_STORAGE_CLEAR: int + REFUND_AUTH_PER_EXISTING_ACCOUNT: int + + # Precompiles PRECOMPILE_ECRECOVER: int PRECOMPILE_SHA256_BASE: int PRECOMPILE_SHA256_PER_WORD: int @@ -68,17 +78,13 @@ class GasCosts: PRECOMPILE_RIPEMD160_PER_WORD: int PRECOMPILE_IDENTITY_BASE: int PRECOMPILE_IDENTITY_PER_WORD: int - PRECOMPILE_ECADD: int PRECOMPILE_ECMUL: int PRECOMPILE_ECPAIRING_BASE: int PRECOMPILE_ECPAIRING_PER_POINT: int - PRECOMPILE_BLAKE2F_BASE: int PRECOMPILE_BLAKE2F_PER_ROUND: int - PRECOMPILE_POINT_EVALUATION: int - PRECOMPILE_BLS_G1ADD: int PRECOMPILE_BLS_G1MUL: int PRECOMPILE_BLS_G1MAP: int @@ -87,16 +93,12 @@ class GasCosts: PRECOMPILE_BLS_G2MAP: int PRECOMPILE_BLS_PAIRING_BASE: int PRECOMPILE_BLS_PAIRING_PER_PAIR: int - PRECOMPILE_P256VERIFY: int - # Refund constants - REFUND_STORAGE_CLEAR: int - REFUND_AUTH_PER_EXISTING_ACCOUNT: int - - GAS_BLOCK_ACCESS_LIST_ITEM: int + # Block Access Lists + BLOCK_ACCESS_LIST_ITEM: int - # Opcode specific gas constants for repricing + # Opcodes OPCODE_ADD: int OPCODE_SUB: int OPCODE_MUL: int @@ -122,15 +124,19 @@ class GasCosts: OPCODE_JUMPI: int OPCODE_JUMPDEST: int OPCODE_CALLDATALOAD: int + OPCODE_BLOCKHASH: int + OPCODE_COINBASE: int + OPCODE_PUSH: int + OPCODE_DUP: int + OPCODE_SWAP: int + + # Dynamic Opcodes OPCODE_CALLDATACOPY: int OPCODE_CODECOPY: int - OPCODE_BLOCKHASH: int OPCODE_MLOAD: int OPCODE_MSTORE: int OPCODE_MSTORE8: int - OPCODE_PUSH: int - OPCODE_DUP: int - OPCODE_SWAP: int + OPCODE_SELFDESTRUCT: int # Defined post-Frontier OPCODE_SHL: int = 0 diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 39fb7ac2279..62b3944492e 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -15,55 +15,55 @@ Osaka, Op.MSTORE(new_memory_size=1), Osaka.memory_expansion_gas_calculator()(new_bytes=1) - + Osaka.gas_costs().GAS_VERY_LOW, + + Osaka.gas_costs().VERY_LOW, id="mstore_memory_expansion", ), pytest.param( Osaka, Op.SSTORE, - Osaka.gas_costs().GAS_STORAGE_SET - + Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS, + Osaka.gas_costs().STORAGE_SET + + Osaka.gas_costs().COLD_STORAGE_ACCESS, id="sstore_defaults", ), pytest.param( Osaka, Op.SSTORE(key_warm=True), - Osaka.gas_costs().GAS_STORAGE_SET, + Osaka.gas_costs().STORAGE_SET, id="sstore_warm_key", ), # EXP tests pytest.param( Osaka, Op.EXP(exponent=0), - Osaka.gas_costs().GAS_EXPONENTIATION, + Osaka.gas_costs().EXPONENTIATION, id="exp_zero_exponent", ), pytest.param( Osaka, Op.EXP(exponent=0xFFFFFF), # 3 bytes - Osaka.gas_costs().GAS_EXPONENTIATION - + Osaka.gas_costs().GAS_EXPONENTIATION_PER_BYTE * 3, + Osaka.gas_costs().EXPONENTIATION + + Osaka.gas_costs().EXPONENTIATION_PER_BYTE * 3, id="exp_three_bytes", ), pytest.param( Osaka, Op.EXP(exponent=0x1FFFFFF), # 3 bytes - Osaka.gas_costs().GAS_EXPONENTIATION - + Osaka.gas_costs().GAS_EXPONENTIATION_PER_BYTE * 4, + Osaka.gas_costs().EXPONENTIATION + + Osaka.gas_costs().EXPONENTIATION_PER_BYTE * 4, id="exp_three_bytes_plus_one_bit", ), # SHA3 tests pytest.param( Osaka, Op.SHA3(data_size=0), - Osaka.gas_costs().GAS_KECCAK256, + Osaka.gas_costs().KECCAK256, id="sha3_zero_data", ), pytest.param( Osaka, Op.SHA3(data_size=64, new_memory_size=96), - Osaka.gas_costs().GAS_KECCAK256 - + Osaka.gas_costs().GAS_KECCAK256_PER_WORD * 2 + Osaka.gas_costs().KECCAK256 + + Osaka.gas_costs().KECCAK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="sha3_with_data_and_memory", ), @@ -71,21 +71,21 @@ pytest.param( Osaka, Op.BALANCE(address_warm=False), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS, id="balance_cold_address", ), pytest.param( Osaka, Op.BALANCE(address_warm=True), - Osaka.gas_costs().GAS_WARM_ACCESS, + Osaka.gas_costs().WARM_ACCESS, id="balance_warm_address", ), # CALLDATACOPY tests pytest.param( Osaka, Op.CALLDATACOPY(data_size=32, new_memory_size=32), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 1 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="calldatacopy_one_word", ), @@ -94,8 +94,8 @@ Op.CALLDATACOPY( data_size=64, new_memory_size=64, old_memory_size=32 ), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 2 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 2 + Osaka.memory_expansion_gas_calculator()( new_bytes=64, previous_bytes=32 ), @@ -105,8 +105,8 @@ pytest.param( Osaka, Op.CODECOPY(data_size=96, new_memory_size=96), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 3 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="codecopy_three_words", ), @@ -114,13 +114,13 @@ pytest.param( Osaka, Op.EXTCODESIZE(address_warm=False), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS, id="extcodesize_cold", ), pytest.param( Osaka, Op.EXTCODESIZE(address_warm=True), - Osaka.gas_costs().GAS_WARM_ACCESS, + Osaka.gas_costs().WARM_ACCESS, id="extcodesize_warm", ), # EXTCODECOPY tests @@ -129,8 +129,8 @@ Op.EXTCODECOPY( address_warm=True, data_size=32, new_memory_size=32 ), - Osaka.gas_costs().GAS_WARM_ACCESS - + Osaka.gas_costs().GAS_COPY * 1 + Osaka.gas_costs().WARM_ACCESS + + Osaka.gas_costs().COPY * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="extcodecopy_warm", ), @@ -139,8 +139,8 @@ Op.EXTCODECOPY( address_warm=False, data_size=64, new_memory_size=64 ), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_COPY * 2 + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().COPY * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="extcodecopy_cold", ), @@ -148,21 +148,21 @@ pytest.param( Osaka, Op.EXTCODEHASH(address_warm=False), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS, id="extcodehash_cold", ), pytest.param( Osaka, Op.EXTCODEHASH(address_warm=True), - Osaka.gas_costs().GAS_WARM_ACCESS, + Osaka.gas_costs().WARM_ACCESS, id="extcodehash_warm", ), # RETURNDATACOPY tests pytest.param( Osaka, Op.RETURNDATACOPY(data_size=32, new_memory_size=32), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 1 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="returndatacopy", ), @@ -170,7 +170,7 @@ pytest.param( Osaka, Op.MLOAD(new_memory_size=32), - Osaka.gas_costs().GAS_VERY_LOW + Osaka.gas_costs().VERY_LOW + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="mload_memory_expansion", ), @@ -178,7 +178,7 @@ pytest.param( Osaka, Op.MSTORE8(new_memory_size=1), - Osaka.gas_costs().GAS_VERY_LOW + Osaka.gas_costs().VERY_LOW + Osaka.memory_expansion_gas_calculator()(new_bytes=1), id="mstore8_memory_expansion", ), @@ -186,29 +186,29 @@ pytest.param( Osaka, Op.SLOAD(key_warm=False), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS, + Osaka.gas_costs().COLD_STORAGE_ACCESS, id="sload_cold", ), pytest.param( Osaka, Op.SLOAD(key_warm=True), - Osaka.gas_costs().GAS_WARM_SLOAD, + Osaka.gas_costs().WARM_SLOAD, id="sload_warm", ), # MCOPY tests pytest.param( Osaka, Op.MCOPY(data_size=32, new_memory_size=32), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 1 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="mcopy_one_word", ), pytest.param( Osaka, Op.MCOPY(data_size=96, new_memory_size=128, old_memory_size=64), - Osaka.gas_costs().GAS_VERY_LOW - + Osaka.gas_costs().GAS_COPY * 3 + Osaka.gas_costs().VERY_LOW + + Osaka.gas_costs().COPY * 3 + Osaka.memory_expansion_gas_calculator()( new_bytes=128, previous_bytes=64 ), @@ -218,8 +218,8 @@ pytest.param( Osaka, Op.LOG0(data_size=32, new_memory_size=32), - Osaka.gas_costs().GAS_LOG - + Osaka.gas_costs().GAS_LOG_DATA_PER_BYTE * 32 + Osaka.gas_costs().LOG + + Osaka.gas_costs().LOG_DATA_PER_BYTE * 32 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="log0", ), @@ -227,9 +227,9 @@ pytest.param( Osaka, Op.LOG1(data_size=64, new_memory_size=64), - Osaka.gas_costs().GAS_LOG - + Osaka.gas_costs().GAS_LOG_DATA_PER_BYTE * 64 - + Osaka.gas_costs().GAS_LOG_TOPIC + Osaka.gas_costs().LOG + + Osaka.gas_costs().LOG_DATA_PER_BYTE * 64 + + Osaka.gas_costs().LOG_TOPIC + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="log1", ), @@ -237,9 +237,9 @@ pytest.param( Osaka, Op.LOG2(data_size=128, new_memory_size=128), - Osaka.gas_costs().GAS_LOG - + Osaka.gas_costs().GAS_LOG_DATA_PER_BYTE * 128 - + Osaka.gas_costs().GAS_LOG_TOPIC * 2 + Osaka.gas_costs().LOG + + Osaka.gas_costs().LOG_DATA_PER_BYTE * 128 + + Osaka.gas_costs().LOG_TOPIC * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=128), id="log2", ), @@ -247,9 +247,9 @@ pytest.param( Osaka, Op.LOG3(data_size=256, new_memory_size=256), - Osaka.gas_costs().GAS_LOG - + Osaka.gas_costs().GAS_LOG_DATA_PER_BYTE * 256 - + Osaka.gas_costs().GAS_LOG_TOPIC * 3 + Osaka.gas_costs().LOG + + Osaka.gas_costs().LOG_DATA_PER_BYTE * 256 + + Osaka.gas_costs().LOG_TOPIC * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=256), id="log3", ), @@ -257,9 +257,9 @@ pytest.param( Osaka, Op.LOG4(data_size=512, new_memory_size=512), - Osaka.gas_costs().GAS_LOG - + Osaka.gas_costs().GAS_LOG_DATA_PER_BYTE * 512 - + Osaka.gas_costs().GAS_LOG_TOPIC * 4 + Osaka.gas_costs().LOG + + Osaka.gas_costs().LOG_DATA_PER_BYTE * 512 + + Osaka.gas_costs().LOG_TOPIC * 4 + Osaka.memory_expansion_gas_calculator()(new_bytes=512), id="log4", ), @@ -267,9 +267,9 @@ pytest.param( Osaka, Op.CREATE(init_code_size=100, new_memory_size=100), - Osaka.gas_costs().GAS_CREATE + Osaka.gas_costs().CREATE # (100 + 31) // 32 = 4 - + Osaka.gas_costs().GAS_CODE_INIT_PER_WORD * 4 + + Osaka.gas_costs().CODE_INIT_PER_WORD * 4 + Osaka.memory_expansion_gas_calculator()(new_bytes=100), id="create_with_initcode", ), @@ -277,9 +277,9 @@ pytest.param( Osaka, Op.CREATE2(init_code_size=64, new_memory_size=64), - Osaka.gas_costs().GAS_CREATE - + Osaka.gas_costs().GAS_CODE_INIT_PER_WORD * 2 - + Osaka.gas_costs().GAS_KECCAK256_PER_WORD * 2 + Osaka.gas_costs().CREATE + + Osaka.gas_costs().CODE_INIT_PER_WORD * 2 + + Osaka.gas_costs().KECCAK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="create2_with_initcode_and_hash", ), @@ -289,15 +289,15 @@ Op.CALL( address_warm=True, value_transfer=False, new_memory_size=64 ), - Osaka.gas_costs().GAS_WARM_ACCESS + Osaka.gas_costs().WARM_ACCESS + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="call_warm_no_value", ), pytest.param( Osaka, Op.CALL(address_warm=False, delegated_address=True), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().COLD_ACCOUNT_ACCESS, id="call_cold_delegated_address", ), pytest.param( @@ -307,22 +307,22 @@ delegated_address=True, delegated_address_warm=True, ), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_WARM_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().WARM_ACCESS, id="call_warm_delegated_address", ), pytest.param( Osaka, Op.CALL(address_warm=False, value_transfer=True, account_new=True), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_CALL_VALUE - + Osaka.gas_costs().GAS_NEW_ACCOUNT, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().CALL_VALUE + + Osaka.gas_costs().NEW_ACCOUNT, id="call_cold_account_new", ), pytest.param( Homestead, Op.CALL(address_warm=False, value_transfer=True, account_new=True), - Homestead.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Homestead.gas_costs().COLD_ACCOUNT_ACCESS, id="call_cold_account_new_homestead", ), pytest.param( @@ -333,8 +333,8 @@ account_new=False, new_memory_size=32, ), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_CALL_VALUE + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().CALL_VALUE + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="call_cold_with_value", ), @@ -346,9 +346,9 @@ account_new=True, new_memory_size=32, ), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().GAS_CALL_VALUE - + Osaka.gas_costs().GAS_NEW_ACCOUNT + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + + Osaka.gas_costs().CALL_VALUE + + Osaka.gas_costs().NEW_ACCOUNT + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="call_cold_new_account", ), @@ -358,7 +358,7 @@ Op.CALLCODE( address_warm=True, value_transfer=False, new_memory_size=32 ), - Osaka.gas_costs().GAS_WARM_ACCESS + Osaka.gas_costs().WARM_ACCESS + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="callcode_warm", ), @@ -366,14 +366,14 @@ pytest.param( Osaka, Op.DELEGATECALL(address_warm=True, new_memory_size=32), - Osaka.gas_costs().GAS_WARM_ACCESS + Osaka.gas_costs().WARM_ACCESS + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="delegatecall_warm", ), pytest.param( Osaka, Op.DELEGATECALL(address_warm=False, new_memory_size=64), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS + Osaka.gas_costs().COLD_ACCOUNT_ACCESS + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="delegatecall_cold", ), @@ -381,14 +381,14 @@ pytest.param( Osaka, Op.STATICCALL(address_warm=True, new_memory_size=32), - Osaka.gas_costs().GAS_WARM_ACCESS + Osaka.gas_costs().WARM_ACCESS + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="staticcall_warm", ), pytest.param( Osaka, Op.STATICCALL(address_warm=False, new_memory_size=0), - Osaka.gas_costs().GAS_COLD_ACCOUNT_ACCESS, + Osaka.gas_costs().COLD_ACCOUNT_ACCESS, id="staticcall_cold_no_memory", ), # RETURN tests @@ -401,7 +401,7 @@ pytest.param( Osaka, Op.RETURN(code_deposit_size=100, new_memory_size=32), - Osaka.gas_costs().GAS_CODE_DEPOSIT_PER_BYTE * 100 + Osaka.gas_costs().CODE_DEPOSIT_PER_BYTE * 100 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="return_with_code_deposit", ), @@ -416,7 +416,7 @@ pytest.param( Osaka, Op.CLZ, - Osaka.gas_costs().GAS_LOW, + Osaka.gas_costs().LOW, id="clz_osaka", ), ], @@ -432,20 +432,19 @@ def test_opcode_gas_costs(fork: Fork, opcode: Op, expected_cost: int) -> None: pytest.param( Osaka, Op.ADD + Op.SUB, - Osaka.gas_costs().GAS_VERY_LOW * 2, + Osaka.gas_costs().VERY_LOW * 2, id="sum_of_opcodes", ), pytest.param( Osaka, Op.ADD(1, 1), - Osaka.gas_costs().GAS_VERY_LOW * 3, + Osaka.gas_costs().VERY_LOW * 3, id="opcode_with_args", ), pytest.param( Osaka, Op.SSTORE(1, 2, key_warm=True), - Osaka.gas_costs().GAS_STORAGE_SET - + Osaka.gas_costs().GAS_VERY_LOW * 2, + Osaka.gas_costs().STORAGE_SET + Osaka.gas_costs().VERY_LOW * 2, id="opcode_with_metadata", ), ], @@ -540,69 +539,69 @@ def test_bytecode_refunds( # noqa: D103 pytest.param( Osaka, Op.SSTORE(key_warm=True, original_value=0, new_value=0), - Osaka.gas_costs().GAS_WARM_SLOAD, + Osaka.gas_costs().WARM_SLOAD, id="sstore_noop_zero_warm", # 0 → 0 ), pytest.param( Osaka, Op.SSTORE(key_warm=False, original_value=0, new_value=0), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS - + Osaka.gas_costs().GAS_WARM_SLOAD, + Osaka.gas_costs().COLD_STORAGE_ACCESS + + Osaka.gas_costs().WARM_SLOAD, id="sstore_noop_zero_cold", # 0 → 0 ), pytest.param( Osaka, Op.SSTORE(key_warm=True, original_value=5, new_value=5), - Osaka.gas_costs().GAS_WARM_SLOAD, + Osaka.gas_costs().WARM_SLOAD, id="sstore_noop_nonzero_warm", # 5 → 5 ), pytest.param( Osaka, Op.SSTORE(key_warm=False, original_value=5, new_value=5), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS - + Osaka.gas_costs().GAS_WARM_SLOAD, + Osaka.gas_costs().COLD_STORAGE_ACCESS + + Osaka.gas_costs().WARM_SLOAD, id="sstore_noop_nonzero_cold", # 5 → 5 ), # Create storage: 0 → X (original == 0) pytest.param( Osaka, Op.SSTORE(key_warm=True, new_value=5), - Osaka.gas_costs().GAS_STORAGE_SET, + Osaka.gas_costs().STORAGE_SET, id="sstore_create_warm", # 0 → 5 ), pytest.param( Osaka, Op.SSTORE(key_warm=False, new_value=5), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS - + Osaka.gas_costs().GAS_STORAGE_SET, + Osaka.gas_costs().COLD_STORAGE_ACCESS + + Osaka.gas_costs().STORAGE_SET, id="sstore_create_cold", # 0 → 5 ), # Modify storage: X → Y (original != 0, new != 0, new != original) pytest.param( Osaka, Op.SSTORE(key_warm=True, original_value=5, new_value=7), - Osaka.gas_costs().GAS_STORAGE_RESET, + Osaka.gas_costs().STORAGE_RESET, id="sstore_modify_warm", # 5 → 7 ), pytest.param( Osaka, Op.SSTORE(key_warm=False, original_value=5, new_value=7), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS - + Osaka.gas_costs().GAS_STORAGE_RESET, + Osaka.gas_costs().COLD_STORAGE_ACCESS + + Osaka.gas_costs().STORAGE_RESET, id="sstore_modify_cold", # 5 → 7 ), # Clear storage: X → 0 (original != 0, new == 0) pytest.param( Osaka, Op.SSTORE(key_warm=True, original_value=5, new_value=0), - Osaka.gas_costs().GAS_STORAGE_RESET, + Osaka.gas_costs().STORAGE_RESET, id="sstore_clear_warm", # 5 → 0 ), pytest.param( Osaka, Op.SSTORE(key_warm=False, original_value=5, new_value=0), - Osaka.gas_costs().GAS_COLD_STORAGE_ACCESS - + Osaka.gas_costs().GAS_STORAGE_RESET, + Osaka.gas_costs().COLD_STORAGE_ACCESS + + Osaka.gas_costs().STORAGE_RESET, id="sstore_clear_cold", # 5 → 0 ), ], diff --git a/packages/testing/src/execution_testing/tools/utility/generators.py b/packages/testing/src/execution_testing/tools/utility/generators.py index 56dcfcda034..78a9f172c51 100644 --- a/packages/testing/src/execution_testing/tools/utility/generators.py +++ b/packages/testing/src/execution_testing/tools/utility/generators.py @@ -358,9 +358,9 @@ def wrapper( # code will only work once, so if the system contract is re- # executed in a subsequent block, it will consume less gas. gas_used_per_storage = ( - gas_costs.GAS_STORAGE_SET - + gas_costs.GAS_COLD_STORAGE_ACCESS - + (gas_costs.GAS_VERY_LOW * 2) + gas_costs.STORAGE_SET + + gas_costs.COLD_STORAGE_ACCESS + + (gas_costs.VERY_LOW * 2) ) modified_system_contract_code += sum( Op.SSTORE(i, 1) @@ -506,13 +506,13 @@ def gas_test( # 2 times GAS, POP, CALL, 6 times PUSH1 - instructions charged for at every # gas run gas_costs = fork.gas_costs() - opcode_gas_cost = gas_costs.GAS_BASE - opcode_pop_cost = gas_costs.GAS_BASE - opcode_push_cost = gas_costs.GAS_VERY_LOW + opcode_gas_cost = gas_costs.BASE + opcode_pop_cost = gas_costs.BASE + opcode_push_cost = gas_costs.VERY_LOW gas_single_gas_run = ( 2 * opcode_gas_cost + opcode_pop_cost - + gas_costs.GAS_WARM_ACCESS + + gas_costs.WARM_ACCESS + 6 * opcode_push_cost ) address_legacy_harness = pre.deploy_contract( diff --git a/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py b/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py index 87a8907b048..ba4fbd5f221 100644 --- a/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py +++ b/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py @@ -2670,7 +2670,7 @@ def test_bal_gas_limit_boundary( Test the BAL max items gas limit boundary for an empty block. The consensus rule requires - ``bal_items <= block_gas_limit // GAS_BLOCK_ACCESS_LIST_ITEM``. + ``bal_items <= block_gas_limit // BLOCK_ACCESS_LIST_ITEM``. The boundary gas limit is derived from the fork's system-contract BAL footprint. At the boundary the check passes; one below it fails. """ @@ -2678,7 +2678,7 @@ def test_bal_gas_limit_boundary( # bal_items <= block_gas_limit // ITEM_COST min_gas_limit = ( fork.empty_block_bal_item_count() - * fork.gas_costs().GAS_BLOCK_ACCESS_LIST_ITEM + * fork.gas_costs().BLOCK_ACCESS_LIST_ITEM ) gas_limit = min_gas_limit + boundary_offset diff --git a/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py b/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py index 68321d8e3b1..adcbba9b944 100644 --- a/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py +++ b/tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py @@ -124,16 +124,16 @@ def test_bal_sstore_and_oog( intrinsic_gas_cost = fork.transaction_intrinsic_cost_calculator()() - # Full cost: PUSHes + SSTORE (GAS_COLD_STORAGE_ACCESS + GAS_STORAGE_SET) + # Full cost: PUSHes + SSTORE (COLD_STORAGE_ACCESS + STORAGE_SET) full_cost = storage_contract_code.gas_cost(fork) # Push cost for stipend boundary calculations push_code = Op.PUSH1(0x42) + Op.PUSH1(0x01) push_cost = push_code.gas_cost(fork) - # GAS_CALL_STIPEND is a threshold check, not a gas cost + # CALL_STIPEND is a threshold check, not a gas cost # Keep from gas_costs - stipend = fork.gas_costs().GAS_CALL_STIPEND + stipend = fork.gas_costs().CALL_STIPEND if out_of_gas_at == OutOfGasAt.EIP_2200_STIPEND: # 2300 after PUSHes (fails stipend check: 2300 <= 2300) @@ -561,7 +561,7 @@ def test_bal_call_no_delegation_oog_after_target_access( - target is always empty - required for create cost - value=1 (greater than 0) - required for create cost - The create_cost (GAS_NEW_ACCOUNT = 25000) is charged only for value + The create_cost (NEW_ACCOUNT = 25000) is charged only for value transfers to empty accounts, creating the gap tested here. """ diff --git a/tests/benchmark/compute/instruction/test_system.py b/tests/benchmark/compute/instruction/test_system.py index 4f9161ae213..551a1e242d0 100644 --- a/tests/benchmark/compute/instruction/test_system.py +++ b/tests/benchmark/compute/instruction/test_system.py @@ -73,7 +73,7 @@ def loop(threshold: int) -> Bytecode: intrinsic_cost_calc = fork.transaction_intrinsic_cost_calculator() intrinsic_cost = intrinsic_cost_calc() - access_list_addr_cost = fork.gas_costs().GAS_TX_ACCESS_LIST_ADDRESS + access_list_addr_cost = fork.gas_costs().TX_ACCESS_LIST_ADDRESS txs = [] remaining_gas = gas_benchmark_value diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index 7d406990681..377627733f4 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -609,7 +609,7 @@ def test_ec_pairing( per_variant_gas = ( iteration_cost + pair_size * 16 - + words_per_variant * (gsc.GAS_COPY + gsc.GAS_MEMORY) + + words_per_variant * (gsc.COPY + gsc.MEMORY) ) empty_intrinsic = intrinsic_gas_calculator( calldata=[], return_cost_deducted_prior_execution=True @@ -640,7 +640,7 @@ def test_ec_pairing( per_tx_gas - execution_intrinsic - setup_cost - - math.ceil(len(calldata) / 32) * gsc.GAS_COPY + - math.ceil(len(calldata) / 32) * gsc.COPY - mem_exp(new_bytes=len(calldata) + 32) ) diff --git a/tests/benchmark/compute/scenario/test_transaction_types.py b/tests/benchmark/compute/scenario/test_transaction_types.py index 8ee1ed6546b..b23d3180d22 100644 --- a/tests/benchmark/compute/scenario/test_transaction_types.py +++ b/tests/benchmark/compute/scenario/test_transaction_types.py @@ -268,13 +268,13 @@ def test_ether_transfers_to_precompile( @pytest.fixture def total_cost_floor_per_token(fork: Fork) -> int: """Total cost floor per token (EIP-7623).""" - return fork.gas_costs().GAS_TX_DATA_TOKEN_FLOOR + return fork.gas_costs().TX_DATA_TOKEN_FLOOR @pytest.fixture def total_cost_standard_per_token(fork: Fork) -> int: """Standard cost per token (EIP-7623).""" - return fork.gas_costs().GAS_TX_DATA_TOKEN_STANDARD + return fork.gas_costs().TX_DATA_TOKEN_STANDARD def calldata_generator( @@ -286,11 +286,11 @@ def calldata_generator( # Gas cost calculation based on EIP-7683: (https://eips.ethereum.org/EIPS/eip-7683) # # tx.gasUsed = 21000 + max( - # GAS_TX_DATA_TOKEN_STANDARD * tokens_in_calldata + # TX_DATA_TOKEN_STANDARD * tokens_in_calldata # + execution_gas_used # + isContractCreation * (32000 + # INITCODE_WORD_COST * words(calldata)), - # GAS_TX_DATA_TOKEN_FLOOR * tokens_in_calldata) + # TX_DATA_TOKEN_FLOOR * tokens_in_calldata) # # Simplified in this test case: # - No execution gas used (no opcodes are executed) @@ -298,10 +298,10 @@ def calldata_generator( # # Therefore: # max_token_cost = - # max(GAS_TX_DATA_TOKEN_STANDARD, GAS_TX_DATA_TOKEN_FLOOR) + # max(TX_DATA_TOKEN_STANDARD, TX_DATA_TOKEN_FLOOR) # tx.gasUsed = 21000 + tokens_in_calldata * max_token_cost # - # Since max(GAS_TX_DATA_TOKEN_STANDARD, GAS_TX_DATA_TOKEN_FLOOR) = 10: + # Since max(TX_DATA_TOKEN_STANDARD, TX_DATA_TOKEN_FLOOR) = 10: # tx.gasUsed = 21000 + tokens_in_calldata * 10 # # Token accounting: @@ -421,8 +421,8 @@ def test_block_full_access_list_and_data( # Access list gas costs from fork's gas_costs gas_costs = fork.gas_costs() - gas_per_address = gas_costs.GAS_TX_ACCESS_LIST_ADDRESS - gas_per_storage_key = gas_costs.GAS_TX_ACCESS_LIST_STORAGE_KEY + gas_per_address = gas_costs.TX_ACCESS_LIST_ADDRESS + gas_per_storage_key = gas_costs.TX_ACCESS_LIST_STORAGE_KEY # Calculate number of storage keys we can fit gas_after_address = gas_for_access_list - gas_per_address @@ -594,7 +594,7 @@ def test_auth_transaction( total_refund += min( tx_gas_used // 5, ( - gas_costs.GAS_AUTH_PER_EMPTY_ACCOUNT + gas_costs.AUTH_PER_EMPTY_ACCOUNT - gas_costs.REFUND_AUTH_PER_EXISTING_ACCOUNT ) * auths_in_this_tx, diff --git a/tests/benchmark/stateful/bloatnet/test_multi_opcode.py b/tests/benchmark/stateful/bloatnet/test_multi_opcode.py index 050f3107eb8..4e38786bb37 100755 --- a/tests/benchmark/stateful/bloatnet/test_multi_opcode.py +++ b/tests/benchmark/stateful/bloatnet/test_multi_opcode.py @@ -208,7 +208,7 @@ def test_bloatnet_balance_opcode( # test_bloatnet_call_value_existing: # Same factory pattern as test_bloatnet_balance_opcode, but performs # CALL with value=1 wei to each factory contract. The subcall fails -# (insufficient gas for 24KB bytecode), but GAS_CALL_VALUE (9000 gas) +# (insufficient gas for 24KB bytecode), but CALL_VALUE (9000 gas) # is still charged on top of the cold account access cost. # # test_bloatnet_call_value_new_account: @@ -232,7 +232,7 @@ def test_bloatnet_call_value_existing( Benchmark CALL with value transfer to cold existing factory contracts. Unlike the existing CALL test which uses gas=1 and value=0, this test - passes value=1 wei per call, adding GAS_CALL_VALUE (9000 gas) to each + passes value=1 wei per call, adding CALL_VALUE (9000 gas) to each cold account access. The subcall fails (insufficient gas for bytecode execution), so value is not actually transferred, but the gas penalty is still charged. @@ -332,8 +332,8 @@ def test_bloatnet_call_value_new_account( (via the 2300 gas stipend), transferring value and creating a new account in the trie. Each iteration costs ~36,600 gas: - GAS_COLD_ACCOUNT_ACCESS: 2,600 - - GAS_CALL_VALUE: 9,000 - - GAS_NEW_ACCOUNT: 25,000 + - CALL_VALUE: 9,000 + - NEW_ACCOUNT: 25,000 This stresses trie expansion through massive new account creation. """ diff --git a/tests/berlin/eip2929_gas_cost_increases/test_create.py b/tests/berlin/eip2929_gas_cost_increases/test_create.py index d6bbb4570d8..3e73407f5d9 100644 --- a/tests/berlin/eip2929_gas_cost_increases/test_create.py +++ b/tests/berlin/eip2929_gas_cost_increases/test_create.py @@ -57,8 +57,8 @@ def test_create_insufficient_balance( A creator contract with zero balance attempts to create with value=1. The create aborts, and a subsequent BALANCE check on the would-be - contract address verifies it remains cold (costs G_COLD_ACCOUNT_ACCESS - instead of G_WARM_STORAGE_READ). + contract address verifies it remains cold (costs COLD_ACCOUNT_ACCESS + instead of WARM_STORAGE_READ). """ initcode = Op.STOP diff --git a/tests/byzantium/eip196_ec_add_mul/test_gas.py b/tests/byzantium/eip196_ec_add_mul/test_gas.py index b5fa091eb5f..bcf5012bc25 100644 --- a/tests/byzantium/eip196_ec_add_mul/test_gas.py +++ b/tests/byzantium/eip196_ec_add_mul/test_gas.py @@ -116,10 +116,10 @@ def test_invalid_gas_consumption( address_warm=False ).gas_cost(fork) - # Pre-EIP-2929: fixed G_call = 700; Berlin+: warm access cost. + # Pre-EIP-2929: fixed call = 700; Berlin+: warm access cost. gas_costs = fork.gas_costs() if fork >= Berlin: - staticcall_base = gas_costs.GAS_WARM_ACCESS + staticcall_base = gas_costs.WARM_ACCESS else: staticcall_base = 700 diff --git a/tests/byzantium/eip197_ec_pairing/test_gas.py b/tests/byzantium/eip197_ec_pairing/test_gas.py index a38b8d58431..1a1108c37f0 100644 --- a/tests/byzantium/eip197_ec_pairing/test_gas.py +++ b/tests/byzantium/eip197_ec_pairing/test_gas.py @@ -106,10 +106,10 @@ def test_invalid_gas_consumption( address_warm=False ).gas_cost(fork) - # Pre-EIP-2929: fixed G_call = 700; Berlin+: warm access cost. + # Pre-EIP-2929: fixed call = 700; Berlin+: warm access cost. gas_costs = fork.gas_costs() if fork >= Berlin: - staticcall_base = gas_costs.GAS_WARM_ACCESS + staticcall_base = gas_costs.WARM_ACCESS else: staticcall_base = 700 diff --git a/tests/frontier/opcodes/test_call.py b/tests/frontier/opcodes/test_call.py index e8345e9d5bb..95ad749a868 100644 --- a/tests/frontier/opcodes/test_call.py +++ b/tests/frontier/opcodes/test_call.py @@ -33,7 +33,7 @@ def test_call_large_offset_mstore( mem_offset = 128 # arbitrary number - # Cost of pushing args onto the stack (each PUSH costs G_VERY_LOW) + # Cost of pushing args onto the stack (each PUSH costs VERY_LOW) call_push_cost = (Op.PUSH1(0) * len(Op.CALL.kwargs)).gas_cost(fork) mstore_push_cost = (Op.PUSH1(0) * len(Op.MSTORE.kwargs)).gas_cost(fork) @@ -101,7 +101,7 @@ def test_call_memory_expands_on_early_revert( # arbitrary number, greater than memory size to trigger an expansion ret_size = 128 - # Cost of pushing args onto the stack (each PUSH costs G_VERY_LOW) + # Cost of pushing args onto the stack (each PUSH costs VERY_LOW) call_push_cost = (Op.PUSH1(0) * len(Op.CALL.kwargs)).gas_cost(fork) mstore_push_cost = (Op.PUSH1(0) * len(Op.MSTORE.kwargs)).gas_cost(fork) @@ -137,7 +137,7 @@ def test_call_memory_expands_on_early_revert( # call cost: # address_access_cost+new_acc_cost+memory_expansion_cost+value-stipend - # G_CALL_STIPEND is a threshold check, not a gas cost — keep from gas_costs + # CALL_STIPEND is a threshold check, not a gas cost — keep from gas_costs gsc = fork.gas_costs() call_cost = ( Op.CALL( @@ -146,7 +146,7 @@ def test_call_memory_expands_on_early_revert( account_new=True, new_memory_size=ret_size, ).gas_cost(fork) - - gsc.GAS_CALL_STIPEND + - gsc.CALL_STIPEND ) # mstore cost: base cost. No memory expansion cost needed, it was expanded @@ -186,7 +186,7 @@ def test_call_large_args_offset_size_zero( very_large_offset = 2**100 - # Cost of pushing args onto the stack (each PUSH costs G_VERY_LOW) + # Cost of pushing args onto the stack (each PUSH costs VERY_LOW) push_cost = (Op.PUSH1(0) * len(call_opcode.kwargs)).gas_cost(fork) call_measure = CodeGasMeasure( diff --git a/tests/frontier/opcodes/test_call_and_callcode_gas_calculation.py b/tests/frontier/opcodes/test_call_and_callcode_gas_calculation.py index 0c76bd57947..198045b3e3d 100644 --- a/tests/frontier/opcodes/test_call_and_callcode_gas_calculation.py +++ b/tests/frontier/opcodes/test_call_and_callcode_gas_calculation.py @@ -94,17 +94,17 @@ def sufficient_gas( cost = 700 # Pre-Berlin call cost gas_costs = fork.gas_costs() if is_value_call: - cost += gas_costs.GAS_CALL_VALUE + cost += gas_costs.CALL_VALUE if callee_opcode == Op.CALL: - cost += gas_costs.GAS_NEW_ACCOUNT + cost += gas_costs.NEW_ACCOUNT elif fork == Homestead: cost = 40 # Homestead call cost cost += 1 # mandatory callee gas allowance gas_costs = fork.gas_costs() if is_value_call: - cost += gas_costs.GAS_CALL_VALUE + cost += gas_costs.CALL_VALUE if callee_opcode == Op.CALL: - cost += gas_costs.GAS_NEW_ACCOUNT + cost += gas_costs.NEW_ACCOUNT else: raise Exception("Only forks Homestead and >=Byzantium supported") diff --git a/tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py b/tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py index 8ef1d237eb1..62ec21497af 100644 --- a/tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py +++ b/tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py @@ -328,7 +328,7 @@ def test_maximum_gas_refund( def total_cost_floor_per_token(fork: Fork) -> int: """Total cost floor per token.""" gas_costs = fork.gas_costs() - return gas_costs.GAS_TX_DATA_TOKEN_FLOOR + return gas_costs.TX_DATA_TOKEN_FLOOR @pytest.mark.xdist_group(name="bigmem") @@ -678,7 +678,7 @@ def intrinsic_cost_for_auth_list_length(auth_count: int) -> int: # EIP-7702 authorization transaction cost: # 21000 + 16 * non-zero calldata bytes + 4 * zero calldata bytes + 1900 * # access list storage key count + 2400 * access list address count + access - # list data cost + GAS_AUTH_PER_EMPTY_ACCOUNT_COST * authorization list + # list data cost + AUTH_PER_EMPTY_ACCOUNT_COST * authorization list # length # # There is no calldata and no storage keys in this test case. diff --git a/tests/prague/eip7623_increase_calldata_cost/spec.py b/tests/prague/eip7623_increase_calldata_cost/spec.py index ebca1ee7041..6527e5c69c5 100644 --- a/tests/prague/eip7623_increase_calldata_cost/spec.py +++ b/tests/prague/eip7623_increase_calldata_cost/spec.py @@ -24,5 +24,5 @@ class Spec: https://eips.ethereum.org/EIPS/eip-7623. """ - GAS_TX_DATA_TOKEN_STANDARD = 4 - GAS_TX_DATA_TOKEN_FLOOR = 10 + TX_DATA_TOKEN_STANDARD = 4 + TX_DATA_TOKEN_FLOOR = 10 diff --git a/tests/prague/eip7702_set_code_tx/spec.py b/tests/prague/eip7702_set_code_tx/spec.py index 2be51b6c99c..8f1eaac1fab 100644 --- a/tests/prague/eip7702_set_code_tx/spec.py +++ b/tests/prague/eip7702_set_code_tx/spec.py @@ -28,7 +28,7 @@ class Spec: SET_CODE_TX_TYPE = 0x04 MAGIC = 0x05 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12_500 - GAS_AUTH_PER_EMPTY_ACCOUNT = 25_000 + AUTH_PER_EMPTY_ACCOUNT = 25_000 DELEGATION_DESIGNATION = Bytes("ef0100") RESET_DELEGATION_ADDRESS = Address(0) diff --git a/tests/prague/eip7702_set_code_tx/test_gas.py b/tests/prague/eip7702_set_code_tx/test_gas.py index b2b8233d1b4..7aea82b335a 100644 --- a/tests/prague/eip7702_set_code_tx/test_gas.py +++ b/tests/prague/eip7702_set_code_tx/test_gas.py @@ -800,7 +800,7 @@ def gas_test_parameter_args( if execution_gas_allowance: # Leave some gas for the execution of the test code. max_gas -= 1_000_000 - many_authorizations_count = max_gas // Spec.GAS_AUTH_PER_EMPTY_ACCOUNT + many_authorizations_count = max_gas // Spec.AUTH_PER_EMPTY_ACCOUNT cases += [ pytest.param( { @@ -876,7 +876,7 @@ def test_gas_cost( seen_authority.add(authority) discount_gas = ( - Spec.GAS_AUTH_PER_EMPTY_ACCOUNT - Spec.REFUND_AUTH_PER_EXISTING_ACCOUNT + Spec.AUTH_PER_EMPTY_ACCOUNT - Spec.REFUND_AUTH_PER_EXISTING_ACCOUNT ) * discounted_authorizations # We calculate the exact gas required to execute the test code. We add diff --git a/tests/prague/eip7702_set_code_tx/test_set_code_txs.py b/tests/prague/eip7702_set_code_tx/test_set_code_txs.py index eeca854e337..fe48936c1d5 100644 --- a/tests/prague/eip7702_set_code_tx/test_set_code_txs.py +++ b/tests/prague/eip7702_set_code_tx/test_set_code_txs.py @@ -773,8 +773,9 @@ def test_set_code_to_contract_creator( ) @pytest.mark.with_all_call_opcodes @pytest.mark.filter_combinations( - lambda call_opcode, value, **_: "value" in call_opcode.kwargs - or value == 0, + lambda call_opcode, value, **_: ( + "value" in call_opcode.kwargs or value == 0 + ), reason="opcode does not support value argument", ) def test_set_code_to_self_caller( @@ -908,8 +909,9 @@ def test_set_code_max_depth_call_stack( [0, 1], ) @pytest.mark.filter_combinations( - lambda call_opcode, value, **_: "value" in call_opcode.kwargs - or value == 0, + lambda call_opcode, value, **_: ( + "value" in call_opcode.kwargs or value == 0 + ), reason="opcode does not support value argument", ) @pytest.mark.eels_base_coverage @@ -2916,8 +2918,7 @@ def test_set_code_to_precompile_not_enough_gas_for_precompile_execution( authorization_list_or_count=[auth], ) discount = min( - Spec.GAS_AUTH_PER_EMPTY_ACCOUNT - - Spec.REFUND_AUTH_PER_EXISTING_ACCOUNT, + Spec.AUTH_PER_EMPTY_ACCOUNT - Spec.REFUND_AUTH_PER_EXISTING_ACCOUNT, intrinsic_gas // 5, # max discount EIP-3529 ) @@ -3845,7 +3846,7 @@ def test_many_delegations( max_gas = env.gas_limit gas_for_delegations = max_gas - 21_000 - 20_000 - (3 * 2) - delegation_count = gas_for_delegations // Spec.GAS_AUTH_PER_EMPTY_ACCOUNT + delegation_count = gas_for_delegations // Spec.AUTH_PER_EMPTY_ACCOUNT success_slot = 1 entry_code = Op.SSTORE(success_slot, 1) + Op.STOP diff --git a/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py b/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py index 9bd855017f7..0279bfda1b6 100644 --- a/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py +++ b/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py @@ -1,7 +1,7 @@ """ Tests for EIP-150 SELFDESTRUCT operation gas costs. -EIP-150 introduced G_SELF_DESTRUCT for SELFDESTRUCT and precise gas +EIP-150 introduced SELF_DESTRUCT for SELFDESTRUCT and precise gas boundaries for state access during the operation. """ @@ -52,7 +52,7 @@ def calculate_selfdestruct_gas( originator_balance: int, ) -> int: """Calculate exact gas needed for SELFDESTRUCT.""" - # G_NEW_ACCOUNT: + # NEW_ACCOUNT: # - Pre-EIP-161 (TangerineWhistle): charged when beneficiary is dead # - Post-EIP-161 (>=SpuriousDragon): charged when beneficiary is dead # AND originator has balance > 0 @@ -351,13 +351,13 @@ def test_selfdestruct_to_account( code=Op.STOP, balance=beneficiary_initial_balance ) - # Determine if beneficiary is dead (for G_NEW_ACCOUNT calculation) + # Determine if beneficiary is dead (for NEW_ACCOUNT calculation) # Contract with code is NOT dead even with balance=0 beneficiary_dead = ( beneficiary_initial_balance == 0 and beneficiary == "eoa" ) - # Calculate exact gas for success (includes G_NEW_ACCOUNT if applicable) + # Calculate exact gas for success (includes NEW_ACCOUNT if applicable) inner_call_gas = calculate_selfdestruct_gas( fork, beneficiary_warm=warm, @@ -367,7 +367,7 @@ def test_selfdestruct_to_account( if not is_success: inner_call_gas -= 1 - # In BAL if: success OR G_NEW_ACCOUNT charged (OOG after access) + # In BAL if: success OR NEW_ACCOUNT charged (OOG after access) needs_new_account = False if beneficiary_dead: if fork >= SpuriousDragon: @@ -463,7 +463,7 @@ def test_selfdestruct_state_access_boundary( Test state access boundary for account beneficiaries. Consensus check: beneficiary must be accessed at base cost boundary, - before G_NEW_ACCOUNT is evaluated. + before NEW_ACCOUNT is evaluated. - exact_gas: beneficiary IS accessed (in BAL) - exact_gas_minus_1: beneficiary NOT accessed (not in BAL) @@ -478,14 +478,14 @@ def test_selfdestruct_state_access_boundary( code=Op.STOP, balance=beneficiary_initial_balance ) - # Determine if beneficiary is dead (for G_NEW_ACCOUNT calculation) + # Determine if beneficiary is dead (for NEW_ACCOUNT calculation) # Contract with code is NOT dead even with balance=0 beneficiary_dead = ( beneficiary_initial_balance == 0 and beneficiary == "eoa" ) # Calculate gas for state access boundary only (base + cold access) - # Does NOT include G_NEW_ACCOUNT + # Does NOT include NEW_ACCOUNT inner_call_gas = Op.SELFDESTRUCT( 0, # beneficiary address (generates a PUSH) address_warm=warm or fork < Berlin, @@ -497,7 +497,7 @@ def test_selfdestruct_state_access_boundary( # Determine if operation succeeds at this gas level # At state access boundary, we have enough gas for base + cold access - # Operation succeeds if NO G_NEW_ACCOUNT is needed: + # Operation succeeds if NO NEW_ACCOUNT is needed: # - Beneficiary is alive (has balance or has code) # - OR beneficiary is dead but originator_balance=0 (>=SpuriousDragon) needs_new_account = False @@ -507,7 +507,7 @@ def test_selfdestruct_state_access_boundary( else: needs_new_account = True - # At exact_gas: success if no G_NEW_ACCOUNT needed + # At exact_gas: success if no NEW_ACCOUNT needed # At exact_gas_minus_1: always OOG (before state access) operation_success = is_success and not needs_new_account @@ -602,7 +602,7 @@ def test_selfdestruct_to_precompile( # Precompiles are dead when they have no balance beneficiary_dead = beneficiary_initial_balance == 0 - # Calculate exact gas for success (includes G_NEW_ACCOUNT if applicable) + # Calculate exact gas for success (includes NEW_ACCOUNT if applicable) # Precompiles are always warm inner_call_gas = calculate_selfdestruct_gas( fork, @@ -613,7 +613,7 @@ def test_selfdestruct_to_precompile( if not is_success: inner_call_gas -= 1 - # In BAL if: success OR G_NEW_ACCOUNT charged (OOG after access) + # In BAL if: success OR NEW_ACCOUNT charged (OOG after access) needs_new_account = False if beneficiary_dead: if fork >= SpuriousDragon: @@ -700,7 +700,7 @@ def test_selfdestruct_to_precompile_state_access_boundary( Test state access boundary for precompile beneficiaries. Consensus check: precompile must be accessed at base cost boundary, - before G_NEW_ACCOUNT is evaluated. Precompiles are always warm. + before NEW_ACCOUNT is evaluated. Precompiles are always warm. - exact_gas: precompile IS accessed (in BAL) - exact_gas_minus_1: precompile NOT accessed (not in BAL) @@ -711,7 +711,7 @@ def test_selfdestruct_to_precompile_state_access_boundary( beneficiary_dead = beneficiary_initial_balance == 0 - # State access boundary: base cost only (no G_NEW_ACCOUNT) + # State access boundary: base cost only (no NEW_ACCOUNT) # Precompiles are always warm inner_call_gas = Op.SELFDESTRUCT( 0, address_warm=True, account_new=False @@ -720,7 +720,7 @@ def test_selfdestruct_to_precompile_state_access_boundary( if not is_success: inner_call_gas -= 1 - # Success at base cost if no G_NEW_ACCOUNT needed + # Success at base cost if no NEW_ACCOUNT needed needs_new_account = False if beneficiary_dead: if fork >= SpuriousDragon: @@ -802,7 +802,7 @@ def test_selfdestruct_to_system_contract( Test SELFDESTRUCT success boundary for system contract beneficiaries. System contracts are always warm (no cold access charge) and always have - code (so beneficiary is never dead, no G_NEW_ACCOUNT charge). + code (so beneficiary is never dead, no NEW_ACCOUNT charge). - exact_gas: succeeds, balance transferred - exact_gas_minus_1: OOG, operation fails @@ -952,7 +952,7 @@ def test_selfdestruct_to_self( Key characteristics: - Beneficiary is always warm (it's the executing contract) - Beneficiary is always alive (EIP-161 nonce=1) - - No G_NEW_ACCOUNT charge + - No NEW_ACCOUNT charge - No cold access charge (>=Berlin) - Balance is "transferred" to self (no net change until destruction) @@ -967,7 +967,7 @@ def test_selfdestruct_to_self( alice = pre.fund_eoa() victim_code = Op.SELFDESTRUCT(Op.ADDRESS) - # Gas: ADDRESS + SELFDESTRUCT (no cold access, no G_NEW_ACCOUNT) + # Gas: ADDRESS + SELFDESTRUCT (no cold access, no NEW_ACCOUNT) base_gas = Op.SELFDESTRUCT( Op.ADDRESS, address_warm=True, account_new=False ).gas_cost(fork) @@ -1135,7 +1135,7 @@ def test_initcode_selfdestruct_to_self( - During initcode, the contract has no code yet - Contract has nonce=1 (post-EIP-161) making it non-empty - Beneficiary is always warm (it's the executing contract) - - No G_NEW_ACCOUNT charge (contract has nonce > 0) + - No NEW_ACCOUNT charge (contract has nonce > 0) - No cold access charge (>=Berlin) Note: Gas boundary testing not possible for initcode since CREATE From 215f4ae1ac25d943c1e1f99bc24cd3746e1f2668 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 1 Apr 2026 02:04:11 -0400 Subject: [PATCH 43/61] refactor: alt_bn128 now uses precompile gas constants in spec --- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++++ .../amsterdam/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/arrow_glacier/vm/gas.py | 4 ++++ .../vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/berlin/vm/gas.py | 4 ++++ .../berlin/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/bpo1/vm/gas.py | 4 ++++ .../forks/bpo1/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/bpo2/vm/gas.py | 4 ++++ .../forks/bpo2/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/bpo3/vm/gas.py | 4 ++++ .../forks/bpo3/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/bpo4/vm/gas.py | 4 ++++ .../forks/bpo4/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/bpo5/vm/gas.py | 4 ++++ .../forks/bpo5/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/byzantium/vm/gas.py | 4 ++++ .../byzantium/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/cancun/vm/gas.py | 4 ++++ .../cancun/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/constantinople/vm/gas.py | 4 ++++ .../vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++++ .../vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/istanbul/vm/gas.py | 4 ++++ .../istanbul/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/london/vm/gas.py | 4 ++++ .../london/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++++ .../vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/osaka/vm/gas.py | 4 ++++ .../osaka/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/paris/vm/gas.py | 4 ++++ .../paris/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/prague/vm/gas.py | 4 ++++ .../prague/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- src/ethereum/forks/shanghai/vm/gas.py | 4 ++++ .../shanghai/vm/precompiled_contracts/alt_bn128.py | 12 ++++++++---- 38 files changed, 228 insertions(+), 76 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index dad1da67c76..140f5aad3f1 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -87,6 +87,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index a1c25d967d5..9eb919869de 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -75,6 +75,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index db25ac3a8d9..3d3ab3e153f 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -76,6 +76,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index c23c9c29e0f..6b174c28190 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 9229ef704eb..0c3ee2592ac 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 9229ef704eb..0c3ee2592ac 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 9229ef704eb..0c3ee2592ac 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 9229ef704eb..0c3ee2592ac 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 6f880ad18f9..3abdce437b0 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -75,6 +75,10 @@ class GasCosts: PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_ECADD = Uint(500) + PRECOMPILE_ECMUL = Uint(40000) + PRECOMPILE_ECPAIRING_BASE = Uint(100000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(80000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/alt_bn128.py index d579abb2b8a..09bed4a0282 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(500)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(40000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(80000 * (len(data) // 192) + 100000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 467c1d902eb..1a3cbce2de0 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -79,6 +79,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 7edaaab6b87..7a754f5500c 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -76,6 +76,10 @@ class GasCosts: PRECOMPILE_RIPEMD160_PER_WORD = Uint(120) PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) + PRECOMPILE_ECADD = Uint(500) + PRECOMPILE_ECMUL = Uint(40000) + PRECOMPILE_ECPAIRING_BASE = Uint(100000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(80000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/alt_bn128.py index d579abb2b8a..09bed4a0282 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(500)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(40000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(80000 * (len(data) // 192) + 100000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index a1c25d967d5..9eb919869de 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -75,6 +75,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 241aa6a9a5b..4ce8aed11ac 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -78,6 +78,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index a1c25d967d5..9eb919869de 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -75,6 +75,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/london/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 241aa6a9a5b..4ce8aed11ac 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -78,6 +78,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 3d124f3b8a6..543d8f6305f 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -86,6 +86,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index a1c25d967d5..9eb919869de 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -75,6 +75,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/paris/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 1c83b7b98b8..acee78c4508 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -85,6 +85,10 @@ class GasCosts: PRECOMPILE_BLS_G2ADD = Uint(600) PRECOMPILE_BLS_G2MUL = Uint(22500) PRECOMPILE_BLS_G2MAP = Uint(23800) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Blobs PER_BLOB = U64(2**17) diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/prague/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 36bf312d215..3370310413a 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -76,6 +76,10 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_ECADD = Uint(150) + PRECOMPILE_ECMUL = Uint(6000) + PRECOMPILE_ECPAIRING_BASE = Uint(45000) + PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) # Opcodes OPCODE_ADD = VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/alt_bn128.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/alt_bn128.py index 214725d8da0..09bed4a0282 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/alt_bn128.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/alt_bn128.py @@ -31,7 +31,7 @@ from py_ecc.typing import Optimized_Point3D as Point3D from ...vm import Evm -from ...vm.gas import charge_gas +from ...vm.gas import GasCosts, charge_gas from ...vm.memory import buffer_read from ..exceptions import InvalidParameter, OutOfGasError @@ -149,7 +149,7 @@ def alt_bn128_add(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(150)) + charge_gas(evm, GasCosts.PRECOMPILE_ECADD) # OPERATION try: @@ -177,7 +177,7 @@ def alt_bn128_mul(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(6000)) + charge_gas(evm, GasCosts.PRECOMPILE_ECMUL) # OPERATION try: @@ -205,7 +205,11 @@ def alt_bn128_pairing_check(evm: Evm) -> None: data = evm.message.data # GAS - charge_gas(evm, Uint(34000 * (len(data) // 192) + 45000)) + charge_gas( + evm, + GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192) + + GasCosts.PRECOMPILE_ECPAIRING_BASE, + ) # OPERATION if len(data) % 192 != 0: From d14f63e24d7faabdcfb3ac1d61bd2e87dcf72b62 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 1 Apr 2026 17:12:01 -0400 Subject: [PATCH 44/61] reafactor(spec): reorganize gas.py, refactor two constant names --- src/ethereum/forks/amsterdam/vm/gas.py | 69 +++++++++++-------- .../amsterdam/vm/instructions/environment.py | 6 +- .../forks/amsterdam/vm/instructions/memory.py | 2 +- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/berlin/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/bpo1/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 60 +++++++++------- src/ethereum/forks/cancun/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/dao_fork/vm/gas.py | 56 +++++++++------ src/ethereum/forks/frontier/vm/gas.py | 56 +++++++++------ src/ethereum/forks/gray_glacier/vm/gas.py | 60 +++++++++------- src/ethereum/forks/homestead/vm/gas.py | 56 +++++++++------ src/ethereum/forks/istanbul/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/london/vm/gas.py | 60 +++++++++------- src/ethereum/forks/muir_glacier/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/osaka/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 60 +++++++++------- src/ethereum/forks/prague/vm/gas.py | 64 ++++++++++------- .../precompiled_contracts/point_evaluation.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 62 ++++++++++------- src/ethereum/forks/spurious_dragon/vm/gas.py | 60 +++++++++------- .../forks/tangerine_whistle/vm/gas.py | 60 +++++++++------- 35 files changed, 898 insertions(+), 609 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 140f5aad3f1..01b174b5bef 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -40,33 +40,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - RETURN_DATA_COPY = Uint(3) - FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) + + # Utility + ZERO = Uint(0) + RETURN_DATA_COPY = Uint(3) # TODO refactor to OPCODE_RETURNDATACOPY? + FAST_STEP = Uint(5) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -81,6 +76,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -104,7 +100,7 @@ class GasCosts: # Block Access Lists BLOCK_ACCESS_LIST_ITEM = Uint(2000) - # Opcodes + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW @@ -134,20 +130,37 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_COPY_BASE = Uint(3) + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + + # TODO + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) # rename for above + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index ee695e331cf..2034c2f55e2 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -224,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -285,7 +285,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 4b03a0386ef..3f334f96fcb 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 9eb919869de..68006d9c66c 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -37,31 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,7 +76,7 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW @@ -109,18 +105,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Copcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 3d3ab3e153f..eac42e1ba80 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -37,31 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -81,7 +77,7 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW @@ -110,18 +106,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 6b174c28190..0662dd71b3a 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 0c3ee2592ac..e10d825a024 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 0c3ee2592ac..e10d825a024 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 0c3ee2592ac..e10d825a024 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 0c3ee2592ac..e10d825a024 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 3abdce437b0..dd97a1b6f7c 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -37,30 +37,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(200) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(400) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) # Refunds @@ -106,18 +99,37 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 1a3cbce2de0..478246fdb8d 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -79,6 +74,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_ECADD = Uint(150) PRECOMPILE_ECMUL = Uint(6000) PRECOMPILE_ECPAIRING_BASE = Uint(45000) @@ -119,20 +115,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 7a754f5500c..43346043239 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -37,33 +37,26 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(200) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(400) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - RETURN_DATA_COPY = Uint(3) + NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(400) + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) + RETURN_DATA_COPY = Uint(3) + # Refunds REFUND_STORAGE_CLEAR = 15000 REFUND_SELF_DESTRUCT = 24000 @@ -110,18 +103,37 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 5867cd74d48..b0a2c9996f4 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -39,28 +39,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(50) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(20) - BALANCE = Uint(20) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(40) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,17 +96,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + CREATE = Uint(32000) + CALL = Uint(40) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 5867cd74d48..b0a2c9996f4 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -39,28 +39,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(50) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(20) - BALANCE = Uint(20) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(40) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,17 +96,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + CREATE = Uint(32000) + CALL = Uint(40) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 9eb919869de..e4e578fcfd5 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -37,31 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -109,18 +105,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 5867cd74d48..b0a2c9996f4 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -39,28 +39,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(50) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(20) - BALANCE = Uint(20) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(40) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,17 +96,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(20) + BALANCE = Uint(20) + CREATE = Uint(32000) + CALL = Uint(40) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 4ce8aed11ac..19c1533e6d2 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -37,32 +37,25 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(800) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - RETURN_DATA_COPY = Uint(3) + NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(700) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) + RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -112,18 +105,37 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(700) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 9eb919869de..e4e578fcfd5 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -37,31 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -109,18 +105,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 4ce8aed11ac..19c1533e6d2 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -37,32 +37,25 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(800) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) - RETURN_DATA_COPY = Uint(3) + NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(700) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) + RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -112,18 +105,37 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(700) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 543d8f6305f..ab289909d44 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -80,6 +75,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -130,20 +126,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 9eb919869de..e4e578fcfd5 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -37,31 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -109,18 +105,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index acee78c4508..67917fac048 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -39,33 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) - POINT_EVALUATION = Uint(50000) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -79,6 +74,7 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1) + PRECOMPILE_POINT_EVALUATION = Uint(50000) PRECOMPILE_BLS_G1ADD = Uint(375) PRECOMPILE_BLS_G1MUL = Uint(12000) PRECOMPILE_BLS_G1MAP = Uint(5500) @@ -125,20 +121,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py index 302abba4cfe..d2d105ba13b 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/point_evaluation.py @@ -51,7 +51,7 @@ def point_evaluation(evm: Evm) -> None: proof = Bytes48(data[144:192]) # GAS - charge_gas(evm, GasCosts.POINT_EVALUATION) + charge_gas(evm, GasCosts.PRECOMPILE_POINT_EVALUATION) if kzg_commitment_to_versioned_hash(commitment) != versioned_hash: raise KZGProofError diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 3370310413a..a7d94d05e16 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -37,32 +37,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs + WARM_ACCESS = Uint(100) + COLD_ACCOUNT_ACCESS = Uint(2600) + COLD_STORAGE_ACCESS = Uint(2100) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + CODE_INIT_PER_WORD = Uint(2) + + # Utility + ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) FAST_STEP = Uint(5) - COLD_STORAGE_ACCESS = Uint(2100) - COLD_ACCOUNT_ACCESS = Uint(2600) - WARM_ACCESS = Uint(100) - CODE_INIT_PER_WORD = Uint(2) # Refunds REFUND_STORAGE_CLEAR = 4800 @@ -110,18 +106,34 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + CREATE = Uint(32000) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index e96097141d8..54c1464f401 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -37,30 +37,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(200) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(400) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,17 +94,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(50) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 2a767e41ea2..d9cd6525135 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -37,30 +37,23 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # General + # Access Costs SLOAD = Uint(200) + + # Storage Costs STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) - MEMORY = Uint(3) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) - COPY = Uint(3) - EXTERNAL = Uint(700) - BALANCE = Uint(400) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) - CREATE = Uint(32000) - CODE_DEPOSIT_PER_BYTE = Uint(200) - ZERO = Uint(0) - CALL = Uint(700) - NEW_ACCOUNT = Uint(25000) + + # Call Costs CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + NEW_ACCOUNT = Uint(25000) + + # Contract Creation Costs + CODE_DEPOSIT_PER_BYTE = Uint(200) + + # Utility + ZERO = Uint(0) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,17 +94,36 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW + # Dynamic Opcodes + OPCODE_CALLDATACOPY = VERY_LOW + OPCODE_CODECOPY = VERY_LOW + OPCODE_MLOAD = VERY_LOW + OPCODE_MSTORE = VERY_LOW + OPCODE_MSTORE8 = VERY_LOW + + # TODO + COPY = Uint(3) + MEMORY = Uint(3) + EXTERNAL = Uint(700) + BALANCE = Uint(400) + CREATE = Uint(32000) + CALL = Uint(700) + EXPONENTIATION = Uint(10) + EXPONENTIATION_PER_BYTE = Uint(10) + KECCAK256 = Uint(30) + KECCAK256_PER_WORD = Uint(6) + LOG = Uint(375) + LOG_DATA_PER_BYTE = Uint(8) + LOG_TOPIC = Uint(375) + SELF_DESTRUCT = Uint(5000) + SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + @dataclass class ExtendMemory: From b5a013f40137bea1c8ead6db196964c27e2335f7 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Thu, 2 Apr 2026 13:08:25 -0400 Subject: [PATCH 45/61] refactor: COPY=>OPCODE_COPY_PER_WORD --- .../execution_testing/forks/forks/forks.py | 27 ++++++++++--------- .../src/execution_testing/forks/gas_costs.py | 24 ++++++++--------- .../forks/tests/test_opcode_gas_costs.py | 16 +++++------ src/ethereum/forks/amsterdam/vm/gas.py | 2 +- .../amsterdam/vm/instructions/environment.py | 6 ++--- .../forks/amsterdam/vm/instructions/memory.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- src/ethereum/forks/berlin/vm/gas.py | 2 +- .../berlin/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/bpo1/vm/gas.py | 2 +- .../forks/bpo1/vm/instructions/environment.py | 6 ++--- .../forks/bpo1/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- .../forks/bpo2/vm/instructions/environment.py | 6 ++--- .../forks/bpo2/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- .../forks/bpo3/vm/instructions/environment.py | 6 ++--- .../forks/bpo3/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- .../forks/bpo4/vm/instructions/environment.py | 6 ++--- .../forks/bpo4/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- .../forks/bpo5/vm/instructions/environment.py | 6 ++--- .../forks/bpo5/vm/instructions/memory.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- .../byzantium/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/cancun/vm/gas.py | 2 +- .../cancun/vm/instructions/environment.py | 6 ++--- .../forks/cancun/vm/instructions/memory.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- src/ethereum/forks/dao_fork/vm/gas.py | 2 +- .../dao_fork/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/frontier/vm/gas.py | 2 +- .../frontier/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- src/ethereum/forks/homestead/vm/gas.py | 2 +- .../homestead/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/istanbul/vm/gas.py | 2 +- .../istanbul/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/london/vm/gas.py | 2 +- .../london/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- src/ethereum/forks/osaka/vm/gas.py | 2 +- .../osaka/vm/instructions/environment.py | 6 ++--- .../forks/osaka/vm/instructions/memory.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- .../paris/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/prague/vm/gas.py | 2 +- .../prague/vm/instructions/environment.py | 6 ++--- .../forks/prague/vm/instructions/memory.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- .../shanghai/vm/instructions/environment.py | 6 ++--- src/ethereum/forks/spurious_dragon/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- .../forks/tangerine_whistle/vm/gas.py | 2 +- .../vm/instructions/environment.py | 6 ++--- .../compute/precompile/test_alt_bn128.py | 4 +-- 61 files changed, 141 insertions(+), 140 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index ae0a7ccc528..8abaf676f60 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -119,17 +119,6 @@ def gas_costs(cls) -> GasCosts: # Contract Creation Costs CODE_DEPOSIT_PER_BYTE=200, CODE_INIT_PER_WORD=2, - # Component Costs for Dynamic Opcodes - COPY=3, - CREATE=32_000, - MEMORY=3, - EXPONENTIATION=10, - EXPONENTIATION_PER_BYTE=50, - LOG=375, - LOG_DATA_PER_BYTE=8, - LOG_TOPIC=375, - KECCAK256=30, - KECCAK256_PER_WORD=6, # Transactions TX_BASE=21_000, TX_ACCESS_LIST_ADDRESS=2_400, @@ -185,6 +174,17 @@ def gas_costs(cls) -> GasCosts: OPCODE_MSTORE=VERY_LOW, OPCODE_MSTORE8=VERY_LOW, OPCODE_SELFDESTRUCT=5_000, + # Dynamic Opcode Component Costs + COPY_PER_WORD=3, + CREATE=32_000, + MEMORY=3, + EXPONENTIATION=10, + EXPONENTIATION_PER_BYTE=50, + LOG=375, + LOG_DATA_PER_BYTE=8, + LOG_TOPIC=375, + KECCAK256=30, + KECCAK256_PER_WORD=6, # Zero-initialized: introduced in later forks, set via # replace() in the fork that activates them. TX_DATA_TOKEN_STANDARD=0, @@ -296,7 +296,8 @@ def _with_data_copy( Args: base_gas: Either a constant gas cost (int) or a callable that calculates it - gas_costs: The gas costs dataclass for accessing COPY + gas_costs: The gas costs dataclass for accessing + COPY_PER_WORD Returns: A callable that calculates base_gas + copy_cost @@ -313,7 +314,7 @@ def wrapper(opcode: OpcodeBase) -> int: # Add copy cost based on data size data_size = opcode.metadata["data_size"] word_count = (data_size + 31) // 32 - copy_cost = gas_costs.COPY * word_count + copy_cost = gas_costs.COPY_PER_WORD * word_count return base_cost + copy_cost diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 5c1c4bdce18..fa45f4673c4 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -44,18 +44,6 @@ class GasCosts: # Authorization Costs AUTH_PER_EMPTY_ACCOUNT: int - # Component Costs for Dynamic Opcodes - COPY: int - CREATE: int - MEMORY: int - EXPONENTIATION: int - EXPONENTIATION_PER_BYTE: int - LOG: int - LOG_DATA_PER_BYTE: int - LOG_TOPIC: int - KECCAK256: int - KECCAK256_PER_WORD: int - # Transactions TX_BASE: int TX_CREATE: int @@ -138,6 +126,18 @@ class GasCosts: OPCODE_MSTORE8: int OPCODE_SELFDESTRUCT: int + # Dynamic Opcode Component Costs + COPY_PER_WORD: int + CREATE: int + MEMORY: int + EXPONENTIATION: int + EXPONENTIATION_PER_BYTE: int + LOG: int + LOG_DATA_PER_BYTE: int + LOG_TOPIC: int + KECCAK256: int + KECCAK256_PER_WORD: int + # Defined post-Frontier OPCODE_SHL: int = 0 OPCODE_SHR: int = 0 diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 62b3944492e..8f8b01ae0ac 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -85,7 +85,7 @@ Osaka, Op.CALLDATACOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 1 + + Osaka.gas_costs().COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="calldatacopy_one_word", ), @@ -95,7 +95,7 @@ data_size=64, new_memory_size=64, old_memory_size=32 ), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 2 + + Osaka.gas_costs().COPY_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()( new_bytes=64, previous_bytes=32 ), @@ -106,7 +106,7 @@ Osaka, Op.CODECOPY(data_size=96, new_memory_size=96), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 3 + + Osaka.gas_costs().COPY_PER_WORD * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="codecopy_three_words", ), @@ -130,7 +130,7 @@ address_warm=True, data_size=32, new_memory_size=32 ), Osaka.gas_costs().WARM_ACCESS - + Osaka.gas_costs().COPY * 1 + + Osaka.gas_costs().COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="extcodecopy_warm", ), @@ -140,7 +140,7 @@ address_warm=False, data_size=64, new_memory_size=64 ), Osaka.gas_costs().COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().COPY * 2 + + Osaka.gas_costs().COPY_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="extcodecopy_cold", ), @@ -162,7 +162,7 @@ Osaka, Op.RETURNDATACOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 1 + + Osaka.gas_costs().COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="returndatacopy", ), @@ -200,7 +200,7 @@ Osaka, Op.MCOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 1 + + Osaka.gas_costs().COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="mcopy_one_word", ), @@ -208,7 +208,7 @@ Osaka, Op.MCOPY(data_size=96, new_memory_size=128, old_memory_size=64), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY * 3 + + Osaka.gas_costs().COPY_PER_WORD * 3 + Osaka.memory_expansion_gas_calculator()( new_bytes=128, previous_bytes=64 ), diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 01b174b5bef..0f2d59f4501 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -140,7 +140,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_COPY_BASE = Uint(3) + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 2034c2f55e2..06ca4cee568 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -224,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -285,7 +285,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 3f334f96fcb..cf60b982664 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.OPCODE_COPY_BASE * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 68006d9c66c..5d66d73f092 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Copcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 76784f10948..b2c2feeb6ef 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index eac42e1ba80..8c5cc7a272f 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index a7eb88e2e70..15ade44f740 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 0662dd71b3a..4ca0207eca5 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index e10d825a024..f22cff6355f 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index e10d825a024..f22cff6355f 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index e10d825a024..f22cff6355f 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index e10d825a024..f22cff6355f 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index dd97a1b6f7c..b865ab15408 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -107,6 +107,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -114,7 +115,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 4fa99946626..44bab49c5bb 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -216,7 +216,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -277,7 +277,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -363,7 +363,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 478246fdb8d..3877eeb74c3 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -125,6 +125,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -132,7 +133,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 43346043239..956d200c7e0 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -111,6 +111,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -118,7 +119,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index f4492840724..789970e3ba3 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index b0a2c9996f4..48d7f70bdae 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -110,7 +111,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 0981b35f615..2118d0435a3 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index b0a2c9996f4..48d7f70bdae 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -110,7 +111,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 0981b35f615..2118d0435a3 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index e4e578fcfd5..ed022f2858b 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 76784f10948..b2c2feeb6ef 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index b0a2c9996f4..48d7f70bdae 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -103,6 +103,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -110,7 +111,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 0981b35f615..2118d0435a3 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 19c1533e6d2..f05f4a121c8 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(700) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 4c3b815e5ef..b60f50e2bbb 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index e4e578fcfd5..ed022f2858b 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 76784f10948..b2c2feeb6ef 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 19c1533e6d2..f05f4a121c8 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(700) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 4c3b815e5ef..b60f50e2bbb 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index ab289909d44..c4000fa524f 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -136,6 +136,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -143,7 +144,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index e4e578fcfd5..ed022f2858b 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -113,6 +113,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -120,7 +121,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 20c0dd10fa0..3eec4835ee6 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 67917fac048..3ece7625e13 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -131,6 +131,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -138,7 +139,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index a834e81efdc..854ceb81848 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 4b03a0386ef..cf60b982664 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index a7d94d05e16..c643b2481d8 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 20c0dd10fa0..3eec4835ee6 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 54c1464f401..fbba38429bf 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -101,6 +101,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -108,7 +109,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 0981b35f615..2118d0435a3 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index d9cd6525135..c8a6b2689b2 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -101,6 +101,7 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + COPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -108,7 +109,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - COPY = Uint(3) MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 0981b35f615..2118d0435a3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY * words + copy_gas_cost = GasCosts.COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index 377627733f4..2104817a779 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -609,7 +609,7 @@ def test_ec_pairing( per_variant_gas = ( iteration_cost + pair_size * 16 - + words_per_variant * (gsc.COPY + gsc.MEMORY) + + words_per_variant * (gsc.COPY_PER_WORD + gsc.MEMORY) ) empty_intrinsic = intrinsic_gas_calculator( calldata=[], return_cost_deducted_prior_execution=True @@ -640,7 +640,7 @@ def test_ec_pairing( per_tx_gas - execution_intrinsic - setup_cost - - math.ceil(len(calldata) / 32) * gsc.COPY + - math.ceil(len(calldata) / 32) * gsc.COPY_PER_WORD - mem_exp(new_bytes=len(calldata) + 32) ) From 9e013e2cab01aad04e46cad2ec3034d902d8a8bd Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 10:52:04 -0400 Subject: [PATCH 46/61] refactor: MEMORY=>MEMORY_PER_WORD --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 6 +++--- src/ethereum/forks/berlin/vm/gas.py | 4 ++-- src/ethereum/forks/bpo1/vm/gas.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 4 ++-- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- src/ethereum/forks/cancun/vm/gas.py | 4 ++-- src/ethereum/forks/constantinople/vm/gas.py | 4 ++-- src/ethereum/forks/dao_fork/vm/gas.py | 4 ++-- src/ethereum/forks/frontier/vm/gas.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/homestead/vm/gas.py | 4 ++-- src/ethereum/forks/istanbul/vm/gas.py | 4 ++-- src/ethereum/forks/london/vm/gas.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/osaka/vm/gas.py | 4 ++-- src/ethereum/forks/paris/vm/gas.py | 4 ++-- src/ethereum/forks/prague/vm/gas.py | 4 ++-- src/ethereum/forks/shanghai/vm/gas.py | 4 ++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 4 ++-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 4 ++-- tests/benchmark/compute/precompile/test_alt_bn128.py | 2 +- 27 files changed, 53 insertions(+), 53 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 8abaf676f60..41149272159 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -177,7 +177,7 @@ def gas_costs(cls) -> GasCosts: # Dynamic Opcode Component Costs COPY_PER_WORD=3, CREATE=32_000, - MEMORY=3, + MEMORY_PER_WORD=3, EXPONENTIATION=10, EXPONENTIATION_PER_BYTE=50, LOG=375, @@ -733,7 +733,7 @@ def fn(*, new_bytes: int, previous_bytes: int = 0) -> int: previous_words = ceiling_division(previous_bytes, 32) def c(w: int) -> int: - return (gas_costs.MEMORY * w) + ((w * w) // 512) + return (gas_costs.MEMORY_PER_WORD * w) + ((w * w) // 512) return c(new_words) - c(previous_words) diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index fa45f4673c4..6a7bc46c78b 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -129,7 +129,7 @@ class GasCosts: # Dynamic Opcode Component Costs COPY_PER_WORD: int CREATE: int - MEMORY: int + MEMORY_PER_WORD: int EXPONENTIATION: int EXPONENTIATION_PER_BYTE: int LOG: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 0f2d59f4501..16b12d29dd9 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -141,6 +141,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -149,7 +150,6 @@ class GasCosts: OPCODE_SELFDESTRUCT_BASE = Uint(5000) # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -250,7 +250,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 5d66d73f092..6924067c9cb 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -112,8 +112,9 @@ class GasCosts: OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW - # Dynamic Copcodes + # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -205,7 +205,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 8c5cc7a272f..e748bbca10b 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -115,6 +115,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -122,7 +123,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -206,7 +206,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 4ca0207eca5..7a627d5a357 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index f22cff6355f..a37de5e18e3 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index f22cff6355f..a37de5e18e3 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index f22cff6355f..a37de5e18e3 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index f22cff6355f..a37de5e18e3 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index b865ab15408..720fc4a06a2 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -108,6 +108,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -115,7 +116,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) CREATE = Uint(32000) @@ -202,7 +202,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 3877eeb74c3..c9e8faa2365 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -126,6 +126,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -133,7 +134,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -217,7 +217,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 956d200c7e0..b7e670c2b4e 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -112,6 +112,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -119,7 +120,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) CREATE = Uint(32000) @@ -206,7 +206,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 48d7f70bdae..1ccdeddc83f 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -104,6 +104,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -111,7 +112,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) CREATE = Uint(32000) @@ -196,7 +196,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 48d7f70bdae..1ccdeddc83f 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -104,6 +104,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -111,7 +112,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) CREATE = Uint(32000) @@ -196,7 +196,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index ed022f2858b..72b81b7f9c9 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -205,7 +205,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 48d7f70bdae..1ccdeddc83f 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -104,6 +104,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -111,7 +112,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(20) BALANCE = Uint(20) CREATE = Uint(32000) @@ -196,7 +196,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index f05f4a121c8..52b0c2c1a51 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(700) CREATE = Uint(32000) @@ -208,7 +208,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index ed022f2858b..72b81b7f9c9 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -205,7 +205,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index f05f4a121c8..52b0c2c1a51 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(700) CREATE = Uint(32000) @@ -208,7 +208,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index c4000fa524f..1dfaf1f43cb 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -137,6 +137,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -144,7 +145,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -228,7 +228,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index ed022f2858b..72b81b7f9c9 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -114,6 +114,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -121,7 +122,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -205,7 +205,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 3ece7625e13..5c5d24fd189 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -132,6 +132,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -139,7 +140,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -223,7 +223,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index c643b2481d8..ab1dd9edd0e 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -115,6 +115,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -122,7 +123,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) @@ -206,7 +206,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index fbba38429bf..6a65242badb 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -109,7 +110,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) CREATE = Uint(32000) @@ -196,7 +196,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index c8a6b2689b2..53b83ffe460 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -102,6 +102,7 @@ class GasCosts: # Dynamic Opcodes COPY_PER_WORD = Uint(3) + MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW @@ -109,7 +110,6 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW # TODO - MEMORY = Uint(3) EXTERNAL = Uint(700) BALANCE = Uint(400) CREATE = Uint(32000) @@ -196,7 +196,7 @@ def calculate_memory_gas_cost(size_in_bytes: Uint) -> Uint: """ size_in_words = ceil32(size_in_bytes) // Uint(32) - linear_cost = size_in_words * GasCosts.MEMORY + linear_cost = size_in_words * GasCosts.MEMORY_PER_WORD quadratic_cost = size_in_words ** Uint(2) // Uint(512) total_gas_cost = linear_cost + quadratic_cost try: diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index 2104817a779..cfb56b0d21b 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -609,7 +609,7 @@ def test_ec_pairing( per_variant_gas = ( iteration_cost + pair_size * 16 - + words_per_variant * (gsc.COPY_PER_WORD + gsc.MEMORY) + + words_per_variant * (gsc.COPY_PER_WORD + gsc.MEMORY_PER_WORD) ) empty_intrinsic = intrinsic_gas_calculator( calldata=[], return_cost_deducted_prior_execution=True From 250570bdf678720897c66800071950cfa786f2c6 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 13:17:02 -0400 Subject: [PATCH 47/61] refactor: CREATE=>CREATE_BASE --- .../execution_testing/forks/forks/forks.py | 25 ++++++++++--------- .../src/execution_testing/forks/gas_costs.py | 23 +++++++++-------- .../forks/tests/test_opcode_gas_costs.py | 20 +++++++-------- src/ethereum/forks/amsterdam/vm/gas.py | 23 +++++++++-------- .../amsterdam/vm/instructions/environment.py | 6 ++--- .../forks/amsterdam/vm/instructions/memory.py | 2 +- .../forks/amsterdam/vm/instructions/system.py | 6 +++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../arrow_glacier/vm/instructions/system.py | 4 +-- src/ethereum/forks/berlin/vm/gas.py | 15 ++++++----- .../berlin/vm/instructions/environment.py | 6 ++--- .../forks/berlin/vm/instructions/system.py | 4 +-- src/ethereum/forks/bpo1/vm/gas.py | 15 ++++++----- .../forks/bpo1/vm/instructions/environment.py | 6 ++--- .../forks/bpo1/vm/instructions/memory.py | 2 +- .../forks/bpo1/vm/instructions/system.py | 4 +-- src/ethereum/forks/bpo2/vm/gas.py | 15 ++++++----- .../forks/bpo2/vm/instructions/environment.py | 6 ++--- .../forks/bpo2/vm/instructions/memory.py | 2 +- .../forks/bpo2/vm/instructions/system.py | 6 +++-- src/ethereum/forks/bpo3/vm/gas.py | 15 ++++++----- .../forks/bpo3/vm/instructions/environment.py | 6 ++--- .../forks/bpo3/vm/instructions/memory.py | 2 +- .../forks/bpo3/vm/instructions/system.py | 6 +++-- src/ethereum/forks/bpo4/vm/gas.py | 15 ++++++----- .../forks/bpo4/vm/instructions/environment.py | 6 ++--- .../forks/bpo4/vm/instructions/memory.py | 2 +- .../forks/bpo4/vm/instructions/system.py | 4 +-- src/ethereum/forks/bpo5/vm/gas.py | 15 ++++++----- .../forks/bpo5/vm/instructions/environment.py | 6 ++--- .../forks/bpo5/vm/instructions/memory.py | 2 +- .../forks/bpo5/vm/instructions/system.py | 4 +-- src/ethereum/forks/byzantium/vm/gas.py | 15 ++++++----- .../byzantium/vm/instructions/environment.py | 6 ++--- .../forks/byzantium/vm/instructions/system.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 15 ++++++----- .../cancun/vm/instructions/environment.py | 6 ++--- .../forks/cancun/vm/instructions/memory.py | 2 +- .../forks/cancun/vm/instructions/system.py | 6 +++-- src/ethereum/forks/constantinople/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../constantinople/vm/instructions/system.py | 4 +-- src/ethereum/forks/dao_fork/vm/gas.py | 15 ++++++----- .../dao_fork/vm/instructions/environment.py | 6 ++--- .../forks/dao_fork/vm/instructions/system.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 15 ++++++----- .../frontier/vm/instructions/environment.py | 6 ++--- .../forks/frontier/vm/instructions/system.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../gray_glacier/vm/instructions/system.py | 4 +-- src/ethereum/forks/homestead/vm/gas.py | 15 ++++++----- .../homestead/vm/instructions/environment.py | 6 ++--- .../forks/homestead/vm/instructions/system.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 15 ++++++----- .../istanbul/vm/instructions/environment.py | 6 ++--- .../forks/istanbul/vm/instructions/system.py | 4 +-- src/ethereum/forks/london/vm/gas.py | 15 ++++++----- .../london/vm/instructions/environment.py | 6 ++--- .../forks/london/vm/instructions/system.py | 4 +-- src/ethereum/forks/muir_glacier/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../muir_glacier/vm/instructions/system.py | 4 +-- src/ethereum/forks/osaka/vm/gas.py | 15 ++++++----- .../osaka/vm/instructions/environment.py | 6 ++--- .../forks/osaka/vm/instructions/memory.py | 2 +- .../forks/osaka/vm/instructions/system.py | 4 +-- src/ethereum/forks/paris/vm/gas.py | 15 ++++++----- .../paris/vm/instructions/environment.py | 6 ++--- .../forks/paris/vm/instructions/system.py | 4 +-- src/ethereum/forks/prague/vm/gas.py | 15 ++++++----- .../prague/vm/instructions/environment.py | 6 ++--- .../forks/prague/vm/instructions/memory.py | 2 +- .../forks/prague/vm/instructions/system.py | 6 +++-- src/ethereum/forks/shanghai/vm/gas.py | 15 ++++++----- .../shanghai/vm/instructions/environment.py | 6 ++--- .../forks/shanghai/vm/instructions/system.py | 6 +++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../spurious_dragon/vm/instructions/system.py | 2 +- .../forks/tangerine_whistle/vm/gas.py | 15 ++++++----- .../vm/instructions/environment.py | 6 ++--- .../vm/instructions/system.py | 2 +- .../compute/precompile/test_alt_bn128.py | 4 +-- 85 files changed, 345 insertions(+), 353 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 41149272159..fd418cf44d8 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -103,22 +103,24 @@ def gas_costs(cls) -> GasCosts: LOW=LOW, MID=MID, HIGH=HIGH, - # Access Costs + # Access WARM_ACCESS=100, COLD_ACCOUNT_ACCESS=2_600, WARM_SLOAD=100, COLD_STORAGE_ACCESS=2_100, - # Storage Costs + # Storage STORAGE_SET=20_000, COLD_STORAGE_WRITE=5_000, STORAGE_RESET=2_900, - # Call Costs + # Call CALL_VALUE=9_000, CALL_STIPEND=2_300, NEW_ACCOUNT=25_000, - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE=200, CODE_INIT_PER_WORD=2, + # Utility + MEMORY_PER_WORD=3, # Transactions TX_BASE=21_000, TX_ACCESS_LIST_ADDRESS=2_400, @@ -167,17 +169,16 @@ def gas_costs(cls) -> GasCosts: OPCODE_PUSH=VERY_LOW, OPCODE_DUP=VERY_LOW, OPCODE_SWAP=VERY_LOW, - # Dynamic Opcodes + # Dynamic Opcode Component OPCODE_CALLDATACOPY=VERY_LOW, OPCODE_CODECOPY=VERY_LOW, OPCODE_MLOAD=VERY_LOW, OPCODE_MSTORE=VERY_LOW, OPCODE_MSTORE8=VERY_LOW, OPCODE_SELFDESTRUCT=5_000, - # Dynamic Opcode Component Costs - COPY_PER_WORD=3, - CREATE=32_000, - MEMORY_PER_WORD=3, + OPCODE_COPY_PER_WORD=3, + OPCODE_CREATE_BASE=32_000, + # TODO EXPONENTIATION=10, EXPONENTIATION_PER_BYTE=50, LOG=375, @@ -297,7 +298,7 @@ def _with_data_copy( base_gas: Either a constant gas cost (int) or a callable that calculates it gas_costs: The gas costs dataclass for accessing - COPY_PER_WORD + OPCODE_COPY_PER_WORD Returns: A callable that calculates base_gas + copy_cost @@ -314,7 +315,7 @@ def wrapper(opcode: OpcodeBase) -> int: # Add copy cost based on data size data_size = opcode.metadata["data_size"] word_count = (data_size + 31) // 32 - copy_cost = gas_costs.COPY_PER_WORD * word_count + copy_cost = gas_costs.OPCODE_COPY_PER_WORD * word_count return base_cost + copy_cost @@ -675,7 +676,7 @@ def _calculate_create_gas( ) -> int: """CREATE gas is constant at Frontier.""" del opcode - return gas_costs.CREATE + return gas_costs.OPCODE_CREATE_BASE @classmethod def _calculate_create2_gas( diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 6a7bc46c78b..93065448ac4 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -21,29 +21,32 @@ class GasCosts: MID: int HIGH: int - # Access Costs + # Access WARM_ACCESS: int COLD_ACCOUNT_ACCESS: int WARM_SLOAD: int COLD_STORAGE_ACCESS: int - # Storage Costs + # Storage STORAGE_SET: int COLD_STORAGE_WRITE: int STORAGE_RESET: int - # Call Costs + # Call CALL_VALUE: int CALL_STIPEND: int NEW_ACCOUNT: int - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE: int CODE_INIT_PER_WORD: int - # Authorization Costs + # Authorization AUTH_PER_EMPTY_ACCOUNT: int + # Utility + MEMORY_PER_WORD: int + # Transactions TX_BASE: int TX_CREATE: int @@ -118,18 +121,16 @@ class GasCosts: OPCODE_DUP: int OPCODE_SWAP: int - # Dynamic Opcodes + # Dynamic Opcode Components OPCODE_CALLDATACOPY: int OPCODE_CODECOPY: int OPCODE_MLOAD: int OPCODE_MSTORE: int OPCODE_MSTORE8: int OPCODE_SELFDESTRUCT: int - - # Dynamic Opcode Component Costs - COPY_PER_WORD: int - CREATE: int - MEMORY_PER_WORD: int + OPCODE_COPY_PER_WORD: int + OPCODE_CREATE_BASE: int + # TODO EXPONENTIATION: int EXPONENTIATION_PER_BYTE: int LOG: int diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 8f8b01ae0ac..ca80c1e0e8d 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -85,7 +85,7 @@ Osaka, Op.CALLDATACOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 1 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="calldatacopy_one_word", ), @@ -95,7 +95,7 @@ data_size=64, new_memory_size=64, old_memory_size=32 ), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 2 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()( new_bytes=64, previous_bytes=32 ), @@ -106,7 +106,7 @@ Osaka, Op.CODECOPY(data_size=96, new_memory_size=96), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 3 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="codecopy_three_words", ), @@ -130,7 +130,7 @@ address_warm=True, data_size=32, new_memory_size=32 ), Osaka.gas_costs().WARM_ACCESS - + Osaka.gas_costs().COPY_PER_WORD * 1 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="extcodecopy_warm", ), @@ -140,7 +140,7 @@ address_warm=False, data_size=64, new_memory_size=64 ), Osaka.gas_costs().COLD_ACCOUNT_ACCESS - + Osaka.gas_costs().COPY_PER_WORD * 2 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="extcodecopy_cold", ), @@ -162,7 +162,7 @@ Osaka, Op.RETURNDATACOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 1 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="returndatacopy", ), @@ -200,7 +200,7 @@ Osaka, Op.MCOPY(data_size=32, new_memory_size=32), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 1 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 1 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="mcopy_one_word", ), @@ -208,7 +208,7 @@ Osaka, Op.MCOPY(data_size=96, new_memory_size=128, old_memory_size=64), Osaka.gas_costs().VERY_LOW - + Osaka.gas_costs().COPY_PER_WORD * 3 + + Osaka.gas_costs().OPCODE_COPY_PER_WORD * 3 + Osaka.memory_expansion_gas_calculator()( new_bytes=128, previous_bytes=64 ), @@ -267,7 +267,7 @@ pytest.param( Osaka, Op.CREATE(init_code_size=100, new_memory_size=100), - Osaka.gas_costs().CREATE + Osaka.gas_costs().OPCODE_CREATE_BASE # (100 + 31) // 32 = 4 + Osaka.gas_costs().CODE_INIT_PER_WORD * 4 + Osaka.memory_expansion_gas_calculator()(new_bytes=100), @@ -277,7 +277,7 @@ pytest.param( Osaka, Op.CREATE2(init_code_size=64, new_memory_size=64), - Osaka.gas_costs().CREATE + Osaka.gas_costs().OPCODE_CREATE_BASE + Osaka.gas_costs().CODE_INIT_PER_WORD * 2 + Osaka.gas_costs().KECCAK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 16b12d29dd9..19fecca4ad0 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -40,27 +40,30 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) # TODO refactor to OPCODE_RETURNDATACOPY? + RETURN_DATA_COPY = Uint( + 3 + ) # TODO refactor=>OPCODE_RETURNDATAOPCODE_COPY_PER_WORD + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -130,7 +133,7 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW + OPCODE_RETURNDATACOPY = VERY_LOW # TODO OPCODE_RETURNDATACOPY_BASE OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) @@ -139,18 +142,16 @@ class GasCosts: OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW - # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) + # Dynamic Opcode Components OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW OPCODE_SELFDESTRUCT_BASE = Uint(5000) - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 06ca4cee568..3e0e65d9012 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -224,7 +224,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -285,7 +285,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/amsterdam/vm/instructions/system.py b/src/ethereum/forks/amsterdam/vm/instructions/system.py index d309023903c..3fa84ffd05a 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/system.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/system.py @@ -166,7 +166,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -216,7 +218,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 6924067c9cb..475c6c3a8bd 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -37,26 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,16 +114,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index b2c2feeb6ef..67f9b502690 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py index d2ff1afe683..80608a122e2 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index e748bbca10b..146d3a10751 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -37,26 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -114,16 +115,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 15ade44f740..5ee3a7c1810 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/berlin/vm/instructions/system.py b/src/ethereum/forks/berlin/vm/instructions/system.py index 6fef8addff6..846a7cfb020 100644 --- a/src/ethereum/forks/berlin/vm/instructions/system.py +++ b/src/ethereum/forks/berlin/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 7a627d5a357..f302c35a5a8 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo1/vm/instructions/system.py b/src/ethereum/forks/bpo1/vm/instructions/system.py index 50d4e74c341..790af3583f7 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/system.py +++ b/src/ethereum/forks/bpo1/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.CREATE + extend_memory.cost + init_code_gas, + GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index a37de5e18e3..169f11a1d31 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo2/vm/instructions/system.py b/src/ethereum/forks/bpo2/vm/instructions/system.py index e9952c58e97..1a1c02d0238 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/system.py +++ b/src/ethereum/forks/bpo2/vm/instructions/system.py @@ -158,7 +158,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,7 +210,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index a37de5e18e3..169f11a1d31 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo3/vm/instructions/system.py b/src/ethereum/forks/bpo3/vm/instructions/system.py index e9952c58e97..1a1c02d0238 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/system.py +++ b/src/ethereum/forks/bpo3/vm/instructions/system.py @@ -158,7 +158,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,7 +210,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index a37de5e18e3..169f11a1d31 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo4/vm/instructions/system.py b/src/ethereum/forks/bpo4/vm/instructions/system.py index 50d4e74c341..790af3583f7 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/system.py +++ b/src/ethereum/forks/bpo4/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.CREATE + extend_memory.cost + init_code_gas, + GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index a37de5e18e3..169f11a1d31 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/bpo5/vm/instructions/system.py b/src/ethereum/forks/bpo5/vm/instructions/system.py index 50d4e74c341..790af3583f7 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/system.py +++ b/src/ethereum/forks/bpo5/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.CREATE + extend_memory.cost + init_code_gas, + GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 720fc4a06a2..908ba40b933 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -37,24 +37,25 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(200) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -107,18 +108,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 44bab49c5bb..e3392288575 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -216,7 +216,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -277,7 +277,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -363,7 +363,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/byzantium/vm/instructions/system.py b/src/ethereum/forks/byzantium/vm/instructions/system.py index e99e2a66766..ae9c43250d2 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/system.py +++ b/src/ethereum/forks/byzantium/vm/instructions/system.py @@ -69,7 +69,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index c9e8faa2365..aaf45c5e96d 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -125,16 +126,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/cancun/vm/instructions/system.py b/src/ethereum/forks/cancun/vm/instructions/system.py index 64cd5b2cac7..e7489460713 100644 --- a/src/ethereum/forks/cancun/vm/instructions/system.py +++ b/src/ethereum/forks/cancun/vm/instructions/system.py @@ -157,7 +157,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -207,7 +209,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index b7e670c2b4e..210f8d51e56 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -37,25 +37,26 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(200) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(400) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -111,18 +112,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index 789970e3ba3..4d9ef8740f5 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index 633bd05e34d..d20c4017544 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 1ccdeddc83f..6c6f349919f 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -39,23 +39,24 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(50) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -103,18 +104,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) - CREATE = Uint(32000) CALL = Uint(40) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 2118d0435a3..1edc79679f5 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/system.py b/src/ethereum/forks/dao_fork/vm/instructions/system.py index 53daba51cee..466252ba735 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/system.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 1ccdeddc83f..6c6f349919f 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -39,23 +39,24 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(50) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -103,18 +104,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) - CREATE = Uint(32000) CALL = Uint(40) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 2118d0435a3..1edc79679f5 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/frontier/vm/instructions/system.py b/src/ethereum/forks/frontier/vm/instructions/system.py index 3b614b76344..6426fbfa04c 100644 --- a/src/ethereum/forks/frontier/vm/instructions/system.py +++ b/src/ethereum/forks/frontier/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 72b81b7f9c9..fbd5e2b38d6 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -37,26 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,16 +114,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index b2c2feeb6ef..67f9b502690 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/system.py b/src/ethereum/forks/gray_glacier/vm/instructions/system.py index da80d3c7122..34cf81306da 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 1ccdeddc83f..6c6f349919f 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -39,23 +39,24 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(50) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -103,18 +104,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) - CREATE = Uint(32000) CALL = Uint(40) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 2118d0435a3..1edc79679f5 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/homestead/vm/instructions/system.py b/src/ethereum/forks/homestead/vm/instructions/system.py index 53daba51cee..466252ba735 100644 --- a/src/ethereum/forks/homestead/vm/instructions/system.py +++ b/src/ethereum/forks/homestead/vm/instructions/system.py @@ -65,7 +65,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = evm.gas_left evm.gas_left = Uint(0) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 52b0c2c1a51..ad0a9529db0 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -37,25 +37,26 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(800) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(700) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,18 +114,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index b60f50e2bbb..af80fe8aac3 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index adc16d7eb7f..23ca08b3f1d 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 72b81b7f9c9..fbd5e2b38d6 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -37,26 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,16 +114,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index b2c2feeb6ef..67f9b502690 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/london/vm/instructions/system.py b/src/ethereum/forks/london/vm/instructions/system.py index da80d3c7122..34cf81306da 100644 --- a/src/ethereum/forks/london/vm/instructions/system.py +++ b/src/ethereum/forks/london/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 52b0c2c1a51..ad0a9529db0 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -37,25 +37,26 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(800) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) CODE_HASH = Uint(700) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,18 +114,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index b60f50e2bbb..af80fe8aac3 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -217,7 +217,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -278,7 +278,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -364,7 +364,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index adc16d7eb7f..23ca08b3f1d 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -149,7 +149,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 1dfaf1f43cb..230231b26c0 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -136,16 +137,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/osaka/vm/instructions/system.py b/src/ethereum/forks/osaka/vm/instructions/system.py index ecedf2851a1..da6f63ff63d 100644 --- a/src/ethereum/forks/osaka/vm/instructions/system.py +++ b/src/ethereum/forks/osaka/vm/instructions/system.py @@ -160,7 +160,7 @@ def create(evm: Evm) -> None: charge_gas( evm, - GasCosts.CREATE + extend_memory.cost + init_code_gas, + GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas, ) # OPERATION @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 72b81b7f9c9..fbd5e2b38d6 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -37,26 +37,27 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -113,16 +114,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 3eec4835ee6..c055dae2dac 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/paris/vm/instructions/system.py b/src/ethereum/forks/paris/vm/instructions/system.py index 1466a9677f5..3ac91c62b15 100644 --- a/src/ethereum/forks/paris/vm/instructions/system.py +++ b/src/ethereum/forks/paris/vm/instructions/system.py @@ -148,7 +148,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -193,7 +193,7 @@ def create2(evm: Evm) -> None: call_data_words = ceil32(Uint(memory_size)) // Uint(32) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 5c5d24fd189..4d9a1b7326c 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -39,27 +39,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -131,16 +132,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 854ceb81848..10810bc79f5 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -376,7 +376,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index cf60b982664..9fdc69dd39e 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -159,7 +159,7 @@ def mcopy(evm: Evm) -> None: # GAS words = ceil32(Uint(length)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(source, length), (destination, length)] diff --git a/src/ethereum/forks/prague/vm/instructions/system.py b/src/ethereum/forks/prague/vm/instructions/system.py index e9952c58e97..1a1c02d0238 100644 --- a/src/ethereum/forks/prague/vm/instructions/system.py +++ b/src/ethereum/forks/prague/vm/instructions/system.py @@ -158,7 +158,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -208,7 +210,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index ab1dd9edd0e..9d113e26b16 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -37,27 +37,28 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access WARM_ACCESS = Uint(100) COLD_ACCOUNT_ACCESS = Uint(2600) COLD_STORAGE_ACCESS = Uint(2100) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) # Utility ZERO = Uint(0) RETURN_DATA_COPY = Uint(3) + MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) # Refunds @@ -114,16 +115,14 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO - CREATE = Uint(32000) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 3eec4835ee6..c055dae2dac 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -374,7 +374,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/shanghai/vm/instructions/system.py b/src/ethereum/forks/shanghai/vm/instructions/system.py index 2ac2e1d3b22..99029f9764a 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/system.py +++ b/src/ethereum/forks/shanghai/vm/instructions/system.py @@ -156,7 +156,9 @@ def create(evm: Evm) -> None: ) init_code_gas = init_code_cost(Uint(memory_size)) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost + init_code_gas) + charge_gas( + evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost + init_code_gas + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -206,7 +208,7 @@ def create2(evm: Evm) -> None: init_code_gas = init_code_cost(Uint(memory_size)) charge_gas( evm, - GasCosts.CREATE + GasCosts.OPCODE_CREATE_BASE + GasCosts.KECCAK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 6a65242badb..36578d6b8cc 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -37,23 +37,24 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(200) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,18 +102,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(50) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 2118d0435a3..1edc79679f5 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py index 00cebb30ea3..a5235bb873a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py @@ -68,7 +68,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 53b83ffe460..d601adb84a3 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -37,23 +37,24 @@ class GasCosts: MID = Uint(8) HIGH = Uint(10) - # Access Costs + # Access SLOAD = Uint(200) - # Storage Costs + # Storage STORAGE_SET = Uint(20000) COLD_STORAGE_WRITE = Uint(5000) - # Call Costs + # Call CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - # Contract Creation Costs + # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) + MEMORY_PER_WORD = Uint(3) # Refunds REFUND_STORAGE_CLEAR = 15000 @@ -101,18 +102,16 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - COPY_PER_WORD = Uint(3) - MEMORY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY = VERY_LOW OPCODE_CODECOPY = VERY_LOW OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - + OPCODE_COPY_PER_WORD = Uint(3) + OPCODE_CREATE_BASE = Uint(32000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) - CREATE = Uint(32000) CALL = Uint(700) EXPONENTIATION = Uint(10) EXPONENTIATION_PER_BYTE = Uint(10) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 2118d0435a3..1edc79679f5 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -215,7 +215,7 @@ def calldatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -276,7 +276,7 @@ def codecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) @@ -362,7 +362,7 @@ def extcodecopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.COPY_PER_WORD * words + copy_gas_cost = GasCosts.OPCODE_COPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py index 4b95c5986f3..0e3d408a4bb 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py @@ -67,7 +67,7 @@ def create(evm: Evm) -> None: evm.memory, [(memory_start_position, memory_size)] ) - charge_gas(evm, GasCosts.CREATE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CREATE_BASE + extend_memory.cost) create_message_gas = max_message_call_gas(Uint(evm.gas_left)) evm.gas_left -= create_message_gas diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index cfb56b0d21b..3078f3a422c 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -609,7 +609,7 @@ def test_ec_pairing( per_variant_gas = ( iteration_cost + pair_size * 16 - + words_per_variant * (gsc.COPY_PER_WORD + gsc.MEMORY_PER_WORD) + + words_per_variant * (gsc.OPCODE_COPY_PER_WORD + gsc.MEMORY_PER_WORD) ) empty_intrinsic = intrinsic_gas_calculator( calldata=[], return_cost_deducted_prior_execution=True @@ -640,7 +640,7 @@ def test_ec_pairing( per_tx_gas - execution_intrinsic - setup_cost - - math.ceil(len(calldata) / 32) * gsc.COPY_PER_WORD + - math.ceil(len(calldata) / 32) * gsc.OPCODE_COPY_PER_WORD - mem_exp(new_bytes=len(calldata) + 32) ) From b3a7d3a229ef264d36d8d95c2e3f2825a43435c8 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 15:17:16 -0400 Subject: [PATCH 48/61] refactor: EXPONENTIATION=>OPCODE_EXP_BASE, EXPONENTIATION_PER_BYTE OPCODE_EXP_PER_BYTE --- .../testing/src/execution_testing/forks/forks/forks.py | 8 ++++---- .../testing/src/execution_testing/forks/gas_costs.py | 4 ++-- .../forks/tests/test_opcode_gas_costs.py | 10 +++++----- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++-- .../forks/amsterdam/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 4 ++-- .../forks/arrow_glacier/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/berlin/vm/gas.py | 4 ++-- .../forks/berlin/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/bpo1/vm/gas.py | 4 ++-- src/ethereum/forks/bpo1/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 4 ++-- src/ethereum/forks/bpo2/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 4 ++-- src/ethereum/forks/bpo3/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 4 ++-- src/ethereum/forks/bpo4/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 4 ++-- src/ethereum/forks/bpo5/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- .../forks/byzantium/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/cancun/vm/gas.py | 4 ++-- .../forks/cancun/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/constantinople/vm/gas.py | 4 ++-- .../forks/constantinople/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/dao_fork/vm/gas.py | 4 ++-- .../forks/dao_fork/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/frontier/vm/gas.py | 4 ++-- .../forks/frontier/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++-- .../forks/gray_glacier/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/homestead/vm/gas.py | 4 ++-- .../forks/homestead/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/istanbul/vm/gas.py | 4 ++-- .../forks/istanbul/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/london/vm/gas.py | 4 ++-- .../forks/london/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++-- .../forks/muir_glacier/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/osaka/vm/gas.py | 4 ++-- src/ethereum/forks/osaka/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/paris/vm/gas.py | 4 ++-- src/ethereum/forks/paris/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/prague/vm/gas.py | 4 ++-- .../forks/prague/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/shanghai/vm/gas.py | 4 ++-- .../forks/shanghai/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 4 ++-- .../spurious_dragon/vm/instructions/arithmetic.py | 4 ++-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 4 ++-- .../tangerine_whistle/vm/instructions/arithmetic.py | 4 ++-- 51 files changed, 107 insertions(+), 107 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index fd418cf44d8..a2f0bc5878e 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -178,9 +178,9 @@ def gas_costs(cls) -> GasCosts: OPCODE_SELFDESTRUCT=5_000, OPCODE_COPY_PER_WORD=3, OPCODE_CREATE_BASE=32_000, + OPCODE_EXP_BASE=10, + OPCODE_EXP_PER_BYTE=50, # TODO - EXPONENTIATION=10, - EXPONENTIATION_PER_BYTE=50, LOG=375, LOG_DATA_PER_BYTE=8, LOG_TOPIC=375, @@ -353,8 +353,8 @@ def opcode_gas_map( Opcodes.ADDMOD: gas_costs.OPCODE_ADDMOD, Opcodes.MULMOD: gas_costs.OPCODE_MULMOD, Opcodes.EXP: lambda op: ( - gas_costs.EXPONENTIATION - + gas_costs.EXPONENTIATION_PER_BYTE + gas_costs.OPCODE_EXP_BASE + + gas_costs.OPCODE_EXP_PER_BYTE * ((op.metadata["exponent"].bit_length() + 7) // 8) ), Opcodes.SIGNEXTEND: gas_costs.OPCODE_SIGNEXTEND, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 93065448ac4..c176d0192f0 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -130,9 +130,9 @@ class GasCosts: OPCODE_SELFDESTRUCT: int OPCODE_COPY_PER_WORD: int OPCODE_CREATE_BASE: int + OPCODE_EXP_BASE: int + OPCODE_EXP_PER_BYTE: int # TODO - EXPONENTIATION: int - EXPONENTIATION_PER_BYTE: int LOG: int LOG_DATA_PER_BYTE: int LOG_TOPIC: int diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index ca80c1e0e8d..95be16861cb 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -35,21 +35,21 @@ pytest.param( Osaka, Op.EXP(exponent=0), - Osaka.gas_costs().EXPONENTIATION, + Osaka.gas_costs().OPCODE_EXP_BASE, id="exp_zero_exponent", ), pytest.param( Osaka, Op.EXP(exponent=0xFFFFFF), # 3 bytes - Osaka.gas_costs().EXPONENTIATION - + Osaka.gas_costs().EXPONENTIATION_PER_BYTE * 3, + Osaka.gas_costs().OPCODE_EXP_BASE + + Osaka.gas_costs().OPCODE_EXP_PER_BYTE * 3, id="exp_three_bytes", ), pytest.param( Osaka, Op.EXP(exponent=0x1FFFFFF), # 3 bytes - Osaka.gas_costs().EXPONENTIATION - + Osaka.gas_costs().EXPONENTIATION_PER_BYTE * 4, + Osaka.gas_costs().OPCODE_EXP_BASE + + Osaka.gas_costs().OPCODE_EXP_PER_BYTE * 4, id="exp_three_bytes_plus_one_bit", ), # SHA3 tests diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 19fecca4ad0..57006100b70 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -151,9 +151,9 @@ class GasCosts: OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 475c6c3a8bd..e4ababcc281 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -121,9 +121,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 146d3a10751..645a7835fd4 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -122,9 +122,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/berlin/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/berlin/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index f302c35a5a8..9cbb95fea34 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo1/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 169f11a1d31..5eabfe89330 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo2/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 169f11a1d31..5eabfe89330 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo3/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 169f11a1d31..5eabfe89330 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo4/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 169f11a1d31..5eabfe89330 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/bpo5/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 908ba40b933..14c6a01a3cc 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -115,12 +115,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/byzantium/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index aaf45c5e96d..dd3f12d4259 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -133,9 +133,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/cancun/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/cancun/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 210f8d51e56..af24fe4242e 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -119,12 +119,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/constantinople/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 6c6f349919f..90be1357f70 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -111,12 +111,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(10) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 6c6f349919f..90be1357f70 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -111,12 +111,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(10) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/frontier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/frontier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index fbd5e2b38d6..c19a204212a 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -121,9 +121,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 6c6f349919f..90be1357f70 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -111,12 +111,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(10) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/homestead/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/homestead/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index ad0a9529db0..0b4d7f65252 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -121,12 +121,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/istanbul/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index fbd5e2b38d6..c19a204212a 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -121,9 +121,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/london/vm/instructions/arithmetic.py b/src/ethereum/forks/london/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/london/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/london/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index ad0a9529db0..0b4d7f65252 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -121,12 +121,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 230231b26c0..2746a58a94c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -144,9 +144,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/osaka/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/osaka/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index fbd5e2b38d6..c19a204212a 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -121,9 +121,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/paris/vm/instructions/arithmetic.py b/src/ethereum/forks/paris/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/paris/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/paris/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 4d9a1b7326c..51455bc0b8f 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -139,9 +139,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/prague/vm/instructions/arithmetic.py b/src/ethereum/forks/prague/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/prague/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/prague/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 9d113e26b16..4b0fa385e17 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -122,9 +122,9 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py index be213222ec6..c361db7373f 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/shanghai/vm/instructions/arithmetic.py @@ -312,8 +312,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 36578d6b8cc..c6879552db4 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -109,12 +109,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(50) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(50) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index d601adb84a3..a677728ad67 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -109,12 +109,12 @@ class GasCosts: OPCODE_MSTORE8 = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) + OPCODE_EXP_BASE = Uint(10) + OPCODE_EXP_PER_BYTE = Uint(10) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - EXPONENTIATION = Uint(10) - EXPONENTIATION_PER_BYTE = Uint(10) KECCAK256 = Uint(30) KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py index 6ce0b105c04..4c7423cba8e 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/arithmetic.py @@ -315,8 +315,8 @@ def exp(evm: Evm) -> None: exponent_bytes = (exponent_bits + Uint(7)) // Uint(8) charge_gas( evm, - GasCosts.EXPONENTIATION - + GasCosts.EXPONENTIATION_PER_BYTE * exponent_bytes, + GasCosts.OPCODE_EXP_BASE + + GasCosts.OPCODE_EXP_PER_BYTE * exponent_bytes, ) # OPERATION From eec2354c773c5db80feae95078d24e8822dd1fa5 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 15:37:38 -0400 Subject: [PATCH 49/61] refactor: KECCAK256=>OPCODE_KECCAK256_BASE, KECCAK256_PER_WORD=>OPCODE_KECCAK256_PER_WORD --- .../testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- .../execution_testing/forks/tests/test_opcode_gas_costs.py | 4 ++-- src/ethereum/forks/amsterdam/vm/gas.py | 4 ++-- src/ethereum/forks/amsterdam/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/amsterdam/vm/instructions/system.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/instructions/system.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 4 ++-- src/ethereum/forks/berlin/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/berlin/vm/instructions/system.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 4 ++-- src/ethereum/forks/bpo1/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/bpo1/vm/instructions/system.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 4 ++-- src/ethereum/forks/bpo2/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/bpo2/vm/instructions/system.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 4 ++-- src/ethereum/forks/bpo3/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/bpo3/vm/instructions/system.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 4 ++-- src/ethereum/forks/bpo4/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/bpo4/vm/instructions/system.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 4 ++-- src/ethereum/forks/bpo5/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/bpo5/vm/instructions/system.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- src/ethereum/forks/byzantium/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/cancun/vm/gas.py | 4 ++-- src/ethereum/forks/cancun/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/cancun/vm/instructions/system.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 4 ++-- .../forks/constantinople/vm/instructions/keccak.py | 7 +++++-- .../forks/constantinople/vm/instructions/system.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 4 ++-- src/ethereum/forks/dao_fork/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/frontier/vm/gas.py | 4 ++-- src/ethereum/forks/frontier/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/instructions/system.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 4 ++-- src/ethereum/forks/homestead/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/istanbul/vm/gas.py | 4 ++-- src/ethereum/forks/istanbul/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/istanbul/vm/instructions/system.py | 2 +- src/ethereum/forks/london/vm/gas.py | 4 ++-- src/ethereum/forks/london/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/london/vm/instructions/system.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/muir_glacier/vm/instructions/system.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 4 ++-- src/ethereum/forks/osaka/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/osaka/vm/instructions/system.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 4 ++-- src/ethereum/forks/paris/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/paris/vm/instructions/system.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 4 ++-- src/ethereum/forks/prague/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/prague/vm/instructions/system.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 4 ++-- src/ethereum/forks/shanghai/vm/instructions/keccak.py | 4 ++-- src/ethereum/forks/shanghai/vm/instructions/system.py | 2 +- src/ethereum/forks/spurious_dragon/vm/gas.py | 4 ++-- .../forks/spurious_dragon/vm/instructions/keccak.py | 7 +++++-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 4 ++-- .../forks/tangerine_whistle/vm/instructions/keccak.py | 7 +++++-- 69 files changed, 146 insertions(+), 119 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index a2f0bc5878e..83215dde068 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -185,7 +185,7 @@ def gas_costs(cls) -> GasCosts: LOG_DATA_PER_BYTE=8, LOG_TOPIC=375, KECCAK256=30, - KECCAK256_PER_WORD=6, + OPCODE_KECCACK256_PER_WORD=6, # Zero-initialized: introduced in later forks, set via # replace() in the fork that activates them. TX_DATA_TOKEN_STANDARD=0, @@ -374,7 +374,7 @@ def opcode_gas_map( Opcodes.SHA3: cls._with_memory_expansion( lambda op: ( gas_costs.KECCAK256 - + gas_costs.KECCAK256_PER_WORD + + gas_costs.OPCODE_KECCACK256_PER_WORD * ((op.metadata["data_size"] + 31) // 32) ), memory_expansion_calculator, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index c176d0192f0..67ad2998c74 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -137,7 +137,7 @@ class GasCosts: LOG_DATA_PER_BYTE: int LOG_TOPIC: int KECCAK256: int - KECCAK256_PER_WORD: int + OPCODE_KECCACK256_PER_WORD: int # Defined post-Frontier OPCODE_SHL: int = 0 diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 95be16861cb..2fe32d4035c 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -63,7 +63,7 @@ Osaka, Op.SHA3(data_size=64, new_memory_size=96), Osaka.gas_costs().KECCAK256 - + Osaka.gas_costs().KECCAK256_PER_WORD * 2 + + Osaka.gas_costs().OPCODE_KECCACK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="sha3_with_data_and_memory", ), @@ -279,7 +279,7 @@ Op.CREATE2(init_code_size=64, new_memory_size=64), Osaka.gas_costs().OPCODE_CREATE_BASE + Osaka.gas_costs().CODE_INIT_PER_WORD * 2 - + Osaka.gas_costs().KECCAK256_PER_WORD * 2 + + Osaka.gas_costs().OPCODE_KECCACK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="create2_with_initcode_and_hash", ), diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 57006100b70..793ff511c40 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -153,9 +153,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/keccak.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/amsterdam/vm/instructions/system.py b/src/ethereum/forks/amsterdam/vm/instructions/system.py index 3fa84ffd05a..7dbcc36cc82 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/system.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/system.py @@ -219,7 +219,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index e4ababcc281..5ccb4f87a47 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -123,9 +123,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py index 80608a122e2..c833b51b684 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 645a7835fd4..845f0cfdfee 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -124,9 +124,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/berlin/vm/instructions/keccak.py b/src/ethereum/forks/berlin/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/berlin/vm/instructions/keccak.py +++ b/src/ethereum/forks/berlin/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/instructions/system.py b/src/ethereum/forks/berlin/vm/instructions/system.py index 846a7cfb020..678ec865c3b 100644 --- a/src/ethereum/forks/berlin/vm/instructions/system.py +++ b/src/ethereum/forks/berlin/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 9cbb95fea34..1d859e24f65 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/bpo1/vm/instructions/keccak.py b/src/ethereum/forks/bpo1/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo1/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/system.py b/src/ethereum/forks/bpo1/vm/instructions/system.py index 790af3583f7..0f793ada155 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/system.py +++ b/src/ethereum/forks/bpo1/vm/instructions/system.py @@ -212,7 +212,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 5eabfe89330..0a0588afd34 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/bpo2/vm/instructions/keccak.py b/src/ethereum/forks/bpo2/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo2/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/system.py b/src/ethereum/forks/bpo2/vm/instructions/system.py index 1a1c02d0238..6772bb54fd5 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/system.py +++ b/src/ethereum/forks/bpo2/vm/instructions/system.py @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 5eabfe89330..0a0588afd34 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/bpo3/vm/instructions/keccak.py b/src/ethereum/forks/bpo3/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo3/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/system.py b/src/ethereum/forks/bpo3/vm/instructions/system.py index 1a1c02d0238..6772bb54fd5 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/system.py +++ b/src/ethereum/forks/bpo3/vm/instructions/system.py @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 5eabfe89330..0a0588afd34 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/bpo4/vm/instructions/keccak.py b/src/ethereum/forks/bpo4/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo4/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/system.py b/src/ethereum/forks/bpo4/vm/instructions/system.py index 790af3583f7..0f793ada155 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/system.py +++ b/src/ethereum/forks/bpo4/vm/instructions/system.py @@ -212,7 +212,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 5eabfe89330..0a0588afd34 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/bpo5/vm/instructions/keccak.py b/src/ethereum/forks/bpo5/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/keccak.py +++ b/src/ethereum/forks/bpo5/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/system.py b/src/ethereum/forks/bpo5/vm/instructions/system.py index 790af3583f7..0f793ada155 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/system.py +++ b/src/ethereum/forks/bpo5/vm/instructions/system.py @@ -212,7 +212,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 14c6a01a3cc..e28b2868a8f 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -117,12 +117,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/byzantium/vm/instructions/keccak.py b/src/ethereum/forks/byzantium/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/keccak.py +++ b/src/ethereum/forks/byzantium/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index dd3f12d4259..55e6fa7c052 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -135,9 +135,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/cancun/vm/instructions/keccak.py b/src/ethereum/forks/cancun/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/cancun/vm/instructions/keccak.py +++ b/src/ethereum/forks/cancun/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/system.py b/src/ethereum/forks/cancun/vm/instructions/system.py index e7489460713..9a3da2bc1a6 100644 --- a/src/ethereum/forks/cancun/vm/instructions/system.py +++ b/src/ethereum/forks/cancun/vm/instructions/system.py @@ -210,7 +210,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index af24fe4242e..a5eb7dc9586 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -121,12 +121,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/constantinople/vm/instructions/keccak.py b/src/ethereum/forks/constantinople/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/keccak.py +++ b/src/ethereum/forks/constantinople/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index d20c4017544..5cc045bc392 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 90be1357f70..abae33391d3 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -113,12 +113,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(10) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/keccak.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 90be1357f70..abae33391d3 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -113,12 +113,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(10) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/frontier/vm/instructions/keccak.py b/src/ethereum/forks/frontier/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/frontier/vm/instructions/keccak.py +++ b/src/ethereum/forks/frontier/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index c19a204212a..26f9a61ff0f 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -123,9 +123,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/system.py b/src/ethereum/forks/gray_glacier/vm/instructions/system.py index 34cf81306da..d7498992b06 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 90be1357f70..abae33391d3 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -113,12 +113,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(10) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/homestead/vm/instructions/keccak.py b/src/ethereum/forks/homestead/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/homestead/vm/instructions/keccak.py +++ b/src/ethereum/forks/homestead/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 0b4d7f65252..7f268a320dc 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -123,12 +123,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/istanbul/vm/instructions/keccak.py b/src/ethereum/forks/istanbul/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/keccak.py +++ b/src/ethereum/forks/istanbul/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index 23ca08b3f1d..ddc36107c28 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index c19a204212a..26f9a61ff0f 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -123,9 +123,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/london/vm/instructions/keccak.py b/src/ethereum/forks/london/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/london/vm/instructions/keccak.py +++ b/src/ethereum/forks/london/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/instructions/system.py b/src/ethereum/forks/london/vm/instructions/system.py index 34cf81306da..d7498992b06 100644 --- a/src/ethereum/forks/london/vm/instructions/system.py +++ b/src/ethereum/forks/london/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 0b4d7f65252..7f268a320dc 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -123,12 +123,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index 23ca08b3f1d..ddc36107c28 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -195,7 +195,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 2746a58a94c..e490093b898 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -146,9 +146,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/osaka/vm/instructions/keccak.py b/src/ethereum/forks/osaka/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/osaka/vm/instructions/keccak.py +++ b/src/ethereum/forks/osaka/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/system.py b/src/ethereum/forks/osaka/vm/instructions/system.py index da6f63ff63d..546d5e3f5a9 100644 --- a/src/ethereum/forks/osaka/vm/instructions/system.py +++ b/src/ethereum/forks/osaka/vm/instructions/system.py @@ -212,7 +212,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index c19a204212a..26f9a61ff0f 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -123,9 +123,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/paris/vm/instructions/keccak.py b/src/ethereum/forks/paris/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/paris/vm/instructions/keccak.py +++ b/src/ethereum/forks/paris/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/instructions/system.py b/src/ethereum/forks/paris/vm/instructions/system.py index 3ac91c62b15..5f6c7f0a9cb 100644 --- a/src/ethereum/forks/paris/vm/instructions/system.py +++ b/src/ethereum/forks/paris/vm/instructions/system.py @@ -194,7 +194,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost, ) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 51455bc0b8f..7e5e703cbde 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -141,9 +141,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/prague/vm/instructions/keccak.py b/src/ethereum/forks/prague/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/prague/vm/instructions/keccak.py +++ b/src/ethereum/forks/prague/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/system.py b/src/ethereum/forks/prague/vm/instructions/system.py index 1a1c02d0238..6772bb54fd5 100644 --- a/src/ethereum/forks/prague/vm/instructions/system.py +++ b/src/ethereum/forks/prague/vm/instructions/system.py @@ -211,7 +211,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 4b0fa385e17..51cf3a8f0c4 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -124,9 +124,9 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/shanghai/vm/instructions/keccak.py b/src/ethereum/forks/shanghai/vm/instructions/keccak.py index 931cb45d875..c8099ee0ecc 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/keccak.py +++ b/src/ethereum/forks/shanghai/vm/instructions/keccak.py @@ -45,13 +45,13 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) charge_gas( evm, - GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/instructions/system.py b/src/ethereum/forks/shanghai/vm/instructions/system.py index 99029f9764a..c5ddef97546 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/system.py +++ b/src/ethereum/forks/shanghai/vm/instructions/system.py @@ -209,7 +209,7 @@ def create2(evm: Evm) -> None: charge_gas( evm, GasCosts.OPCODE_CREATE_BASE - + GasCosts.KECCAK256_PER_WORD * call_data_words + + GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words + extend_memory.cost + init_code_gas, ) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index c6879552db4..27f805584f0 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -111,12 +111,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(50) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index a677728ad67..f1106506297 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -111,12 +111,12 @@ class GasCosts: OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) OPCODE_EXP_PER_BYTE = Uint(10) + OPCODE_KECCAK256_BASE = Uint(30) + OPCODE_KECCACK256_PER_WORD = Uint(6) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - KECCAK256 = Uint(30) - KECCAK256_PER_WORD = Uint(6) LOG = Uint(375) LOG_DATA_PER_BYTE = Uint(8) LOG_TOPIC = Uint(375) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py index 497024b578b..c8099ee0ecc 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/keccak.py @@ -45,11 +45,14 @@ def keccak(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - word_gas_cost = GasCosts.KECCAK256_PER_WORD * words + word_gas_cost = GasCosts.OPCODE_KECCACK256_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.KECCAK256 + word_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_KECCAK256_BASE + word_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by From 9a84b4f24cddbd844be426a345f1ba56d274826a Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 15:51:12 -0400 Subject: [PATCH 50/61] refactor: KECCAK256=>OPCODE_KECCAK256_BASE, KECCAK256_PER_WORD=>OPCODE_KECCAK256_PER_WORD --- .../execution_testing/forks/forks/forks.py | 27 +++++++++++-------- .../src/execution_testing/forks/gas_costs.py | 4 +-- .../forks/tests/test_opcode_gas_costs.py | 18 ++++++------- src/ethereum/forks/amsterdam/vm/gas.py | 6 ++--- .../forks/amsterdam/vm/instructions/log.py | 6 ++--- src/ethereum/forks/arrow_glacier/vm/gas.py | 6 ++--- .../arrow_glacier/vm/instructions/log.py | 6 ++--- src/ethereum/forks/berlin/vm/gas.py | 6 ++--- .../forks/berlin/vm/instructions/log.py | 6 ++--- src/ethereum/forks/bpo1/vm/gas.py | 6 ++--- .../forks/bpo1/vm/instructions/log.py | 6 ++--- src/ethereum/forks/bpo2/vm/gas.py | 6 ++--- .../forks/bpo2/vm/instructions/log.py | 6 ++--- src/ethereum/forks/bpo3/vm/gas.py | 6 ++--- .../forks/bpo3/vm/instructions/log.py | 6 ++--- src/ethereum/forks/bpo4/vm/gas.py | 6 ++--- .../forks/bpo4/vm/instructions/log.py | 6 ++--- src/ethereum/forks/bpo5/vm/gas.py | 6 ++--- .../forks/bpo5/vm/instructions/log.py | 6 ++--- src/ethereum/forks/byzantium/vm/gas.py | 6 ++--- .../forks/byzantium/vm/instructions/log.py | 6 ++--- src/ethereum/forks/cancun/vm/gas.py | 6 ++--- .../forks/cancun/vm/instructions/log.py | 6 ++--- src/ethereum/forks/constantinople/vm/gas.py | 6 ++--- .../constantinople/vm/instructions/log.py | 6 ++--- src/ethereum/forks/dao_fork/vm/gas.py | 6 ++--- .../forks/dao_fork/vm/instructions/log.py | 6 ++--- src/ethereum/forks/frontier/vm/gas.py | 6 ++--- .../forks/frontier/vm/instructions/log.py | 6 ++--- src/ethereum/forks/gray_glacier/vm/gas.py | 6 ++--- .../forks/gray_glacier/vm/instructions/log.py | 6 ++--- src/ethereum/forks/homestead/vm/gas.py | 6 ++--- .../forks/homestead/vm/instructions/log.py | 6 ++--- src/ethereum/forks/istanbul/vm/gas.py | 6 ++--- .../forks/istanbul/vm/instructions/log.py | 6 ++--- src/ethereum/forks/london/vm/gas.py | 6 ++--- .../forks/london/vm/instructions/log.py | 6 ++--- src/ethereum/forks/muir_glacier/vm/gas.py | 6 ++--- .../forks/muir_glacier/vm/instructions/log.py | 6 ++--- src/ethereum/forks/osaka/vm/gas.py | 6 ++--- .../forks/osaka/vm/instructions/log.py | 6 ++--- src/ethereum/forks/paris/vm/gas.py | 6 ++--- .../forks/paris/vm/instructions/log.py | 6 ++--- src/ethereum/forks/prague/vm/gas.py | 6 ++--- .../forks/prague/vm/instructions/log.py | 6 ++--- src/ethereum/forks/shanghai/vm/gas.py | 6 ++--- .../forks/shanghai/vm/instructions/log.py | 6 ++--- src/ethereum/forks/spurious_dragon/vm/gas.py | 6 ++--- .../spurious_dragon/vm/instructions/log.py | 6 ++--- .../forks/tangerine_whistle/vm/gas.py | 6 ++--- .../tangerine_whistle/vm/instructions/log.py | 6 ++--- 51 files changed, 171 insertions(+), 166 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 83215dde068..d024b44a70b 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -182,8 +182,8 @@ def gas_costs(cls) -> GasCosts: OPCODE_EXP_PER_BYTE=50, # TODO LOG=375, - LOG_DATA_PER_BYTE=8, - LOG_TOPIC=375, + OPCODE_LOG_DATA_PER_BYTE=8, + OPCODE_LOG_TOPIC=375, KECCAK256=30, OPCODE_KECCACK256_PER_WORD=6, # Zero-initialized: introduced in later forks, set via @@ -459,39 +459,44 @@ def opcode_gas_map( Opcodes.LOG0: cls._with_memory_expansion( lambda op: ( gas_costs.LOG - + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] + + gas_costs.OPCODE_LOG_DATA_PER_BYTE + * op.metadata["data_size"] ), memory_expansion_calculator, ), Opcodes.LOG1: cls._with_memory_expansion( lambda op: ( gas_costs.LOG - + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] - + gas_costs.LOG_TOPIC + + gas_costs.OPCODE_LOG_DATA_PER_BYTE + * op.metadata["data_size"] + + gas_costs.OPCODE_LOG_TOPIC ), memory_expansion_calculator, ), Opcodes.LOG2: cls._with_memory_expansion( lambda op: ( gas_costs.LOG - + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] - + gas_costs.LOG_TOPIC * 2 + + gas_costs.OPCODE_LOG_DATA_PER_BYTE + * op.metadata["data_size"] + + gas_costs.OPCODE_LOG_TOPIC * 2 ), memory_expansion_calculator, ), Opcodes.LOG3: cls._with_memory_expansion( lambda op: ( gas_costs.LOG - + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] - + gas_costs.LOG_TOPIC * 3 + + gas_costs.OPCODE_LOG_DATA_PER_BYTE + * op.metadata["data_size"] + + gas_costs.OPCODE_LOG_TOPIC * 3 ), memory_expansion_calculator, ), Opcodes.LOG4: cls._with_memory_expansion( lambda op: ( gas_costs.LOG - + gas_costs.LOG_DATA_PER_BYTE * op.metadata["data_size"] - + gas_costs.LOG_TOPIC * 4 + + gas_costs.OPCODE_LOG_DATA_PER_BYTE + * op.metadata["data_size"] + + gas_costs.OPCODE_LOG_TOPIC * 4 ), memory_expansion_calculator, ), diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 67ad2998c74..4bdf4fbf38d 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -134,8 +134,8 @@ class GasCosts: OPCODE_EXP_PER_BYTE: int # TODO LOG: int - LOG_DATA_PER_BYTE: int - LOG_TOPIC: int + OPCODE_LOG_DATA_PER_BYTE: int + OPCODE_LOG_TOPIC: int KECCAK256: int OPCODE_KECCACK256_PER_WORD: int diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 2fe32d4035c..22e83eb8ada 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -219,7 +219,7 @@ Osaka, Op.LOG0(data_size=32, new_memory_size=32), Osaka.gas_costs().LOG - + Osaka.gas_costs().LOG_DATA_PER_BYTE * 32 + + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 32 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="log0", ), @@ -228,8 +228,8 @@ Osaka, Op.LOG1(data_size=64, new_memory_size=64), Osaka.gas_costs().LOG - + Osaka.gas_costs().LOG_DATA_PER_BYTE * 64 - + Osaka.gas_costs().LOG_TOPIC + + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 64 + + Osaka.gas_costs().OPCODE_LOG_TOPIC + Osaka.memory_expansion_gas_calculator()(new_bytes=64), id="log1", ), @@ -238,8 +238,8 @@ Osaka, Op.LOG2(data_size=128, new_memory_size=128), Osaka.gas_costs().LOG - + Osaka.gas_costs().LOG_DATA_PER_BYTE * 128 - + Osaka.gas_costs().LOG_TOPIC * 2 + + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 128 + + Osaka.gas_costs().OPCODE_LOG_TOPIC * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=128), id="log2", ), @@ -248,8 +248,8 @@ Osaka, Op.LOG3(data_size=256, new_memory_size=256), Osaka.gas_costs().LOG - + Osaka.gas_costs().LOG_DATA_PER_BYTE * 256 - + Osaka.gas_costs().LOG_TOPIC * 3 + + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 256 + + Osaka.gas_costs().OPCODE_LOG_TOPIC * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=256), id="log3", ), @@ -258,8 +258,8 @@ Osaka, Op.LOG4(data_size=512, new_memory_size=512), Osaka.gas_costs().LOG - + Osaka.gas_costs().LOG_DATA_PER_BYTE * 512 - + Osaka.gas_costs().LOG_TOPIC * 4 + + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 512 + + Osaka.gas_costs().OPCODE_LOG_TOPIC * 4 + Osaka.memory_expansion_gas_calculator()(new_bytes=512), id="log4", ), diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 793ff511c40..dac5069996d 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -155,10 +155,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) # rename for above SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/log.py b/src/ethereum/forks/amsterdam/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/log.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 5ccb4f87a47..d042b162d70 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -125,10 +125,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 845f0cfdfee..246507b44c2 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -126,10 +126,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/berlin/vm/instructions/log.py b/src/ethereum/forks/berlin/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/berlin/vm/instructions/log.py +++ b/src/ethereum/forks/berlin/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 1d859e24f65..901f87b9074 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/bpo1/vm/instructions/log.py b/src/ethereum/forks/bpo1/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/log.py +++ b/src/ethereum/forks/bpo1/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 0a0588afd34..35b688e7516 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/bpo2/vm/instructions/log.py b/src/ethereum/forks/bpo2/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/log.py +++ b/src/ethereum/forks/bpo2/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 0a0588afd34..35b688e7516 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/bpo3/vm/instructions/log.py b/src/ethereum/forks/bpo3/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/log.py +++ b/src/ethereum/forks/bpo3/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 0a0588afd34..35b688e7516 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/bpo4/vm/instructions/log.py b/src/ethereum/forks/bpo4/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/log.py +++ b/src/ethereum/forks/bpo4/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 0a0588afd34..35b688e7516 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/bpo5/vm/instructions/log.py b/src/ethereum/forks/bpo5/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/log.py +++ b/src/ethereum/forks/bpo5/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index e28b2868a8f..f923037b5af 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -119,13 +119,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/byzantium/vm/instructions/log.py b/src/ethereum/forks/byzantium/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/log.py +++ b/src/ethereum/forks/byzantium/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 55e6fa7c052..c25ac46fe14 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -137,10 +137,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/cancun/vm/instructions/log.py b/src/ethereum/forks/cancun/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/cancun/vm/instructions/log.py +++ b/src/ethereum/forks/cancun/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index a5eb7dc9586..ca64efaeef0 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -123,13 +123,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/constantinople/vm/instructions/log.py b/src/ethereum/forks/constantinople/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/log.py +++ b/src/ethereum/forks/constantinople/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index abae33391d3..6c5d5cf746a 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -115,13 +115,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(10) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) @dataclass diff --git a/src/ethereum/forks/dao_fork/vm/instructions/log.py b/src/ethereum/forks/dao_fork/vm/instructions/log.py index 7b1fed7c967..e3e3ebd7e76 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/log.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index abae33391d3..6c5d5cf746a 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -115,13 +115,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(10) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) @dataclass diff --git a/src/ethereum/forks/frontier/vm/instructions/log.py b/src/ethereum/forks/frontier/vm/instructions/log.py index 7b1fed7c967..e3e3ebd7e76 100644 --- a/src/ethereum/forks/frontier/vm/instructions/log.py +++ b/src/ethereum/forks/frontier/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 26f9a61ff0f..e87376e53d0 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -125,10 +125,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/log.py b/src/ethereum/forks/gray_glacier/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index abae33391d3..6c5d5cf746a 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -115,13 +115,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(10) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(20) BALANCE = Uint(20) CALL = Uint(40) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) @dataclass diff --git a/src/ethereum/forks/homestead/vm/instructions/log.py b/src/ethereum/forks/homestead/vm/instructions/log.py index 7b1fed7c967..e3e3ebd7e76 100644 --- a/src/ethereum/forks/homestead/vm/instructions/log.py +++ b/src/ethereum/forks/homestead/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 7f268a320dc..0f607a8b6a8 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -125,13 +125,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/istanbul/vm/instructions/log.py b/src/ethereum/forks/istanbul/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/log.py +++ b/src/ethereum/forks/istanbul/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 26f9a61ff0f..e87376e53d0 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -125,10 +125,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/london/vm/instructions/log.py b/src/ethereum/forks/london/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/london/vm/instructions/log.py +++ b/src/ethereum/forks/london/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 7f268a320dc..0f607a8b6a8 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -125,13 +125,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/log.py b/src/ethereum/forks/muir_glacier/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/log.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index e490093b898..c101a5fda5c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -148,10 +148,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/osaka/vm/instructions/log.py b/src/ethereum/forks/osaka/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/osaka/vm/instructions/log.py +++ b/src/ethereum/forks/osaka/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 26f9a61ff0f..e87376e53d0 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -125,10 +125,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/paris/vm/instructions/log.py b/src/ethereum/forks/paris/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/paris/vm/instructions/log.py +++ b/src/ethereum/forks/paris/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 7e5e703cbde..876755df13e 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -143,10 +143,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/prague/vm/instructions/log.py b/src/ethereum/forks/prague/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/prague/vm/instructions/log.py +++ b/src/ethereum/forks/prague/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 51cf3a8f0c4..0c4d2d854e1 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -126,10 +126,10 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/shanghai/vm/instructions/log.py b/src/ethereum/forks/shanghai/vm/instructions/log.py index 72877b99176..bd5e652db22 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/log.py +++ b/src/ethereum/forks/shanghai/vm/instructions/log.py @@ -57,9 +57,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 27f805584f0..b423be5e332 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -113,13 +113,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(50) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py index 7b1fed7c967..e3e3ebd7e76 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/log.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index f1106506297..2dc156044ca 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -113,13 +113,13 @@ class GasCosts: OPCODE_EXP_PER_BYTE = Uint(10) OPCODE_KECCAK256_BASE = Uint(30) OPCODE_KECCACK256_PER_WORD = Uint(6) + OPCODE_LOG_BASE = Uint(375) + OPCODE_LOG_DATA_PER_BYTE = Uint(8) + OPCODE_LOG_TOPIC = Uint(375) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - LOG = Uint(375) - LOG_DATA_PER_BYTE = Uint(8) - LOG_TOPIC = Uint(375) SELF_DESTRUCT = Uint(5000) SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py index 7b1fed7c967..e3e3ebd7e76 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/log.py @@ -56,9 +56,9 @@ def log_n(evm: Evm, num_topics: int) -> None: ) charge_gas( evm, - GasCosts.LOG - + GasCosts.LOG_DATA_PER_BYTE * Uint(size) - + GasCosts.LOG_TOPIC * Uint(num_topics) + GasCosts.OPCODE_LOG_BASE + + GasCosts.OPCODE_LOG_DATA_PER_BYTE * Uint(size) + + GasCosts.OPCODE_LOG_TOPIC * Uint(num_topics) + extend_memory.cost, ) From ddd0db6aeeab8a440b2baf3ceed93ce256a6a255 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 16:33:40 -0400 Subject: [PATCH 51/61] refactor: SELF_DESTRUCT=>OPCODE_SELFDESTRUCT_BASE, SELF_DESTRUCT_NEW_ACCOUNT=>OPCODE_SELF_DESTRUCT_NEW_ACCOUNT --- packages/testing/src/execution_testing/forks/forks/forks.py | 4 ++-- packages/testing/src/execution_testing/forks/gas_costs.py | 2 +- src/ethereum/forks/amsterdam/vm/gas.py | 6 ++---- src/ethereum/forks/amsterdam/vm/instructions/system.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 5 ++--- src/ethereum/forks/arrow_glacier/vm/instructions/system.py | 4 ++-- src/ethereum/forks/berlin/vm/gas.py | 5 ++--- src/ethereum/forks/berlin/vm/instructions/system.py | 4 ++-- src/ethereum/forks/bpo1/vm/gas.py | 5 ++--- src/ethereum/forks/bpo1/vm/instructions/system.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 5 ++--- src/ethereum/forks/bpo2/vm/instructions/system.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 5 ++--- src/ethereum/forks/bpo3/vm/instructions/system.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 5 ++--- src/ethereum/forks/bpo4/vm/instructions/system.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 5 ++--- src/ethereum/forks/bpo5/vm/instructions/system.py | 4 ++-- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- src/ethereum/forks/byzantium/vm/instructions/system.py | 4 ++-- src/ethereum/forks/cancun/vm/gas.py | 5 ++--- src/ethereum/forks/cancun/vm/instructions/system.py | 4 ++-- src/ethereum/forks/constantinople/vm/gas.py | 4 ++-- src/ethereum/forks/constantinople/vm/instructions/system.py | 4 ++-- src/ethereum/forks/gray_glacier/vm/gas.py | 5 ++--- src/ethereum/forks/gray_glacier/vm/instructions/system.py | 4 ++-- src/ethereum/forks/istanbul/vm/gas.py | 4 ++-- src/ethereum/forks/istanbul/vm/instructions/system.py | 4 ++-- src/ethereum/forks/london/vm/gas.py | 5 ++--- src/ethereum/forks/london/vm/instructions/system.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/gas.py | 4 ++-- src/ethereum/forks/muir_glacier/vm/instructions/system.py | 4 ++-- src/ethereum/forks/osaka/vm/gas.py | 5 ++--- src/ethereum/forks/osaka/vm/instructions/system.py | 4 ++-- src/ethereum/forks/paris/vm/gas.py | 5 ++--- src/ethereum/forks/paris/vm/instructions/system.py | 4 ++-- src/ethereum/forks/prague/vm/gas.py | 5 ++--- src/ethereum/forks/prague/vm/instructions/system.py | 4 ++-- src/ethereum/forks/shanghai/vm/gas.py | 5 ++--- src/ethereum/forks/shanghai/vm/instructions/system.py | 4 ++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 4 ++-- .../forks/spurious_dragon/vm/instructions/system.py | 4 ++-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 4 ++-- .../forks/tangerine_whistle/vm/instructions/system.py | 4 ++-- .../eip150_operation_gas_costs/test_eip150_selfdestruct.py | 2 +- 45 files changed, 88 insertions(+), 104 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index d024b44a70b..5755e9e5f61 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -175,7 +175,7 @@ def gas_costs(cls) -> GasCosts: OPCODE_MLOAD=VERY_LOW, OPCODE_MSTORE=VERY_LOW, OPCODE_MSTORE8=VERY_LOW, - OPCODE_SELFDESTRUCT=5_000, + OPCODE_SELFDESTRUCT_BASE=5_000, OPCODE_COPY_PER_WORD=3, OPCODE_CREATE_BASE=32_000, OPCODE_EXP_BASE=10, @@ -712,7 +712,7 @@ def _calculate_selfdestruct_gas( """Calculate SELFDESTRUCT gas cost based on metadata.""" metadata = opcode.metadata - base_cost = gas_costs.OPCODE_SELFDESTRUCT + base_cost = gas_costs.OPCODE_SELFDESTRUCT_BASE # Check if the beneficiary is cold if not metadata["address_warm"]: diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 4bdf4fbf38d..f3d41b5679c 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -127,7 +127,7 @@ class GasCosts: OPCODE_MLOAD: int OPCODE_MSTORE: int OPCODE_MSTORE8: int - OPCODE_SELFDESTRUCT: int + OPCODE_SELFDESTRUCT_BASE: int OPCODE_COPY_PER_WORD: int OPCODE_CREATE_BASE: int OPCODE_EXP_BASE: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index dac5069996d..c14ae6531e2 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -148,7 +148,6 @@ class GasCosts: OPCODE_MLOAD = VERY_LOW OPCODE_MSTORE = VERY_LOW OPCODE_MSTORE8 = VERY_LOW - OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) @@ -158,9 +157,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) # rename for above - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/amsterdam/vm/instructions/system.py b/src/ethereum/forks/amsterdam/vm/instructions/system.py index 7dbcc36cc82..42a4643f9c0 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/system.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/system.py @@ -578,7 +578,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE is_cold_access = beneficiary not in evm.accessed_addresses if is_cold_access: @@ -596,7 +596,7 @@ def selfdestruct(evm: Evm) -> None: not is_account_alive(tx_state, beneficiary) and get_account(tx_state, evm.message.current_target).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index d042b162d70..855470d9221 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -128,9 +128,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py index c833b51b684..0282da0d90e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/system.py @@ -483,7 +483,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 246507b44c2..4a94e14e2c7 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -129,9 +129,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/berlin/vm/instructions/system.py b/src/ethereum/forks/berlin/vm/instructions/system.py index 678ec865c3b..4c0e63d6dbe 100644 --- a/src/ethereum/forks/berlin/vm/instructions/system.py +++ b/src/ethereum/forks/berlin/vm/instructions/system.py @@ -483,7 +483,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 901f87b9074..352f9f4e071 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/bpo1/vm/instructions/system.py b/src/ethereum/forks/bpo1/vm/instructions/system.py index 0f793ada155..1fe8daf44d5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/system.py +++ b/src/ethereum/forks/bpo1/vm/instructions/system.py @@ -526,7 +526,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 35b688e7516..1878250387e 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/bpo2/vm/instructions/system.py b/src/ethereum/forks/bpo2/vm/instructions/system.py index 6772bb54fd5..2d99ac93e61 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/system.py +++ b/src/ethereum/forks/bpo2/vm/instructions/system.py @@ -525,7 +525,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -537,7 +537,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 35b688e7516..1878250387e 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/bpo3/vm/instructions/system.py b/src/ethereum/forks/bpo3/vm/instructions/system.py index 6772bb54fd5..2d99ac93e61 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/system.py +++ b/src/ethereum/forks/bpo3/vm/instructions/system.py @@ -525,7 +525,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -537,7 +537,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 35b688e7516..1878250387e 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/bpo4/vm/instructions/system.py b/src/ethereum/forks/bpo4/vm/instructions/system.py index 0f793ada155..1fe8daf44d5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/system.py +++ b/src/ethereum/forks/bpo4/vm/instructions/system.py @@ -526,7 +526,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 35b688e7516..1878250387e 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/bpo5/vm/instructions/system.py b/src/ethereum/forks/bpo5/vm/instructions/system.py index 0f793ada155..1fe8daf44d5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/system.py +++ b/src/ethereum/forks/bpo5/vm/instructions/system.py @@ -526,7 +526,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -538,7 +538,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index f923037b5af..00c71ff68e4 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -122,12 +122,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/byzantium/vm/instructions/system.py b/src/ethereum/forks/byzantium/vm/instructions/system.py index ae9c43250d2..a3c67cc53fd 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/system.py +++ b/src/ethereum/forks/byzantium/vm/instructions/system.py @@ -397,7 +397,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -405,7 +405,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index c25ac46fe14..7985a879f2f 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -140,9 +140,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/cancun/vm/instructions/system.py b/src/ethereum/forks/cancun/vm/instructions/system.py index 9a3da2bc1a6..0808eb1f7a7 100644 --- a/src/ethereum/forks/cancun/vm/instructions/system.py +++ b/src/ethereum/forks/cancun/vm/instructions/system.py @@ -503,7 +503,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -515,7 +515,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index ca64efaeef0..72b864f2655 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -126,12 +126,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index 5cc045bc392..c786ec17519 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index e87376e53d0..1b4d92ac1ea 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -128,9 +128,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/system.py b/src/ethereum/forks/gray_glacier/vm/instructions/system.py index d7498992b06..55c72f0fa9a 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/system.py @@ -483,7 +483,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 0f607a8b6a8..d50e526848e 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -128,12 +128,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index ddc36107c28..9ba6ea00fc5 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index e87376e53d0..1b4d92ac1ea 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -128,9 +128,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/london/vm/instructions/system.py b/src/ethereum/forks/london/vm/instructions/system.py index d7498992b06..55c72f0fa9a 100644 --- a/src/ethereum/forks/london/vm/instructions/system.py +++ b/src/ethereum/forks/london/vm/instructions/system.py @@ -483,7 +483,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -495,7 +495,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 0f607a8b6a8..d50e526848e 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -128,12 +128,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(700) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index ddc36107c28..9ba6ea00fc5 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -468,7 +468,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -476,7 +476,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index c101a5fda5c..fb5738ff0ab 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -151,9 +151,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/osaka/vm/instructions/system.py b/src/ethereum/forks/osaka/vm/instructions/system.py index 546d5e3f5a9..0708c9041e2 100644 --- a/src/ethereum/forks/osaka/vm/instructions/system.py +++ b/src/ethereum/forks/osaka/vm/instructions/system.py @@ -527,7 +527,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -540,7 +540,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index e87376e53d0..1b4d92ac1ea 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -128,9 +128,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/paris/vm/instructions/system.py b/src/ethereum/forks/paris/vm/instructions/system.py index 5f6c7f0a9cb..01791beb50f 100644 --- a/src/ethereum/forks/paris/vm/instructions/system.py +++ b/src/ethereum/forks/paris/vm/instructions/system.py @@ -482,7 +482,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -494,7 +494,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 876755df13e..dcb192a573c 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -146,9 +146,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/prague/vm/instructions/system.py b/src/ethereum/forks/prague/vm/instructions/system.py index 6772bb54fd5..2d99ac93e61 100644 --- a/src/ethereum/forks/prague/vm/instructions/system.py +++ b/src/ethereum/forks/prague/vm/instructions/system.py @@ -525,7 +525,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -537,7 +537,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 0c4d2d854e1..238ea14f0fd 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -129,9 +129,8 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/shanghai/vm/instructions/system.py b/src/ethereum/forks/shanghai/vm/instructions/system.py index c5ddef97546..b3fc0cd3dbb 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/system.py +++ b/src/ethereum/forks/shanghai/vm/instructions/system.py @@ -502,7 +502,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if beneficiary not in evm.accessed_addresses: evm.accessed_addresses.add(beneficiary) gas_cost += GasCosts.COLD_ACCOUNT_ACCESS @@ -514,7 +514,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT charge_gas(evm, gas_cost) if evm.message.is_static: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index b423be5e332..5a15355d60e 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -116,12 +116,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py index a5235bb873a..bad86c96896 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py @@ -381,7 +381,7 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if ( not is_account_alive(evm.message.block_env.state, beneficiary) and get_account( @@ -389,7 +389,7 @@ def selfdestruct(evm: Evm) -> None: ).balance != 0 ): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 2dc156044ca..0ec2bf5966e 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -116,12 +116,12 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) + OPCODE_SELFDESTRUCT_BASE = Uint(5000) + OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) # TODO EXTERNAL = Uint(700) BALANCE = Uint(400) CALL = Uint(700) - SELF_DESTRUCT = Uint(5000) - SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000) @dataclass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py index 0e3d408a4bb..47e609d983c 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py @@ -379,9 +379,9 @@ def selfdestruct(evm: Evm) -> None: beneficiary = to_address_masked(pop(evm.stack)) # GAS - gas_cost = GasCosts.SELF_DESTRUCT + gas_cost = GasCosts.OPCODE_SELFDESTRUCT_BASE if not account_exists(evm.message.block_env.state, beneficiary): - gas_cost += GasCosts.SELF_DESTRUCT_NEW_ACCOUNT + gas_cost += GasCosts.OPCODE_SELFDESTRUCT_NEW_ACCOUNT originator = evm.message.current_target diff --git a/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py b/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py index 0279bfda1b6..c81aff2a27b 100644 --- a/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py +++ b/tests/tangerine_whistle/eip150_operation_gas_costs/test_eip150_selfdestruct.py @@ -1,7 +1,7 @@ """ Tests for EIP-150 SELFDESTRUCT operation gas costs. -EIP-150 introduced SELF_DESTRUCT for SELFDESTRUCT and precise gas +EIP-150 introduced a gas cost for the SELFDESTRUCT opcode and precise gas boundaries for state access during the operation. """ From 4798b20b61570b83ec05be1116786b906faf3e59 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 16:38:13 -0400 Subject: [PATCH 52/61] refactor: forgot KECCAK256 and LOG in test code --- .../src/execution_testing/forks/forks/forks.py | 16 ++++++++-------- .../src/execution_testing/forks/gas_costs.py | 4 ++-- .../forks/tests/test_opcode_gas_costs.py | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 5755e9e5f61..934692bc305 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -181,10 +181,10 @@ def gas_costs(cls) -> GasCosts: OPCODE_EXP_BASE=10, OPCODE_EXP_PER_BYTE=50, # TODO - LOG=375, + OPCODE_LOG_BASE=375, OPCODE_LOG_DATA_PER_BYTE=8, OPCODE_LOG_TOPIC=375, - KECCAK256=30, + OPCODE_KECCAK256_BASE=30, OPCODE_KECCACK256_PER_WORD=6, # Zero-initialized: introduced in later forks, set via # replace() in the fork that activates them. @@ -373,7 +373,7 @@ def opcode_gas_map( # SHA3 Opcodes.SHA3: cls._with_memory_expansion( lambda op: ( - gas_costs.KECCAK256 + gas_costs.OPCODE_KECCAK256_BASE + gas_costs.OPCODE_KECCACK256_PER_WORD * ((op.metadata["data_size"] + 31) // 32) ), @@ -458,7 +458,7 @@ def opcode_gas_map( # Logging operations Opcodes.LOG0: cls._with_memory_expansion( lambda op: ( - gas_costs.LOG + gas_costs.OPCODE_LOG_BASE + gas_costs.OPCODE_LOG_DATA_PER_BYTE * op.metadata["data_size"] ), @@ -466,7 +466,7 @@ def opcode_gas_map( ), Opcodes.LOG1: cls._with_memory_expansion( lambda op: ( - gas_costs.LOG + gas_costs.OPCODE_LOG_BASE + gas_costs.OPCODE_LOG_DATA_PER_BYTE * op.metadata["data_size"] + gas_costs.OPCODE_LOG_TOPIC @@ -475,7 +475,7 @@ def opcode_gas_map( ), Opcodes.LOG2: cls._with_memory_expansion( lambda op: ( - gas_costs.LOG + gas_costs.OPCODE_LOG_BASE + gas_costs.OPCODE_LOG_DATA_PER_BYTE * op.metadata["data_size"] + gas_costs.OPCODE_LOG_TOPIC * 2 @@ -484,7 +484,7 @@ def opcode_gas_map( ), Opcodes.LOG3: cls._with_memory_expansion( lambda op: ( - gas_costs.LOG + gas_costs.OPCODE_LOG_BASE + gas_costs.OPCODE_LOG_DATA_PER_BYTE * op.metadata["data_size"] + gas_costs.OPCODE_LOG_TOPIC * 3 @@ -493,7 +493,7 @@ def opcode_gas_map( ), Opcodes.LOG4: cls._with_memory_expansion( lambda op: ( - gas_costs.LOG + gas_costs.OPCODE_LOG_BASE + gas_costs.OPCODE_LOG_DATA_PER_BYTE * op.metadata["data_size"] + gas_costs.OPCODE_LOG_TOPIC * 4 diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index f3d41b5679c..bbf04d8c8d6 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -133,10 +133,10 @@ class GasCosts: OPCODE_EXP_BASE: int OPCODE_EXP_PER_BYTE: int # TODO - LOG: int + OPCODE_LOG_BASE: int OPCODE_LOG_DATA_PER_BYTE: int OPCODE_LOG_TOPIC: int - KECCAK256: int + OPCODE_KECCAK256_BASE: int OPCODE_KECCACK256_PER_WORD: int # Defined post-Frontier diff --git a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py index 22e83eb8ada..472b499edd0 100644 --- a/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py +++ b/packages/testing/src/execution_testing/forks/tests/test_opcode_gas_costs.py @@ -56,13 +56,13 @@ pytest.param( Osaka, Op.SHA3(data_size=0), - Osaka.gas_costs().KECCAK256, + Osaka.gas_costs().OPCODE_KECCAK256_BASE, id="sha3_zero_data", ), pytest.param( Osaka, Op.SHA3(data_size=64, new_memory_size=96), - Osaka.gas_costs().KECCAK256 + Osaka.gas_costs().OPCODE_KECCAK256_BASE + Osaka.gas_costs().OPCODE_KECCACK256_PER_WORD * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=96), id="sha3_with_data_and_memory", @@ -218,7 +218,7 @@ pytest.param( Osaka, Op.LOG0(data_size=32, new_memory_size=32), - Osaka.gas_costs().LOG + Osaka.gas_costs().OPCODE_LOG_BASE + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 32 + Osaka.memory_expansion_gas_calculator()(new_bytes=32), id="log0", @@ -227,7 +227,7 @@ pytest.param( Osaka, Op.LOG1(data_size=64, new_memory_size=64), - Osaka.gas_costs().LOG + Osaka.gas_costs().OPCODE_LOG_BASE + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 64 + Osaka.gas_costs().OPCODE_LOG_TOPIC + Osaka.memory_expansion_gas_calculator()(new_bytes=64), @@ -237,7 +237,7 @@ pytest.param( Osaka, Op.LOG2(data_size=128, new_memory_size=128), - Osaka.gas_costs().LOG + Osaka.gas_costs().OPCODE_LOG_BASE + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 128 + Osaka.gas_costs().OPCODE_LOG_TOPIC * 2 + Osaka.memory_expansion_gas_calculator()(new_bytes=128), @@ -247,7 +247,7 @@ pytest.param( Osaka, Op.LOG3(data_size=256, new_memory_size=256), - Osaka.gas_costs().LOG + Osaka.gas_costs().OPCODE_LOG_BASE + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 256 + Osaka.gas_costs().OPCODE_LOG_TOPIC * 3 + Osaka.memory_expansion_gas_calculator()(new_bytes=256), @@ -257,7 +257,7 @@ pytest.param( Osaka, Op.LOG4(data_size=512, new_memory_size=512), - Osaka.gas_costs().LOG + Osaka.gas_costs().OPCODE_LOG_BASE + Osaka.gas_costs().OPCODE_LOG_DATA_PER_BYTE * 512 + Osaka.gas_costs().OPCODE_LOG_TOPIC * 4 + Osaka.memory_expansion_gas_calculator()(new_bytes=512), From 2237a877b3105828d0ee4767000ba5c6d61298cc Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 21:12:21 -0400 Subject: [PATCH 53/61] refactor: EXTERNAL=>OPCODE_EXTERNAL_BASE, BALANCE=>OPCODE_BALANCE --- .../src/execution_testing/forks/forks/forks.py | 3 +-- .../testing/src/execution_testing/forks/gas_costs.py | 1 - src/ethereum/forks/byzantium/vm/gas.py | 7 +++---- .../forks/byzantium/vm/instructions/environment.py | 9 ++++++--- .../forks/byzantium/vm/instructions/system.py | 12 ++++++++---- src/ethereum/forks/constantinople/vm/gas.py | 7 +++---- .../constantinople/vm/instructions/environment.py | 9 ++++++--- .../forks/constantinople/vm/instructions/system.py | 12 ++++++++---- src/ethereum/forks/dao_fork/vm/gas.py | 11 ++++++----- .../forks/dao_fork/vm/instructions/environment.py | 9 ++++++--- .../forks/dao_fork/vm/instructions/system.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 11 ++++++----- .../forks/frontier/vm/instructions/environment.py | 9 ++++++--- src/ethereum/forks/homestead/vm/gas.py | 11 ++++++----- .../forks/homestead/vm/instructions/environment.py | 9 ++++++--- .../forks/homestead/vm/instructions/system.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 7 +++---- .../forks/istanbul/vm/instructions/environment.py | 9 ++++++--- .../forks/istanbul/vm/instructions/system.py | 12 ++++++++---- src/ethereum/forks/muir_glacier/vm/gas.py | 7 +++---- .../muir_glacier/vm/instructions/environment.py | 9 ++++++--- .../forks/muir_glacier/vm/instructions/system.py | 12 ++++++++---- src/ethereum/forks/spurious_dragon/vm/gas.py | 7 +++---- .../spurious_dragon/vm/instructions/environment.py | 9 ++++++--- .../forks/spurious_dragon/vm/instructions/system.py | 10 +++++++--- src/ethereum/forks/tangerine_whistle/vm/gas.py | 7 +++---- .../tangerine_whistle/vm/instructions/environment.py | 9 ++++++--- .../tangerine_whistle/vm/instructions/system.py | 10 +++++++--- 28 files changed, 139 insertions(+), 93 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 934692bc305..534c03dfe69 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -130,6 +130,7 @@ def gas_costs(cls) -> GasCosts: TX_CREATE=32_000, # Refunds REFUND_STORAGE_CLEAR=4_800, + REFUND_AUTH_PER_EXISTING_ACCOUNT=0, # Precompiles PRECOMPILE_ECRECOVER=3_000, PRECOMPILE_SHA256_BASE=60, @@ -180,7 +181,6 @@ def gas_costs(cls) -> GasCosts: OPCODE_CREATE_BASE=32_000, OPCODE_EXP_BASE=10, OPCODE_EXP_PER_BYTE=50, - # TODO OPCODE_LOG_BASE=375, OPCODE_LOG_DATA_PER_BYTE=8, OPCODE_LOG_TOPIC=375, @@ -191,7 +191,6 @@ def gas_costs(cls) -> GasCosts: TX_DATA_TOKEN_STANDARD=0, TX_DATA_TOKEN_FLOOR=0, AUTH_PER_EMPTY_ACCOUNT=0, - REFUND_AUTH_PER_EXISTING_ACCOUNT=0, PRECOMPILE_ECADD=0, PRECOMPILE_ECMUL=0, PRECOMPILE_ECPAIRING_BASE=0, diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index bbf04d8c8d6..2f2ce3a772e 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -132,7 +132,6 @@ class GasCosts: OPCODE_CREATE_BASE: int OPCODE_EXP_BASE: int OPCODE_EXP_PER_BYTE: int - # TODO OPCODE_LOG_BASE: int OPCODE_LOG_DATA_PER_BYTE: int OPCODE_LOG_TOPIC: int diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 00c71ff68e4..092a63f782d 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -124,10 +124,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(400) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(400) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index e3392288575..34cf158ca3f 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -65,7 +65,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -332,7 +332,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -367,7 +367,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/instructions/system.py b/src/ethereum/forks/byzantium/vm/instructions/system.py index a3c67cc53fd..01e4048cc67 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/system.py +++ b/src/ethereum/forks/byzantium/vm/instructions/system.py @@ -282,7 +282,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -350,7 +350,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -481,7 +481,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -540,7 +544,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 72b864f2655..b9d32a04498 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -128,10 +128,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(400) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(400) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index 4d9ef8740f5..c9c4884aaab 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -368,7 +368,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/instructions/system.py b/src/ethereum/forks/constantinople/vm/instructions/system.py index c786ec17519..bd66624215d 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/system.py +++ b/src/ethereum/forks/constantinople/vm/instructions/system.py @@ -353,7 +353,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -421,7 +421,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -553,7 +553,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +616,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 6c5d5cf746a..84c6b3c33ad 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -118,10 +118,9 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - EXTERNAL = Uint(20) - BALANCE = Uint(20) - CALL = Uint(40) + OPCODE_EXTERNAL_BASE = Uint(20) + OPCODE_BALANCE = Uint(20) + OPCODE_CALL_BASE = Uint(40) @dataclass @@ -270,6 +269,8 @@ def calculate_message_call_gas( Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE - cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + cost = ( + GasCosts.OPCODE_CALL_BASE + gas + create_gas_cost + transfer_gas_cost + ) stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index 1edc79679f5..ef703e36b32 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -366,7 +366,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/instructions/system.py b/src/ethereum/forks/dao_fork/vm/instructions/system.py index 466252ba735..c40a241886a 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/system.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/system.py @@ -435,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GasCosts.CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CALL_BASE + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 6c5d5cf746a..84c6b3c33ad 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -118,10 +118,9 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - EXTERNAL = Uint(20) - BALANCE = Uint(20) - CALL = Uint(40) + OPCODE_EXTERNAL_BASE = Uint(20) + OPCODE_BALANCE = Uint(20) + OPCODE_CALL_BASE = Uint(40) @dataclass @@ -270,6 +269,8 @@ def calculate_message_call_gas( Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE - cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + cost = ( + GasCosts.OPCODE_CALL_BASE + gas + create_gas_cost + transfer_gas_cost + ) stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index 1edc79679f5..ef703e36b32 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -366,7 +366,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 6c5d5cf746a..84c6b3c33ad 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -118,10 +118,9 @@ class GasCosts: OPCODE_LOG_BASE = Uint(375) OPCODE_LOG_DATA_PER_BYTE = Uint(8) OPCODE_LOG_TOPIC = Uint(375) - # TODO - EXTERNAL = Uint(20) - BALANCE = Uint(20) - CALL = Uint(40) + OPCODE_EXTERNAL_BASE = Uint(20) + OPCODE_BALANCE = Uint(20) + OPCODE_CALL_BASE = Uint(40) @dataclass @@ -270,6 +269,8 @@ def calculate_message_call_gas( Uint(0) if account_exists(state, to) else GasCosts.NEW_ACCOUNT ) transfer_gas_cost = Uint(0) if value == 0 else GasCosts.CALL_VALUE - cost = GasCosts.CALL + gas + create_gas_cost + transfer_gas_cost + cost = ( + GasCosts.OPCODE_CALL_BASE + gas + create_gas_cost + transfer_gas_cost + ) stipend = gas if value == 0 else GasCosts.CALL_STIPEND + gas return MessageCallGas(cost, stipend) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index 1edc79679f5..ef703e36b32 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -366,7 +366,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/instructions/system.py b/src/ethereum/forks/homestead/vm/instructions/system.py index 466252ba735..c40a241886a 100644 --- a/src/ethereum/forks/homestead/vm/instructions/system.py +++ b/src/ethereum/forks/homestead/vm/instructions/system.py @@ -435,7 +435,7 @@ def delegatecall(evm: Evm) -> None: (memory_output_start_position, memory_output_size), ], ) - charge_gas(evm, GasCosts.CALL + gas + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_CALL_BASE + gas + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index d50e526848e..08d9ed6e4a4 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -130,10 +130,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(700) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(700) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index af80fe8aac3..90f4c3b0e40 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -368,7 +368,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/instructions/system.py b/src/ethereum/forks/istanbul/vm/instructions/system.py index 9ba6ea00fc5..12f69d1131d 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/system.py +++ b/src/ethereum/forks/istanbul/vm/instructions/system.py @@ -353,7 +353,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -421,7 +421,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -553,7 +553,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +616,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index d50e526848e..08d9ed6e4a4 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -130,10 +130,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(700) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(700) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index af80fe8aac3..90f4c3b0e40 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -66,7 +66,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -333,7 +333,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -368,7 +368,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/system.py b/src/ethereum/forks/muir_glacier/vm/instructions/system.py index 9ba6ea00fc5..12f69d1131d 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/system.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/system.py @@ -353,7 +353,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) if evm.message.is_static and value != U256(0): @@ -421,7 +421,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -553,7 +553,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -612,7 +616,7 @@ def staticcall(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 5a15355d60e..fa20f6ce76b 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -118,10 +118,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(400) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(400) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index 1edc79679f5..ef703e36b32 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -366,7 +366,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py index bad86c96896..037a54da3f9 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/system.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/system.py @@ -270,7 +270,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -336,7 +336,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -463,7 +463,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 0ec2bf5966e..65200227b6a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -118,10 +118,9 @@ class GasCosts: OPCODE_LOG_TOPIC = Uint(375) OPCODE_SELFDESTRUCT_BASE = Uint(5000) OPCODE_SELFDESTRUCT_NEW_ACCOUNT = Uint(25000) - # TODO - EXTERNAL = Uint(700) - BALANCE = Uint(400) - CALL = Uint(700) + OPCODE_EXTERNAL_BASE = Uint(700) + OPCODE_BALANCE = Uint(400) + OPCODE_CALL_BASE = Uint(700) @dataclass diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index 1edc79679f5..ef703e36b32 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -64,7 +64,7 @@ def balance(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.BALANCE) + charge_gas(evm, GasCosts.OPCODE_BALANCE) # OPERATION # Non-existent accounts default to EMPTY_ACCOUNT, which has balance 0. @@ -331,7 +331,7 @@ def extcodesize(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.EXTERNAL) + charge_gas(evm, GasCosts.OPCODE_EXTERNAL_BASE) # OPERATION account = get_account(evm.message.block_env.state, address) @@ -366,7 +366,10 @@ def extcodecopy(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) - charge_gas(evm, GasCosts.EXTERNAL + copy_gas_cost + extend_memory.cost) + charge_gas( + evm, + GasCosts.OPCODE_EXTERNAL_BASE + copy_gas_cost + extend_memory.cost, + ) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py index 47e609d983c..6ef0f1a0015 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/system.py @@ -268,7 +268,7 @@ def call(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + create_gas_cost + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + create_gas_cost + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -334,7 +334,7 @@ def callcode(evm: Evm) -> None: gas, Uint(evm.gas_left), extend_memory.cost, - GasCosts.CALL + transfer_gas_cost, + GasCosts.OPCODE_CALL_BASE + transfer_gas_cost, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) @@ -452,7 +452,11 @@ def delegatecall(evm: Evm) -> None: ], ) message_call_gas = calculate_message_call_gas( - U256(0), gas, Uint(evm.gas_left), extend_memory.cost, GasCosts.CALL + U256(0), + gas, + Uint(evm.gas_left), + extend_memory.cost, + GasCosts.OPCODE_CALL_BASE, ) charge_gas(evm, message_call_gas.cost + extend_memory.cost) From d7aca84301fbda98a064b12190046084b2cfb004 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 22:56:02 -0400 Subject: [PATCH 54/61] refactor: added _BASE suffix to CALLDATACOPY, CODECOPY, MLOAD, MSTORE, MSTORE8 --- .../execution_testing/forks/forks/forks.py | 22 ++++++++++--------- .../src/execution_testing/forks/gas_costs.py | 10 ++++----- src/ethereum/forks/amsterdam/vm/gas.py | 10 ++++----- .../amsterdam/vm/instructions/environment.py | 4 ++-- .../forks/amsterdam/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/arrow_glacier/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../arrow_glacier/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/berlin/vm/gas.py | 10 ++++----- .../berlin/vm/instructions/environment.py | 4 ++-- .../forks/berlin/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/bpo1/vm/gas.py | 10 ++++----- .../forks/bpo1/vm/instructions/environment.py | 4 ++-- .../forks/bpo1/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/bpo2/vm/gas.py | 10 ++++----- .../forks/bpo2/vm/instructions/environment.py | 4 ++-- .../forks/bpo2/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/bpo3/vm/gas.py | 10 ++++----- .../forks/bpo3/vm/instructions/environment.py | 4 ++-- .../forks/bpo3/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/bpo4/vm/gas.py | 10 ++++----- .../forks/bpo4/vm/instructions/environment.py | 4 ++-- .../forks/bpo4/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/bpo5/vm/gas.py | 10 ++++----- .../forks/bpo5/vm/instructions/environment.py | 4 ++-- .../forks/bpo5/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/byzantium/vm/gas.py | 10 ++++----- .../byzantium/vm/instructions/environment.py | 4 ++-- .../forks/byzantium/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/cancun/vm/gas.py | 10 ++++----- .../cancun/vm/instructions/environment.py | 4 ++-- .../forks/cancun/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/constantinople/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../constantinople/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/dao_fork/vm/gas.py | 10 ++++----- .../dao_fork/vm/instructions/environment.py | 4 ++-- .../forks/dao_fork/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/frontier/vm/gas.py | 10 ++++----- .../frontier/vm/instructions/environment.py | 4 ++-- .../forks/frontier/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/gray_glacier/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../gray_glacier/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/homestead/vm/gas.py | 10 ++++----- .../homestead/vm/instructions/environment.py | 4 ++-- .../forks/homestead/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/istanbul/vm/gas.py | 10 ++++----- .../istanbul/vm/instructions/environment.py | 4 ++-- .../forks/istanbul/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/london/vm/gas.py | 10 ++++----- .../london/vm/instructions/environment.py | 4 ++-- .../forks/london/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/muir_glacier/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../muir_glacier/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/osaka/vm/gas.py | 10 ++++----- .../osaka/vm/instructions/environment.py | 4 ++-- .../forks/osaka/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/paris/vm/gas.py | 10 ++++----- .../paris/vm/instructions/environment.py | 4 ++-- .../forks/paris/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/prague/vm/gas.py | 10 ++++----- .../prague/vm/instructions/environment.py | 4 ++-- .../forks/prague/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/shanghai/vm/gas.py | 10 ++++----- .../shanghai/vm/instructions/environment.py | 4 ++-- .../forks/shanghai/vm/instructions/memory.py | 6 ++--- src/ethereum/forks/spurious_dragon/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../spurious_dragon/vm/instructions/memory.py | 6 ++--- .../forks/tangerine_whistle/vm/gas.py | 10 ++++----- .../vm/instructions/environment.py | 4 ++-- .../vm/instructions/memory.py | 6 ++--- 74 files changed, 257 insertions(+), 255 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 534c03dfe69..93e350150d6 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -171,11 +171,11 @@ def gas_costs(cls) -> GasCosts: OPCODE_DUP=VERY_LOW, OPCODE_SWAP=VERY_LOW, # Dynamic Opcode Component - OPCODE_CALLDATACOPY=VERY_LOW, - OPCODE_CODECOPY=VERY_LOW, - OPCODE_MLOAD=VERY_LOW, - OPCODE_MSTORE=VERY_LOW, - OPCODE_MSTORE8=VERY_LOW, + OPCODE_CALLDATACOPY_BASE=VERY_LOW, + OPCODE_CODECOPY_BASE=VERY_LOW, + OPCODE_MLOAD_BASE=VERY_LOW, + OPCODE_MSTORE_BASE=VERY_LOW, + OPCODE_MSTORE8_BASE=VERY_LOW, OPCODE_SELFDESTRUCT_BASE=5_000, OPCODE_COPY_PER_WORD=3, OPCODE_CREATE_BASE=32_000, @@ -387,12 +387,14 @@ def opcode_gas_map( Opcodes.CALLDATALOAD: gas_costs.OPCODE_CALLDATALOAD, Opcodes.CALLDATASIZE: gas_costs.BASE, Opcodes.CALLDATACOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.OPCODE_CALLDATACOPY, gas_costs), + cls._with_data_copy( + gas_costs.OPCODE_CALLDATACOPY_BASE, gas_costs + ), memory_expansion_calculator, ), Opcodes.CODESIZE: gas_costs.BASE, Opcodes.CODECOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.OPCODE_CODECOPY, gas_costs), + cls._with_data_copy(gas_costs.OPCODE_CODECOPY_BASE, gas_costs), memory_expansion_calculator, ), Opcodes.GASPRICE: gas_costs.BASE, @@ -414,15 +416,15 @@ def opcode_gas_map( # Stack, memory, storage and flow operations Opcodes.POP: gas_costs.BASE, Opcodes.MLOAD: cls._with_memory_expansion( - gas_costs.OPCODE_MLOAD, + gas_costs.OPCODE_MLOAD_BASE, memory_expansion_calculator, ), Opcodes.MSTORE: cls._with_memory_expansion( - gas_costs.OPCODE_MSTORE, + gas_costs.OPCODE_MSTORE_BASE, memory_expansion_calculator, ), Opcodes.MSTORE8: cls._with_memory_expansion( - gas_costs.OPCODE_MSTORE8, + gas_costs.OPCODE_MSTORE8_BASE, memory_expansion_calculator, ), Opcodes.SLOAD: lambda op: ( diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 2f2ce3a772e..079f5a5ee65 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -122,11 +122,11 @@ class GasCosts: OPCODE_SWAP: int # Dynamic Opcode Components - OPCODE_CALLDATACOPY: int - OPCODE_CODECOPY: int - OPCODE_MLOAD: int - OPCODE_MSTORE: int - OPCODE_MSTORE8: int + OPCODE_CALLDATACOPY_BASE: int + OPCODE_CODECOPY_BASE: int + OPCODE_MLOAD_BASE: int + OPCODE_MSTORE_BASE: int + OPCODE_MSTORE8_BASE: int OPCODE_SELFDESTRUCT_BASE: int OPCODE_COPY_PER_WORD: int OPCODE_CREATE_BASE: int diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index c14ae6531e2..ae7d4795ddd 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -143,11 +143,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcode Components - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 3e0e65d9012..660b748dfd4 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -230,7 +230,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -291,7 +291,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 855470d9221..6031a5d3682 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 67f9b502690..301b2473d43 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 4a94e14e2c7..d60a07667b7 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -115,11 +115,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 5ee3a7c1810..d83b6898fe3 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 352f9f4e071..45cea3b3b50 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 1878250387e..e517cf24ad4 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 1878250387e..e517cf24ad4 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 1878250387e..e517cf24ad4 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 1878250387e..e517cf24ad4 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 092a63f782d..41803d1941e 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -108,11 +108,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 34cf158ca3f..cb74405d7d3 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -222,7 +222,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -283,7 +283,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 7985a879f2f..cecd0636083 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -126,11 +126,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index b9d32a04498..a90ad8290c4 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -112,11 +112,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index c9c4884aaab..e25177b9e06 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 84c6b3c33ad..13086c4ae4d 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -104,11 +104,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index ef703e36b32..df6814c794f 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 84c6b3c33ad..13086c4ae4d 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -104,11 +104,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index ef703e36b32..df6814c794f 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 1b4d92ac1ea..15c2cf8532b 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 67f9b502690..301b2473d43 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 84c6b3c33ad..13086c4ae4d 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -104,11 +104,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index ef703e36b32..df6814c794f 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 08d9ed6e4a4..60938fcd850 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 90f4c3b0e40..0e37c8bbf68 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 1b4d92ac1ea..15c2cf8532b 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 67f9b502690..301b2473d43 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 08d9ed6e4a4..60938fcd850 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 90f4c3b0e40..0e37c8bbf68 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -223,7 +223,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -284,7 +284,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index fb5738ff0ab..b3630b6886c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -137,11 +137,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 1b4d92ac1ea..15c2cf8532b 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -114,11 +114,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index c055dae2dac..9516f02e826 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index dcb192a573c..e98a57f104f 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -132,11 +132,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 10810bc79f5..5dadec6093f 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -229,7 +229,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -290,7 +290,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 9fdc69dd39e..ba0f17847da 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -47,7 +47,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -78,7 +78,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -106,7 +106,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 238ea14f0fd..3e533161e8a 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -115,11 +115,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index c055dae2dac..9516f02e826 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -227,7 +227,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -288,7 +288,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index fa20f6ce76b..603786aa259 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -102,11 +102,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index ef703e36b32..df6814c794f 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 65200227b6a..ff61fc8653a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -102,11 +102,11 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes - OPCODE_CALLDATACOPY = VERY_LOW - OPCODE_CODECOPY = VERY_LOW - OPCODE_MLOAD = VERY_LOW - OPCODE_MSTORE = VERY_LOW - OPCODE_MSTORE8 = VERY_LOW + OPCODE_CALLDATACOPY_BASE = VERY_LOW + OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MLOAD_BASE = VERY_LOW + OPCODE_MSTORE_BASE = VERY_LOW + OPCODE_MSTORE8_BASE = VERY_LOW OPCODE_COPY_PER_WORD = Uint(3) OPCODE_CREATE_BASE = Uint(32000) OPCODE_EXP_BASE = Uint(10) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index ef703e36b32..df6814c794f 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -221,7 +221,7 @@ def calldatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CALLDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CALLDATACOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION @@ -282,7 +282,7 @@ def codecopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_CODECOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_CODECOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index 0b3d4d1de51..d1bbcd9e197 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -45,7 +45,7 @@ def mstore(evm: Evm) -> None: evm.memory, [(start_position, U256(len(value)))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -76,7 +76,7 @@ def mstore8(evm: Evm) -> None: evm.memory, [(start_position, U256(1))] ) - charge_gas(evm, GasCosts.OPCODE_MSTORE8 + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by @@ -104,7 +104,7 @@ def mload(evm: Evm) -> None: extend_memory = calculate_gas_extend_memory( evm.memory, [(start_position, U256(32))] ) - charge_gas(evm, GasCosts.OPCODE_MLOAD + extend_memory.cost) + charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) # OPERATION evm.memory += b"\x00" * extend_memory.expand_by From 16fc81cbc2a7fdb2e1df09391fa9878f33366d93 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Tue, 7 Apr 2026 23:29:03 -0400 Subject: [PATCH 55/61] refactor: RETURN_DATA_COPY=>OPCODE_RETURNDATACOPY_PER_WORD --- src/ethereum/forks/amsterdam/vm/gas.py | 4 +--- src/ethereum/forks/amsterdam/vm/instructions/environment.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 2 +- .../forks/arrow_glacier/vm/instructions/environment.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 2 +- src/ethereum/forks/berlin/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 2 +- src/ethereum/forks/bpo1/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 2 +- src/ethereum/forks/bpo2/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 2 +- src/ethereum/forks/bpo3/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 2 +- src/ethereum/forks/bpo4/vm/instructions/environment.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 2 +- src/ethereum/forks/bpo5/vm/instructions/environment.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 2 +- src/ethereum/forks/byzantium/vm/instructions/environment.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 2 +- src/ethereum/forks/cancun/vm/instructions/environment.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 2 +- .../forks/constantinople/vm/instructions/environment.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 2 +- .../forks/gray_glacier/vm/instructions/environment.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 2 +- src/ethereum/forks/istanbul/vm/instructions/environment.py | 2 +- src/ethereum/forks/london/vm/gas.py | 2 +- src/ethereum/forks/london/vm/instructions/environment.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 2 +- .../forks/muir_glacier/vm/instructions/environment.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 2 +- src/ethereum/forks/osaka/vm/instructions/environment.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 2 +- src/ethereum/forks/paris/vm/instructions/environment.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 2 +- src/ethereum/forks/prague/vm/instructions/environment.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 2 +- src/ethereum/forks/shanghai/vm/instructions/environment.py | 2 +- 38 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index ae7d4795ddd..36925dafaeb 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -60,9 +60,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint( - 3 - ) # TODO refactor=>OPCODE_RETURNDATAOPCODE_COPY_PER_WORD + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 660b748dfd4..62268b2d137 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -444,7 +444,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 6031a5d3682..2e8875ec693 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -56,7 +56,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 301b2473d43..e85b6293b3a 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index d60a07667b7..5bea978b0c3 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -56,7 +56,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index d83b6898fe3..ae8c5f47215 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 45cea3b3b50..61df01f4f27 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index e517cf24ad4..a851de2ebf3 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index e517cf24ad4..a851de2ebf3 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index e517cf24ad4..a851de2ebf3 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index e517cf24ad4..a851de2ebf3 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 41803d1941e..8051efe4c46 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -54,7 +54,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) # Refunds diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index cb74405d7d3..a5e9d855834 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -424,7 +424,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index cecd0636083..f236259b876 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index a90ad8290c4..df2b4e6ce86 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -55,7 +55,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) # Refunds diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index e25177b9e06..820fa9fe1c2 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -425,7 +425,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 15c2cf8532b..4e614044980 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -56,7 +56,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 301b2473d43..e85b6293b3a 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 60938fcd850..e733498c9e6 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -55,7 +55,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 0e37c8bbf68..fff485d755c 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -425,7 +425,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 15c2cf8532b..4e614044980 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -56,7 +56,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 301b2473d43..e85b6293b3a 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 60938fcd850..e733498c9e6 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -55,7 +55,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 0e37c8bbf68..fff485d755c 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -425,7 +425,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index b3630b6886c..7c41837f374 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 15c2cf8532b..4e614044980 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -56,7 +56,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 9516f02e826..761014b9eee 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index e98a57f104f..cba628ef4e6 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -59,7 +59,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 5dadec6093f..29e40cb1efb 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -441,7 +441,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 3e533161e8a..899e711fe90 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -57,7 +57,7 @@ class GasCosts: # Utility ZERO = Uint(0) - RETURN_DATA_COPY = Uint(3) + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 9516f02e826..761014b9eee 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -439,7 +439,7 @@ def returndatacopy(evm: Evm) -> None: # GAS words = ceil32(Uint(size)) // Uint(32) - copy_gas_cost = GasCosts.RETURN_DATA_COPY * words + copy_gas_cost = GasCosts.OPCODE_RETURNDATACOPY_PER_WORD * words extend_memory = calculate_gas_extend_memory( evm.memory, [(memory_start_index, size)] ) From 184148b23a7f6be4994dc11dc3008ada58ef3d3f Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 8 Apr 2026 00:58:52 -0400 Subject: [PATCH 56/61] refactor: last few opcode refactors --- packages/testing/src/execution_testing/forks/gas_costs.py | 4 ++-- src/ethereum/forks/amsterdam/vm/gas.py | 6 +++--- src/ethereum/forks/amsterdam/vm/instructions/environment.py | 4 +++- src/ethereum/forks/amsterdam/vm/instructions/memory.py | 2 +- src/ethereum/forks/arrow_glacier/vm/gas.py | 4 ++-- .../forks/arrow_glacier/vm/instructions/environment.py | 4 +++- src/ethereum/forks/berlin/vm/gas.py | 4 ++-- src/ethereum/forks/berlin/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo1/vm/gas.py | 6 +++--- src/ethereum/forks/bpo1/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo1/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo2/vm/gas.py | 6 +++--- src/ethereum/forks/bpo2/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo2/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo3/vm/gas.py | 6 +++--- src/ethereum/forks/bpo3/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo3/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo4/vm/gas.py | 6 +++--- src/ethereum/forks/bpo4/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo4/vm/instructions/memory.py | 2 +- src/ethereum/forks/bpo5/vm/gas.py | 6 +++--- src/ethereum/forks/bpo5/vm/instructions/environment.py | 4 +++- src/ethereum/forks/bpo5/vm/instructions/memory.py | 2 +- src/ethereum/forks/byzantium/vm/gas.py | 4 ++-- src/ethereum/forks/byzantium/vm/instructions/environment.py | 4 +++- src/ethereum/forks/cancun/vm/gas.py | 6 +++--- src/ethereum/forks/cancun/vm/instructions/environment.py | 4 +++- src/ethereum/forks/cancun/vm/instructions/memory.py | 2 +- src/ethereum/forks/constantinople/vm/gas.py | 6 +++--- .../forks/constantinople/vm/instructions/environment.py | 6 ++++-- src/ethereum/forks/frontier/vm/gas.py | 1 - src/ethereum/forks/gray_glacier/vm/gas.py | 4 ++-- .../forks/gray_glacier/vm/instructions/environment.py | 4 +++- src/ethereum/forks/istanbul/vm/gas.py | 6 +++--- src/ethereum/forks/istanbul/vm/instructions/environment.py | 6 ++++-- src/ethereum/forks/london/vm/gas.py | 4 ++-- src/ethereum/forks/london/vm/instructions/environment.py | 4 +++- src/ethereum/forks/muir_glacier/vm/gas.py | 6 +++--- .../forks/muir_glacier/vm/instructions/environment.py | 6 ++++-- src/ethereum/forks/osaka/vm/gas.py | 6 +++--- src/ethereum/forks/osaka/vm/instructions/environment.py | 4 +++- src/ethereum/forks/osaka/vm/instructions/memory.py | 2 +- src/ethereum/forks/paris/vm/gas.py | 4 ++-- src/ethereum/forks/paris/vm/instructions/environment.py | 4 +++- src/ethereum/forks/prague/vm/gas.py | 6 +++--- src/ethereum/forks/prague/vm/instructions/environment.py | 4 +++- src/ethereum/forks/prague/vm/instructions/memory.py | 2 +- src/ethereum/forks/shanghai/vm/gas.py | 4 ++-- src/ethereum/forks/shanghai/vm/instructions/environment.py | 4 +++- 49 files changed, 121 insertions(+), 84 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/gas_costs.py b/packages/testing/src/execution_testing/forks/gas_costs.py index 079f5a5ee65..7e637b1d37c 100644 --- a/packages/testing/src/execution_testing/forks/gas_costs.py +++ b/packages/testing/src/execution_testing/forks/gas_costs.py @@ -142,7 +142,7 @@ class GasCosts: OPCODE_SHL: int = 0 OPCODE_SHR: int = 0 OPCODE_SAR: int = 0 - OPCODE_RETURNDATACOPY: int = 0 + OPCODE_RETURNDATACOPY_BASE: int = 0 OPCODE_BLOBHASH: int = 0 - OPCODE_MCOPY: int = 0 + OPCODE_MCOPY_BASE: int = 0 OPCODE_CLZ: int = 0 diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 36925dafaeb..aebcd13c022 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -60,7 +60,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -131,18 +130,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW # TODO OPCODE_RETURNDATACOPY_BASE OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcode Components + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index 62268b2d137..ebd6579119e 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -450,7 +450,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 2e8875ec693..1b4a767eb53 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -56,7 +56,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +105,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index e85b6293b3a..768b5665e16 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 5bea978b0c3..a7c36c16371 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -56,7 +56,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -107,7 +106,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -115,6 +113,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index ae8c5f47215..715031f52fb 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 61df01f4f27..4cd3ea98255 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index a851de2ebf3..18787296393 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index a851de2ebf3..18787296393 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index a851de2ebf3..18787296393 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index a851de2ebf3..18787296393 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 8051efe4c46..8c5ea6dd6a8 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -54,7 +54,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) # Refunds @@ -100,7 +99,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -108,6 +106,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index a5e9d855834..5f989f8580e 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -430,7 +430,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index f236259b876..20b3ee2b965 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -116,18 +115,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index df2b4e6ce86..6ffd26bb5ea 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -48,14 +48,12 @@ class GasCosts: CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - CODE_HASH = Uint(400) # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) # Refunds @@ -104,7 +102,7 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW + OPCODE_EXTCODEHASH = Uint(400) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -112,6 +110,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index 820fa9fe1c2..8ce901bba4a 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -431,7 +431,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -460,7 +462,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.CODE_HASH) + charge_gas(evm, GasCosts.OPCODE_EXTCODEHASH) # OPERATION account = get_account(evm.message.block_env.state, address) diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 13086c4ae4d..33441e9b9b1 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -103,7 +103,6 @@ class GasCosts: OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW - # Dynamic Opcodes OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 4e614044980..3d3b17332f8 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -56,7 +56,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +105,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index e85b6293b3a..768b5665e16 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index e733498c9e6..70da2fb14b0 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -48,14 +48,12 @@ class GasCosts: CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - CODE_HASH = Uint(700) # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +104,7 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW + OPCODE_EXTCODEHASH = Uint(700) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index fff485d755c..7d721cab606 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -431,7 +431,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -460,7 +462,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.CODE_HASH) + charge_gas(evm, GasCosts.OPCODE_EXTCODEHASH) # OPERATION account = get_account(evm.message.block_env.state, address) diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 4e614044980..3d3b17332f8 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -56,7 +56,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +105,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index e85b6293b3a..768b5665e16 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index e733498c9e6..70da2fb14b0 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -48,14 +48,12 @@ class GasCosts: CALL_VALUE = Uint(9000) CALL_STIPEND = Uint(2300) NEW_ACCOUNT = Uint(25000) - CODE_HASH = Uint(700) # Contract Creation CODE_DEPOSIT_PER_BYTE = Uint(200) # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +104,7 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW + OPCODE_EXTCODEHASH = Uint(700) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index fff485d755c..7d721cab606 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -431,7 +431,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead @@ -460,7 +462,7 @@ def extcodehash(evm: Evm) -> None: address = to_address_masked(pop(evm.stack)) # GAS - charge_gas(evm, GasCosts.CODE_HASH) + charge_gas(evm, GasCosts.OPCODE_EXTCODEHASH) # OPERATION account = get_account(evm.message.block_env.state, address) diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 7c41837f374..652ed60cc09 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -127,18 +126,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 4e614044980..3d3b17332f8 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -56,7 +56,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -106,7 +105,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -114,6 +112,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 761014b9eee..9ea49ffeb59 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index cba628ef4e6..fb3e2c500b5 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -59,7 +59,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -122,18 +121,19 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_BLOBHASH = Uint(3) - OPCODE_MCOPY = VERY_LOW OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW + OPCODE_MCOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW OPCODE_MSTORE_BASE = VERY_LOW OPCODE_MSTORE8_BASE = VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index 29e40cb1efb..dea6e2016c5 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -447,7 +447,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index ba0f17847da..55f6544d1c6 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -166,7 +166,7 @@ def mcopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_MCOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_MCOPY_BASE + copy_gas_cost + extend_memory.cost, ) # OPERATION diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 899e711fe90..99b31920c91 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -57,7 +57,6 @@ class GasCosts: # Utility ZERO = Uint(0) - OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) MEMORY_PER_WORD = Uint(3) FAST_STEP = Uint(5) @@ -107,7 +106,6 @@ class GasCosts: OPCODE_JUMPI = HIGH OPCODE_JUMPDEST = Uint(1) OPCODE_CALLDATALOAD = VERY_LOW - OPCODE_RETURNDATACOPY = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE OPCODE_PUSH = VERY_LOW @@ -115,6 +113,8 @@ class GasCosts: OPCODE_SWAP = VERY_LOW # Dynamic Opcodes + OPCODE_RETURNDATACOPY_BASE = VERY_LOW + OPCODE_RETURNDATACOPY_PER_WORD = Uint(3) OPCODE_CALLDATACOPY_BASE = VERY_LOW OPCODE_CODECOPY_BASE = VERY_LOW OPCODE_MLOAD_BASE = VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 761014b9eee..9ea49ffeb59 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -445,7 +445,9 @@ def returndatacopy(evm: Evm) -> None: ) charge_gas( evm, - GasCosts.OPCODE_RETURNDATACOPY + copy_gas_cost + extend_memory.cost, + GasCosts.OPCODE_RETURNDATACOPY_BASE + + copy_gas_cost + + extend_memory.cost, ) if Uint(return_data_start_position) + Uint(size) > ulen(evm.return_data): raise OutOfBoundsRead From 4dad95b93a00f8efd150cca64e18f57793fa6275 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Wed, 8 Apr 2026 14:21:09 -0400 Subject: [PATCH 57/61] fix: merge fixes --- .../forks/forks/eips/amsterdam/eip_7928.py | 2 +- .../forks/forks/eips/berlin/eip_2930.py | 6 ++---- .../forks/forks/eips/byzantium/eip_196.py | 4 ++-- .../forks/forks/eips/byzantium/eip_197.py | 4 ++-- .../forks/forks/eips/byzantium/eip_211.py | 4 ++-- .../forks/forks/eips/cancun/eip_1153.py | 4 ++-- .../forks/forks/eips/cancun/eip_4844.py | 4 ++-- .../forks/forks/eips/cancun/eip_5656.py | 2 +- .../forks/forks/eips/cancun/eip_7516.py | 2 +- .../forks/forks/eips/constantinople/eip_1014.py | 4 ++-- .../forks/forks/eips/constantinople/eip_145.py | 6 +++--- .../forks/forks/eips/homestead/eip_2.py | 2 +- .../forks/forks/eips/istanbul/eip_1108.py | 8 ++++---- .../forks/forks/eips/istanbul/eip_1344.py | 2 +- .../forks/forks/eips/istanbul/eip_152.py | 2 +- .../forks/forks/eips/istanbul/eip_1884.py | 2 +- .../forks/forks/eips/istanbul/eip_2028.py | 2 +- .../forks/forks/eips/london/eip_3198.py | 2 +- .../forks/forks/eips/osaka/eip_7939.py | 2 +- .../forks/forks/eips/osaka/eip_7951.py | 2 +- .../forks/forks/eips/prague/eip_2537.py | 16 ++++++++-------- .../forks/forks/eips/prague/eip_7623.py | 10 +++++----- .../forks/forks/eips/prague/eip_7702.py | 8 ++++---- .../forks/forks/eips/shanghai/eip_3855.py | 2 +- .../forks/forks/eips/shanghai/eip_3860.py | 4 ++-- .../forks/forks/eips/spurious_dragon/eip_161.py | 4 ++-- .../src/execution_testing/forks/forks/forks.py | 2 +- 27 files changed, 55 insertions(+), 57 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_7928.py b/packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_7928.py index 5e46e0ccb95..d4b1b9a6e17 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_7928.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_7928.py @@ -36,7 +36,7 @@ def gas_costs(cls) -> GasCosts: """ return replace( super(EIP7928, cls).gas_costs(), - GAS_BLOCK_ACCESS_LIST_ITEM=2000, + BLOCK_ACCESS_LIST_ITEM=2000, ) @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/berlin/eip_2930.py b/packages/testing/src/execution_testing/forks/forks/eips/berlin/eip_2930.py index 7544ae1580a..7dede0ace15 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/berlin/eip_2930.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/berlin/eip_2930.py @@ -55,11 +55,9 @@ def fn( ) if access_list is not None: for access in access_list: - intrinsic_cost += gas_costs.GAS_TX_ACCESS_LIST_ADDRESS + intrinsic_cost += gas_costs.TX_ACCESS_LIST_ADDRESS for _ in access.storage_keys: - intrinsic_cost += ( - gas_costs.GAS_TX_ACCESS_LIST_STORAGE_KEY - ) + intrinsic_cost += gas_costs.TX_ACCESS_LIST_STORAGE_KEY return intrinsic_cost return fn diff --git a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_196.py b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_196.py index 2d7178efdca..343e8ba9947 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_196.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_196.py @@ -30,6 +30,6 @@ def gas_costs(cls) -> GasCosts: """Set gas costs for BN254 addition and multiplication.""" return replace( super(EIP196, cls).gas_costs(), - GAS_PRECOMPILE_ECADD=500, - GAS_PRECOMPILE_ECMUL=40_000, + PRECOMPILE_ECADD=500, + PRECOMPILE_ECMUL=40_000, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_197.py b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_197.py index 55a4e60c34c..4d18dc85b3e 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_197.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_197.py @@ -29,6 +29,6 @@ def gas_costs(cls) -> GasCosts: """Set gas costs for BN254 pairing check.""" return replace( super(EIP197, cls).gas_costs(), - GAS_PRECOMPILE_ECPAIRING_BASE=100_000, - GAS_PRECOMPILE_ECPAIRING_PER_POINT=80_000, + PRECOMPILE_ECPAIRING_BASE=100_000, + PRECOMPILE_ECPAIRING_PER_POINT=80_000, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_211.py b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_211.py index 51b958f741e..d8e053c26ef 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_211.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/byzantium/eip_211.py @@ -24,9 +24,9 @@ def opcode_gas_map( base_map = super(EIP211, cls).opcode_gas_map() return { **base_map, - Opcodes.RETURNDATASIZE: gas_costs.GAS_BASE, + Opcodes.RETURNDATASIZE: gas_costs.BASE, Opcodes.RETURNDATACOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.GAS_VERY_LOW, gas_costs), + cls._with_data_copy(gas_costs.VERY_LOW, gas_costs), memory_expansion_calculator, ), } diff --git a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_1153.py b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_1153.py index 0481a794842..c98a22bc3f4 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_1153.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_1153.py @@ -26,8 +26,8 @@ def opcode_gas_map( base_map = super(EIP1153, cls).opcode_gas_map() return { **base_map, - Opcodes.TLOAD: gas_costs.GAS_WARM_SLOAD, - Opcodes.TSTORE: gas_costs.GAS_WARM_SLOAD, + Opcodes.TLOAD: gas_costs.WARM_SLOAD, + Opcodes.TSTORE: gas_costs.WARM_SLOAD, } @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_4844.py b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_4844.py index ac6733817e6..9774befab96 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_4844.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_4844.py @@ -189,7 +189,7 @@ def gas_costs(cls) -> GasCosts: """On Cancun, the point evaluation precompile gas cost is set.""" return replace( super(EIP4844, cls).gas_costs(), - GAS_PRECOMPILE_POINT_EVALUATION=50_000, + PRECOMPILE_POINT_EVALUATION=50_000, ) @classmethod @@ -208,7 +208,7 @@ def opcode_gas_map( base_map = super(EIP4844, cls).opcode_gas_map() # Add Cancun-specific opcodes - return {**base_map, Opcodes.BLOBHASH: gas_costs.GAS_VERY_LOW} + return {**base_map, Opcodes.BLOBHASH: gas_costs.VERY_LOW} @classmethod def valid_opcodes(cls) -> List[Opcodes]: diff --git a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_5656.py b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_5656.py index a3d0190c6f3..3365f3c2296 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_5656.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_5656.py @@ -27,7 +27,7 @@ def opcode_gas_map( return { **base_map, Opcodes.MCOPY: cls._with_memory_expansion( - cls._with_data_copy(gas_costs.GAS_VERY_LOW, gas_costs), + cls._with_data_copy(gas_costs.VERY_LOW, gas_costs), memory_expansion_calculator, ), } diff --git a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_7516.py b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_7516.py index 87fde9fc426..194e3e27852 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_7516.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/cancun/eip_7516.py @@ -29,7 +29,7 @@ def opcode_gas_map( # Add Cancun-specific opcodes return { **base_map, - Opcodes.BLOBBASEFEE: gas_costs.GAS_BASE, + Opcodes.BLOBBASEFEE: gas_costs.BASE, } @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_1014.py b/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_1014.py index 5dacb5b54cd..01201e0559a 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_1014.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_1014.py @@ -26,9 +26,9 @@ def _calculate_create2_gas( init_code_size = metadata["init_code_size"] init_code_words = (init_code_size + 31) // 32 - hash_gas = gas_costs.GAS_KECCAK256_PER_WORD * init_code_words + hash_gas = gas_costs.OPCODE_KECCACK256_PER_WORD * init_code_words - return gas_costs.GAS_CREATE + hash_gas + return gas_costs.OPCODE_CREATE_BASE + hash_gas @classmethod def create_opcodes(cls) -> List[Opcodes]: diff --git a/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_145.py b/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_145.py index 2ca9ca345c6..6a1b1cd854a 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_145.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/constantinople/eip_145.py @@ -25,9 +25,9 @@ def opcode_gas_map( base_map = super(EIP145, cls).opcode_gas_map() return { **base_map, - Opcodes.SHL: gas_costs.GAS_VERY_LOW, - Opcodes.SHR: gas_costs.GAS_VERY_LOW, - Opcodes.SAR: gas_costs.GAS_VERY_LOW, + Opcodes.SHL: gas_costs.VERY_LOW, + Opcodes.SHR: gas_costs.VERY_LOW, + Opcodes.SAR: gas_costs.VERY_LOW, } @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/homestead/eip_2.py b/packages/testing/src/execution_testing/forks/forks/eips/homestead/eip_2.py index 29007094e3d..811094f0a98 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/homestead/eip_2.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/homestead/eip_2.py @@ -43,7 +43,7 @@ def fn( authorization_list_or_count=authorization_list_or_count, ) if contract_creation: - intrinsic_cost += gas_costs.GAS_TX_CREATE + intrinsic_cost += gas_costs.TX_CREATE return intrinsic_cost return fn diff --git a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1108.py b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1108.py index 6d45947dc1f..512a2c2c44f 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1108.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1108.py @@ -18,8 +18,8 @@ def gas_costs(cls) -> GasCosts: """Reduce BN254 precompile gas costs.""" return replace( super(EIP1108, cls).gas_costs(), - GAS_PRECOMPILE_ECADD=150, - GAS_PRECOMPILE_ECMUL=6000, - GAS_PRECOMPILE_ECPAIRING_BASE=45_000, - GAS_PRECOMPILE_ECPAIRING_PER_POINT=34_000, + PRECOMPILE_ECADD=150, + PRECOMPILE_ECMUL=6000, + PRECOMPILE_ECPAIRING_BASE=45_000, + PRECOMPILE_ECPAIRING_PER_POINT=34_000, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1344.py b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1344.py index 89a7272f497..207aae46994 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1344.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1344.py @@ -24,7 +24,7 @@ def opcode_gas_map( """Add CHAINID opcode gas cost.""" gas_costs = cls.gas_costs() base_map = super(EIP1344, cls).opcode_gas_map() - return {**base_map, Opcodes.CHAINID: gas_costs.GAS_BASE} + return {**base_map, Opcodes.CHAINID: gas_costs.BASE} @classmethod def valid_opcodes(cls) -> List[Opcodes]: diff --git a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_152.py b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_152.py index 9979cc4076d..e8451f88fdf 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_152.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_152.py @@ -28,5 +28,5 @@ def gas_costs(cls) -> GasCosts: """Set BLAKE2F per-round gas cost.""" return replace( super(EIP152, cls).gas_costs(), - GAS_PRECOMPILE_BLAKE2F_PER_ROUND=1, + PRECOMPILE_BLAKE2F_PER_ROUND=1, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1884.py b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1884.py index f434b90a56e..b79a3c1e4fa 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1884.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_1884.py @@ -23,7 +23,7 @@ def opcode_gas_map( """Add SELFBALANCE opcode gas cost.""" gas_costs = cls.gas_costs() base_map = super(EIP1884, cls).opcode_gas_map() - return {**base_map, Opcodes.SELFBALANCE: gas_costs.GAS_LOW} + return {**base_map, Opcodes.SELFBALANCE: gas_costs.LOW} @classmethod def valid_opcodes(cls) -> List[Opcodes]: diff --git a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_2028.py b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_2028.py index 6dbb2446b43..ca6fed863ed 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_2028.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/istanbul/eip_2028.py @@ -20,5 +20,5 @@ def gas_costs(cls) -> GasCosts: """Reduce non-zero calldata byte gas cost to 16.""" return replace( super(EIP2028, cls).gas_costs(), - GAS_TX_DATA_PER_NON_ZERO=16, + TX_DATA_PER_NON_ZERO=16, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/london/eip_3198.py b/packages/testing/src/execution_testing/forks/forks/eips/london/eip_3198.py index 5be886c92f5..df8e3f1373d 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/london/eip_3198.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/london/eip_3198.py @@ -24,7 +24,7 @@ def opcode_gas_map( """Add BASEFEE opcode gas cost.""" gas_costs = cls.gas_costs() base_map = super(EIP3198, cls).opcode_gas_map() - return {**base_map, Opcodes.BASEFEE: gas_costs.GAS_BASE} + return {**base_map, Opcodes.BASEFEE: gas_costs.BASE} @classmethod def valid_opcodes(cls) -> List[Opcodes]: diff --git a/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7939.py b/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7939.py index 88b5a23e783..c53935a4d4d 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7939.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7939.py @@ -25,7 +25,7 @@ def opcode_gas_map( base_map = super(EIP7939, cls).opcode_gas_map() return { **base_map, - Opcodes.CLZ: gas_costs.GAS_LOW, + Opcodes.CLZ: gas_costs.LOW, } @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7951.py b/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7951.py index 1729515f158..e80674d2725 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7951.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/osaka/eip_7951.py @@ -35,5 +35,5 @@ def gas_costs(cls) -> GasCosts: """Set the P256VERIFY precompile gas cost.""" return replace( super(EIP7951, cls).gas_costs(), - GAS_PRECOMPILE_P256VERIFY=6_900, + PRECOMPILE_P256VERIFY=6_900, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_2537.py b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_2537.py index 92702858ed6..d0cb4edc70b 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_2537.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_2537.py @@ -47,12 +47,12 @@ def gas_costs(cls) -> GasCosts: """Add gas costs for BLS12-381 precompiles.""" return replace( super(EIP2537, cls).gas_costs(), - GAS_PRECOMPILE_BLS_G1ADD=375, - GAS_PRECOMPILE_BLS_G1MUL=12_000, - GAS_PRECOMPILE_BLS_G1MAP=5_500, - GAS_PRECOMPILE_BLS_G2ADD=600, - GAS_PRECOMPILE_BLS_G2MUL=22_500, - GAS_PRECOMPILE_BLS_G2MAP=23_800, - GAS_PRECOMPILE_BLS_PAIRING_BASE=37_700, - GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR=32_600, + PRECOMPILE_BLS_G1ADD=375, + PRECOMPILE_BLS_G1MUL=12_000, + PRECOMPILE_BLS_G1MAP=5_500, + PRECOMPILE_BLS_G2ADD=600, + PRECOMPILE_BLS_G2MUL=22_500, + PRECOMPILE_BLS_G2MAP=23_800, + PRECOMPILE_BLS_PAIRING_BASE=37_700, + PRECOMPILE_BLS_PAIRING_PER_PAIR=32_600, ) diff --git a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7623.py b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7623.py index 894ac85b433..1a073f11a92 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7623.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7623.py @@ -29,8 +29,8 @@ def gas_costs(cls) -> GasCosts: """Add standard and floor token costs for calldata.""" return replace( super(EIP7623, cls).gas_costs(), - GAS_TX_DATA_TOKEN_STANDARD=4, - GAS_TX_DATA_TOKEN_FLOOR=10, + TX_DATA_TOKEN_STANDARD=4, + TX_DATA_TOKEN_FLOOR=10, ) @classmethod @@ -47,8 +47,8 @@ def fn(*, data: BytesConvertible, floor: bool = False) -> int: num_non_zeros = len(raw) - num_zeros tokens = num_zeros + num_non_zeros * 4 if floor: - return tokens * gas_costs.GAS_TX_DATA_TOKEN_FLOOR - return tokens * gas_costs.GAS_TX_DATA_TOKEN_STANDARD + return tokens * gas_costs.TX_DATA_TOKEN_FLOOR + return tokens * gas_costs.TX_DATA_TOKEN_STANDARD return fn @@ -65,7 +65,7 @@ def transaction_data_floor_cost_calculator( def fn(*, data: BytesConvertible) -> int: return ( calldata_gas_calculator(data=data, floor=True) - + gas_costs.GAS_TX_BASE + + gas_costs.TX_BASE ) return fn diff --git a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7702.py b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7702.py index 1904b135f6a..d19fd6009c1 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7702.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7702.py @@ -33,7 +33,7 @@ def gas_costs(cls) -> GasCosts: """Add gas costs for authorization operations.""" return replace( super(EIP7702, cls).gas_costs(), - GAS_AUTH_PER_EMPTY_ACCOUNT=25_000, + AUTH_PER_EMPTY_ACCOUNT=25_000, REFUND_AUTH_PER_EXISTING_ACCOUNT=12_500, ) @@ -50,9 +50,9 @@ def _calculate_call_gas( if metadata["delegated_address"] or metadata["delegated_address_warm"]: if metadata["delegated_address_warm"]: - base_cost += gas_costs.GAS_WARM_ACCESS + base_cost += gas_costs.WARM_ACCESS else: - base_cost += gas_costs.GAS_COLD_ACCOUNT_ACCESS + base_cost += gas_costs.COLD_ACCOUNT_ACCESS return base_cost @@ -89,7 +89,7 @@ def fn( ) intrinsic_cost += ( authorization_list_or_count - * gas_costs.GAS_AUTH_PER_EMPTY_ACCOUNT + * gas_costs.AUTH_PER_EMPTY_ACCOUNT ) return intrinsic_cost diff --git a/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3855.py b/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3855.py index cf734cb3f3d..fd6586dfa71 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3855.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3855.py @@ -26,7 +26,7 @@ def opcode_gas_map( base_map = super(EIP3855, cls).opcode_gas_map() return { **base_map, - Opcodes.PUSH0: gas_costs.GAS_BASE, + Opcodes.PUSH0: gas_costs.BASE, } @classmethod diff --git a/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3860.py b/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3860.py index c5e52708bce..128c162cc9d 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3860.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/shanghai/eip_3860.py @@ -36,7 +36,7 @@ def _calculate_create_gas( init_code_size = metadata["init_code_size"] init_code_words = (init_code_size + 31) // 32 - init_code_gas = gas_costs.GAS_CODE_INIT_PER_WORD * init_code_words + init_code_gas = gas_costs.CODE_INIT_PER_WORD * init_code_words return base_cost + init_code_gas @@ -55,6 +55,6 @@ def _calculate_create2_gas( init_code_size = metadata["init_code_size"] init_code_words = (init_code_size + 31) // 32 - init_code_gas = gas_costs.GAS_CODE_INIT_PER_WORD * init_code_words + init_code_gas = gas_costs.CODE_INIT_PER_WORD * init_code_words return base_cost + init_code_gas diff --git a/packages/testing/src/execution_testing/forks/forks/eips/spurious_dragon/eip_161.py b/packages/testing/src/execution_testing/forks/forks/eips/spurious_dragon/eip_161.py index 6a5b61d919c..2806276fb3e 100644 --- a/packages/testing/src/execution_testing/forks/forks/eips/spurious_dragon/eip_161.py +++ b/packages/testing/src/execution_testing/forks/forks/eips/spurious_dragon/eip_161.py @@ -26,9 +26,9 @@ def _calculate_call_gas( metadata = opcode.metadata if "value_transfer" in metadata: if metadata["value_transfer"]: - base_cost += gas_costs.GAS_CALL_VALUE + base_cost += gas_costs.CALL_VALUE if metadata["account_new"]: - base_cost += gas_costs.GAS_NEW_ACCOUNT + base_cost += gas_costs.NEW_ACCOUNT elif metadata["account_new"]: raise ValueError("Account new requires value transfer") diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 93e350150d6..1eb3486eea6 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -32,7 +32,7 @@ TransactionDataFloorCostCalculator, TransactionIntrinsicCostCalculator, ) -from ..gas_costs import GasCosts +from ..gas_costs import BASE, HIGH, LOW, MID, VERY_LOW, GasCosts from . import eips from .helpers import ceiling_division From a6a5607cb80752c9ac0ae314ea38740181bdbe52 Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Sun, 12 Apr 2026 23:22:33 -0400 Subject: [PATCH 58/61] refactor: move transaction gas constatns with other gas constants for repricing mechanism. --- .../execution_testing/forks/forks/forks.py | 5 +- src/ethereum/forks/amsterdam/fork.py | 22 ++++--- src/ethereum/forks/amsterdam/transactions.py | 58 ++++--------------- .../forks/amsterdam/vm/eoa_delegation.py | 4 +- src/ethereum/forks/amsterdam/vm/gas.py | 15 +++++ src/ethereum/forks/arrow_glacier/fork.py | 11 ++-- .../forks/arrow_glacier/transactions.py | 47 +++------------ src/ethereum/forks/arrow_glacier/vm/gas.py | 12 ++++ src/ethereum/forks/berlin/fork.py | 23 ++++---- src/ethereum/forks/berlin/transactions.py | 47 +++------------ src/ethereum/forks/berlin/vm/gas.py | 12 ++++ src/ethereum/forks/bpo1/fork.py | 22 ++++--- src/ethereum/forks/bpo1/transactions.py | 58 ++++--------------- src/ethereum/forks/bpo1/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo1/vm/gas.py | 17 +++++- src/ethereum/forks/bpo2/fork.py | 22 ++++--- src/ethereum/forks/bpo2/transactions.py | 58 ++++--------------- src/ethereum/forks/bpo2/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo2/vm/gas.py | 17 +++++- src/ethereum/forks/bpo3/fork.py | 22 ++++--- src/ethereum/forks/bpo3/transactions.py | 58 ++++--------------- src/ethereum/forks/bpo3/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo3/vm/gas.py | 17 +++++- src/ethereum/forks/bpo4/fork.py | 22 ++++--- src/ethereum/forks/bpo4/transactions.py | 58 ++++--------------- src/ethereum/forks/bpo4/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo4/vm/gas.py | 17 +++++- src/ethereum/forks/bpo5/fork.py | 22 ++++--- src/ethereum/forks/bpo5/transactions.py | 58 ++++--------------- src/ethereum/forks/bpo5/vm/eoa_delegation.py | 4 +- src/ethereum/forks/bpo5/vm/gas.py | 17 +++++- src/ethereum/forks/byzantium/fork.py | 11 ++-- src/ethereum/forks/byzantium/transactions.py | 33 +++-------- src/ethereum/forks/byzantium/vm/gas.py | 12 +++- src/ethereum/forks/cancun/fork.py | 11 ++-- src/ethereum/forks/cancun/transactions.py | 47 +++------------ src/ethereum/forks/cancun/vm/gas.py | 14 ++++- src/ethereum/forks/constantinople/fork.py | 11 ++-- .../forks/constantinople/transactions.py | 33 +++-------- src/ethereum/forks/constantinople/vm/gas.py | 12 +++- src/ethereum/forks/dao_fork/fork.py | 11 ++-- src/ethereum/forks/dao_fork/transactions.py | 33 +++-------- src/ethereum/forks/dao_fork/vm/gas.py | 12 +++- src/ethereum/forks/frontier/fork.py | 23 ++++---- src/ethereum/forks/frontier/transactions.py | 26 ++------- src/ethereum/forks/frontier/vm/gas.py | 11 +++- src/ethereum/forks/gray_glacier/fork.py | 11 ++-- .../forks/gray_glacier/transactions.py | 47 +++------------ src/ethereum/forks/gray_glacier/vm/gas.py | 14 ++++- src/ethereum/forks/homestead/fork.py | 11 ++-- src/ethereum/forks/homestead/transactions.py | 33 +++-------- src/ethereum/forks/homestead/vm/gas.py | 12 +++- src/ethereum/forks/istanbul/fork.py | 23 ++++---- src/ethereum/forks/istanbul/transactions.py | 33 +++-------- src/ethereum/forks/istanbul/vm/gas.py | 12 +++- src/ethereum/forks/london/fork.py | 11 ++-- src/ethereum/forks/london/transactions.py | 47 +++------------ src/ethereum/forks/london/vm/gas.py | 14 ++++- src/ethereum/forks/muir_glacier/fork.py | 23 ++++---- .../forks/muir_glacier/transactions.py | 33 +++-------- src/ethereum/forks/muir_glacier/vm/gas.py | 12 +++- src/ethereum/forks/osaka/fork.py | 22 ++++--- src/ethereum/forks/osaka/transactions.py | 58 ++++--------------- src/ethereum/forks/osaka/vm/eoa_delegation.py | 4 +- src/ethereum/forks/osaka/vm/gas.py | 17 +++++- src/ethereum/forks/paris/fork.py | 11 ++-- src/ethereum/forks/paris/transactions.py | 47 +++------------ src/ethereum/forks/paris/vm/gas.py | 14 ++++- src/ethereum/forks/prague/fork.py | 23 ++++---- src/ethereum/forks/prague/transactions.py | 58 ++++--------------- .../forks/prague/vm/eoa_delegation.py | 4 +- src/ethereum/forks/prague/vm/gas.py | 17 +++++- src/ethereum/forks/shanghai/fork.py | 11 ++-- src/ethereum/forks/shanghai/transactions.py | 47 +++------------ src/ethereum/forks/shanghai/vm/gas.py | 14 ++++- src/ethereum/forks/spurious_dragon/fork.py | 11 ++-- .../forks/spurious_dragon/transactions.py | 33 +++-------- src/ethereum/forks/spurious_dragon/vm/gas.py | 12 +++- src/ethereum/forks/tangerine_whistle/fork.py | 11 ++-- .../forks/tangerine_whistle/transactions.py | 33 +++-------- .../forks/tangerine_whistle/vm/gas.py | 12 +++- 81 files changed, 729 insertions(+), 1127 deletions(-) diff --git a/packages/testing/src/execution_testing/forks/forks/forks.py b/packages/testing/src/execution_testing/forks/forks/forks.py index 1eb3486eea6..49fcaf32cd9 100644 --- a/packages/testing/src/execution_testing/forks/forks/forks.py +++ b/packages/testing/src/execution_testing/forks/forks/forks.py @@ -119,6 +119,8 @@ def gas_costs(cls) -> GasCosts: # Contract Creation CODE_DEPOSIT_PER_BYTE=200, CODE_INIT_PER_WORD=2, + # Authorization + AUTH_PER_EMPTY_ACCOUNT=0, # Utility MEMORY_PER_WORD=3, # Transactions @@ -170,7 +172,7 @@ def gas_costs(cls) -> GasCosts: OPCODE_PUSH=VERY_LOW, OPCODE_DUP=VERY_LOW, OPCODE_SWAP=VERY_LOW, - # Dynamic Opcode Component + # Dynamic Opcode Components OPCODE_CALLDATACOPY_BASE=VERY_LOW, OPCODE_CODECOPY_BASE=VERY_LOW, OPCODE_MLOAD_BASE=VERY_LOW, @@ -190,7 +192,6 @@ def gas_costs(cls) -> GasCosts: # replace() in the fork that activates them. TX_DATA_TOKEN_STANDARD=0, TX_DATA_TOKEN_FLOOR=0, - AUTH_PER_EMPTY_ACCOUNT=0, PRECOMPILE_ECADD=0, PRECOMPILE_ECMUL=0, PRECOMPILE_ECPAIRING_BASE=0, diff --git a/src/ethereum/forks/amsterdam/fork.py b/src/ethereum/forks/amsterdam/fork.py index 0d4c69d2b34..e673bc3d8fd 100644 --- a/src/ethereum/forks/amsterdam/fork.py +++ b/src/ethereum/forks/amsterdam/fork.py @@ -105,8 +105,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1121,14 +1119,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1144,12 +1142,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/amsterdam/transactions.py b/src/ethereum/forks/amsterdam/transactions.py index da7dfd13f5e..f88d5b551f8 100644 --- a/src/ethereum/forks/amsterdam/transactions.py +++ b/src/ethereum/forks/amsterdam/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -608,7 +571,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -619,8 +582,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -628,31 +590,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py index cf8ddb73807..6262f42a0bc 100644 --- a/src/ethereum/forks/amsterdam/vm/eoa_delegation.py +++ b/src/ethereum/forks/amsterdam/vm/eoa_delegation.py @@ -28,7 +28,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(tx_state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index aebcd13c022..033fb0242fe 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -58,6 +58,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -100,6 +103,18 @@ class GasCosts: # Block Access Lists BLOCK_ACCESS_LIST_ITEM = Uint(2000) + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/fork.py b/src/ethereum/forks/arrow_glacier/fork.py index f833fe71c5f..1ca5a51b6ac 100644 --- a/src/ethereum/forks/arrow_glacier/fork.py +++ b/src/ethereum/forks/arrow_glacier/fork.py @@ -61,13 +61,12 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 10700000 @@ -849,12 +848,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -872,12 +871,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/arrow_glacier/transactions.py b/src/ethereum/forks/arrow_glacier/transactions.py index ca951f085c2..0e40010c617 100644 --- a/src/ethereum/forks/arrow_glacier/transactions.py +++ b/src/ethereum/forks/arrow_glacier/transactions.py @@ -23,37 +23,6 @@ from .exceptions import TransactionTypeError from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -370,7 +339,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -378,27 +347,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 1b4a767eb53..dcfdf54c08e 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -76,6 +76,18 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW diff --git a/src/ethereum/forks/berlin/fork.py b/src/ethereum/forks/berlin/fork.py index 54bc85a6aa6..72d37ec2bae 100644 --- a/src/ethereum/forks/berlin/fork.py +++ b/src/ethereum/forks/berlin/fork.py @@ -56,11 +56,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 9000000 @@ -734,14 +733,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -757,12 +756,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/berlin/transactions.py b/src/ethereum/forks/berlin/transactions.py index 10a9e22a2c0..2721c25520c 100644 --- a/src/ethereum/forks/berlin/transactions.py +++ b/src/ethereum/forks/berlin/transactions.py @@ -23,37 +23,6 @@ from .exceptions import TransactionTypeError from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -287,7 +256,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -295,27 +264,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, AccessListTransaction): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index a7c36c16371..d546950fe4d 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -77,6 +77,18 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW diff --git a/src/ethereum/forks/bpo1/fork.py b/src/ethereum/forks/bpo1/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/bpo1/fork.py +++ b/src/ethereum/forks/bpo1/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/bpo1/transactions.py b/src/ethereum/forks/bpo1/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/bpo1/transactions.py +++ b/src/ethereum/forks/bpo1/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/bpo1/vm/eoa_delegation.py b/src/ethereum/forks/bpo1/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/bpo1/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo1/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 4cd3ea98255..2a631facb7d 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(8346193) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/bpo2/fork.py b/src/ethereum/forks/bpo2/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/bpo2/fork.py +++ b/src/ethereum/forks/bpo2/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/bpo2/transactions.py b/src/ethereum/forks/bpo2/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/bpo2/transactions.py +++ b/src/ethereum/forks/bpo2/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/bpo2/vm/eoa_delegation.py b/src/ethereum/forks/bpo2/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/bpo2/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo2/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 18787296393..b982a66190f 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/bpo3/fork.py b/src/ethereum/forks/bpo3/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/bpo3/fork.py +++ b/src/ethereum/forks/bpo3/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/bpo3/transactions.py b/src/ethereum/forks/bpo3/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/bpo3/transactions.py +++ b/src/ethereum/forks/bpo3/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/bpo3/vm/eoa_delegation.py b/src/ethereum/forks/bpo3/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/bpo3/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo3/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 18787296393..b982a66190f 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/bpo4/fork.py b/src/ethereum/forks/bpo4/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/bpo4/fork.py +++ b/src/ethereum/forks/bpo4/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/bpo4/transactions.py b/src/ethereum/forks/bpo4/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/bpo4/transactions.py +++ b/src/ethereum/forks/bpo4/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/bpo4/vm/eoa_delegation.py b/src/ethereum/forks/bpo4/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/bpo4/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo4/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 18787296393..b982a66190f 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/bpo5/fork.py b/src/ethereum/forks/bpo5/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/bpo5/fork.py +++ b/src/ethereum/forks/bpo5/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/bpo5/transactions.py b/src/ethereum/forks/bpo5/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/bpo5/transactions.py +++ b/src/ethereum/forks/bpo5/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/bpo5/vm/eoa_delegation.py b/src/ethereum/forks/bpo5/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/bpo5/vm/eoa_delegation.py +++ b/src/ethereum/forks/bpo5/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 18787296393..b982a66190f 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/byzantium/fork.py b/src/ethereum/forks/byzantium/fork.py index 3cbf03500b3..848a1edf547 100644 --- a/src/ethereum/forks/byzantium/fork.py +++ b/src/ethereum/forks/byzantium/fork.py @@ -51,11 +51,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(3 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 3000000 @@ -711,12 +710,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -734,12 +733,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/byzantium/transactions.py b/src/ethereum/forks/byzantium/transactions.py index 278238f8d5a..e8cde82b198 100644 --- a/src/ethereum/forks/byzantium/transactions.py +++ b/src/ethereum/forks/byzantium/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 8c5ea6dd6a8..450ff27f5bc 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -73,7 +73,17 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(100000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(80000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/cancun/fork.py b/src/ethereum/forks/cancun/fork.py index 1c1dbab2865..ac5373fac95 100644 --- a/src/ethereum/forks/cancun/fork.py +++ b/src/ethereum/forks/cancun/fork.py @@ -70,6 +70,7 @@ from .utils.message import prepare_message from .vm import Message from .vm.gas import ( + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -79,8 +80,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -852,12 +851,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -875,12 +874,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/cancun/transactions.py b/src/ethereum/forks/cancun/transactions.py index c94f3df0647..b8f431f64e0 100644 --- a/src/ethereum/forks/cancun/transactions.py +++ b/src/ethereum/forks/cancun/transactions.py @@ -24,37 +24,6 @@ from .exceptions import InitCodeTooLargeError, TransactionTypeError from .fork_types import VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -480,7 +449,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -488,17 +457,17 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) @@ -507,12 +476,12 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: tx, (AccessListTransaction, FeeMarketTransaction, BlobTransaction) ): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 20b3ee2b965..e9e4ae722b7 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -86,7 +86,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(3338477) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/constantinople/fork.py b/src/ethereum/forks/constantinople/fork.py index 7ed470d41e3..a75b6656f14 100644 --- a/src/ethereum/forks/constantinople/fork.py +++ b/src/ethereum/forks/constantinople/fork.py @@ -51,11 +51,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 5000000 @@ -711,12 +710,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -734,12 +733,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/constantinople/transactions.py b/src/ethereum/forks/constantinople/transactions.py index 278238f8d5a..e8cde82b198 100644 --- a/src/ethereum/forks/constantinople/transactions.py +++ b/src/ethereum/forks/constantinople/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 6ffd26bb5ea..397e685e23f 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -73,7 +73,17 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(100000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(80000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/dao_fork/fork.py b/src/ethereum/forks/dao_fork/fork.py index 9dc372bec66..8dae3e9f95a 100644 --- a/src/ethereum/forks/dao_fork/fork.py +++ b/src/ethereum/forks/dao_fork/fork.py @@ -53,11 +53,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(5 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) @@ -721,12 +720,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -744,12 +743,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/dao_fork/transactions.py b/src/ethereum/forks/dao_fork/transactions.py index 934540874ca..e17bafae49d 100644 --- a/src/ethereum/forks/dao_fork/transactions.py +++ b/src/ethereum/forks/dao_fork/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(tx: Transaction) -> Address: diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 13086c4ae4d..e973be6b5cf 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -71,7 +71,17 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/frontier/fork.py b/src/ethereum/forks/frontier/fork.py index 5f062710138..70c52a0c056 100644 --- a/src/ethereum/forks/frontier/fork.py +++ b/src/ethereum/forks/frontier/fork.py @@ -49,11 +49,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(5 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) @@ -700,14 +699,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -723,12 +722,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/frontier/transactions.py b/src/ethereum/forks/frontier/transactions.py index 32be1dcdf0a..69b9ec52083 100644 --- a/src/ethereum/forks/frontier/transactions.py +++ b/src/ethereum/forks/frontier/transactions.py @@ -21,22 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - @slotted_freezable @dataclass @@ -138,20 +122,22 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) - return GAS_TX_BASE + data_cost + return GasCosts.TX_BASE + data_cost def recover_sender(tx: Transaction) -> Address: diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 33441e9b9b1..155156fdc79 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -71,7 +71,16 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/gray_glacier/fork.py b/src/ethereum/forks/gray_glacier/fork.py index 301fdb2cd05..a5e2080c744 100644 --- a/src/ethereum/forks/gray_glacier/fork.py +++ b/src/ethereum/forks/gray_glacier/fork.py @@ -62,13 +62,12 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 11400000 @@ -850,12 +849,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -873,12 +872,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/gray_glacier/transactions.py b/src/ethereum/forks/gray_glacier/transactions.py index ca951f085c2..0e40010c617 100644 --- a/src/ethereum/forks/gray_glacier/transactions.py +++ b/src/ethereum/forks/gray_glacier/transactions.py @@ -23,37 +23,6 @@ from .exceptions import TransactionTypeError from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -370,7 +339,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -378,27 +347,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 3d3b17332f8..dcfdf54c08e 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -76,7 +76,19 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/homestead/fork.py b/src/ethereum/forks/homestead/fork.py index 162a6bd1b7a..78592e2d770 100644 --- a/src/ethereum/forks/homestead/fork.py +++ b/src/ethereum/forks/homestead/fork.py @@ -49,11 +49,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(5 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) @@ -700,12 +699,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -723,12 +722,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/homestead/transactions.py b/src/ethereum/forks/homestead/transactions.py index 934540874ca..e17bafae49d 100644 --- a/src/ethereum/forks/homestead/transactions.py +++ b/src/ethereum/forks/homestead/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(tx: Transaction) -> Address: diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 13086c4ae4d..e973be6b5cf 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -71,7 +71,17 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/istanbul/fork.py b/src/ethereum/forks/istanbul/fork.py index 7ed470d41e3..7765455cdb8 100644 --- a/src/ethereum/forks/istanbul/fork.py +++ b/src/ethereum/forks/istanbul/fork.py @@ -51,11 +51,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 5000000 @@ -711,14 +710,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -734,12 +733,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/istanbul/transactions.py b/src/ethereum/forks/istanbul/transactions.py index a831530b311..e8cde82b198 100644 --- a/src/ethereum/forks/istanbul/transactions.py +++ b/src/ethereum/forks/istanbul/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 70da2fb14b0..7f6e8287c6b 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -75,7 +75,17 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/london/fork.py b/src/ethereum/forks/london/fork.py index a095e5fb6b9..026a6824881 100644 --- a/src/ethereum/forks/london/fork.py +++ b/src/ethereum/forks/london/fork.py @@ -62,13 +62,12 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) INITIAL_BASE_FEE = Uint(1000000000) MAX_OMMER_DEPTH = Uint(6) @@ -858,12 +857,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -881,12 +880,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/london/transactions.py b/src/ethereum/forks/london/transactions.py index ca951f085c2..0e40010c617 100644 --- a/src/ethereum/forks/london/transactions.py +++ b/src/ethereum/forks/london/transactions.py @@ -23,37 +23,6 @@ from .exceptions import TransactionTypeError from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -370,7 +339,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -378,27 +347,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 3d3b17332f8..dcfdf54c08e 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -76,7 +76,19 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/muir_glacier/fork.py b/src/ethereum/forks/muir_glacier/fork.py index 22fbdd1d988..dc79ce95617 100644 --- a/src/ethereum/forks/muir_glacier/fork.py +++ b/src/ethereum/forks/muir_glacier/fork.py @@ -51,11 +51,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(2 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) BOMB_DELAY_BLOCKS = 9000000 @@ -713,14 +712,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -736,12 +735,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/muir_glacier/transactions.py b/src/ethereum/forks/muir_glacier/transactions.py index a831530b311..e8cde82b198 100644 --- a/src/ethereum/forks/muir_glacier/transactions.py +++ b/src/ethereum/forks/muir_glacier/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 70da2fb14b0..7f6e8287c6b 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -75,7 +75,17 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/osaka/fork.py b/src/ethereum/forks/osaka/fork.py index 6cd7998cfe7..19ce50f243d 100644 --- a/src/ethereum/forks/osaka/fork.py +++ b/src/ethereum/forks/osaka/fork.py @@ -91,8 +91,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1029,14 +1027,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1052,12 +1050,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/osaka/transactions.py b/src/ethereum/forks/osaka/transactions.py index c8f1826324e..486b21f99b0 100644 --- a/src/ethereum/forks/osaka/transactions.py +++ b/src/ethereum/forks/osaka/transactions.py @@ -28,43 +28,6 @@ ) from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - TX_MAX_GAS_LIMIT = Uint(16_777_216) @@ -601,7 +564,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -612,8 +575,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -621,31 +583,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/osaka/vm/eoa_delegation.py b/src/ethereum/forks/osaka/vm/eoa_delegation.py index d63c540ed47..474ca9ae033 100644 --- a/src/ethereum/forks/osaka/vm/eoa_delegation.py +++ b/src/ethereum/forks/osaka/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -200,7 +199,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 652ed60cc09..f9b2b03f946 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -96,7 +99,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/paris/fork.py b/src/ethereum/forks/paris/fork.py index 601f7064cfb..18be9678a70 100644 --- a/src/ethereum/forks/paris/fork.py +++ b/src/ethereum/forks/paris/fork.py @@ -57,12 +57,11 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) @@ -617,12 +616,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -640,12 +639,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/paris/transactions.py b/src/ethereum/forks/paris/transactions.py index 3b2f8b4425f..7ee0abbf8ef 100644 --- a/src/ethereum/forks/paris/transactions.py +++ b/src/ethereum/forks/paris/transactions.py @@ -23,37 +23,6 @@ from .exceptions import TransactionTypeError -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -370,7 +339,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -378,27 +347,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 3d3b17332f8..dcfdf54c08e 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -76,7 +76,19 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/prague/fork.py b/src/ethereum/forks/prague/fork.py index b1189cfa75e..9a14a702850 100644 --- a/src/ethereum/forks/prague/fork.py +++ b/src/ethereum/forks/prague/fork.py @@ -80,6 +80,7 @@ from .vm import Message from .vm.eoa_delegation import is_valid_delegation from .vm.gas import ( + GasCosts, calculate_blob_gas_price, calculate_data_fee, calculate_excess_blob_gas, @@ -89,8 +90,6 @@ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe") BEACON_ROOTS_ADDRESS = hex_to_address( @@ -1013,14 +1012,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- @@ -1036,12 +1035,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/prague/transactions.py b/src/ethereum/forks/prague/transactions.py index 485a2460ba4..48845de1aa6 100644 --- a/src/ethereum/forks/prague/transactions.py +++ b/src/ethereum/forks/prague/transactions.py @@ -24,43 +24,6 @@ from .exceptions import InitCodeTooLargeError, TransactionTypeError from .fork_types import Authorization, VersionedHash -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_TOKEN_FLOOR = Uint(10) -""" -Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate -the minimum gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_DATA_TOKEN_STANDARD = Uint(4) -""" -Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the -gas cost for transactions that include calldata. - -[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623 -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -593,7 +556,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -604,8 +567,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size. """ - from .vm.eoa_delegation import GAS_AUTH_PER_EMPTY_ACCOUNT - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros @@ -613,31 +575,33 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]: tokens_in_calldata = num_zeros + num_non_zeros * Uint(4) # EIP-7623 floor price (note: no EVM costs) calldata_floor_gas_cost = ( - tokens_in_calldata * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE + tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE ) - data_cost = tokens_in_calldata * GAS_TX_DATA_TOKEN_STANDARD + data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if has_access_list(tx): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) auth_cost = Uint(0) if isinstance(tx, SetCodeTransaction): - auth_cost += Uint(GAS_AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)) + auth_cost += Uint( + GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations) + ) return ( Uint( - GAS_TX_BASE + GasCosts.TX_BASE + data_cost + create_cost + access_list_cost diff --git a/src/ethereum/forks/prague/vm/eoa_delegation.py b/src/ethereum/forks/prague/vm/eoa_delegation.py index d4ff0ff9fb8..3fd42910817 100644 --- a/src/ethereum/forks/prague/vm/eoa_delegation.py +++ b/src/ethereum/forks/prague/vm/eoa_delegation.py @@ -29,7 +29,6 @@ EOA_DELEGATION_MARKER = b"\xef\x01\x00" EOA_DELEGATION_MARKER_LENGTH = len(EOA_DELEGATION_MARKER) EOA_DELEGATED_CODE_LENGTH = 23 -GAS_AUTH_PER_EMPTY_ACCOUNT = 25000 REFUND_AUTH_PER_EXISTING_ACCOUNT = 12500 NULL_ADDRESS = hex_to_address("0x0000000000000000000000000000000000000000") @@ -199,7 +198,8 @@ def set_delegation(message: Message) -> U256: if account_exists(state, authority): refund_counter += U256( - GAS_AUTH_PER_EMPTY_ACCOUNT - REFUND_AUTH_PER_EXISTING_ACCOUNT + GasCosts.AUTH_PER_EMPTY_ACCOUNT + - REFUND_AUTH_PER_EXISTING_ACCOUNT ) if auth.address == NULL_ADDRESS: diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index fb3e2c500b5..dae7cfe7c17 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -57,6 +57,9 @@ class GasCosts: CODE_DEPOSIT_PER_BYTE = Uint(200) CODE_INIT_PER_WORD = Uint(2) + # Authorization + AUTH_PER_EMPTY_ACCOUNT = 25000 + # Utility ZERO = Uint(0) MEMORY_PER_WORD = Uint(3) @@ -92,7 +95,19 @@ class GasCosts: BLOB_MIN_GASPRICE = Uint(1) BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_TOKEN_STANDARD = Uint(4) + TX_DATA_TOKEN_FLOOR = Uint(10) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/shanghai/fork.py b/src/ethereum/forks/shanghai/fork.py index ed186933edf..7604389956a 100644 --- a/src/ethereum/forks/shanghai/fork.py +++ b/src/ethereum/forks/shanghai/fork.py @@ -58,12 +58,11 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8) ELASTICITY_MULTIPLIER = Uint(2) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) EMPTY_OMMER_HASH = keccak256(rlp.encode([])) @@ -652,12 +651,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -675,12 +674,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/shanghai/transactions.py b/src/ethereum/forks/shanghai/transactions.py index 871782b3a73..459c70cb23c 100644 --- a/src/ethereum/forks/shanghai/transactions.py +++ b/src/ethereum/forks/shanghai/transactions.py @@ -23,37 +23,6 @@ from .exceptions import InitCodeTooLargeError, TransactionTypeError -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(16) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - -GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400) -""" -Gas cost for including an address in the access list of a transaction. -""" - -GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) -""" -Gas cost for including a storage key in the access list of a transaction. -""" - @slotted_freezable @dataclass @@ -380,7 +349,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) 4. Cost for access list entries (if applicable) @@ -388,29 +357,29 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ - from .vm.gas import init_code_cost + from .vm.gas import GasCosts, init_code_cost num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + init_code_cost(ulen(tx.data)) + create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data)) else: create_cost = Uint(0) access_list_cost = Uint(0) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): for access in tx.access_list: - access_list_cost += GAS_TX_ACCESS_LIST_ADDRESS + access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS access_list_cost += ( - ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY + ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY ) - return GAS_TX_BASE + data_cost + create_cost + access_list_cost + return GasCosts.TX_BASE + data_cost + create_cost + access_list_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 99b31920c91..1bbd79b2485 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -77,7 +77,19 @@ class GasCosts: PRECOMPILE_ECPAIRING_BASE = Uint(45000) PRECOMPILE_ECPAIRING_PER_POINT = Uint(34000) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(16) + TX_ACCESS_LIST_ADDRESS = Uint(2400) + TX_ACCESS_LIST_STORAGE_KEY = Uint(1900) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/spurious_dragon/fork.py b/src/ethereum/forks/spurious_dragon/fork.py index a115049d968..7c3101d25a3 100644 --- a/src/ethereum/forks/spurious_dragon/fork.py +++ b/src/ethereum/forks/spurious_dragon/fork.py @@ -51,11 +51,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(5 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) @@ -709,12 +708,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -732,12 +731,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/spurious_dragon/transactions.py b/src/ethereum/forks/spurious_dragon/transactions.py index 278238f8d5a..e8cde82b198 100644 --- a/src/ethereum/forks/spurious_dragon/transactions.py +++ b/src/ethereum/forks/spurious_dragon/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(chain_id: U64, tx: Transaction) -> Address: diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 603786aa259..22735b5f13a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -69,7 +69,17 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW diff --git a/src/ethereum/forks/tangerine_whistle/fork.py b/src/ethereum/forks/tangerine_whistle/fork.py index 162a6bd1b7a..78592e2d770 100644 --- a/src/ethereum/forks/tangerine_whistle/fork.py +++ b/src/ethereum/forks/tangerine_whistle/fork.py @@ -49,11 +49,10 @@ ) from .trie import root, trie_set from .utils.message import prepare_message +from .vm.gas import GasCosts from .vm.interpreter import process_message_call BLOCK_REWARD = U256(5 * 10**18) -GAS_LIMIT_ADJUSTMENT_FACTOR = Uint(1024) -GAS_LIMIT_MINIMUM = Uint(5000) MINIMUM_DIFFICULTY = Uint(131072) MAX_OMMER_DEPTH = Uint(6) @@ -700,12 +699,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + delta *or* the predefined ``LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. @@ -723,12 +722,12 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: True if gas limit constraints are satisfied, False otherwise. """ - max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR + max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR if gas_limit >= parent_gas_limit + max_adjustment_delta: return False if gas_limit <= parent_gas_limit - max_adjustment_delta: return False - if gas_limit < GAS_LIMIT_MINIMUM: + if gas_limit < GasCosts.LIMIT_MINIMUM: return False return True diff --git a/src/ethereum/forks/tangerine_whistle/transactions.py b/src/ethereum/forks/tangerine_whistle/transactions.py index 934540874ca..e17bafae49d 100644 --- a/src/ethereum/forks/tangerine_whistle/transactions.py +++ b/src/ethereum/forks/tangerine_whistle/transactions.py @@ -21,27 +21,6 @@ from .fork_types import Address -GAS_TX_BASE = Uint(21000) -""" -Base cost of a transaction in gas units. This is the minimum amount of gas -required to execute a transaction. -""" - -GAS_TX_DATA_PER_NON_ZERO = Uint(68) -""" -Gas cost per non-zero byte in the transaction data. -""" - -GAS_TX_DATA_PER_ZERO = Uint(4) -""" -Gas cost per zero byte in the transaction data. -""" - -GAS_TX_CREATE = Uint(32000) -""" -Additional gas cost for creating a new contract. -""" - @slotted_freezable @dataclass @@ -143,26 +122,28 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: for all operations to be implemented. The intrinsic cost includes: - 1. Base cost (`GAS_TX_BASE`) + 1. Base cost (`TX_BASE`) 2. Cost for data (zero and non-zero bytes) 3. Cost for contract creation (if applicable) This function takes a transaction as a parameter and returns the intrinsic gas cost of the transaction. """ + from .vm.gas import GasCosts + num_zeros = Uint(tx.data.count(0)) num_non_zeros = ulen(tx.data) - num_zeros data_cost = ( - num_zeros * GAS_TX_DATA_PER_ZERO - + num_non_zeros * GAS_TX_DATA_PER_NON_ZERO + num_zeros * GasCosts.TX_DATA_PER_ZERO + + num_non_zeros * GasCosts.TX_DATA_PER_NON_ZERO ) if tx.to == Bytes0(b""): - create_cost = GAS_TX_CREATE + create_cost = GasCosts.TX_CREATE else: create_cost = Uint(0) - return GAS_TX_BASE + data_cost + create_cost + return GasCosts.TX_BASE + data_cost + create_cost def recover_sender(tx: Transaction) -> Address: diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index ff61fc8653a..ec2e8a59757 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -69,7 +69,17 @@ class GasCosts: PRECOMPILE_IDENTITY_BASE = Uint(15) PRECOMPILE_IDENTITY_PER_WORD = Uint(3) - # Opcodes + # Transactions + TX_BASE = Uint(21000) + TX_CREATE = Uint(32000) + TX_DATA_PER_ZERO = Uint(4) + TX_DATA_PER_NON_ZERO = Uint(68) + + # Block + LIMIT_ADJUSTMENT_FACTOR = Uint(1024) + LIMIT_MINIMUM = Uint(5000) + + # Static Opcodes OPCODE_ADD = VERY_LOW OPCODE_SUB = VERY_LOW OPCODE_MUL = LOW From 235c51023792e0041287c0035ead1db9a5593a1d Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 13 Apr 2026 00:55:33 -0400 Subject: [PATCH 59/61] refactor: add missing opcode gas constants and replace usage in functions --- src/ethereum/forks/amsterdam/vm/gas.py | 20 +++++++++++++++++++ .../forks/amsterdam/vm/instructions/block.py | 12 +++++------ .../amsterdam/vm/instructions/control_flow.py | 4 ++-- .../amsterdam/vm/instructions/environment.py | 20 +++++++++---------- .../forks/amsterdam/vm/instructions/memory.py | 2 +- .../forks/amsterdam/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/arrow_glacier/vm/gas.py | 18 +++++++++++++++++ .../arrow_glacier/vm/instructions/block.py | 12 +++++------ .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 18 ++++++++--------- .../arrow_glacier/vm/instructions/memory.py | 2 +- .../arrow_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/berlin/vm/gas.py | 17 ++++++++++++++++ .../forks/berlin/vm/instructions/block.py | 12 +++++------ .../berlin/vm/instructions/control_flow.py | 4 ++-- .../berlin/vm/instructions/environment.py | 16 +++++++-------- .../forks/berlin/vm/instructions/memory.py | 2 +- .../forks/berlin/vm/instructions/stack.py | 2 +- src/ethereum/forks/bpo1/vm/gas.py | 20 +++++++++++++++++++ .../forks/bpo1/vm/instructions/block.py | 12 +++++------ .../bpo1/vm/instructions/control_flow.py | 4 ++-- .../forks/bpo1/vm/instructions/environment.py | 20 +++++++++---------- .../forks/bpo1/vm/instructions/memory.py | 2 +- .../forks/bpo1/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/bpo2/vm/gas.py | 20 +++++++++++++++++++ .../forks/bpo2/vm/instructions/block.py | 12 +++++------ .../bpo2/vm/instructions/control_flow.py | 4 ++-- .../forks/bpo2/vm/instructions/environment.py | 20 +++++++++---------- .../forks/bpo2/vm/instructions/memory.py | 2 +- .../forks/bpo2/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/bpo3/vm/gas.py | 20 +++++++++++++++++++ .../forks/bpo3/vm/instructions/block.py | 12 +++++------ .../bpo3/vm/instructions/control_flow.py | 4 ++-- .../forks/bpo3/vm/instructions/environment.py | 20 +++++++++---------- .../forks/bpo3/vm/instructions/memory.py | 2 +- .../forks/bpo3/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/bpo4/vm/gas.py | 20 +++++++++++++++++++ .../forks/bpo4/vm/instructions/block.py | 12 +++++------ .../bpo4/vm/instructions/control_flow.py | 4 ++-- .../forks/bpo4/vm/instructions/environment.py | 20 +++++++++---------- .../forks/bpo4/vm/instructions/memory.py | 2 +- .../forks/bpo4/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/bpo5/vm/gas.py | 20 +++++++++++++++++++ .../forks/bpo5/vm/instructions/block.py | 12 +++++------ .../bpo5/vm/instructions/control_flow.py | 4 ++-- .../forks/bpo5/vm/instructions/environment.py | 20 +++++++++---------- .../forks/bpo5/vm/instructions/memory.py | 2 +- .../forks/bpo5/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/byzantium/vm/gas.py | 16 +++++++++++++++ .../forks/byzantium/vm/instructions/block.py | 10 +++++----- .../byzantium/vm/instructions/control_flow.py | 4 ++-- .../byzantium/vm/instructions/environment.py | 16 +++++++-------- .../forks/byzantium/vm/instructions/memory.py | 2 +- .../forks/byzantium/vm/instructions/stack.py | 2 +- src/ethereum/forks/cancun/vm/gas.py | 20 +++++++++++++++++++ .../forks/cancun/vm/instructions/block.py | 12 +++++------ .../cancun/vm/instructions/control_flow.py | 4 ++-- .../cancun/vm/instructions/environment.py | 20 +++++++++---------- .../forks/cancun/vm/instructions/memory.py | 2 +- .../forks/cancun/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/constantinople/vm/gas.py | 16 +++++++++++++++ .../constantinople/vm/instructions/block.py | 10 +++++----- .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 16 +++++++-------- .../constantinople/vm/instructions/memory.py | 2 +- .../constantinople/vm/instructions/stack.py | 2 +- src/ethereum/forks/dao_fork/vm/gas.py | 15 ++++++++++++++ .../forks/dao_fork/vm/instructions/block.py | 10 +++++----- .../dao_fork/vm/instructions/control_flow.py | 4 ++-- .../dao_fork/vm/instructions/environment.py | 14 ++++++------- .../forks/dao_fork/vm/instructions/memory.py | 2 +- .../forks/dao_fork/vm/instructions/stack.py | 2 +- src/ethereum/forks/frontier/vm/gas.py | 15 ++++++++++++++ .../forks/frontier/vm/instructions/block.py | 10 +++++----- .../frontier/vm/instructions/control_flow.py | 4 ++-- .../frontier/vm/instructions/environment.py | 14 ++++++------- .../forks/frontier/vm/instructions/memory.py | 2 +- .../forks/frontier/vm/instructions/stack.py | 2 +- src/ethereum/forks/gray_glacier/vm/gas.py | 18 +++++++++++++++++ .../gray_glacier/vm/instructions/block.py | 12 +++++------ .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 18 ++++++++--------- .../gray_glacier/vm/instructions/memory.py | 2 +- .../gray_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/homestead/vm/gas.py | 15 ++++++++++++++ .../forks/homestead/vm/instructions/block.py | 10 +++++----- .../homestead/vm/instructions/control_flow.py | 4 ++-- .../homestead/vm/instructions/environment.py | 14 ++++++------- .../forks/homestead/vm/instructions/memory.py | 2 +- .../forks/homestead/vm/instructions/stack.py | 2 +- src/ethereum/forks/istanbul/vm/gas.py | 17 ++++++++++++++++ .../forks/istanbul/vm/instructions/block.py | 12 +++++------ .../istanbul/vm/instructions/control_flow.py | 4 ++-- .../istanbul/vm/instructions/environment.py | 16 +++++++-------- .../forks/istanbul/vm/instructions/memory.py | 2 +- .../forks/istanbul/vm/instructions/stack.py | 2 +- src/ethereum/forks/london/vm/gas.py | 18 +++++++++++++++++ .../forks/london/vm/instructions/block.py | 12 +++++------ .../london/vm/instructions/control_flow.py | 4 ++-- .../london/vm/instructions/environment.py | 18 ++++++++--------- .../forks/london/vm/instructions/memory.py | 2 +- .../forks/london/vm/instructions/stack.py | 2 +- src/ethereum/forks/muir_glacier/vm/gas.py | 17 ++++++++++++++++ .../muir_glacier/vm/instructions/block.py | 12 +++++------ .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 16 +++++++-------- .../muir_glacier/vm/instructions/memory.py | 2 +- .../muir_glacier/vm/instructions/stack.py | 2 +- src/ethereum/forks/osaka/vm/gas.py | 20 +++++++++++++++++++ .../forks/osaka/vm/instructions/block.py | 12 +++++------ .../osaka/vm/instructions/control_flow.py | 4 ++-- .../osaka/vm/instructions/environment.py | 20 +++++++++---------- .../forks/osaka/vm/instructions/memory.py | 2 +- .../forks/osaka/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/paris/vm/gas.py | 18 +++++++++++++++++ .../forks/paris/vm/instructions/block.py | 12 +++++------ .../paris/vm/instructions/control_flow.py | 4 ++-- .../paris/vm/instructions/environment.py | 18 ++++++++--------- .../forks/paris/vm/instructions/memory.py | 2 +- .../forks/paris/vm/instructions/stack.py | 2 +- src/ethereum/forks/prague/vm/gas.py | 20 +++++++++++++++++++ .../forks/prague/vm/instructions/block.py | 12 +++++------ .../prague/vm/instructions/control_flow.py | 4 ++-- .../prague/vm/instructions/environment.py | 20 +++++++++---------- .../forks/prague/vm/instructions/memory.py | 2 +- .../forks/prague/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/shanghai/vm/gas.py | 19 ++++++++++++++++++ .../forks/shanghai/vm/instructions/block.py | 12 +++++------ .../shanghai/vm/instructions/control_flow.py | 4 ++-- .../shanghai/vm/instructions/environment.py | 18 ++++++++--------- .../forks/shanghai/vm/instructions/memory.py | 2 +- .../forks/shanghai/vm/instructions/stack.py | 4 ++-- src/ethereum/forks/spurious_dragon/vm/gas.py | 15 ++++++++++++++ .../spurious_dragon/vm/instructions/block.py | 10 +++++----- .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 14 ++++++------- .../spurious_dragon/vm/instructions/memory.py | 2 +- .../spurious_dragon/vm/instructions/stack.py | 2 +- .../forks/tangerine_whistle/vm/gas.py | 15 ++++++++++++++ .../vm/instructions/block.py | 10 +++++----- .../vm/instructions/control_flow.py | 4 ++-- .../vm/instructions/environment.py | 14 ++++++------- .../vm/instructions/memory.py | 2 +- .../vm/instructions/stack.py | 2 +- 144 files changed, 882 insertions(+), 453 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 033fb0242fe..54f16cd26cc 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -147,8 +147,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/amsterdam/vm/instructions/block.py b/src/ethereum/forks/amsterdam/vm/instructions/block.py index 0fc62deba97..8c93840b384 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/block.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/environment.py b/src/ethereum/forks/amsterdam/vm/instructions/environment.py index ebd6579119e..431cd3ba4c6 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/environment.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -100,7 +100,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -123,7 +123,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -146,7 +146,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -195,7 +195,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -256,7 +256,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -317,7 +317,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -418,7 +418,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -546,7 +546,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -596,7 +596,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/amsterdam/vm/instructions/memory.py b/src/ethereum/forks/amsterdam/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/memory.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/amsterdam/vm/instructions/stack.py b/src/ethereum/forks/amsterdam/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/amsterdam/vm/instructions/stack.py +++ b/src/ethereum/forks/amsterdam/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index dcfdf54c08e..b5440bdd34f 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -119,6 +119,24 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py index 768b5665e16..851ab39b142 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/arrow_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index d546950fe4d..37018b50d66 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -120,6 +120,23 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/berlin/vm/instructions/block.py b/src/ethereum/forks/berlin/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/berlin/vm/instructions/block.py +++ b/src/ethereum/forks/berlin/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/berlin/vm/instructions/control_flow.py b/src/ethereum/forks/berlin/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/berlin/vm/instructions/control_flow.py +++ b/src/ethereum/forks/berlin/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/berlin/vm/instructions/environment.py b/src/ethereum/forks/berlin/vm/instructions/environment.py index 715031f52fb..9e7b817ace6 100644 --- a/src/ethereum/forks/berlin/vm/instructions/environment.py +++ b/src/ethereum/forks/berlin/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) diff --git a/src/ethereum/forks/berlin/vm/instructions/memory.py b/src/ethereum/forks/berlin/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/berlin/vm/instructions/memory.py +++ b/src/ethereum/forks/berlin/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/berlin/vm/instructions/stack.py b/src/ethereum/forks/berlin/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/berlin/vm/instructions/stack.py +++ b/src/ethereum/forks/berlin/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 2a631facb7d..2a30bfc32ae 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/bpo1/vm/instructions/block.py b/src/ethereum/forks/bpo1/vm/instructions/block.py index 82e4a4c502c..7e32893722b 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/block.py +++ b/src/ethereum/forks/bpo1/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo1/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo1/vm/instructions/environment.py b/src/ethereum/forks/bpo1/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo1/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo1/vm/instructions/memory.py b/src/ethereum/forks/bpo1/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo1/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/bpo1/vm/instructions/stack.py b/src/ethereum/forks/bpo1/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/bpo1/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo1/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index b982a66190f..3df538a9f16 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/bpo2/vm/instructions/block.py b/src/ethereum/forks/bpo2/vm/instructions/block.py index 046ddc3b6d7..76ab809b06b 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/block.py +++ b/src/ethereum/forks/bpo2/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py index 76948ae4796..d74e7b90340 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo2/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo2/vm/instructions/environment.py b/src/ethereum/forks/bpo2/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo2/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo2/vm/instructions/memory.py b/src/ethereum/forks/bpo2/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo2/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/bpo2/vm/instructions/stack.py b/src/ethereum/forks/bpo2/vm/instructions/stack.py index dec0bc81afe..d7b3df986b0 100644 --- a/src/ethereum/forks/bpo2/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo2/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index b982a66190f..3df538a9f16 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/bpo3/vm/instructions/block.py b/src/ethereum/forks/bpo3/vm/instructions/block.py index ace26d66c3d..54183f4773e 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/block.py +++ b/src/ethereum/forks/bpo3/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py index 76948ae4796..d74e7b90340 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo3/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo3/vm/instructions/environment.py b/src/ethereum/forks/bpo3/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo3/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo3/vm/instructions/memory.py b/src/ethereum/forks/bpo3/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo3/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/bpo3/vm/instructions/stack.py b/src/ethereum/forks/bpo3/vm/instructions/stack.py index dec0bc81afe..d7b3df986b0 100644 --- a/src/ethereum/forks/bpo3/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo3/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index b982a66190f..3df538a9f16 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/bpo4/vm/instructions/block.py b/src/ethereum/forks/bpo4/vm/instructions/block.py index aaf58be49f4..e53d2a57a35 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/block.py +++ b/src/ethereum/forks/bpo4/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo4/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo4/vm/instructions/environment.py b/src/ethereum/forks/bpo4/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo4/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo4/vm/instructions/memory.py b/src/ethereum/forks/bpo4/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo4/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/bpo4/vm/instructions/stack.py b/src/ethereum/forks/bpo4/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/bpo4/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo4/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index b982a66190f..3df538a9f16 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/bpo5/vm/instructions/block.py b/src/ethereum/forks/bpo5/vm/instructions/block.py index 09e8d711af0..faa2e0fa040 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/block.py +++ b/src/ethereum/forks/bpo5/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/control_flow.py +++ b/src/ethereum/forks/bpo5/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/bpo5/vm/instructions/environment.py b/src/ethereum/forks/bpo5/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/environment.py +++ b/src/ethereum/forks/bpo5/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/bpo5/vm/instructions/memory.py b/src/ethereum/forks/bpo5/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/memory.py +++ b/src/ethereum/forks/bpo5/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/bpo5/vm/instructions/stack.py b/src/ethereum/forks/bpo5/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/bpo5/vm/instructions/stack.py +++ b/src/ethereum/forks/bpo5/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 450ff27f5bc..9bdef74ca46 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -111,6 +111,22 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/byzantium/vm/instructions/block.py b/src/ethereum/forks/byzantium/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/block.py +++ b/src/ethereum/forks/byzantium/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/control_flow.py +++ b/src/ethereum/forks/byzantium/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/byzantium/vm/instructions/environment.py b/src/ethereum/forks/byzantium/vm/instructions/environment.py index 5f989f8580e..c459b2aebec 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/environment.py +++ b/src/ethereum/forks/byzantium/vm/instructions/environment.py @@ -42,7 +42,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -92,7 +92,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -115,7 +115,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -138,7 +138,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -187,7 +187,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -248,7 +248,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -309,7 +309,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -398,7 +398,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) diff --git a/src/ethereum/forks/byzantium/vm/instructions/memory.py b/src/ethereum/forks/byzantium/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/memory.py +++ b/src/ethereum/forks/byzantium/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/byzantium/vm/instructions/stack.py b/src/ethereum/forks/byzantium/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/byzantium/vm/instructions/stack.py +++ b/src/ethereum/forks/byzantium/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index e9e4ae722b7..b1be96a0c5f 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -129,8 +129,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/cancun/vm/instructions/block.py b/src/ethereum/forks/cancun/vm/instructions/block.py index d5c0aa656d8..82378940859 100644 --- a/src/ethereum/forks/cancun/vm/instructions/block.py +++ b/src/ethereum/forks/cancun/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/cancun/vm/instructions/control_flow.py b/src/ethereum/forks/cancun/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/cancun/vm/instructions/control_flow.py +++ b/src/ethereum/forks/cancun/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/cancun/vm/instructions/environment.py b/src/ethereum/forks/cancun/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/cancun/vm/instructions/environment.py +++ b/src/ethereum/forks/cancun/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/cancun/vm/instructions/memory.py b/src/ethereum/forks/cancun/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/cancun/vm/instructions/memory.py +++ b/src/ethereum/forks/cancun/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/cancun/vm/instructions/stack.py b/src/ethereum/forks/cancun/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/cancun/vm/instructions/stack.py +++ b/src/ethereum/forks/cancun/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 397e685e23f..67ef3ea2c64 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -115,6 +115,22 @@ class GasCosts: OPCODE_EXTCODEHASH = Uint(400) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/constantinople/vm/instructions/block.py b/src/ethereum/forks/constantinople/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/block.py +++ b/src/ethereum/forks/constantinople/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/control_flow.py +++ b/src/ethereum/forks/constantinople/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/constantinople/vm/instructions/environment.py b/src/ethereum/forks/constantinople/vm/instructions/environment.py index 8ce901bba4a..2761ffda5fe 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/environment.py +++ b/src/ethereum/forks/constantinople/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -399,7 +399,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) diff --git a/src/ethereum/forks/constantinople/vm/instructions/memory.py b/src/ethereum/forks/constantinople/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/memory.py +++ b/src/ethereum/forks/constantinople/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/constantinople/vm/instructions/stack.py b/src/ethereum/forks/constantinople/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/constantinople/vm/instructions/stack.py +++ b/src/ethereum/forks/constantinople/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index e973be6b5cf..99e3f7966a8 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -109,6 +109,21 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/dao_fork/vm/instructions/block.py b/src/ethereum/forks/dao_fork/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/block.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/environment.py b/src/ethereum/forks/dao_fork/vm/instructions/environment.py index df6814c794f..d930368fdd9 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/environment.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/memory.py b/src/ethereum/forks/dao_fork/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/memory.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/dao_fork/vm/instructions/stack.py b/src/ethereum/forks/dao_fork/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/dao_fork/vm/instructions/stack.py +++ b/src/ethereum/forks/dao_fork/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index 155156fdc79..be297bced56 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -108,6 +108,21 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/frontier/vm/instructions/block.py b/src/ethereum/forks/frontier/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/frontier/vm/instructions/block.py +++ b/src/ethereum/forks/frontier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/frontier/vm/instructions/control_flow.py b/src/ethereum/forks/frontier/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/frontier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/frontier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/frontier/vm/instructions/environment.py b/src/ethereum/forks/frontier/vm/instructions/environment.py index df6814c794f..d930368fdd9 100644 --- a/src/ethereum/forks/frontier/vm/instructions/environment.py +++ b/src/ethereum/forks/frontier/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) diff --git a/src/ethereum/forks/frontier/vm/instructions/memory.py b/src/ethereum/forks/frontier/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/frontier/vm/instructions/memory.py +++ b/src/ethereum/forks/frontier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/frontier/vm/instructions/stack.py b/src/ethereum/forks/frontier/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/frontier/vm/instructions/stack.py +++ b/src/ethereum/forks/frontier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index dcfdf54c08e..b5440bdd34f 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -119,6 +119,24 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/block.py b/src/ethereum/forks/gray_glacier/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py index 768b5665e16..851ab39b142 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/gray_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/gray_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index e973be6b5cf..99e3f7966a8 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -109,6 +109,21 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/homestead/vm/instructions/block.py b/src/ethereum/forks/homestead/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/homestead/vm/instructions/block.py +++ b/src/ethereum/forks/homestead/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/homestead/vm/instructions/control_flow.py b/src/ethereum/forks/homestead/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/homestead/vm/instructions/control_flow.py +++ b/src/ethereum/forks/homestead/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/homestead/vm/instructions/environment.py b/src/ethereum/forks/homestead/vm/instructions/environment.py index df6814c794f..d930368fdd9 100644 --- a/src/ethereum/forks/homestead/vm/instructions/environment.py +++ b/src/ethereum/forks/homestead/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) diff --git a/src/ethereum/forks/homestead/vm/instructions/memory.py b/src/ethereum/forks/homestead/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/homestead/vm/instructions/memory.py +++ b/src/ethereum/forks/homestead/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/homestead/vm/instructions/stack.py b/src/ethereum/forks/homestead/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/homestead/vm/instructions/stack.py +++ b/src/ethereum/forks/homestead/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 7f6e8287c6b..460f37a8a36 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -117,6 +117,23 @@ class GasCosts: OPCODE_EXTCODEHASH = Uint(700) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/istanbul/vm/instructions/block.py b/src/ethereum/forks/istanbul/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/block.py +++ b/src/ethereum/forks/istanbul/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/control_flow.py +++ b/src/ethereum/forks/istanbul/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/istanbul/vm/instructions/environment.py b/src/ethereum/forks/istanbul/vm/instructions/environment.py index 7d721cab606..b3ac54a689a 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/environment.py +++ b/src/ethereum/forks/istanbul/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -399,7 +399,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) diff --git a/src/ethereum/forks/istanbul/vm/instructions/memory.py b/src/ethereum/forks/istanbul/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/memory.py +++ b/src/ethereum/forks/istanbul/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/istanbul/vm/instructions/stack.py b/src/ethereum/forks/istanbul/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/istanbul/vm/instructions/stack.py +++ b/src/ethereum/forks/istanbul/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index dcfdf54c08e..b5440bdd34f 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -119,6 +119,24 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/london/vm/instructions/block.py b/src/ethereum/forks/london/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/london/vm/instructions/block.py +++ b/src/ethereum/forks/london/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/london/vm/instructions/control_flow.py b/src/ethereum/forks/london/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/london/vm/instructions/control_flow.py +++ b/src/ethereum/forks/london/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/london/vm/instructions/environment.py b/src/ethereum/forks/london/vm/instructions/environment.py index 768b5665e16..851ab39b142 100644 --- a/src/ethereum/forks/london/vm/instructions/environment.py +++ b/src/ethereum/forks/london/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/london/vm/instructions/memory.py b/src/ethereum/forks/london/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/london/vm/instructions/memory.py +++ b/src/ethereum/forks/london/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/london/vm/instructions/stack.py b/src/ethereum/forks/london/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/london/vm/instructions/stack.py +++ b/src/ethereum/forks/london/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 7f6e8287c6b..460f37a8a36 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -117,6 +117,23 @@ class GasCosts: OPCODE_EXTCODEHASH = Uint(700) OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/block.py b/src/ethereum/forks/muir_glacier/vm/instructions/block.py index 7392e5dfa6c..e3400f9461a 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/block.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py index 7d721cab606..b3ac54a689a 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/environment.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -93,7 +93,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -116,7 +116,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -139,7 +139,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -188,7 +188,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -249,7 +249,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -310,7 +310,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -399,7 +399,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/memory.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/muir_glacier/vm/instructions/stack.py +++ b/src/ethereum/forks/muir_glacier/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index f9b2b03f946..84eed4f895c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -143,8 +143,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/osaka/vm/instructions/block.py b/src/ethereum/forks/osaka/vm/instructions/block.py index ce1507800c7..d0aa17fe959 100644 --- a/src/ethereum/forks/osaka/vm/instructions/block.py +++ b/src/ethereum/forks/osaka/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/osaka/vm/instructions/control_flow.py b/src/ethereum/forks/osaka/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/osaka/vm/instructions/control_flow.py +++ b/src/ethereum/forks/osaka/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/osaka/vm/instructions/environment.py b/src/ethereum/forks/osaka/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/osaka/vm/instructions/environment.py +++ b/src/ethereum/forks/osaka/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/osaka/vm/instructions/memory.py b/src/ethereum/forks/osaka/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/osaka/vm/instructions/memory.py +++ b/src/ethereum/forks/osaka/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/osaka/vm/instructions/stack.py b/src/ethereum/forks/osaka/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/osaka/vm/instructions/stack.py +++ b/src/ethereum/forks/osaka/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index dcfdf54c08e..2f88aa47fba 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -119,6 +119,24 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/paris/vm/instructions/block.py b/src/ethereum/forks/paris/vm/instructions/block.py index d1b1194b94c..19216cef9d5 100644 --- a/src/ethereum/forks/paris/vm/instructions/block.py +++ b/src/ethereum/forks/paris/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/paris/vm/instructions/control_flow.py b/src/ethereum/forks/paris/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/paris/vm/instructions/control_flow.py +++ b/src/ethereum/forks/paris/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/paris/vm/instructions/environment.py b/src/ethereum/forks/paris/vm/instructions/environment.py index 9ea49ffeb59..588022b5722 100644 --- a/src/ethereum/forks/paris/vm/instructions/environment.py +++ b/src/ethereum/forks/paris/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/paris/vm/instructions/memory.py b/src/ethereum/forks/paris/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/paris/vm/instructions/memory.py +++ b/src/ethereum/forks/paris/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/paris/vm/instructions/stack.py b/src/ethereum/forks/paris/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/paris/vm/instructions/stack.py +++ b/src/ethereum/forks/paris/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index dae7cfe7c17..e0ff6017014 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -138,8 +138,28 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE + OPCODE_BLOBBASEFEE = BASE OPCODE_BLOBHASH = Uint(3) OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/prague/vm/instructions/block.py b/src/ethereum/forks/prague/vm/instructions/block.py index 555f100c519..4c405ad5194 100644 --- a/src/ethereum/forks/prague/vm/instructions/block.py +++ b/src/ethereum/forks/prague/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/prague/vm/instructions/control_flow.py b/src/ethereum/forks/prague/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/prague/vm/instructions/control_flow.py +++ b/src/ethereum/forks/prague/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/prague/vm/instructions/environment.py b/src/ethereum/forks/prague/vm/instructions/environment.py index dea6e2016c5..7fa57b90d8b 100644 --- a/src/ethereum/forks/prague/vm/instructions/environment.py +++ b/src/ethereum/forks/prague/vm/instructions/environment.py @@ -45,7 +45,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -99,7 +99,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -122,7 +122,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -145,7 +145,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -194,7 +194,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -255,7 +255,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -316,7 +316,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -415,7 +415,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -542,7 +542,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) @@ -592,7 +592,7 @@ def blob_base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE) # OPERATION blob_base_fee = calculate_blob_gas_price( diff --git a/src/ethereum/forks/prague/vm/instructions/memory.py b/src/ethereum/forks/prague/vm/instructions/memory.py index 55f6544d1c6..bba3ddf19d5 100644 --- a/src/ethereum/forks/prague/vm/instructions/memory.py +++ b/src/ethereum/forks/prague/vm/instructions/memory.py @@ -133,7 +133,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/prague/vm/instructions/stack.py b/src/ethereum/forks/prague/vm/instructions/stack.py index 5520ac8303a..366cf79f5e4 100644 --- a/src/ethereum/forks/prague/vm/instructions/stack.py +++ b/src/ethereum/forks/prague/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 1bbd79b2485..90badfa3b53 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -120,7 +120,26 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_PREVRANDAO = BASE + OPCODE_RETURNDATASIZE = BASE + OPCODE_CHAINID = BASE + OPCODE_BASEFEE = BASE OPCODE_PUSH = VERY_LOW + OPCODE_PUSH0 = BASE OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/shanghai/vm/instructions/block.py b/src/ethereum/forks/shanghai/vm/instructions/block.py index 7d98aa2a41e..cfba646567f 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/block.py +++ b/src/ethereum/forks/shanghai/vm/instructions/block.py @@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -156,7 +156,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PREVRANDAO) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao)) @@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) @@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CHAINID) # OPERATION push(evm.stack, U256(evm.message.block_env.chain_id)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py index 76948ae4796..d74e7b90340 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/control_flow.py +++ b/src/ethereum/forks/shanghai/vm/instructions/control_flow.py @@ -113,7 +113,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -137,7 +137,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/environment.py b/src/ethereum/forks/shanghai/vm/instructions/environment.py index 9ea49ffeb59..588022b5722 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/environment.py +++ b/src/ethereum/forks/shanghai/vm/instructions/environment.py @@ -43,7 +43,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -97,7 +97,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -120,7 +120,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) @@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE) # OPERATION push(evm.stack, U256(len(evm.return_data))) @@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_BASEFEE) # OPERATION push(evm.stack, U256(evm.message.block_env.base_fee_per_gas)) diff --git a/src/ethereum/forks/shanghai/vm/instructions/memory.py b/src/ethereum/forks/shanghai/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/memory.py +++ b/src/ethereum/forks/shanghai/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/shanghai/vm/instructions/stack.py b/src/ethereum/forks/shanghai/vm/instructions/stack.py index dec0bc81afe..d7b3df986b0 100644 --- a/src/ethereum/forks/shanghai/vm/instructions/stack.py +++ b/src/ethereum/forks/shanghai/vm/instructions/stack.py @@ -35,7 +35,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass @@ -63,7 +63,7 @@ def push_n(evm: Evm, num_bytes: int) -> None: # GAS if num_bytes == 0: - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PUSH0) else: charge_gas(evm, GasCosts.OPCODE_PUSH) diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 22735b5f13a..d97783a985b 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -107,6 +107,21 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/block.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py index df6814c794f..d930368fdd9 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py +++ b/src/ethereum/forks/spurious_dragon/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index ec2e8a59757..e1c03061afc 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -107,6 +107,21 @@ class GasCosts: OPCODE_CALLDATALOAD = VERY_LOW OPCODE_BLOCKHASH = Uint(20) OPCODE_COINBASE = BASE + OPCODE_POP = BASE + OPCODE_MSIZE = BASE + OPCODE_PC = BASE + OPCODE_GAS = BASE + OPCODE_ADDRESS = BASE + OPCODE_ORIGIN = BASE + OPCODE_CALLER = BASE + OPCODE_CALLVALUE = BASE + OPCODE_CALLDATASIZE = BASE + OPCODE_CODESIZE = BASE + OPCODE_GASPRICE = BASE + OPCODE_TIMESTAMP = BASE + OPCODE_NUMBER = BASE + OPCODE_GASLIMIT = BASE + OPCODE_DIFFICULTY = BASE OPCODE_PUSH = VERY_LOW OPCODE_DUP = VERY_LOW OPCODE_SWAP = VERY_LOW diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py index f8897e35754..fbca7daa37c 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/block.py @@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_COINBASE) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase)) @@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_TIMESTAMP) # OPERATION push(evm.stack, evm.message.block_env.time) @@ -128,7 +128,7 @@ def number(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_NUMBER) # OPERATION push(evm.stack, U256(evm.message.block_env.number)) @@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_DIFFICULTY) # OPERATION push(evm.stack, U256(evm.message.block_env.difficulty)) @@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASLIMIT) # OPERATION push(evm.stack, U256(evm.message.block_env.block_gas_limit)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py index 9c98154f9aa..548a05d3163 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/control_flow.py @@ -116,7 +116,7 @@ def pc(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_PC) # OPERATION push(evm.stack, U256(evm.pc)) @@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GAS) # OPERATION push(evm.stack, U256(evm.gas_left)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py index df6814c794f..d930368fdd9 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/environment.py @@ -41,7 +41,7 @@ def address(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ADDRESS) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.current_target)) @@ -91,7 +91,7 @@ def origin(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_ORIGIN) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin)) @@ -114,7 +114,7 @@ def caller(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLER) # OPERATION push(evm.stack, U256.from_be_bytes(evm.message.caller)) @@ -137,7 +137,7 @@ def callvalue(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLVALUE) # OPERATION push(evm.stack, evm.message.value) @@ -186,7 +186,7 @@ def calldatasize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE) # OPERATION push(evm.stack, U256(len(evm.message.data))) @@ -247,7 +247,7 @@ def codesize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_CODESIZE) # OPERATION push(evm.stack, U256(len(evm.code))) @@ -308,7 +308,7 @@ def gasprice(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_GASPRICE) # OPERATION push(evm.stack, U256(evm.message.tx_env.gas_price)) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py index d1bbcd9e197..93861811559 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/memory.py @@ -131,7 +131,7 @@ def msize(evm: Evm) -> None: pass # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_MSIZE) # OPERATION push(evm.stack, U256(len(evm.memory))) diff --git a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py index 03049761b31..9104c1e9749 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py +++ b/src/ethereum/forks/tangerine_whistle/vm/instructions/stack.py @@ -38,7 +38,7 @@ def pop(evm: Evm) -> None: stack.pop(evm.stack) # GAS - charge_gas(evm, GasCosts.BASE) + charge_gas(evm, GasCosts.OPCODE_POP) # OPERATION pass From 24762c1f92a1ac5c2aa8d47d116bbce87052a1ad Mon Sep 17 00:00:00 2001 From: carsons-eels Date: Mon, 13 Apr 2026 01:37:07 -0400 Subject: [PATCH 60/61] fix: cr comment misplacement --- src/ethereum/forks/amsterdam/vm/gas.py | 3 +-- src/ethereum/forks/arrow_glacier/vm/gas.py | 3 +-- src/ethereum/forks/berlin/vm/gas.py | 3 +-- src/ethereum/forks/bpo1/vm/gas.py | 3 +-- src/ethereum/forks/bpo2/vm/gas.py | 3 +-- src/ethereum/forks/bpo3/vm/gas.py | 3 +-- src/ethereum/forks/bpo4/vm/gas.py | 3 +-- src/ethereum/forks/bpo5/vm/gas.py | 3 +-- src/ethereum/forks/byzantium/vm/gas.py | 3 +-- src/ethereum/forks/cancun/vm/gas.py | 3 +-- src/ethereum/forks/constantinople/vm/gas.py | 3 +-- src/ethereum/forks/dao_fork/vm/gas.py | 3 +-- src/ethereum/forks/frontier/vm/gas.py | 3 +-- src/ethereum/forks/gray_glacier/vm/gas.py | 3 +-- src/ethereum/forks/homestead/vm/gas.py | 3 +-- src/ethereum/forks/istanbul/vm/gas.py | 3 +-- src/ethereum/forks/london/vm/gas.py | 3 +-- src/ethereum/forks/muir_glacier/vm/gas.py | 3 +-- src/ethereum/forks/osaka/vm/gas.py | 3 +-- src/ethereum/forks/paris/vm/gas.py | 3 +-- src/ethereum/forks/prague/vm/gas.py | 3 +-- src/ethereum/forks/shanghai/vm/gas.py | 3 +-- src/ethereum/forks/spurious_dragon/vm/gas.py | 3 +-- src/ethereum/forks/tangerine_whistle/vm/gas.py | 3 +-- 24 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 54f16cd26cc..b5ef8974d3e 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -26,11 +26,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index b5440bdd34f..c33cf7c0487 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 37018b50d66..1ffb7025f2a 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 2a30bfc32ae..232bbdd4f23 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 3df538a9f16..50edd7d5d7a 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 3df538a9f16..50edd7d5d7a 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 3df538a9f16..50edd7d5d7a 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 3df538a9f16..50edd7d5d7a 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index 9bdef74ca46..6121e3bbce0 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index b1be96a0c5f..c3a65792ec2 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index 67ef3ea2c64..85e4d3be422 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index 99e3f7966a8..f3644b8bf6a 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index be297bced56..ec6e91a20ce 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index b5440bdd34f..c33cf7c0487 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index 99e3f7966a8..f3644b8bf6a 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 460f37a8a36..ba89267f506 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index b5440bdd34f..c33cf7c0487 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 460f37a8a36..ba89267f506 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 84eed4f895c..e54f305e45c 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 2f88aa47fba..d4536445c43 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index e0ff6017014..94352384934 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -25,11 +25,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 90badfa3b53..ca3de745672 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index d97783a985b..49c69c4653a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index e1c03061afc..1dff8b9c25a 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -23,11 +23,10 @@ from .exceptions import OutOfGasError +# These values may be patched at runtime by a future gas repricing utility class GasCosts: """ Constant gas values for the EVM. - - These values may be patched at runtime by a future gas repricing utility """ # Tiers From e67820c949cdf56616285b7d3dc9437ae98efe6d Mon Sep 17 00:00:00 2001 From: knQzx <75641500+knQzx@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:24:05 +0200 Subject: [PATCH 61/61] fix spurious formatting diffs from gas constants refactor --- src/ethereum/forks/arrow_glacier/fork.py | 16 ++++++++-------- src/ethereum/forks/byzantium/fork.py | 16 ++++++++-------- src/ethereum/forks/cancun/fork.py | 16 ++++++++-------- src/ethereum/forks/constantinople/fork.py | 16 ++++++++-------- src/ethereum/forks/dao_fork/fork.py | 16 ++++++++-------- src/ethereum/forks/gray_glacier/fork.py | 16 ++++++++-------- src/ethereum/forks/homestead/fork.py | 16 ++++++++-------- src/ethereum/forks/london/fork.py | 16 ++++++++-------- src/ethereum/forks/paris/fork.py | 16 ++++++++-------- src/ethereum/forks/shanghai/fork.py | 16 ++++++++-------- src/ethereum/forks/spurious_dragon/fork.py | 16 ++++++++-------- src/ethereum/forks/tangerine_whistle/fork.py | 16 ++++++++-------- 12 files changed, 96 insertions(+), 96 deletions(-) diff --git a/src/ethereum/forks/arrow_glacier/fork.py b/src/ethereum/forks/arrow_glacier/fork.py index 1ca5a51b6ac..30ca8c9139a 100644 --- a/src/ethereum/forks/arrow_glacier/fork.py +++ b/src/ethereum/forks/arrow_glacier/fork.py @@ -848,14 +848,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/byzantium/fork.py b/src/ethereum/forks/byzantium/fork.py index 848a1edf547..956b298980f 100644 --- a/src/ethereum/forks/byzantium/fork.py +++ b/src/ethereum/forks/byzantium/fork.py @@ -710,14 +710,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/cancun/fork.py b/src/ethereum/forks/cancun/fork.py index ac5373fac95..c99cc0159e8 100644 --- a/src/ethereum/forks/cancun/fork.py +++ b/src/ethereum/forks/cancun/fork.py @@ -851,14 +851,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/constantinople/fork.py b/src/ethereum/forks/constantinople/fork.py index a75b6656f14..7765455cdb8 100644 --- a/src/ethereum/forks/constantinople/fork.py +++ b/src/ethereum/forks/constantinople/fork.py @@ -710,14 +710,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/dao_fork/fork.py b/src/ethereum/forks/dao_fork/fork.py index 8dae3e9f95a..4c9bed797f4 100644 --- a/src/ethereum/forks/dao_fork/fork.py +++ b/src/ethereum/forks/dao_fork/fork.py @@ -720,14 +720,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/gray_glacier/fork.py b/src/ethereum/forks/gray_glacier/fork.py index a5e2080c744..3629b729a31 100644 --- a/src/ethereum/forks/gray_glacier/fork.py +++ b/src/ethereum/forks/gray_glacier/fork.py @@ -849,14 +849,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/homestead/fork.py b/src/ethereum/forks/homestead/fork.py index 78592e2d770..f5e7eb38b5a 100644 --- a/src/ethereum/forks/homestead/fork.py +++ b/src/ethereum/forks/homestead/fork.py @@ -699,14 +699,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/london/fork.py b/src/ethereum/forks/london/fork.py index 026a6824881..622798e552e 100644 --- a/src/ethereum/forks/london/fork.py +++ b/src/ethereum/forks/london/fork.py @@ -857,14 +857,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/paris/fork.py b/src/ethereum/forks/paris/fork.py index 18be9678a70..46202fa5a8e 100644 --- a/src/ethereum/forks/paris/fork.py +++ b/src/ethereum/forks/paris/fork.py @@ -616,14 +616,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/shanghai/fork.py b/src/ethereum/forks/shanghai/fork.py index 7604389956a..804d9894155 100644 --- a/src/ethereum/forks/shanghai/fork.py +++ b/src/ethereum/forks/shanghai/fork.py @@ -651,14 +651,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/spurious_dragon/fork.py b/src/ethereum/forks/spurious_dragon/fork.py index 7c3101d25a3..7ca5fada91b 100644 --- a/src/ethereum/forks/spurious_dragon/fork.py +++ b/src/ethereum/forks/spurious_dragon/fork.py @@ -708,14 +708,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ---------- diff --git a/src/ethereum/forks/tangerine_whistle/fork.py b/src/ethereum/forks/tangerine_whistle/fork.py index 78592e2d770..f5e7eb38b5a 100644 --- a/src/ethereum/forks/tangerine_whistle/fork.py +++ b/src/ethereum/forks/tangerine_whistle/fork.py @@ -699,14 +699,14 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the - ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is - passed through as a parameter is greater than or equal to the *sum* of - the parent's gas and the adjustment delta then the limit for gas is too - high and fails this function's check. Similarly, if the limit is less - than or equal to the *difference* of the parent's gas and the adjustment - delta *or* the predefined ``LIMIT_MINIMUM`` then this function's - check fails because the gas limit doesn't allow for a sufficient or - reasonable amount of gas to be used on a block. + ``LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed + through as a parameter is greater than or equal to the *sum* of the + parent's gas and the adjustment delta then the limit for gas is too high + and fails this function's check. Similarly, if the limit is less than or + equal to the *difference* of the parent's gas and the adjustment delta *or* + the predefined ``LIMIT_MINIMUM`` then this function's check fails because + the gas limit doesn't allow for a sufficient or reasonable amount of gas to + be used on a block. Parameters ----------