Skip to content

Commit 6f43bc6

Browse files
authored
Replace Uint(len(...)) with ulen(...) (#2580)
* chore(specs): replace `Uint(len(...))` with `ulen(...)` * chore(spec-tool): pevent `Uint(len(...))` with a lint
1 parent e8e9c38 commit 6f43bc6

119 files changed

Lines changed: 306 additions & 234 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ethereum/forks/amsterdam/block_access_lists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ethereum_rlp import rlp
1919
from ethereum_types.bytes import Bytes, Bytes32
2020
from ethereum_types.frozen import slotted_freezable
21-
from ethereum_types.numeric import U32, U64, U256, Uint
21+
from ethereum_types.numeric import U32, U64, U256, Uint, ulen
2222

2323
from ethereum.crypto.hash import Hash32, keccak256
2424
from ethereum.state import EMPTY_CODE_HASH, Account, Address, PreState
@@ -760,7 +760,7 @@ def validate_block_access_list_gas_limit(
760760
unique_slots.add(slot)
761761

762762
# Count each unique storage key as one item
763-
bal_items += Uint(len(unique_slots))
763+
bal_items += ulen(unique_slots)
764764

765765
if bal_items > block_gas_limit // GasCosts.BLOCK_ACCESS_LIST_ITEM:
766766
raise BlockAccessListGasLimitExceededError(

src/ethereum/forks/amsterdam/fork.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ethereum_rlp import rlp
1818
from ethereum_types.bytes import Bytes
1919
from ethereum_types.frozen import slotted_freezable
20-
from ethereum_types.numeric import U64, U256, Uint
20+
from ethereum_types.numeric import U64, U256, Uint, ulen
2121

2222
from ethereum.crypto.hash import Hash32, keccak256
2323
from ethereum.exceptions import (
@@ -850,7 +850,7 @@ def apply_body(
850850

851851
# EIP-7928: Post-execution operations use index N+1
852852
block_env.block_access_list_builder.block_access_index = BlockAccessIndex(
853-
Uint(len(transactions)) + Uint(1)
853+
ulen(transactions) + Uint(1)
854854
)
855855

856856
process_withdrawals(block_env, block_output, withdrawals)

src/ethereum/forks/amsterdam/vm/gas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dataclasses import dataclass
1515
from typing import List, Tuple
1616

17-
from ethereum_types.numeric import U64, U256, Uint
17+
from ethereum_types.numeric import U64, U256, Uint, ulen
1818

1919
from ethereum.forks.bpo5.blocks import Header as PreviousHeader
2020
from ethereum.trace import GasAndRefund, evm_trace
@@ -311,7 +311,7 @@ def calculate_gas_extend_memory(
311311
"""
312312
size_to_extend = Uint(0)
313313
to_be_paid = Uint(0)
314-
current_size = Uint(len(memory))
314+
current_size = ulen(memory)
315315
for start_position, size in extensions:
316316
if size == 0:
317317
continue

src/ethereum/forks/amsterdam/vm/precompiled_contracts/alt_bn128.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
from ethereum_types.bytes import Bytes
15-
from ethereum_types.numeric import U256, Uint
15+
from ethereum_types.numeric import U256, Uint, ulen
1616
from py_ecc.optimized_bn128.optimized_curve import (
1717
FQ,
1818
FQ2,
@@ -207,7 +207,7 @@ def alt_bn128_pairing_check(evm: Evm) -> None:
207207
# GAS
208208
charge_gas(
209209
evm,
210-
GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192)
210+
GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * (ulen(data) // Uint(192))
211211
+ GasCosts.PRECOMPILE_ECPAIRING_BASE,
212212
)
213213

src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Implementation of the `IDENTITY` precompiled contract.
1212
"""
1313

14-
from ethereum_types.numeric import Uint
14+
from ethereum_types.numeric import Uint, ulen
1515

1616
from ethereum.utils.numeric import ceil32
1717

@@ -35,7 +35,7 @@ def identity(evm: Evm) -> None:
3535
data = evm.message.data
3636

3737
# GAS
38-
word_count = ceil32(Uint(len(data))) // Uint(32)
38+
word_count = ceil32(ulen(data)) // Uint(32)
3939
charge_gas(
4040
evm,
4141
GasCosts.PRECOMPILE_IDENTITY_BASE

src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import hashlib
1515

16-
from ethereum_types.numeric import Uint
16+
from ethereum_types.numeric import Uint, ulen
1717

1818
from ethereum.utils.byte import left_pad_zero_bytes
1919
from ethereum.utils.numeric import ceil32
@@ -38,7 +38,7 @@ def ripemd160(evm: Evm) -> None:
3838
data = evm.message.data
3939

4040
# GAS
41-
word_count = ceil32(Uint(len(data))) // Uint(32)
41+
word_count = ceil32(ulen(data)) // Uint(32)
4242
charge_gas(
4343
evm,
4444
GasCosts.PRECOMPILE_RIPEMD160_BASE

src/ethereum/forks/amsterdam/vm/precompiled_contracts/sha256.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import hashlib
1515

16-
from ethereum_types.numeric import Uint
16+
from ethereum_types.numeric import Uint, ulen
1717

1818
from ethereum.utils.numeric import ceil32
1919

@@ -37,7 +37,7 @@ def sha256(evm: Evm) -> None:
3737
data = evm.message.data
3838

3939
# GAS
40-
word_count = ceil32(Uint(len(data))) // Uint(32)
40+
word_count = ceil32(ulen(data)) // Uint(32)
4141
charge_gas(
4242
evm,
4343
GasCosts.PRECOMPILE_SHA256_BASE

src/ethereum/forks/arrow_glacier/vm/gas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dataclasses import dataclass
1515
from typing import List, Tuple
1616

17-
from ethereum_types.numeric import U256, Uint
17+
from ethereum_types.numeric import U256, Uint, ulen
1818

1919
from ethereum.trace import GasAndRefund, evm_trace
2020
from ethereum.utils.numeric import ceil32
@@ -262,7 +262,7 @@ def calculate_gas_extend_memory(
262262
"""
263263
size_to_extend = Uint(0)
264264
to_be_paid = Uint(0)
265-
current_size = Uint(len(memory))
265+
current_size = ulen(memory)
266266
for start_position, size in extensions:
267267
if size == 0:
268268
continue

src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/alt_bn128.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
from ethereum_types.bytes import Bytes
15-
from ethereum_types.numeric import U256, Uint
15+
from ethereum_types.numeric import U256, Uint, ulen
1616
from py_ecc.optimized_bn128.optimized_curve import (
1717
FQ,
1818
FQ2,
@@ -207,7 +207,7 @@ def alt_bn128_pairing_check(evm: Evm) -> None:
207207
# GAS
208208
charge_gas(
209209
evm,
210-
GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * Uint(len(data) // 192)
210+
GasCosts.PRECOMPILE_ECPAIRING_PER_POINT * (ulen(data) // Uint(192))
211211
+ GasCosts.PRECOMPILE_ECPAIRING_BASE,
212212
)
213213

src/ethereum/forks/arrow_glacier/vm/precompiled_contracts/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Implementation of the `IDENTITY` precompiled contract.
1212
"""
1313

14-
from ethereum_types.numeric import Uint
14+
from ethereum_types.numeric import Uint, ulen
1515

1616
from ethereum.utils.numeric import ceil32
1717

@@ -35,7 +35,7 @@ def identity(evm: Evm) -> None:
3535
data = evm.message.data
3636

3737
# GAS
38-
word_count = ceil32(Uint(len(data))) // Uint(32)
38+
word_count = ceil32(ulen(data)) // Uint(32)
3939
charge_gas(
4040
evm,
4141
GasCosts.PRECOMPILE_IDENTITY_BASE

0 commit comments

Comments
 (0)