foundry
foundry copied to clipboard
Using SSTORE2 in tests can exceed contract size limit
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (359dd77 2022-09-15T00:04:51.833948Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
Depends on SSTORE2
Running the below test code allows for contracts to be created that exceed 24576 bytes (contract size limit)
pragma solidity ^0.8.9;
import "sstore2/SSTORE2.sol";
import "sstore2/utils/Bytecode.sol";
contract TestSSTORE2 {
function testWrite() public {
bytes memory data = bytes(vm.readFile("path/to/large/file"));
console.log("data length", data.length);
address memory pointer = SSTORE2.write(data);
console.log("contract size", Bytecode.codeSize(pointer));
}
}
intrinsic gas too high
is thrown if gas exceeds block gas limit
you can manually set --gas-limit for anvil and bump it
sorry for taking so long.
since you're writing an entire file to storage, the tx gas likely exceeds the max block gas limit, but you can bump this manually.
Closing this, lmk if you're still facing issues after increasing anvil's block gas limit
I don’t think this is a gas limit issue. I can write well over the contract size limit before hitting anything close to a block size limit. It seems like anvil and forge tests aren’t respecting EIP-170? See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md
what's the error you get when sending a create tx for a large contract?
what's the error you get when sending a create tx for a large contract?
The problem is there isn’t an error when I expected one. I can throw tons of data at it, well over the contract size limit, and get no errors in anvil/tests.
EIP-170 says anything over ~24kb should be an out of gas error. I can try running this against a testnet and confirm if that’s the error I get for >24kb.
we're not enforcing size limits rn, but I think we should make this configurable.
still don't understand if your issue is that there's no error or whether there's something else wrong?
we're not enforcing size limits rn, but I think we should make this configurable.
still don't understand if your issue is that there's no error or whether there's something else wrong?
The issue is that there is no error. Being able to toggle on/off size limits would be great!
I deleted the earlier comments and updated the original issue. Let me know if that’s more clear.
thanks,
will add an option for this
Is it possible to allow forge test
to configure in the same way? Ultimately I want to write Solidity tests that will fail if the code size is exceeded.
no but we could add if you open a separate issue
we're not enforcing size limits rn, but I think we should make this configurable. still don't understand if your issue is that there's no error or whether there's something else wrong?
The issue is that there is no error. Being able to toggle on/off size limits would be great!
I deleted the earlier comments and updated the original issue. Let me know if that’s more clear.
I came into a similar situation. While EIP 170 introduced a limit of 24KB on bytecode size of smart contracts in Ethereum, NOT .sol file size. My 56KB .sol file compiles in Remix with optimization runs set to 200 and the compiled contract bytecode size was only 14KB in my case, which was far below the limit. Not sure if this is the same issue you met.
While testing my deployment was failing with ABC is above the EIP-170 contract size limit (30134 > 24576).
with the added option of --code-size-limit 31000
to the forge script script/deploy.s.sol
It still fails with Execution reverted: EvmError: CreateContractSizeLimit (gas: 9223372036854775857)
While testing my deployment was failing with
ABC is above the EIP-170 contract size limit (30134 > 24576).
with the added option of
--code-size-limit 31000
to theforge script script/deploy.s.sol
It still fails with
Execution reverted: EvmError: CreateContractSizeLimit (gas: 9223372036854775857)
I have same problem.