-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add code size limit exceeding warning in YulStack
#16885
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
Open
rodiazet
wants to merge
1
commit into
develop
Choose a base branch
from
code-size-warning
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| This file is part of solidity. | ||
|
|
||
| solidity is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| solidity is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
|
|
||
| #include <libevmasm/CodeSizeLimits.h> | ||
|
|
||
| #include <liblangutil/ErrorReporter.h> | ||
|
|
||
| using namespace std::string_literals; | ||
| using namespace solidity::langutil; | ||
|
|
||
| namespace solidity::evmasm | ||
| { | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| /// Runtime code size limit (in bytes) introduced by EIP-170 in the Spurious Dragon release. | ||
| constexpr size_t RUNTIME_CODE_SIZE_LIMIT = 24576; | ||
|
|
||
| /// Initcode size limit (in bytes) introduced by EIP-3860 in the Shanghai release. | ||
| constexpr size_t CREATION_CODE_SIZE_LIMIT = 49152; | ||
|
|
||
| } | ||
|
|
||
| void checkCodeSizeLimits( | ||
| ErrorReporter& _errorReporter, | ||
| EVMVersion _evmVersion, | ||
| SourceLocation const& _location, | ||
| size_t _creationCodeSize, | ||
| size_t _runtimeCodeSize | ||
| ) | ||
| { | ||
| // Warn if EIP-170 limits are exceeded. | ||
| if (_evmVersion >= EVMVersion::spuriousDragon() && _runtimeCodeSize > RUNTIME_CODE_SIZE_LIMIT) | ||
| _errorReporter.warning( | ||
| 5574_error, | ||
| _location, | ||
| "Contract code size is "s + | ||
| std::to_string(_runtimeCodeSize) + | ||
| " bytes and exceeds " + std::to_string(RUNTIME_CODE_SIZE_LIMIT) + | ||
| " bytes (a limit introduced in Spurious Dragon). " | ||
| "This contract may not be deployable on Mainnet. " | ||
| "Consider enabling the optimizer (with a low \"runs\" value!), " | ||
| "turning off revert strings, or using libraries." | ||
| ); | ||
|
|
||
| // Warn if EIP-3860 limits are exceeded. | ||
| if (_evmVersion >= EVMVersion::shanghai() && _creationCodeSize > CREATION_CODE_SIZE_LIMIT) | ||
| _errorReporter.warning( | ||
| 3860_error, | ||
| _location, | ||
| "Contract initcode size is "s + | ||
| std::to_string(_creationCodeSize) + | ||
| " bytes and exceeds " + std::to_string(CREATION_CODE_SIZE_LIMIT) + | ||
| " 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." | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| This file is part of solidity. | ||
|
|
||
| solidity is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| solidity is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <liblangutil/EVMVersion.h> | ||
| #include <liblangutil/SourceLocation.h> | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| namespace solidity::langutil | ||
| { | ||
| class ErrorReporter; | ||
| } | ||
|
|
||
| namespace solidity::evmasm | ||
| { | ||
|
|
||
| /// Reports warnings, via @a _errorReporter, if the given bytecode sizes exceed the limits. | ||
| /// @param _creationCodeSize size in bytes of the assembled creation (init) code. | ||
| /// @param _runtimeCodeSize size in bytes of the assembled runtime code. | ||
| void checkCodeSizeLimits( | ||
| langutil::ErrorReporter& _errorReporter, | ||
| langutil::EVMVersion _evmVersion, | ||
| langutil::SourceLocation const& _location, | ||
| size_t _creationCodeSize, | ||
| size_t _runtimeCodeSize | ||
| ); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changelog entry is missing. This is a visible Yul change so it should be mentioned. Though not sure if I'd classify it as a bugfix or a new feature. Probably the latter, but it should have been included from the beginning so it's both in a way :)