Skip to content

Commit

Permalink
requests as bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurukamath committed Sep 30, 2024
1 parent 0248192 commit a58ab4a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/ethereum/prague/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class Block:
transactions: Tuple[Union[Bytes, LegacyTransaction], ...]
ommers: Tuple[Header, ...]
withdrawals: Tuple[Withdrawal, ...]
requests: Tuple[Bytes, ...]


@slotted_freezable
Expand Down
11 changes: 2 additions & 9 deletions src/ethereum/prague/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def state_transition(chain: BlockChain, block: Block) -> None:
block.withdrawals,
block.header.parent_beacon_block_root,
excess_blob_gas,
block.requests,
)
if apply_body_output.block_gas_used != block.header.gas_used:
raise InvalidBlock
Expand Down Expand Up @@ -652,7 +651,6 @@ def apply_body(
withdrawals: Tuple[Withdrawal, ...],
parent_beacon_block_root: Root,
excess_blob_gas: U64,
requests: Tuple[Bytes, ...],
) -> ApplyBodyOutput:
"""
Executes a block.
Expand Down Expand Up @@ -696,8 +694,6 @@ def apply_body(
The root of the beacon block from the parent block.
excess_blob_gas :
Excess blob gas calculated from the previous block.
requests :
Requests to be processed in the current block.
Returns
-------
Expand All @@ -716,7 +712,7 @@ def apply_body(
secured=False, default=None
)
block_logs: Tuple[Log, ...] = ()
requests_from_execution: Tuple[Bytes, ...] = ()
requests_from_execution: Bytes = b""

process_system_transaction(
BEACON_ROOTS_ADDRESS,
Expand Down Expand Up @@ -861,10 +857,7 @@ def apply_body(

requests_from_execution += consolidation_requests

if requests_from_execution != requests:
raise InvalidBlock

requests_hash = keccak256(rlp.encode(requests_from_execution))
requests_hash = keccak256(requests_from_execution)

return ApplyBodyOutput(
block_gas_used,
Expand Down
23 changes: 10 additions & 13 deletions src/ethereum/prague/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[EIP-7685]: https://eips.ethereum.org/EIPS/eip-7685
"""

from typing import Tuple, Union
from typing import Union

from ..base_types import Bytes
from .blocks import Receipt, decode_receipt
Expand Down Expand Up @@ -40,59 +40,56 @@ def parse_deposit_data(data: Bytes) -> Bytes:

def parse_deposit_requests_from_receipt(
receipt: Union[Bytes, Receipt],
) -> Tuple[Bytes, ...]:
) -> Bytes:
"""
Parse deposit requests from a receipt.
"""
deposit_requests: Tuple[Bytes, ...] = ()
deposit_requests: Bytes = b""
decoded_receipt = decode_receipt(receipt)
for log in decoded_receipt.logs:
if log.address == DEPOSIT_CONTRACT_ADDRESS:
deposit_request = parse_deposit_data(log.data)
deposit_requests += (deposit_request,)
deposit_requests += parse_deposit_data(log.data)

return deposit_requests


def parse_withdrawal_requests_from_system_tx(
evm_call_output: Bytes,
) -> Tuple[Bytes, ...]:
) -> Bytes:
"""
Parse withdrawal requests from the system transaction output.
"""
count_withdrawal_requests = (
len(evm_call_output) // WITHDRAWAL_REQUEST_LENGTH
)

withdrawal_requests: Tuple[Bytes, ...] = ()
withdrawal_requests: Bytes = b""
for i in range(count_withdrawal_requests):
start = i * WITHDRAWAL_REQUEST_LENGTH
withdrawal_request = (
withdrawal_requests += (
WITHDRAWAL_REQUEST_TYPE
+ evm_call_output[start : start + WITHDRAWAL_REQUEST_LENGTH]
)
withdrawal_requests += (withdrawal_request,)

return withdrawal_requests


def parse_consolidation_requests_from_system_tx(
evm_call_output: Bytes,
) -> Tuple[Bytes, ...]:
) -> Bytes:
"""
Parse consolidation requests from the system transaction output.
"""
count_consolidation_requests = (
len(evm_call_output) // CONSOLIDATION_REQUEST_LENGTH
)

consolidation_requests: Tuple[Bytes, ...] = ()
consolidation_requests: Bytes = b""
for i in range(count_consolidation_requests):
start = i * CONSOLIDATION_REQUEST_LENGTH
consolidation_request = (
consolidation_requests += (
CONSOLIDATION_REQUEST_TYPE
+ evm_call_output[start : start + CONSOLIDATION_REQUEST_LENGTH]
)
consolidation_requests += (consolidation_request,)

return consolidation_requests
8 changes: 3 additions & 5 deletions src/ethereum_spec_tools/evm_tools/t8n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import os
from functools import partial
from typing import Any, TextIO, Tuple
from typing import Any, TextIO

from ethereum import rlp, trace
from ethereum.base_types import U64, U256, Bytes, Uint
Expand Down Expand Up @@ -308,7 +308,7 @@ def apply_body(self) -> None:
self.fork.is_after_fork("ethereum.prague")
and not self.options.state_test
):
requests_from_execution: Tuple[Bytes, ...] = ()
requests_from_execution: Bytes = b""

self.fork.process_system_transaction(
self.fork.HISTORY_STORAGE_ADDRESS,
Expand Down Expand Up @@ -501,9 +501,7 @@ def apply_body(self) -> None:
self.fork.is_after_fork("ethereum.prague")
and not self.options.state_test
):
self.result.requests_hash = keccak256(
rlp.encode(requests_from_execution)
)
self.result.requests_hash = keccak256(requests_from_execution)
self.result.requests = requests_from_execution

def run(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Result:
excess_blob_gas: Optional[U64] = None
blob_gas_used: Optional[Uint] = None
requests_hash: Optional[Hash32] = None
requests: Optional[Tuple[Bytes, ...]] = None
requests: Optional[Bytes] = None

def to_json(self) -> Any:
"""Encode the result to JSON"""
Expand Down
4 changes: 0 additions & 4 deletions tests/prague/test_rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@

withdrawal = Withdrawal(U64(0), U64(1), address1, U256(2))

requests = (Bytes(b"01foo"), Bytes(b"01bar"))


header = Header(
parent_hash=hash1,
ommers_hash=hash2,
Expand Down Expand Up @@ -119,7 +116,6 @@
),
ommers=(),
withdrawals=(withdrawal,),
requests=requests,
)

log1 = Log(
Expand Down

0 comments on commit a58ab4a

Please sign in to comment.