mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10765 from ethereum/ir-revert-strings
Include revert strings in IR
This commit is contained in:
commit
aba8d807db
@ -795,7 +795,7 @@ string IRGenerator::deployCode(ContractDefinition const& _contract)
|
|||||||
|
|
||||||
string IRGenerator::callValueCheck()
|
string IRGenerator::callValueCheck()
|
||||||
{
|
{
|
||||||
return "if callvalue() { revert(0, 0) }";
|
return "if callvalue() { " + m_context.revertReasonIfDebug("Ether sent to non-payable function") + " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
|
string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
|
||||||
@ -839,8 +839,10 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
|
|||||||
if (type->stateMutability() > StateMutability::View)
|
if (type->stateMutability() > StateMutability::View)
|
||||||
// If the function is not a view function and is called without DELEGATECALL,
|
// If the function is not a view function and is called without DELEGATECALL,
|
||||||
// we revert.
|
// we revert.
|
||||||
// TODO add revert message.
|
delegatecallCheck =
|
||||||
delegatecallCheck = "if iszero(called_via_delegatecall) { revert(0, 0) }";
|
"if iszero(called_via_delegatecall) { " +
|
||||||
|
m_context.revertReasonIfDebug("Non-view function of library called without DELEGATECALL") +
|
||||||
|
" }";
|
||||||
}
|
}
|
||||||
templ["delegatecallCheck"] = delegatecallCheck;
|
templ["delegatecallCheck"] = delegatecallCheck;
|
||||||
templ["callValueCheck"] = (type->isPayable() || _contract.isLibrary()) ? "" : callValueCheck();
|
templ["callValueCheck"] = (type->isPayable() || _contract.isLibrary()) ? "" : callValueCheck();
|
||||||
@ -864,7 +866,8 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
|
|||||||
templ["abiEncode"] = abiFunctions.tupleEncoder(type->returnParameterTypes(), type->returnParameterTypes(), _contract.isLibrary());
|
templ["abiEncode"] = abiFunctions.tupleEncoder(type->returnParameterTypes(), type->returnParameterTypes(), _contract.isLibrary());
|
||||||
}
|
}
|
||||||
t("cases", functions);
|
t("cases", functions);
|
||||||
if (FunctionDefinition const* etherReceiver = _contract.receiveFunction())
|
FunctionDefinition const* etherReceiver = _contract.receiveFunction();
|
||||||
|
if (etherReceiver)
|
||||||
{
|
{
|
||||||
solAssert(!_contract.isLibrary(), "");
|
solAssert(!_contract.isLibrary(), "");
|
||||||
t("receiveEther", m_context.enqueueFunctionForCodeGeneration(*etherReceiver) + "() stop()");
|
t("receiveEther", m_context.enqueueFunctionForCodeGeneration(*etherReceiver) + "() stop()");
|
||||||
@ -888,9 +891,15 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t("fallback", fallbackCode);
|
t("fallback", fallbackCode);
|
||||||
|
t("revertNoSignature", "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
t("fallback", "revert(0, 0)");
|
t(
|
||||||
|
"fallback",
|
||||||
|
etherReceiver ?
|
||||||
|
m_context.revertReasonIfDebug("Unknown signature and no fallback defined") :
|
||||||
|
m_context.revertReasonIfDebug("Contract does not have fallback nor receive functions")
|
||||||
|
);
|
||||||
return t.render();
|
return t.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2364,7 +2364,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Whiskers templ(R"(
|
Whiskers templ(R"(
|
||||||
if iszero(extcodesize(<address>)) { revert(0, 0) }
|
if iszero(extcodesize(<address>)) { <revertNoCode> }
|
||||||
|
|
||||||
// storage for arguments and returned data
|
// storage for arguments and returned data
|
||||||
let <pos> := <freeMemory>
|
let <pos> := <freeMemory>
|
||||||
@ -2389,6 +2389,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
|||||||
<?+retVars> <retVars> := </+retVars> <abiDecode>(<pos>, add(<pos>, <returnSize>))
|
<?+retVars> <retVars> := </+retVars> <abiDecode>(<pos>, add(<pos>, <returnSize>))
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
templ("revertNoCode", m_context.revertReasonIfDebug("Target contract does not contain code"));
|
||||||
templ("pos", m_context.newYulVariable());
|
templ("pos", m_context.newYulVariable());
|
||||||
templ("end", m_context.newYulVariable());
|
templ("end", m_context.newYulVariable());
|
||||||
if (_functionCall.annotation().tryCall)
|
if (_functionCall.annotation().tryCall)
|
||||||
|
@ -7,6 +7,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
// ====
|
// ====
|
||||||
// EVMVersion: >=byzantium
|
// EVMVersion: >=byzantium
|
||||||
|
// compileViaYul: also
|
||||||
// revertStrings: debug
|
// revertStrings: debug
|
||||||
// ----
|
// ----
|
||||||
// g() -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
|
// g() -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
|
||||||
|
@ -4,6 +4,7 @@ contract C {
|
|||||||
// ====
|
// ====
|
||||||
// EVMVersion: >=byzantium
|
// EVMVersion: >=byzantium
|
||||||
// revertStrings: debug
|
// revertStrings: debug
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f(), 1 ether -> FAILURE, hex"08c379a0", 0x20, 34, "Ether sent to non-payable functi", "on"
|
// f(), 1 ether -> FAILURE, hex"08c379a0", 0x20, 34, "Ether sent to non-payable functi", "on"
|
||||||
// () -> FAILURE, hex"08c379a0", 0x20, 53, "Contract does not have fallback ", "nor receive functions"
|
// () -> FAILURE, hex"08c379a0", 0x20, 53, "Contract does not have fallback ", "nor receive functions"
|
||||||
|
@ -9,6 +9,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ====
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// EVMVersion: >=byzantium
|
// EVMVersion: >=byzantium
|
||||||
// revertStrings: debug
|
// revertStrings: debug
|
||||||
// ----
|
// ----
|
||||||
|
@ -4,5 +4,6 @@ contract A {
|
|||||||
// ====
|
// ====
|
||||||
// EVMVersion: >=byzantium
|
// EVMVersion: >=byzantium
|
||||||
// revertStrings: debug
|
// revertStrings: debug
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// (): hex"00" -> FAILURE, hex"08c379a0", 0x20, 41, "Unknown signature and no fallbac", "k defined"
|
// (): hex"00" -> FAILURE, hex"08c379a0", 0x20, 41, "Unknown signature and no fallbac", "k defined"
|
||||||
|
Loading…
Reference in New Issue
Block a user