diff --git a/src/ethereum/forks/amsterdam/block_access_lists.py b/src/ethereum/forks/amsterdam/block_access_lists.py index c6bcf176886..9e94bcddb80 100644 --- a/src/ethereum/forks/amsterdam/block_access_lists.py +++ b/src/ethereum/forks/amsterdam/block_access_lists.py @@ -18,7 +18,7 @@ from ethereum_rlp import rlp from ethereum_types.bytes import Bytes, Bytes32 from ethereum_types.frozen import slotted_freezable -from ethereum_types.numeric import U16, U64, U256, Uint +from ethereum_types.numeric import U16, U64, U256, Uint, ulen from ethereum.crypto.hash import Hash32, keccak256 from ethereum.state import EMPTY_CODE_HASH, Account, Address, PreState @@ -760,7 +760,7 @@ def validate_block_access_list_gas_limit( unique_slots.add(slot) # Count each unique storage key as one item - bal_items += Uint(len(unique_slots)) + bal_items += ulen(unique_slots) if bal_items > block_gas_limit // GAS_BLOCK_ACCESS_LIST_ITEM: raise BlockAccessListGasLimitExceededError( diff --git a/src/ethereum/forks/amsterdam/fork.py b/src/ethereum/forks/amsterdam/fork.py index c0bd9d5f745..8b3fd5f8f75 100644 --- a/src/ethereum/forks/amsterdam/fork.py +++ b/src/ethereum/forks/amsterdam/fork.py @@ -17,7 +17,7 @@ from ethereum_rlp import rlp from ethereum_types.bytes import Bytes from ethereum_types.frozen import slotted_freezable -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.crypto.hash import Hash32, keccak256 from ethereum.exceptions import ( @@ -854,7 +854,7 @@ def apply_body( # EIP-7928: Post-execution operations use index N+1 block_env.block_access_list_builder.block_access_index = BlockAccessIndex( - Uint(len(transactions)) + Uint(1) + ulen(transactions) + Uint(1) ) process_withdrawals(block_env, block_output, withdrawals) diff --git a/src/ethereum/forks/amsterdam/vm/gas.py b/src/ethereum/forks/amsterdam/vm/gas.py index 6807cba420b..0defcc35ad9 100644 --- a/src/ethereum/forks/amsterdam/vm/gas.py +++ b/src/ethereum/forks/amsterdam/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.forks.bpo5.blocks import Header as PreviousHeader from ethereum.trace import GasAndRefund, evm_trace @@ -206,7 +206,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/amsterdam/vm/interpreter.py b/src/ethereum/forks/amsterdam/vm/interpreter.py index c22f9eef143..cc0943c53f2 100644 --- a/src/ethereum/forks/amsterdam/vm/interpreter.py +++ b/src/ethereum/forks/amsterdam/vm/interpreter.py @@ -200,9 +200,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/arrow_glacier/vm/gas.py b/src/ethereum/forks/arrow_glacier/vm/gas.py index 7ac4146d8cf..6b7c5095980 100644 --- a/src/ethereum/forks/arrow_glacier/vm/gas.py +++ b/src/ethereum/forks/arrow_glacier/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -165,7 +165,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/arrow_glacier/vm/interpreter.py b/src/ethereum/forks/arrow_glacier/vm/interpreter.py index 20d8c31f1e3..2fb24e953a2 100644 --- a/src/ethereum/forks/arrow_glacier/vm/interpreter.py +++ b/src/ethereum/forks/arrow_glacier/vm/interpreter.py @@ -178,9 +178,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: 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..c4237b334ee 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/berlin/vm/gas.py b/src/ethereum/forks/berlin/vm/gas.py index 80441f0e4fd..c880fa98462 100644 --- a/src/ethereum/forks/berlin/vm/gas.py +++ b/src/ethereum/forks/berlin/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -166,7 +166,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/berlin/vm/interpreter.py b/src/ethereum/forks/berlin/vm/interpreter.py index 6edd4cae8ca..f3dbdcf33a2 100644 --- a/src/ethereum/forks/berlin/vm/interpreter.py +++ b/src/ethereum/forks/berlin/vm/interpreter.py @@ -177,9 +177,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/berlin/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/bpo1/vm/gas.py b/src/ethereum/forks/bpo1/vm/gas.py index 51b439cd0a0..1bce7073db6 100644 --- a/src/ethereum/forks/bpo1/vm/gas.py +++ b/src/ethereum/forks/bpo1/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/bpo1/vm/interpreter.py b/src/ethereum/forks/bpo1/vm/interpreter.py index 9c05883b7dc..ae92fc37177 100644 --- a/src/ethereum/forks/bpo1/vm/interpreter.py +++ b/src/ethereum/forks/bpo1/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo1/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/bpo2/vm/gas.py b/src/ethereum/forks/bpo2/vm/gas.py index 5c30cd6a340..c3c09576733 100644 --- a/src/ethereum/forks/bpo2/vm/gas.py +++ b/src/ethereum/forks/bpo2/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/bpo2/vm/interpreter.py b/src/ethereum/forks/bpo2/vm/interpreter.py index a7b27243123..cd40feae801 100644 --- a/src/ethereum/forks/bpo2/vm/interpreter.py +++ b/src/ethereum/forks/bpo2/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo2/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/bpo3/vm/gas.py b/src/ethereum/forks/bpo3/vm/gas.py index 5c30cd6a340..c3c09576733 100644 --- a/src/ethereum/forks/bpo3/vm/gas.py +++ b/src/ethereum/forks/bpo3/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/bpo3/vm/interpreter.py b/src/ethereum/forks/bpo3/vm/interpreter.py index 4111d5b4c78..db829ff4739 100644 --- a/src/ethereum/forks/bpo3/vm/interpreter.py +++ b/src/ethereum/forks/bpo3/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo3/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/bpo4/vm/gas.py b/src/ethereum/forks/bpo4/vm/gas.py index 5c30cd6a340..c3c09576733 100644 --- a/src/ethereum/forks/bpo4/vm/gas.py +++ b/src/ethereum/forks/bpo4/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/bpo4/vm/interpreter.py b/src/ethereum/forks/bpo4/vm/interpreter.py index 7e789cf4b69..3e674772d35 100644 --- a/src/ethereum/forks/bpo4/vm/interpreter.py +++ b/src/ethereum/forks/bpo4/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo4/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/bpo5/vm/gas.py b/src/ethereum/forks/bpo5/vm/gas.py index 5c30cd6a340..c3c09576733 100644 --- a/src/ethereum/forks/bpo5/vm/gas.py +++ b/src/ethereum/forks/bpo5/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/bpo5/vm/interpreter.py b/src/ethereum/forks/bpo5/vm/interpreter.py index d0eda4ef22d..98109d59bb5 100644 --- a/src/ethereum/forks/bpo5/vm/interpreter.py +++ b/src/ethereum/forks/bpo5/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/bpo5/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/byzantium/vm/gas.py b/src/ethereum/forks/byzantium/vm/gas.py index c4aa9846029..30f267d94bc 100644 --- a/src/ethereum/forks/byzantium/vm/gas.py +++ b/src/ethereum/forks/byzantium/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -165,7 +165,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/byzantium/vm/interpreter.py b/src/ethereum/forks/byzantium/vm/interpreter.py index 2cb1ccc3335..f6f8778dd6a 100644 --- a/src/ethereum/forks/byzantium/vm/interpreter.py +++ b/src/ethereum/forks/byzantium/vm/interpreter.py @@ -173,9 +173,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/byzantium/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/cancun/vm/gas.py b/src/ethereum/forks/cancun/vm/gas.py index 0523287c6cf..2659716007f 100644 --- a/src/ethereum/forks/cancun/vm/gas.py +++ b/src/ethereum/forks/cancun/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -175,7 +175,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/cancun/vm/interpreter.py b/src/ethereum/forks/cancun/vm/interpreter.py index 7f4bed0129c..b0d38b11f62 100644 --- a/src/ethereum/forks/cancun/vm/interpreter.py +++ b/src/ethereum/forks/cancun/vm/interpreter.py @@ -170,9 +170,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/cancun/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/constantinople/vm/gas.py b/src/ethereum/forks/constantinople/vm/gas.py index f59699f0347..b236df5c1f8 100644 --- a/src/ethereum/forks/constantinople/vm/gas.py +++ b/src/ethereum/forks/constantinople/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -166,7 +166,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/constantinople/vm/interpreter.py b/src/ethereum/forks/constantinople/vm/interpreter.py index b26937492a9..ddf9a84020a 100644 --- a/src/ethereum/forks/constantinople/vm/interpreter.py +++ b/src/ethereum/forks/constantinople/vm/interpreter.py @@ -173,9 +173,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/constantinople/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/dao_fork/vm/gas.py b/src/ethereum/forks/dao_fork/vm/gas.py index fc01397ceb0..25829ecbaa9 100644 --- a/src/ethereum/forks/dao_fork/vm/gas.py +++ b/src/ethereum/forks/dao_fork/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.state import Address from ethereum.trace import GasAndRefund, evm_trace @@ -164,7 +164,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/dao_fork/vm/interpreter.py b/src/ethereum/forks/dao_fork/vm/interpreter.py index 4d26439da49..6ed2329e370 100644 --- a/src/ethereum/forks/dao_fork/vm/interpreter.py +++ b/src/ethereum/forks/dao_fork/vm/interpreter.py @@ -157,9 +157,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) except ExceptionalHalt as error: 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..c4237b334ee 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/dao_fork/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/frontier/vm/gas.py b/src/ethereum/forks/frontier/vm/gas.py index fc01397ceb0..25829ecbaa9 100644 --- a/src/ethereum/forks/frontier/vm/gas.py +++ b/src/ethereum/forks/frontier/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.state import Address from ethereum.trace import GasAndRefund, evm_trace @@ -164,7 +164,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/frontier/vm/interpreter.py b/src/ethereum/forks/frontier/vm/interpreter.py index 842207405fa..22b92b9419b 100644 --- a/src/ethereum/forks/frontier/vm/interpreter.py +++ b/src/ethereum/forks/frontier/vm/interpreter.py @@ -157,9 +157,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) except ExceptionalHalt: diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/frontier/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/gray_glacier/vm/gas.py b/src/ethereum/forks/gray_glacier/vm/gas.py index 7ac4146d8cf..6b7c5095980 100644 --- a/src/ethereum/forks/gray_glacier/vm/gas.py +++ b/src/ethereum/forks/gray_glacier/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -165,7 +165,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/gray_glacier/vm/interpreter.py b/src/ethereum/forks/gray_glacier/vm/interpreter.py index 1135be95939..9cfe90e32a7 100644 --- a/src/ethereum/forks/gray_glacier/vm/interpreter.py +++ b/src/ethereum/forks/gray_glacier/vm/interpreter.py @@ -178,9 +178,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: 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..c4237b334ee 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/gray_glacier/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/homestead/vm/gas.py b/src/ethereum/forks/homestead/vm/gas.py index fc01397ceb0..25829ecbaa9 100644 --- a/src/ethereum/forks/homestead/vm/gas.py +++ b/src/ethereum/forks/homestead/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.state import Address from ethereum.trace import GasAndRefund, evm_trace @@ -164,7 +164,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/homestead/vm/interpreter.py b/src/ethereum/forks/homestead/vm/interpreter.py index 47530fcf783..32f2d9249a6 100644 --- a/src/ethereum/forks/homestead/vm/interpreter.py +++ b/src/ethereum/forks/homestead/vm/interpreter.py @@ -157,9 +157,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) except ExceptionalHalt as error: diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/homestead/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/istanbul/vm/gas.py b/src/ethereum/forks/istanbul/vm/gas.py index 8425495cd13..6681ce1c176 100644 --- a/src/ethereum/forks/istanbul/vm/gas.py +++ b/src/ethereum/forks/istanbul/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -168,7 +168,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/istanbul/vm/interpreter.py b/src/ethereum/forks/istanbul/vm/interpreter.py index 7a92f7471f3..83d399d94a4 100644 --- a/src/ethereum/forks/istanbul/vm/interpreter.py +++ b/src/ethereum/forks/istanbul/vm/interpreter.py @@ -177,9 +177,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/istanbul/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/london/vm/gas.py b/src/ethereum/forks/london/vm/gas.py index 7ac4146d8cf..6b7c5095980 100644 --- a/src/ethereum/forks/london/vm/gas.py +++ b/src/ethereum/forks/london/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -165,7 +165,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/london/vm/interpreter.py b/src/ethereum/forks/london/vm/interpreter.py index b49ca7be07f..7bedacf403c 100644 --- a/src/ethereum/forks/london/vm/interpreter.py +++ b/src/ethereum/forks/london/vm/interpreter.py @@ -178,9 +178,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/london/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/muir_glacier/vm/gas.py b/src/ethereum/forks/muir_glacier/vm/gas.py index 8425495cd13..6681ce1c176 100644 --- a/src/ethereum/forks/muir_glacier/vm/gas.py +++ b/src/ethereum/forks/muir_glacier/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -168,7 +168,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/muir_glacier/vm/interpreter.py b/src/ethereum/forks/muir_glacier/vm/interpreter.py index e4f53153ce9..24979913f41 100644 --- a/src/ethereum/forks/muir_glacier/vm/interpreter.py +++ b/src/ethereum/forks/muir_glacier/vm/interpreter.py @@ -177,9 +177,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: 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..c4237b334ee 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/muir_glacier/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/osaka/vm/gas.py b/src/ethereum/forks/osaka/vm/gas.py index 99ccfb48145..3d3313973ec 100644 --- a/src/ethereum/forks/osaka/vm/gas.py +++ b/src/ethereum/forks/osaka/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -186,7 +186,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/osaka/vm/interpreter.py b/src/ethereum/forks/osaka/vm/interpreter.py index bdbf6520cc7..dec92501dcc 100644 --- a/src/ethereum/forks/osaka/vm/interpreter.py +++ b/src/ethereum/forks/osaka/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/osaka/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/paris/vm/gas.py b/src/ethereum/forks/paris/vm/gas.py index 7ac4146d8cf..6b7c5095980 100644 --- a/src/ethereum/forks/paris/vm/gas.py +++ b/src/ethereum/forks/paris/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -165,7 +165,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/paris/vm/interpreter.py b/src/ethereum/forks/paris/vm/interpreter.py index 92af867690a..04351ed876f 100644 --- a/src/ethereum/forks/paris/vm/interpreter.py +++ b/src/ethereum/forks/paris/vm/interpreter.py @@ -166,9 +166,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/paris/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/prague/vm/gas.py b/src/ethereum/forks/prague/vm/gas.py index 121292173ef..c6e70dabeb6 100644 --- a/src/ethereum/forks/prague/vm/gas.py +++ b/src/ethereum/forks/prague/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U64, U256, Uint +from ethereum_types.numeric import U64, U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32, taylor_exponential @@ -182,7 +182,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/prague/vm/interpreter.py b/src/ethereum/forks/prague/vm/interpreter.py index 290f2831710..dc6c2082a4f 100644 --- a/src/ethereum/forks/prague/vm/interpreter.py +++ b/src/ethereum/forks/prague/vm/interpreter.py @@ -190,9 +190,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/prague/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/shanghai/vm/gas.py b/src/ethereum/forks/shanghai/vm/gas.py index 44d049d552f..74de755b9b7 100644 --- a/src/ethereum/forks/shanghai/vm/gas.py +++ b/src/ethereum/forks/shanghai/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -166,7 +166,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/shanghai/vm/interpreter.py b/src/ethereum/forks/shanghai/vm/interpreter.py index 6485ebe11f2..b7814e4841f 100644 --- a/src/ethereum/forks/shanghai/vm/interpreter.py +++ b/src/ethereum/forks/shanghai/vm/interpreter.py @@ -167,9 +167,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: if len(contract_code) > 0: if contract_code[0] == 0xEF: diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py index 133a4832bf8..c4237b334ee 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py index d4e28adf0ad..ab5956d1374 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE diff --git a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py index 04dfef6730d..b70400ba9e5 100644 --- a/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/shanghai/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/spurious_dragon/vm/gas.py b/src/ethereum/forks/spurious_dragon/vm/gas.py index 937e953a145..8266b9c8b8a 100644 --- a/src/ethereum/forks/spurious_dragon/vm/gas.py +++ b/src/ethereum/forks/spurious_dragon/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -164,7 +164,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/spurious_dragon/vm/interpreter.py b/src/ethereum/forks/spurious_dragon/vm/interpreter.py index e65ffc2020a..dd1cbb6c0cd 100644 --- a/src/ethereum/forks/spurious_dragon/vm/interpreter.py +++ b/src/ethereum/forks/spurious_dragon/vm/interpreter.py @@ -172,9 +172,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) if len(contract_code) > MAX_CODE_SIZE: 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..c4237b334ee 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/spurious_dragon/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum/forks/tangerine_whistle/vm/gas.py b/src/ethereum/forks/tangerine_whistle/vm/gas.py index 56a9451c117..7f8bb7a18b4 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/gas.py +++ b/src/ethereum/forks/tangerine_whistle/vm/gas.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from typing import List, Tuple -from ethereum_types.numeric import U256, Uint +from ethereum_types.numeric import U256, Uint, ulen from ethereum.trace import GasAndRefund, evm_trace from ethereum.utils.numeric import ceil32 @@ -164,7 +164,7 @@ def calculate_gas_extend_memory( """ size_to_extend = Uint(0) to_be_paid = Uint(0) - current_size = Uint(len(memory)) + current_size = ulen(memory) for start_position, size in extensions: if size == 0: continue diff --git a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py index e6e7c7729c4..357f2376516 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/interpreter.py +++ b/src/ethereum/forks/tangerine_whistle/vm/interpreter.py @@ -157,9 +157,7 @@ def process_create_message(message: Message) -> Evm: evm = process_message(message) if not evm.error: contract_code = evm.output - contract_code_gas = ( - Uint(len(contract_code)) * GAS_CODE_DEPOSIT_PER_BYTE - ) + contract_code_gas = ulen(contract_code) * GAS_CODE_DEPOSIT_PER_BYTE try: charge_gas(evm, contract_code_gas) except ExceptionalHalt as error: 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..c4237b334ee 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/identity.py @@ -11,7 +11,7 @@ Implementation of the `IDENTITY` precompiled contract. """ -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -36,7 +36,7 @@ def identity(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_IDENTITY_BASE 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..ab5956d1374 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/ripemd160.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.byte import left_pad_zero_bytes from ethereum.utils.numeric import ceil32 @@ -39,7 +39,7 @@ def ripemd160(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_RIPEMD160_BASE 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..b70400ba9e5 100644 --- a/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py +++ b/src/ethereum/forks/tangerine_whistle/vm/precompiled_contracts/sha256.py @@ -13,7 +13,7 @@ import hashlib -from ethereum_types.numeric import Uint +from ethereum_types.numeric import Uint, ulen from ethereum.utils.numeric import ceil32 @@ -38,7 +38,7 @@ def sha256(evm: Evm) -> None: data = evm.message.data # GAS - word_count = ceil32(Uint(len(data))) // Uint(32) + word_count = ceil32(ulen(data)) // Uint(32) charge_gas( evm, GAS_PRECOMPILE_SHA256_BASE diff --git a/src/ethereum_spec_tools/lint/lints/uint_len.py b/src/ethereum_spec_tools/lint/lints/uint_len.py new file mode 100644 index 00000000000..91d61581559 --- /dev/null +++ b/src/ethereum_spec_tools/lint/lints/uint_len.py @@ -0,0 +1,68 @@ +""" +Uint(len(...)) Lint. + +Ensures that `Uint(len(...))` is replaced with `ulen(...)`. +""" + +import ast +from typing import List, Sequence + +from ethereum_spec_tools.forks import Hardfork +from ethereum_spec_tools.lint import Diagnostic, Lint, walk_sources + + +class UintLenHygiene(Lint): + """ + Ensure `ulen(...)` is used instead of `Uint(len(...))`. + """ + + def lint( + self, forks: List[Hardfork], position: int + ) -> Sequence[Diagnostic]: + """ + Walk the sources for each hardfork and emit Diagnostic messages. + """ + fork = forks[position] + diagnostics: List[Diagnostic] = [] + + for name, source in walk_sources(fork): + visitor = self._parse(source, _Visitor()) + for lineno in visitor.violations: + diagnostics.append( + Diagnostic( + message=( + f"`Uint(len(...))` at line {lineno} in" + f" `{name}` should be `ulen(...)`" + ) + ) + ) + + return diagnostics + + +class _Visitor(ast.NodeVisitor): + """ + Visit call nodes and detect `Uint(len(...))` patterns. + """ + + violations: List[int] + + def __init__(self) -> None: + self.violations = [] + + def visit_Call(self, node: ast.Call) -> None: + """ + Visit a Call node. + """ + if ( + isinstance(node.func, ast.Name) + and node.func.id == "Uint" + and len(node.args) == 1 + and not node.keywords + and isinstance(node.args[0], ast.Call) + and isinstance(node.args[0].func, ast.Name) + and node.args[0].func.id == "len" + ): + self.violations.append(node.lineno) + + self.generic_visit(node)