Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-7623 #966

Open
wants to merge 17 commits into
base: forks/prague
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Run Tox (CPython)
if: "${{ !startsWith(matrix.py, 'pypy') }}"
run: tox -e static,optimized,py3
run: tox -e static,py3

- name: Run Tox (PyPy)
if: "${{ startsWith(matrix.py, 'pypy') }}"
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ packages =
ethereum/cancun/vm
ethereum/cancun/vm/instructions
ethereum/cancun/vm/precompiled_contracts
ethereum/prague
ethereum/prague/utils
ethereum/prague/vm
ethereum/prague/vm/instructions
ethereum/prague/vm/precompiled_contracts


package_dir =
Expand Down
11 changes: 11 additions & 0 deletions src/ethereum/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,17 @@ class Bytes64(FixedBytes):
"""


class Bytes96(FixedBytes):
"""
Byte array of exactly 96 elements.
"""

LENGTH = 96
"""
Number of bytes in each instance of this class.
"""


class Bytes256(FixedBytes):
"""
Byte array of exactly 256 elements.
Expand Down
159 changes: 114 additions & 45 deletions src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
calculate_total_blob_gas,
init_code_cost,
)
from .vm.interpreter import MAX_CODE_SIZE, process_message_call
from .vm.interpreter import (
MAX_CODE_SIZE,
MessageCallOutput,
process_message_call,
)

BASE_FEE_MAX_CHANGE_DENOMINATOR = 8
ELASTICITY_MULTIPLIER = 2
Expand Down Expand Up @@ -502,6 +506,102 @@ class ApplyBodyOutput:
blob_gas_used: Uint


def process_system_transaction(
target_address: Address,
data: Bytes,
block_hashes: List[Hash32],
coinbase: Address,
block_number: Uint,
base_fee_per_gas: Uint,
block_gas_limit: Uint,
block_time: U256,
prev_randao: Bytes32,
state: State,
chain_id: U64,
excess_blob_gas: U64,
) -> MessageCallOutput:
"""
Process a system transaction.

Parameters
----------
target_address :
Address of the contract to call.
data :
Data to pass to the contract.
block_hashes :
List of hashes of the previous blocks.
coinbase :
Address of the block's coinbase.
block_number :
Block number.
base_fee_per_gas :
Base fee per gas.
block_gas_limit :
Gas limit of the block.
block_time :
Time the block was produced.
prev_randao :
Previous randao value.
state :
Current state.
chain_id :
ID of the chain.
excess_blob_gas :
Excess blob gas.

Returns
-------
system_tx_output : `MessageCallOutput`
Output of processing the system transaction.
"""
system_contract_code = get_account(state, target_address).code

system_tx_message = Message(
caller=SYSTEM_ADDRESS,
target=target_address,
gas=SYSTEM_TRANSACTION_GAS,
value=U256(0),
data=data,
code=system_contract_code,
depth=Uint(0),
current_target=target_address,
code_address=target_address,
should_transfer_value=False,
is_static=False,
accessed_addresses=set(),
accessed_storage_keys=set(),
parent_evm=None,
)

system_tx_env = vm.Environment(
caller=SYSTEM_ADDRESS,
origin=SYSTEM_ADDRESS,
block_hashes=block_hashes,
coinbase=coinbase,
number=block_number,
gas_limit=block_gas_limit,
base_fee_per_gas=base_fee_per_gas,
gas_price=base_fee_per_gas,
time=block_time,
prev_randao=prev_randao,
state=state,
chain_id=chain_id,
traces=[],
excess_blob_gas=excess_blob_gas,
blob_versioned_hashes=(),
transient_storage=TransientStorage(),
)

system_tx_output = process_message_call(system_tx_message, system_tx_env)

destroy_touched_empty_accounts(
system_tx_env.state, system_tx_output.touched_accounts
)

return system_tx_output


def apply_body(
state: State,
block_hashes: List[Hash32],
Expand Down Expand Up @@ -578,50 +678,19 @@ def apply_body(
)
block_logs: Tuple[Log, ...] = ()

beacon_block_roots_contract_code = get_account(
state, BEACON_ROOTS_ADDRESS
).code

system_tx_message = Message(
caller=SYSTEM_ADDRESS,
target=BEACON_ROOTS_ADDRESS,
gas=SYSTEM_TRANSACTION_GAS,
value=U256(0),
data=parent_beacon_block_root,
code=beacon_block_roots_contract_code,
depth=Uint(0),
current_target=BEACON_ROOTS_ADDRESS,
code_address=BEACON_ROOTS_ADDRESS,
should_transfer_value=False,
is_static=False,
accessed_addresses=set(),
accessed_storage_keys=set(),
parent_evm=None,
)

system_tx_env = vm.Environment(
caller=SYSTEM_ADDRESS,
origin=SYSTEM_ADDRESS,
block_hashes=block_hashes,
coinbase=coinbase,
number=block_number,
gas_limit=block_gas_limit,
base_fee_per_gas=base_fee_per_gas,
gas_price=base_fee_per_gas,
time=block_time,
prev_randao=prev_randao,
state=state,
chain_id=chain_id,
traces=[],
excess_blob_gas=excess_blob_gas,
blob_versioned_hashes=(),
transient_storage=TransientStorage(),
)

system_tx_output = process_message_call(system_tx_message, system_tx_env)

destroy_touched_empty_accounts(
system_tx_env.state, system_tx_output.touched_accounts
process_system_transaction(
BEACON_ROOTS_ADDRESS,
parent_beacon_block_root,
block_hashes,
coinbase,
block_number,
base_fee_per_gas,
block_gas_limit,
block_time,
prev_randao,
state,
chain_id,
excess_blob_gas,
)

for i, tx in enumerate(map(decode_transaction, transactions)):
Expand Down
7 changes: 7 additions & 0 deletions src/ethereum/prague/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
The Prague fork.
"""

from ethereum.fork_criteria import Unscheduled

FORK_CRITERIA = Unscheduled()
Loading