Merge pull request #11431 from ethereum/lib-panic

Document the panic function of library deployment
This commit is contained in:
Alex Beregszaszi 2021-05-26 16:37:30 +01:00 committed by GitHub
commit a3634934d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View File

@ -598,6 +598,7 @@ function calls which will cause a Panic.
A Panic exception is generated in the following situations.
The error code supplied with the error data indicates the kind of panic.
#. 0x00: Used for generic compiler inserted panics.
#. 0x01: If you call ``assert`` with an argument that evaluates to false.
#. 0x11: If an arithmetic operation results in underflow or overflow outside of an ``unchecked { ... }`` block.
#. 0x12; If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``).

View File

@ -237,15 +237,18 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract)
codecopy(codepos, subOffset, subSize)
// Check that the first opcode is a PUSH20
if iszero(eq(0x73, byte(0, mload(codepos)))) {
mstore(0, <panicSig>)
mstore(4, 0)
mstore(0, <panicSelector>)
mstore(4, <panicCode>)
revert(0, 0x24)
}
mstore(0, address())
mstore8(codepos, 0x73)
return(codepos, subSize)
}
)")("panicSig", util::selectorFromSignature("Panic(uint256)").str()).render(),
)")
("panicSelector", util::selectorFromSignature("Panic(uint256)").str())
("panicCode", "0")
.render(),
{"subSize", "subOffset"}
);

View File

@ -656,7 +656,6 @@ pair<string, map<ContractDefinition const*, vector<string>>> IRGenerator::evalua
map<ContractDefinition const*, std::vector<ASTPointer<Expression>>const *, InheritanceOrder>
baseConstructorArguments(inheritanceOrder);
;
for (ASTPointer<InheritanceSpecifier> const& base: _contract.baseContracts())
if (FunctionDefinition const* baseConstructor = dynamic_cast<ContractDefinition const*>(

View File

@ -24,8 +24,8 @@ namespace solidity::util
enum class PanicCode
{
Generic = 0x00, // generic / unspecified error.
Assert = 0x01, // generic / unspecified error. Used by assert().
Generic = 0x00, // generic / unspecified error
Assert = 0x01, // used by the assert() builtin
UnderOverflow = 0x11, // arithmetic underflow or overflow
DivisionByZero = 0x12, // division or modulo by zero
EnumConversionError = 0x21, // enum conversion error