-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Panic with error codes. #10013
Panic with error codes. #10013
Conversation
d15ea0b
to
2eb49f0
Compare
23e0f55
to
86b991f
Compare
6d89d37
to
5a8df54
Compare
This actually uses |
Probably? |
I guess? |
5a8df54
to
53941f1
Compare
} | ||
|
||
// ==== | ||
// EVMVersion: <byzantium |
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.
This test runs on pre-byzantium and shows that invalid enum conversions also revert in these cases, but do not provide an error message (because the revert opcode is not available).
52aab54
to
107b564
Compare
Should use hex codes in the yul representation of the panic function. |
2713e74
to
3b99ed9
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.
Started reviewing this yesterday; some old comments. Will review the rest soon.
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.
Some comments about docs and code, have not checked tests yet.
docs/control-structures.rst
Outdated
#. 0x51: If you call a zero-initialized variable of internal function type. | ||
|
||
The ``require`` function either creates an error of type ``Error(string)`` | ||
or ar error without ary error data and it |
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.
or ar error without ary error data and it | |
or an error without any error data and it |
if (_revertOnFailure) | ||
templ("failure", "revert(0, 0)"); | ||
else | ||
templ("failure", panicFunction(panicCode) + "()"); |
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.
What exactly would trigger this? ABI decoding for example?
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.
No, abi decoding failure results in revert. _revertOnFailure
is currently only false for enum conversion checks.
@@ -3411,7 +3415,7 @@ string YulUtilFunctions::storageSetToZeroFunction(Type const& _type) | |||
)") | |||
("functionName", functionName) | |||
("clearStruct", clearStorageStructFunction(dynamic_cast<StructType const&>(_type))) | |||
("panic", panicFunction()) | |||
("panic", panicFunction(PanicCode::Generic)) |
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.
When would this and the above happen?
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.
Only though a bug in the compiler. We hope that the check is optimized away.
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 ok
libsolutil/ErrorCodes.h
Outdated
namespace solidity::util | ||
{ | ||
|
||
|
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.
Extra blank
@@ -378,6 +378,7 @@ EVMDialectTyped::EVMDialectTyped(langutil::EVMVersion _evmVersion, bool _objectA | |||
BuiltinContext&, | |||
std::function<void(Expression const&)> _visitExpression | |||
) { | |||
// TODO this should use a Panic. |
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.
In this 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.
No, this dialect is not really used yet.
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.
Ok
if iszero(length) { | ||
mstore(0, <panicSelector>) | ||
mstore(4, <emptyArrayPop>) | ||
revert(0, 0x24) |
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.
Why not make a call to YulUtilFunctions::panicFunction(util::PanicCode::EmptyArrayPop)
@@ -810,7 +810,7 @@ void CompilerUtils::convertType( | |||
if (_asPartOfArgumentDecoding) | |||
m_context.appendConditionalRevert(false, "Enum out of range"); | |||
else | |||
m_context.appendConditionalInvalid(); | |||
m_context.appendConditionalPanic(util::PanicCode::EnumConversionError); |
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.
In the line above, for "Enum out of range", shouldn't this also be a panic?
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.
Or is this left for the future?
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.
No, it is a revert ("Error()") and not a panic.
mstore8(codepos, 0x73) | ||
return(codepos, subSize) | ||
} | ||
)")("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(), |
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.
)")("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(), | |
)") | |
("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(), |
Not sure if that's the right coding style.
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's not the separator between the ()
-elements that is wrapping, but the content inside a single ()
...
mstore(0, <panicSig>) | ||
mstore(4, 0) | ||
revert(0, 0x24) | ||
} |
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 agree. Is there a reason we are inlining it ourselves?
test/libsolidity/semanticTests/types/mapping_enum_key_library_encoderV2.sol
Show resolved
Hide resolved
invalid() | ||
mstore(0, <selector>) | ||
mstore(4, <code>) | ||
revert(0, 0x24) |
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.
Our selector is 4 byte and code is 2 byte? Can't we pack everything in 32 bytes?
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.
We want to use ABI encoding. Furthermore, there is a missing feature in the RPC interface to the node implementations in that they do not return the success code of a transaction. Computing the length of the return value mod 32 is an indication of whether it succeeded or not.
6e129e7
to
70e7326
Compare
Rebased and squashed. |
TODO: