Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/ethereum/forks/amsterdam/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@
TransactionTypeContractCreationError,
WrongChainIdError,
)
from .fork_types import Authorization, BlockAccessIndex, VersionedHash
from .fork_types import (
Authorization,
BlockAccessIndex,
RegularGas,
StateGas,
VersionedHash,
)
from .requests import (
BUILDER_DEPOSIT_REQUEST_TYPE,
BUILDER_EXIT_REQUEST_TYPE,
Expand Down Expand Up @@ -795,8 +801,8 @@ def process_unchecked_system_transaction(
recipient=target_address,
value=U256(0),
gas_price=block_env.base_fee_per_gas,
gas=SYSTEM_TRANSACTION_GAS,
state_gas_reservoir=(
gas=RegularGas(SYSTEM_TRANSACTION_GAS),
state_gas_reservoir=StateGas(
StateGasCosts.STORAGE_SET * SYSTEM_MAX_SSTORES_PER_CALL
),
access_list_addresses=set(),
Expand All @@ -806,17 +812,17 @@ def process_unchecked_system_transaction(
authorizations=(),
index_in_block=None,
tx_hash=None,
intrinsic_regular_gas=Uint(0),
intrinsic_state_gas=Uint(0),
intrinsic_regular_gas=RegularGas(Uint(0)),
intrinsic_state_gas=StateGas(Uint(0)),
)

system_tx_message = Message(
block_env=block_env,
tx_env=tx_env,
caller=SYSTEM_ADDRESS,
target=target_address,
gas=SYSTEM_TRANSACTION_GAS,
state_gas_reservoir=(
gas=RegularGas(SYSTEM_TRANSACTION_GAS),
state_gas_reservoir=StateGas(
StateGasCosts.STORAGE_SET * SYSTEM_MAX_SSTORES_PER_CALL
),
value=U256(0),
Expand Down Expand Up @@ -1061,8 +1067,8 @@ def process_transaction(
# budget) and state_gas_reservoir.
execution_gas = tx.gas - intrinsic_gas
regular_gas_budget = TX_MAX_GAS_LIMIT - intrinsic.regular
gas = min(regular_gas_budget, execution_gas)
state_gas_reservoir = Uint(execution_gas - gas)
gas = RegularGas(min(regular_gas_budget, execution_gas))
state_gas_reservoir = StateGas(execution_gas - gas)

increment_nonce(tx_state, sender)

Expand Down
58 changes: 34 additions & 24 deletions src/ethereum/forks/amsterdam/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from ..block_access_lists import BlockAccessList, BlockAccessListBuilder
from ..blocks import Log, Receipt, Withdrawal
from ..fork_types import Authorization, StateGas, VersionedHash
from ..fork_types import Authorization, RegularGas, StateGas, VersionedHash
from ..state_tracker import BlockState, TransactionState
from ..transactions import LegacyTransaction

Expand Down Expand Up @@ -123,17 +123,17 @@ class TransactionEnvironment:
recipient: Bytes0 | Address
value: U256
gas_price: Uint
gas: Uint
state_gas_reservoir: Uint
gas: RegularGas
state_gas_reservoir: StateGas
access_list_addresses: Set[Address]
access_list_storage_keys: Set[Tuple[Address, Bytes32]]
state: TransactionState
blob_versioned_hashes: Tuple[VersionedHash, ...]
authorizations: Tuple[Authorization, ...]
index_in_block: Optional[Uint]
tx_hash: Optional[Hash32]
intrinsic_regular_gas: Uint
intrinsic_state_gas: Uint
intrinsic_regular_gas: RegularGas
intrinsic_state_gas: StateGas


@final
Expand All @@ -148,8 +148,8 @@ class Message:
caller: Address
target: Bytes0 | Address
current_target: Address
gas: Uint
state_gas_reservoir: Uint
gas: RegularGas
state_gas_reservoir: StateGas
value: U256
data: Bytes
code_address: Optional[Address]
Expand All @@ -172,8 +172,8 @@ class Evm:
stack: List[U256]
memory: bytearray
code: Bytes
gas_left: Uint
state_gas_left: Uint
gas_left: RegularGas
state_gas_left: StateGas
valid_jump_destinations: Set[Uint]
logs: Tuple[Log, ...]
refund_counter: int
Expand All @@ -185,8 +185,8 @@ class Evm:
error: Optional[EthereumException]
accessed_addresses: Set[Address]
accessed_storage_keys: Set[Tuple[Address, Bytes32]]
regular_gas_used: Uint = Uint(0)
state_gas_spilled: Uint = Uint(0)
regular_gas_used: RegularGas = RegularGas(Uint(0))
state_gas_spilled: StateGas = StateGas(Uint(0))


def credit_state_gas_refund(evm: Evm, amount: StateGas) -> None:
Expand All @@ -206,10 +206,10 @@ def credit_state_gas_refund(evm: Evm, amount: StateGas) -> None:
The refund amount to credit.

"""
from_gas_left = min(amount, evm.state_gas_spilled)
evm.gas_left += from_gas_left
evm.state_gas_spilled -= from_gas_left
evm.state_gas_left += amount - from_gas_left
from_gas_left = StateGas(min(amount, evm.state_gas_spilled))
evm.gas_left = RegularGas(evm.gas_left + Uint(from_gas_left))
evm.state_gas_spilled = StateGas(evm.state_gas_spilled - from_gas_left)
evm.state_gas_left = StateGas(evm.state_gas_left + amount - from_gas_left)


def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None:
Expand All @@ -224,15 +224,21 @@ def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None:
The child evm to incorporate.

"""
evm.gas_left += child_evm.gas_left
evm.state_gas_left += child_evm.state_gas_left
evm.state_gas_spilled += child_evm.state_gas_spilled
evm.gas_left = RegularGas(evm.gas_left + child_evm.gas_left)
evm.state_gas_left = StateGas(
evm.state_gas_left + child_evm.state_gas_left
)
evm.state_gas_spilled = StateGas(
evm.state_gas_spilled + child_evm.state_gas_spilled
)
evm.logs += child_evm.logs
evm.refund_counter += child_evm.refund_counter
evm.accounts_to_delete.update(child_evm.accounts_to_delete)
evm.accessed_addresses.update(child_evm.accessed_addresses)
evm.accessed_storage_keys.update(child_evm.accessed_storage_keys)
evm.regular_gas_used += child_evm.regular_gas_used
evm.regular_gas_used = RegularGas(
evm.regular_gas_used + child_evm.regular_gas_used
)


def refill_frame_state_gas(evm: Evm) -> None:
Expand All @@ -249,9 +255,9 @@ def refill_frame_state_gas(evm: Evm) -> None:
The frame whose state gas is rolled back.

"""
evm.gas_left += evm.state_gas_spilled
evm.gas_left = RegularGas(evm.gas_left + Uint(evm.state_gas_spilled))
evm.state_gas_left = evm.message.state_gas_reservoir
evm.state_gas_spilled = Uint(0)
evm.state_gas_spilled = StateGas(Uint(0))


def frame_state_gas_used(evm: Evm) -> int:
Expand Down Expand Up @@ -298,9 +304,13 @@ def incorporate_child_on_error(
The child evm to incorporate.

"""
evm.gas_left += child_evm.gas_left
evm.state_gas_left += child_evm.state_gas_left
evm.regular_gas_used += child_evm.regular_gas_used
evm.gas_left = RegularGas(evm.gas_left + child_evm.gas_left)
evm.state_gas_left = StateGas(
evm.state_gas_left + child_evm.state_gas_left
)
evm.regular_gas_used = RegularGas(
evm.regular_gas_used + child_evm.regular_gas_used
)


def emit_transfer_log(
Expand Down
8 changes: 4 additions & 4 deletions src/ethereum/forks/amsterdam/vm/eoa_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ethereum.exceptions import InvalidBlock, InvalidSignatureError
from ethereum.state import Address

from ..fork_types import Authorization, StateGas
from ..fork_types import Authorization, RegularGas, StateGas
from ..state_tracker import (
account_exists,
get_account,
Expand Down Expand Up @@ -123,7 +123,7 @@ def recover_authority(authorization: Authorization) -> Address:

def calculate_delegation_cost(
evm: Evm, address: Address
) -> Tuple[bool, Address, Uint]:
) -> Tuple[bool, Address, RegularGas]:
"""
Get the delegation address and the cost of access from the address.

Expand All @@ -136,7 +136,7 @@ def calculate_delegation_cost(

Returns
-------
delegation : `Tuple[bool, Address, Uint]`
delegation : `Tuple[bool, Address, RegularGas]`
The delegation address and access gas cost.

"""
Expand All @@ -145,7 +145,7 @@ def calculate_delegation_cost(
code = get_code(tx_state, get_account(tx_state, address).code_hash)

if not is_valid_delegation(code):
return False, address, Uint(0)
return False, address, RegularGas(Uint(0))

delegated_address = Address(code[EOA_DELEGATION_MARKER_LENGTH:])

Expand Down
Loading