-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Do not remove custom errors in IR codegen when strip revert strings is requested #16466
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1158,10 +1158,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) | |
| solAssert(arguments.size() > 0, "Expected at least one parameter for require/assert"); | ||
| solAssert(arguments.size() <= 2, "Expected no more than two parameters for require/assert"); | ||
|
|
||
| Type const* messageArgumentType = | ||
| arguments.size() > 1 && m_context.revertStrings() != RevertStrings::Strip ? | ||
| arguments[1]->annotation().type : | ||
| nullptr; | ||
| Type const* messageArgumentType = arguments.size() == 2 ? arguments[1]->annotation().type : nullptr; | ||
|
|
||
| auto const* magicType = dynamic_cast<MagicType const*>(messageArgumentType); | ||
| if (magicType && magicType->kind() == MagicType::Kind::Error) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the new version this fragment of the code also generates code for path when the require conditions evaluates to true, but I cannot find tests for this case except
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new version now follows the same path of previous version when revertStrings != Strip, so it should have the same result. I will add a variation of that test with
The handling was the same of a |
||
|
|
@@ -1175,6 +1172,9 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) | |
| } | ||
| else | ||
| { | ||
| // This option only removes strings, not custom errors | ||
| if (m_context.revertStrings() == RevertStrings::Strip) | ||
| messageArgumentType = nullptr; | ||
| ASTPointer<Expression const> stringArgumentExpression = messageArgumentType ? arguments[1] : nullptr; | ||
| std::string requireOrAssertFunction = m_utils.requireOrAssertFunction( | ||
| functionType->kind() == FunctionType::Kind::Assert, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --revert-strings strip --debug-info none --asm --optimize |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| pragma solidity >=0.0; | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
| contract C { | ||
| error MyError(uint errorCode, string errorMsg, bool flag); | ||
| function flag() pure public returns (bool) { return false; } | ||
| function f() pure external { | ||
| uint code = 8; | ||
| string memory eMsg = "error"; | ||
| require(false, MyError(code, eMsg, flag())); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
|
|
||
| ======= input.sol:C ======= | ||
| EVM assembly: | ||
| mstore(0x40, 0x80) | ||
| callvalue | ||
| dup1 | ||
| iszero | ||
| tag_1 | ||
| jumpi | ||
| revert(0x00, 0x00) | ||
| tag_1: | ||
| pop | ||
| dataSize(sub_0) | ||
| dup1 | ||
| dataOffset(sub_0) | ||
| 0x00 | ||
| codecopy | ||
| 0x00 | ||
| return | ||
| stop | ||
|
|
||
| sub_0: assembly { | ||
| mstore(0x40, 0x80) | ||
| callvalue | ||
| dup1 | ||
| iszero | ||
| tag_1 | ||
| jumpi | ||
| revert(0x00, 0x00) | ||
| tag_1: | ||
| pop | ||
| jumpi(tag_2, lt(calldatasize, 0x04)) | ||
| shr(0xe0, calldataload(0x00)) | ||
| dup1 | ||
| 0x26121ff0 | ||
| eq | ||
| tag_3 | ||
| jumpi | ||
| dup1 | ||
| 0x890eba68 | ||
| eq | ||
| tag_4 | ||
| jumpi | ||
| tag_2: | ||
| revert(0x00, 0x00) | ||
| tag_3: | ||
| tag_5 | ||
| tag_6 | ||
| jump // in | ||
| tag_5: | ||
| stop | ||
| tag_4: | ||
| 0x40 | ||
| dup1 | ||
| mload | ||
| 0x00 | ||
| dup2 | ||
| mstore | ||
| swap1 | ||
| mload | ||
| swap1 | ||
| dup2 | ||
| swap1 | ||
| sub | ||
| 0x20 | ||
| add | ||
| swap1 | ||
| return | ||
| tag_6: | ||
| 0x40 | ||
| dup1 | ||
| mload | ||
| dup1 | ||
| dup3 | ||
| add | ||
| swap1 | ||
| swap2 | ||
| mstore | ||
| 0x05 | ||
| dup2 | ||
| mstore | ||
| shl(0xd9, 0x32b93937b9) | ||
| 0x20 | ||
| dup3 | ||
| add | ||
| mstore | ||
| 0x08 | ||
| swap1 | ||
| dup2 | ||
| dup2 | ||
| 0x00 | ||
| mload(0x40) | ||
| shl(0xe5, 0x01676c8b) | ||
| dup2 | ||
| mstore | ||
| 0x04 | ||
| add | ||
| tag_14 | ||
| swap4 | ||
| swap3 | ||
| swap2 | ||
| swap1 | ||
| tag_15 | ||
| jump // in | ||
| tag_14: | ||
| mload(0x40) | ||
| dup1 | ||
| swap2 | ||
| sub | ||
| swap1 | ||
| revert | ||
| tag_15: | ||
| dup4 | ||
| dup2 | ||
| mstore | ||
| 0x60 | ||
| 0x20 | ||
| dup3 | ||
| add | ||
| mstore | ||
| 0x00 | ||
| dup4 | ||
| mload | ||
| dup1 | ||
| 0x60 | ||
| dup5 | ||
| add | ||
| mstore | ||
| dup1 | ||
| 0x20 | ||
| dup7 | ||
| add | ||
| 0x80 | ||
| dup6 | ||
| add | ||
| mcopy | ||
| 0x00 | ||
| 0x80 | ||
| dup3 | ||
| dup6 | ||
| add | ||
| add | ||
| mstore | ||
| 0x80 | ||
| 0x1f | ||
| not | ||
| 0x1f | ||
| dup4 | ||
| add | ||
| and | ||
| dup5 | ||
| add | ||
| add | ||
| swap2 | ||
| pop | ||
| pop | ||
| dup3 | ||
| iszero | ||
| iszero | ||
| 0x40 | ||
| dup4 | ||
| add | ||
| mstore | ||
| swap5 | ||
| swap4 | ||
| pop | ||
| pop | ||
| pop | ||
| pop | ||
| jump // out | ||
|
|
||
| auxdata: <AUXDATA REMOVED> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --revert-strings strip --debug-info none --asm --optimize |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| pragma solidity >=0.0; | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
| contract C { | ||
| error MyError(uint errorCode, string errorMsg); | ||
| uint public counter = 0; | ||
| function count() public returns (uint) { return ++counter; } | ||
| function f() external { | ||
| string memory eMsg = "error"; | ||
| require(false, MyError(count(), eMsg)); | ||
| counter += 2; | ||
| } | ||
| } |
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.
require_error_evaluation_order_2.soltests proper order of require arguments evaluation. Does it also test this in case ofrevertStrings: Strip? Probably not.require_inherited_error.solalso is tested only for non-strip version.require_error_condition_evaluated_only_once.solit's only tested for non-strip version, and it should be tested because it old code had different control flow.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.
Added