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(forge build): add initcode size check #9116

Merged
merged 24 commits into from
Oct 19, 2024

Conversation

mgiagante
Copy link
Contributor

@mgiagante mgiagante commented Oct 15, 2024

Closes #4783
described in the Additional Context of this comment

Motivation

Prior to EIP-3860 there was no size limit on creation code (initcode), and just a 24576 byte size limit on runtime code.
EIP-3860 went live in Shangai so now there is both:

  • a 24576 byte size limit on runtime code
  • a new 24576 * 2 = 49152 byte size limit on initcode.

Currently, forge build --sizes does not account for this new size limit.

Solution

  1. This PR adds a new column pair to the table displayed by forge build --sizes for the contract init code size (bytes) and the margin left counting towards the limit (bytes).
  2. Also, the existing check for the deployed contract size is complemented with a new check for the init code size, making the process exist with status code 1 if the check fails.
  3. Finally, a new option --ignore-eip-3860 allows to ignore the check mentioned in the previous point. This is aimed to users deploying to chains that do not enforce this limit.

Testing

  • Two tests were adjusted to account for the new structure of the table.
  • Two new tests were introduced to verify both failing and ignoring the new init code size limit.

@NelsonGaldeman
Copy link

Finally! Thank you ser 🫡

Tested and worked to me!

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

Thank you! looks good, have added minor nits

crates/common/src/compile.rs Outdated Show resolved Hide resolved
crates/forge/bin/cmd/build.rs Show resolved Hide resolved
@grandizzy grandizzy changed the title Feature/add initcode size check feat(forge build): add initcode size check Oct 15, 2024
@grandizzy grandizzy changed the title feat(forge build): add initcode size check feat(forge build): add initcode size check Oct 15, 2024
@grandizzy grandizzy self-requested a review October 15, 2024 15:25
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

thank you, lgtm! Pending other review

@zerosnacks zerosnacks self-requested a review October 15, 2024 18:37
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good 👍

crates/common/src/compile.rs Outdated Show resolved Hide resolved
crates/common/src/compile.rs Outdated Show resolved Hide resolved
crates/forge/bin/cmd/build.rs Outdated Show resolved Hide resolved
crates/forge/tests/cli/test_helpers.rs Outdated Show resolved Hide resolved
crates/forge/tests/cli/build.rs Outdated Show resolved Hide resolved
crates/forge/tests/cli/build.rs Outdated Show resolved Hide resolved
crates/common/src/compile.rs Outdated Show resolved Hide resolved
crates/common/src/compile.rs Outdated Show resolved Hide resolved
@zerosnacks zerosnacks self-requested a review October 16, 2024 10:44
@mgiagante
Copy link
Contributor Author

@DaniPopes Please let me know if this needs any further improvements before it can be merged. Thank you!

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Thanks!

@DaniPopes DaniPopes enabled auto-merge (squash) October 19, 2024 11:54
@DaniPopes DaniPopes merged commit 8bdcbfa into foundry-rs:master Oct 19, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Update forge build --sizes to add initcode size column + check for EIP3860 limit
6 participants