diff --git a/src/ethereum/forks/amsterdam/blocks.py b/src/ethereum/forks/amsterdam/blocks.py index 57b0e2c2874..73747e8f5a3 100644 --- a/src/ethereum/forks/amsterdam/blocks.py +++ b/src/ethereum/forks/amsterdam/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/amsterdam/fork.py b/src/ethereum/forks/amsterdam/fork.py index fc66f86744d..9c29bacb445 100644 --- a/src/ethereum/forks/amsterdam/fork.py +++ b/src/ethereum/forks/amsterdam/fork.py @@ -1177,7 +1177,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * GWEI_TO_WEI) + create_ether(wd_state, wd.address, U256(wd.amount) * GWEI_TO_WEI) incorporate_tx_into_block(wd_state, block_env.block_access_list_builder) diff --git a/src/ethereum/forks/bpo1/blocks.py b/src/ethereum/forks/bpo1/blocks.py index cd4b2daca34..ffa2ee2800c 100644 --- a/src/ethereum/forks/bpo1/blocks.py +++ b/src/ethereum/forks/bpo1/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/bpo1/fork.py b/src/ethereum/forks/bpo1/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/bpo1/fork.py +++ b/src/ethereum/forks/bpo1/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/bpo2/blocks.py b/src/ethereum/forks/bpo2/blocks.py index 209862680f1..0add3170642 100644 --- a/src/ethereum/forks/bpo2/blocks.py +++ b/src/ethereum/forks/bpo2/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/bpo2/fork.py b/src/ethereum/forks/bpo2/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/bpo2/fork.py +++ b/src/ethereum/forks/bpo2/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/bpo3/blocks.py b/src/ethereum/forks/bpo3/blocks.py index df26affccfb..f043477c0d1 100644 --- a/src/ethereum/forks/bpo3/blocks.py +++ b/src/ethereum/forks/bpo3/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/bpo3/fork.py b/src/ethereum/forks/bpo3/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/bpo3/fork.py +++ b/src/ethereum/forks/bpo3/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/bpo4/blocks.py b/src/ethereum/forks/bpo4/blocks.py index 5fcadec15d9..e8d73c70977 100644 --- a/src/ethereum/forks/bpo4/blocks.py +++ b/src/ethereum/forks/bpo4/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/bpo4/fork.py b/src/ethereum/forks/bpo4/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/bpo4/fork.py +++ b/src/ethereum/forks/bpo4/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/bpo5/blocks.py b/src/ethereum/forks/bpo5/blocks.py index eed86b7e175..6437d0e8c29 100644 --- a/src/ethereum/forks/bpo5/blocks.py +++ b/src/ethereum/forks/bpo5/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/bpo5/fork.py b/src/ethereum/forks/bpo5/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/bpo5/fork.py +++ b/src/ethereum/forks/bpo5/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/cancun/blocks.py b/src/ethereum/forks/cancun/blocks.py index 3507f8a3284..a9badf0daba 100644 --- a/src/ethereum/forks/cancun/blocks.py +++ b/src/ethereum/forks/cancun/blocks.py @@ -58,9 +58,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/cancun/fork.py b/src/ethereum/forks/cancun/fork.py index 67e3b0197d0..319fd225312 100644 --- a/src/ethereum/forks/cancun/fork.py +++ b/src/ethereum/forks/cancun/fork.py @@ -826,7 +826,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/osaka/blocks.py b/src/ethereum/forks/osaka/blocks.py index f1f174f892a..9ccaafe71ea 100644 --- a/src/ethereum/forks/osaka/blocks.py +++ b/src/ethereum/forks/osaka/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/osaka/fork.py b/src/ethereum/forks/osaka/fork.py index c2c43c631dc..fb388c3b9b3 100644 --- a/src/ethereum/forks/osaka/fork.py +++ b/src/ethereum/forks/osaka/fork.py @@ -1008,7 +1008,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/prague/blocks.py b/src/ethereum/forks/prague/blocks.py index e34b1dc4e6f..f437ff74782 100644 --- a/src/ethereum/forks/prague/blocks.py +++ b/src/ethereum/forks/prague/blocks.py @@ -59,9 +59,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/prague/fork.py b/src/ethereum/forks/prague/fork.py index f5c4f81a6f8..2806fdb99c1 100644 --- a/src/ethereum/forks/prague/fork.py +++ b/src/ethereum/forks/prague/fork.py @@ -991,7 +991,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum/forks/shanghai/blocks.py b/src/ethereum/forks/shanghai/blocks.py index 04990ab04ff..37c0ec5a52c 100644 --- a/src/ethereum/forks/shanghai/blocks.py +++ b/src/ethereum/forks/shanghai/blocks.py @@ -57,9 +57,9 @@ class Withdrawal: The execution-layer address receiving the withdrawn ETH. """ - amount: U256 + amount: U64 """ - The amount of ETH being withdrawn. + The amount of ETH being withdrawn, in Gwei. """ diff --git a/src/ethereum/forks/shanghai/fork.py b/src/ethereum/forks/shanghai/fork.py index c038d947014..ecbec7591da 100644 --- a/src/ethereum/forks/shanghai/fork.py +++ b/src/ethereum/forks/shanghai/fork.py @@ -662,7 +662,7 @@ def process_withdrawals( rlp.encode(wd), ) - create_ether(wd_state, wd.address, wd.amount * U256(10**9)) + create_ether(wd_state, wd.address, U256(wd.amount) * U256(10**9)) incorporate_tx_into_block(wd_state) diff --git a/src/ethereum_spec_tools/evm_tools/b11r/b11r_types.py b/src/ethereum_spec_tools/evm_tools/b11r/b11r_types.py index f15a1ce5473..4cc7be9bdc4 100644 --- a/src/ethereum_spec_tools/evm_tools/b11r/b11r_types.py +++ b/src/ethereum_spec_tools/evm_tools/b11r/b11r_types.py @@ -27,7 +27,7 @@ class Body: transactions: rlp.Extended ommers: rlp.Extended - withdrawals: Optional[List[Tuple[U64, U64, Bytes20, Uint]]] + withdrawals: Optional[List[Tuple[U64, U64, Bytes20, U64]]] def __init__(self, options: Any, stdin: Any = None): # Parse transactions @@ -83,7 +83,7 @@ def __init__(self, options: Any, stdin: Any = None): parse_hex_or_int(wd["index"], U64), parse_hex_or_int(wd["validatorIndex"], U64), Bytes20(hex_to_bytes(wd["address"])), - parse_hex_or_int(wd["amount"], Uint), + parse_hex_or_int(wd["amount"], U64), ) ) diff --git a/src/ethereum_spec_tools/evm_tools/loaders/fixture_loader.py b/src/ethereum_spec_tools/evm_tools/loaders/fixture_loader.py index 3a93f850fbd..7eae0ee4d0d 100644 --- a/src/ethereum_spec_tools/evm_tools/loaders/fixture_loader.py +++ b/src/ethereum_spec_tools/evm_tools/loaders/fixture_loader.py @@ -96,7 +96,7 @@ def json_to_withdrawals(self, raw: Any) -> Any: hex_to_u64(raw.get("index")), hex_to_u64(raw.get("validatorIndex")), self.fork.hex_to_address(raw.get("address")), - hex_to_u256(raw.get("amount")), + hex_to_u64(raw.get("amount")), ] return self.fork.Withdrawal(*parameters) diff --git a/src/ethereum_spec_tools/sync.py b/src/ethereum_spec_tools/sync.py index cb72a9ef603..4969cd725db 100644 --- a/src/ethereum_spec_tools/sync.py +++ b/src/ethereum_spec_tools/sync.py @@ -616,7 +616,7 @@ def make_block(self, json: Any, ommers: Any) -> Any: self.module("utils.hexadecimal").hex_to_address( j["address"] ), - hex_to_u256(j["amount"]), + hex_to_u64(j["amount"]), ) ) diff --git a/tests/json_loader/test_withdrawal_codec.py b/tests/json_loader/test_withdrawal_codec.py new file mode 100644 index 00000000000..7818c9147a4 --- /dev/null +++ b/tests/json_loader/test_withdrawal_codec.py @@ -0,0 +1,28 @@ +"""Test that withdrawal amounts decode as 64-bit unsigned integers.""" + +import pytest +from ethereum_rlp import rlp +from ethereum_rlp.exceptions import RLPException +from ethereum_types.numeric import U64, U256 + +from ethereum.forks.amsterdam.blocks import Withdrawal +from ethereum.state import Address + + +def test_decode_max_withdrawal_amount() -> None: + """Round-trip a withdrawal with the largest valid amount.""" + withdrawal = Withdrawal( + index=U64(0), + validator_index=U64(0), + address=Address(b"\x00" * 20), + amount=U64(2**64 - 1), + ) + encoded = rlp.encode(withdrawal) + assert rlp.decode_to(Withdrawal, encoded) == withdrawal + + +def test_decode_oversized_withdrawal_amount() -> None: + """Reject a withdrawal whose amount does not fit in 64 bits.""" + encoded = rlp.encode((U64(0), U64(0), Address(b"\x00" * 20), U256(2**64))) + with pytest.raises(RLPException): + rlp.decode_to(Withdrawal, encoded)