Respect memory model for revert.

This commit is contained in:
chriseth
2021-05-03 18:23:41 +02:00
parent fe4822a1d2
commit 62355aead3
10 changed files with 114 additions and 104 deletions
@@ -177,8 +177,3 @@ ABIFunctions IRGenerationContext::abiFunctions()
{
return ABIFunctions(m_evmVersion, m_revertStrings, m_functions);
}
std::string IRGenerationContext::revertReasonIfDebug(std::string const& _message)
{
return YulUtilFunctions::revertReasonIfDebug(m_revertStrings, _message);
}
@@ -143,10 +143,6 @@ public:
ABIFunctions abiFunctions();
/// @returns code that stores @param _message for revert reason
/// if m_revertStrings is debug.
std::string revertReasonIfDebug(std::string const& _message = "");
RevertStrings revertStrings() const { return m_revertStrings; }
std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
+7 -8
View File
@@ -839,7 +839,7 @@ string IRGenerator::deployCode(ContractDefinition const& _contract)
string IRGenerator::callValueCheck()
{
return "if callvalue() { " + m_context.revertReasonIfDebug("Ether sent to non-payable function") + " }";
return "if callvalue() { " + m_utils.revertReasonIfDebugFunction("Ether sent to non-payable function") + "() }";
}
string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
@@ -885,8 +885,8 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
// we revert.
delegatecallCheck =
"if iszero(called_via_delegatecall) { " +
m_context.revertReasonIfDebug("Non-view function of library called without DELEGATECALL") +
" }";
m_utils.revertReasonIfDebugFunction("Non-view function of library called without DELEGATECALL") +
"() }";
}
templ["delegatecallCheck"] = delegatecallCheck;
templ["callValueCheck"] = (type->isPayable() || _contract.isLibrary()) ? "" : callValueCheck();
@@ -937,12 +937,11 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
t("fallback", fallbackCode);
}
else
t(
"fallback",
t("fallback", (
etherReceiver ?
m_context.revertReasonIfDebug("Unknown signature and no fallback defined") :
m_context.revertReasonIfDebug("Contract does not have fallback nor receive functions")
);
m_utils.revertReasonIfDebugFunction("Unknown signature and no fallback defined") :
m_utils.revertReasonIfDebugFunction("Contract does not have fallback nor receive functions")
) + "()");
return t.render();
}
@@ -2433,7 +2433,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
}
Whiskers templ(R"(
if iszero(extcodesize(<address>)) { <revertNoCode> }
if iszero(extcodesize(<address>)) { <revertNoCode>() }
// storage for arguments and returned data
let <pos> := <allocateUnbounded>()
@@ -2458,7 +2458,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
<?+retVars> <retVars> := </+retVars> <abiDecode>(<pos>, add(<pos>, <returnSize>))
}
)");
templ("revertNoCode", m_context.revertReasonIfDebug("Target contract does not contain code"));
templ("revertNoCode", m_utils.revertReasonIfDebugFunction("Target contract does not contain code"));
templ("pos", m_context.newYulVariable());
templ("end", m_context.newYulVariable());
if (_functionCall.annotation().tryCall)