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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

winsvega
Copy link
Collaborator

@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
Copy link
Collaborator 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
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