Skip to content

feat(framework): disallow assign of fixedbytes of size X to bytes of size Y when X != Y #1010

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

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

winsvega
Copy link
Contributor

@winsvega winsvega commented Dec 9, 2024

🗒️ Description

fields of type fixedbytesizeN should not be assignable to bytes of size other than N

uvx --with=tox-uv tox

🔗 Related Issues

#1008

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • Tests: A PR with removal of converted JSON/YML tests from ethereum/tests have been opened.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@winsvega winsvega added the type:feat type: Feature label Dec 9, 2024
@winsvega winsvega force-pushed the fixedsize branch 2 times, most recently from 07aee0a to 301dd8b Compare December 12, 2024 10:38
@winsvega winsvega self-assigned this Dec 17, 2024
@winsvega winsvega marked this pull request as draft December 17, 2024 13:23
@marioevz
Copy link
Member

Wanted to see why tox was failing and it turns out we have this pattern in some of the tests where we convert an Address to Hash (fixed size bytes 20 to 32) in order to pass it as data in a transaction of the test:

Transaction(
sender=sender,
gas_limit=100000,
to=contract_address,
data=Hash(recipient),
)

We need to decide how to proceed with this pattern because I find it useful to convert between the two types in a test.

One possibility is to simply disallow going from bigger sizes to lower sizes, and disallow a size of zero in the bytes.

Another option is to have a special case coded in Hash to allow an Address as input.

@winsvega winsvega force-pushed the fixedsize branch 2 times, most recently from 0014c5e to 63b2744 Compare December 19, 2024 11:22
@winsvega
Copy link
Contributor Author

winsvega commented Dec 19, 2024

Pushed a solution, why not to be explicit about what you want to achieve:

- data=Hash(recipient),
+ data=left_pad_zeros_up_to_size(recipient, 32),

@winsvega winsvega marked this pull request as ready for review December 19, 2024 11:28
@winsvega winsvega requested a review from marioevz December 19, 2024 11:28
@winsvega winsvega force-pushed the fixedsize branch 2 times, most recently from d922054 to 993d311 Compare January 8, 2025 12:43
marioevz and others added 3 commits January 9, 2025 15:52
Refactor `left_pad_zeros_up_to_size` to a parameter in the `FixedSizeBytes` constructor
Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@marioevz marioevz merged commit 1fb1ab4 into main Jan 21, 2025
14 checks passed
@marioevz marioevz deleted the fixedsize branch January 21, 2025 21:51
fselmo pushed a commit to fselmo/execution-spec-tests that referenced this pull request Jan 24, 2025
…size Y when X != Y (ethereum#1010)

* unit tests

* fix after rebase

* fix(types): Transaction `to` validation fix

* refactor(base_types): replace left_pad_zeros_up_to_size with fixed bytes constructor parameter

---------

Co-authored-by: Mario Vega <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feat type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants