Skip to content
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

Merged
merged 7 commits into from
Oct 22, 2020
Merged

Panic with error codes. #10013

merged 7 commits into from
Oct 22, 2020

Conversation

chriseth
Copy link
Contributor

@chriseth chriseth commented Oct 12, 2020

TODO:

  • document the codes and the behaviour (maybe in the checked PR)

@chriseth chriseth changed the base branch from develop to breaking October 13, 2020 12:50
@chriseth chriseth force-pushed the errorCodesPanic branch 3 times, most recently from 23e0f55 to 86b991f Compare October 13, 2020 16:50
@chriseth chriseth marked this pull request as ready for review October 13, 2020 16:58
@chriseth chriseth force-pushed the errorCodesPanic branch 4 times, most recently from 6d89d37 to 5a8df54 Compare October 14, 2020 15:42
@chriseth
Copy link
Contributor Author

This actually uses revert also on EVM versions that do not support it which causes an "invalid opcode" exception. I guess this is fine?

@ekpyron
Copy link
Member

ekpyron commented Oct 14, 2020

This actually uses revert also on EVM versions that do not support it which causes an "invalid opcode" exception. I guess this is fine?

Probably?

@leonardoalt
Copy link
Member

This actually uses revert also on EVM versions that do not support it which causes an "invalid opcode" exception. I guess this is fine?

Probably?

I guess?

}

// ====
// EVMVersion: <byzantium
Copy link
Contributor Author

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).

@chriseth
Copy link
Contributor Author

Should use hex codes in the yul representation of the panic function.

@chriseth chriseth force-pushed the errorCodesPanic branch 2 times, most recently from 2713e74 to 3b99ed9 Compare October 20, 2020 13:11
Copy link
Member

@hrkrshnn hrkrshnn left a 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.

docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
Copy link
Member

@leonardoalt leonardoalt left a 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.

#. 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or ar error without ary error data and it
or an error without any error data and it

docs/control-structures.rst Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
docs/control-structures.rst Outdated Show resolved Hide resolved
if (_revertOnFailure)
templ("failure", "revert(0, 0)");
else
templ("failure", panicFunction(panicCode) + "()");
Copy link
Member

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?

Copy link
Contributor Author

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))
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok

namespace solidity::util
{


Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

test/ExecutionFramework.cpp Outdated Show resolved Hide resolved
if iszero(length) {
mstore(0, <panicSelector>)
mstore(4, <emptyArrayPop>)
revert(0, 0x24)
Copy link
Member

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);
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)")("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(),
)")
("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(),

Not sure if that's the right coding style.

Copy link
Contributor Author

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)
}
Copy link
Member

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/cmdlineTests/exp_base_literal/output Show resolved Hide resolved
invalid()
mstore(0, <selector>)
mstore(4, <code>)
revert(0, 0x24)
Copy link
Member

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?

Copy link
Contributor Author

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.

@chriseth
Copy link
Contributor Author

Rebased and squashed.

@chriseth chriseth merged commit f22cb64 into breaking Oct 22, 2020
@chriseth chriseth deleted the errorCodesPanic branch October 22, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants