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

Refactor the Environment dataclass #1053

Draft
wants to merge 77 commits into
base: forks/prague
Choose a base branch
from

Conversation

gurukamath
Copy link
Collaborator

What was wrong?

The Environment data class has some transaction scope attributes like sender, origin and a few others. Ideally, this data class should only have block scope attributes and the transaction scope attributes should be moved to the Message data class.

This refactor has a few really nice benefits including

  1. Clear and logical separation between the scopes
  2. Simplifying the signature of a lot of functions including the apply_body function (We can now pass just a single env parameter instead of a large number of individual attributes that might change with hard forks)
  3. Simplification of the code in t8n
  4. Simplification of system transaction processing code

How was it fixed?

Move transaction scope attributes to Message

Cute Animal Picture

Cute Animals - 1 of 1

petertdavies and others added 19 commits September 19, 2024 17:52
This PR incorporates the following updates to the Prague EIPs

EIP-7002: add logging to system contract Update EIP-7002: add logging to system contract EIPs#8890
EIP-7251: max eb, change request to flat encoding Update EIP-7251: change request to flat encoding EIPs#8857
EIP-6110: deposits, change request to flat encoding Update EIP-6110: change request to flat encoding EIPs#8856
EIP-7002: withdrawals, change request to flat encoding Update EIP-7002: change request to flat encoding EIPs#8855
EIP-7685: change requests hash to flat hash Update EIP-7685: change requests hash to flat hash EIPs#8854
Implement Pectra Devnet 4 changes for requests and 7702
Extract t8n arguments from daemon query string
Fix up black and mypy in `fix-t8n-requests`
if block.ommers != ():
raise InvalidBlock

env = vm.Environment(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this change.

src/ethereum/cancun/vm/__init__.py Show resolved Hide resolved
@@ -57,6 +70,8 @@ class Message:
Items that are used by contract creation or message call.
"""

block_env: BlockEnvironment
tx_env: TransactionEnvironment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to introduce a third "environment" for the frame?

class BlockEnvironment:
    ...

class TransactionEnvironment:
    ...

class FrameEnvironment:
    caller: Address
    target: Union[Bytes0, Address]
    current_target: Address
    gas: Uint
    value: U256
    data: Bytes
    code_address: Optional[Address]
    code: Bytes
    depth: Uint
    should_transfer_value: bool
    is_static: bool
    accessed_addresses: Set[Address]
    accessed_storage_keys: Set[Tuple[Address, Bytes32]]
    parent_evm: Optional["Evm"]

class Message:
    block: BlockEnvironment
    transaction: TransactionEnvironment
    frame: FrameEnvironment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would line up the nomenclature pretty well but I have been looking at the Message dataclass serving the same purpose as the FrameEnvironment dataclass in your suggestion. I don't have any strong opinions on either choice tbh.

Copy link
Contributor

@SamWilsn SamWilsn Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be purely for symmetry and organizational purposes. I can imagine the docs looking like:

An EVM message contains three levels of contextual information: block level, transaction level, and call frame level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symmetry argument sounds good to me but the question largely boils down to complexity since introducing FrameEnvironment could be a large change. Also, I think we can introduce FrameEnvironment in the next iteration to avoid a huge PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense.

src/ethereum/cancun/vm/__init__.py Show resolved Hide resolved
@gurukamath gurukamath deleted the branch ethereum:forks/prague January 25, 2025 16:51
@gurukamath gurukamath closed this Jan 25, 2025
@gurukamath gurukamath reopened this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants