From 3edcfce478fbc642c3db90ce5edb1cbff2c0bec8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 15 Apr 2023 13:43:05 +0200 Subject: [PATCH] Add warning for EIP-3860 enforced initcode limits --- libsolidity/interface/CompilerStack.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 13eaae08a..7f2b15261 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1322,7 +1322,7 @@ void CompilerStack::assemble( } // Throw a warning if EIP-170 limits are exceeded: - // If contract creation returns data with length greater than 0x6000 (214 + 213) bytes, + // If contract creation returns data with length greater than 0x6000 (2^14 + 2^13) bytes, // contract creation fails with an out of gas error. if ( m_evmVersion >= langutil::EVMVersion::spuriousDragon() && @@ -1338,6 +1338,24 @@ void CompilerStack::assemble( "Consider enabling the optimizer (with a low \"runs\" value!), " "turning off revert strings, or using libraries." ); + + // Throw a warning if EIP-3860 limits are exceeded: + // If initcode is larger than 0xC000 bytes (twice the runtime code limit), + // then contract creation fails with an out of gas error. + if ( + m_evmVersion >= langutil::EVMVersion::shanghai() && + compiledContract.object.bytecode.size() > 0xC000 + ) + m_errorReporter.warning( + 3860_error, + _contract.location(), + "Contract initcode size is "s + + to_string(compiledContract.object.bytecode.size()) + + " bytes and exceeds 49152 bytes (a limit introduced in Shanghai). " + "This contract may not be deployable on Mainnet. " + "Consider enabling the optimizer (with a low \"runs\" value!), " + "turning off revert strings, or using libraries." + ); } void CompilerStack::compileContract(