-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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): Paris & Shanghai support & add prevrandao
cheatcode
#4856
Conversation
One thing to consider is that many chains users deploy to won’t support Shanghai/PUSH0, so during scripting we may want to check the chain ID (from the RPC url) and warn or error if it’s a chain not known to support Shanghai. Otherwise users might build/deploy contracts that work during testing but not in production |
cli/src/cmd/forge/script/mod.rs
Outdated
let provider = ethers::providers::Provider::<Http>::try_from(rpc)?; | ||
let chain_id = provider.get_chainid().await?; | ||
if chain_id != U256::one() { | ||
shell::println(format!("Shanghai is only supported on Ethereum Mainnet (Chain ID 1). This RPC uses chain id {} therefore contracts using PUSH0 will not work.", chain_id))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change this to a more meaningful description. The average user does not think in terms of assembly. I would instead reference the EIP-3855 and provide a link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also shanghai is also supported on goerli and sepolia, not just mainnet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah agreed this message could be better—and probably a bit louder as well. I'm still not 100% sold on only warning actually though: I've seen some discussion around the topic and we might wanna consider instead erroring (with some mechanism to bypass this). we'll have the same story in cancun with transient storage so that's why I'm giving it some more thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved the warning message here: c5b29b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will support it and make it the default soon, though: ethereum/solidity#14158 Since hardhat and solc are making shanghai the default (which makes sense, since ethereum mainnet is still the primary target of these tools), I think it's ok for foundry to do so also, but a loud warning before deployments feels like a nice mitigation |
prevrandao
cheatcode
prevrandao
cheatcodeprevrandao
cheatcode
6c20c36
to
edef79b
Compare
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
12599da
to
06e493b
Compare
06e493b
to
87aea94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, 1 question which can be resolved in another PR.
/// Converts an `EvmVersion` into a `SpecId` | ||
pub fn evm_spec(evm: &EvmVersion) -> SpecId { | ||
match evm { | ||
EvmVersion::Istanbul => SpecId::ISTANBUL, | ||
EvmVersion::Berlin => SpecId::BERLIN, | ||
EvmVersion::London => SpecId::LONDON, | ||
EvmVersion::Paris => SpecId::MERGE, | ||
EvmVersion::Shanghai => SpecId::SHANGHAI, | ||
_ => panic!("Unsupported EVM version"), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually not sure and is a pending question I have myself—I wanna try and document how we're using the hard forks and if there's any reason not to include them all (and if we want to, ideally in another PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss in separate issue - i dont recall a particular reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
looks good, one nit re error check and message
cli/src/cmd/forge/script/mod.rs
Outdated
if !chain_ids_supported { | ||
let msg = "\ | ||
EIP-3855 is not supported in one or more of the RPCs used. | ||
Contracts deployed with a Solidity version equal or higher than 0.8.20 might not work properly. | ||
For more information, please see https://eips.ethereum.org/EIPS/eip-3855"; | ||
shell::println(Paint::yellow(msg))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be good to include the chain id that does not support it her, otherwise the user needs to identify this manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah will quickly change the message so it points out these are chain IDs. EDIT: ad8803f
EIP-3855 is not supported in one or more of the RPCs used. | ||
Unsupported Chain IDs: {}. | ||
Contracts deployed with a Solidity version equal or higher than 0.8.20 might not work properly. | ||
For more information, please see https://eips.ethereum.org/EIPS/eip-3855"#, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful
/// Converts an `EvmVersion` into a `SpecId` | ||
pub fn evm_spec(evm: &EvmVersion) -> SpecId { | ||
match evm { | ||
EvmVersion::Istanbul => SpecId::ISTANBUL, | ||
EvmVersion::Berlin => SpecId::BERLIN, | ||
EvmVersion::London => SpecId::LONDON, | ||
EvmVersion::Paris => SpecId::MERGE, | ||
EvmVersion::Shanghai => SpecId::SHANGHAI, | ||
_ => panic!("Unsupported EVM version"), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss in separate issue - i dont recall a particular reason
bytes memory bytecode = hex"365f5f37365ff3"; | ||
// 36 CALLDATASIZE | ||
// 5F PUSH0 | ||
// 5F PUSH0 | ||
// 37 CALLDATACOPY -> copies calldata at mem[0..calldatasize] | ||
|
||
// 36 CALLDATASIZE | ||
// 5F PUSH0 | ||
// F3 RETURN -> returns mem[0..calldatasize] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
- update pragmas to 0.8.18 - use preverando instead difficulty (need a version of foundry containing foundry-rs/foundry#4856)
- update pragmas to 0.8.18 - use preverando instead difficulty (need a version of foundry containing foundry-rs/foundry#4856)
Motivation
Right now the default spec is still London and most tooling will now make Shanghai the default spec. We should update everything related to selecting specs post london, for Paris and Shanghai support, but keep Paris as default until solidity .8.20 is out and ethers switches over.
Solution
Adds Paris and Shanghai as supported specs (with Paris as default as Ethers falls back to it), along with updating tests to use the new Prevrandao cheatcode included in this PR. Closes #4855.
This impacts a few things (will look at this after today, getting late):
difficulty
is used on a few I believe, anddifficulty
doesn't work from Paris onwards. I assume we'll want to change/add tests to use prevrandao (which by extension prob means we need a prevrandao cheatcode).The files changed tab looks daunting, but bear with me—most of those changes are just modifying compiler output so that tests pass.