Skip to content

Comments

Refactor the Environment dataclass#1053

Closed
gurukamath wants to merge 77 commits intoethereum:forks/praguefrom
gurukamath:refactor-env
Closed

Refactor the Environment dataclass#1053
gurukamath wants to merge 77 commits intoethereum:forks/praguefrom
gurukamath:refactor-env

Conversation

@gurukamath
Copy link
Contributor

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

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.

"""

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
Contributor 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
Contributor 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.

@gurukamath
Copy link
Contributor Author

Closing in favor of #1131

@gurukamath gurukamath closed this Feb 21, 2025
Carsons-Eels pushed a commit to Carsons-Eels/execution-specs that referenced this pull request Oct 16, 2025
…thereum#1053)

* fix(github): Features for legacy forks

* docs: update changelog

---------

Co-authored-by: danceratopz <danceratopz@gmail.com>
danceratopz added a commit to danceratopz/execution-specs that referenced this pull request Oct 22, 2025
…thereum#1053)

* fix(github): Features for legacy forks

* docs: update changelog

---------

Co-authored-by: danceratopz <danceratopz@gmail.com>
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