foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.17k stars 1.7k forks source link

Update `forge build --sizes` to add `initcode` size column + check for EIP3860 limit #4783

Open rayeaster opened 1 year ago

rayeaster commented 1 year ago

Component

Forge

Describe the feature you would like

With EIP 3860, the contract size limit should be doubled from 24KB to 48KB?

https://github.com/foundry-rs/foundry/blob/master/crates/common/src/compile.rs

-  const CONTRACT_SIZE_LIMIT: usize = 24576;
+ const CONTRACT_SIZE_LIMIT: usize = 24576 * 2;

Additional context

from @mds1

[..]

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 (1) a 24576 byte size limit on runtime code, AND (2) a new 24576 * 2 = 49152 byte size limit on initcode.

Not all EVM chains have this limit, however accounting for this by default in forge seems like a sensible default since that's more conservative.

My suggestion would be to update forge build --sizes to have a second table for initcode size, and exit with an error if either creation code OR initcode is above the size limit, and add a --ignore-eip-3860 flag (or something) to turn it off for users targeting other chains

mattsse commented 1 year ago

what's the current impact of this?

rayeaster commented 1 year ago

what's the current impact of this?

@mattsse @gakonst Not sure if I understand it correctly, but seems that EIP3860 introduce a new limit for initcode during contract creation, instead of increasing limit for runtime bytecode? Adding a new metric around initcode size might make sense

mds1 commented 1 year ago

Right, so 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 (1) a 24576 byte size limit on runtime code, AND (2) a new 24576 * 2 = 49152 byte size limit on initcode.

Not all EVM chains have this limit, however accounting for this by default in forge seems like a sensible default since that's more conservative.

My suggestion would be to update forge build --sizes to have a second table for initcode size, and exit with an error if either creation code OR initcode is above the size limit, and add a --ignore-eip-3860 flag (or something) to turn it off for users targeting other chains

victormer commented 1 year ago

Right, so 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 (1) a 24576 byte size limit on runtime code, AND (2) a new 24576 * 2 = 49152 byte size limit on initcode.

Not all EVM chains have this limit, however accounting for this by default in forge seems like a sensible default since that's more conservative.

My suggestion would be to update forge build --sizes to have a second table for initcode size, and exit with an error if either creation code OR initcode is above the size limit, and add a --ignore-eip-3860 flag (or something) to turn it off for users targeting other chains

You definitely right, this is a desirable feature. I am facing a initcode limit issue when deploying a contract now and I have no idea how to handle it, because locally it goes right in a fork (anvil should have a flag for setting a maximum initcode size too). Meanwhile, do you know how can I know the creation code size so I can reduce it or split transactions?

Thanks!

Philogy commented 1 year ago

Any updates on this? revm seems to already support EIP-3860, foundry's version of it might need to be updated tho

gakonst commented 1 year ago

We're working on it - bumping to the latest.

simplyoptimistic commented 5 months ago

Any updates on this? Doesn't look like it's been implemented.