Return panic code for ether sent to non-payable functions

This commit is contained in:
Alex Beregszaszi 2021-05-24 00:30:37 +01:00
parent 29a995b937
commit b098e2f1a5
3 changed files with 7 additions and 2 deletions

View File

@ -141,7 +141,7 @@ void ContractCompiler::appendCallValueCheck()
{
// Throw if function is not payable but call contained ether.
m_context << Instruction::CALLVALUE;
m_context.appendConditionalRevert(false, "Ether sent to non-payable function");
m_context.appendConditionalPanic(PanicCode::EtherToNonPayable);
}
void ContractCompiler::appendInitAndConstructorCode(ContractDefinition const& _contract)

View File

@ -837,7 +837,11 @@ string IRGenerator::deployCode(ContractDefinition const& _contract)
string IRGenerator::callValueCheck()
{
return "if callvalue() { " + m_utils.revertReasonIfDebugFunction("Ether sent to non-payable function") + "() }";
Whiskers tmpl(R"({
if callvalue() { <panic>() }
})");
tmpl("panic", m_utils.panicFunction(PanicCode::EtherToNonPayable));
return tmpl.render();
}
string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)

View File

@ -26,6 +26,7 @@ enum class PanicCode
{
Generic = 0x00, // generic / unspecified error
Assert = 0x01, // used by the assert() builtin
EtherToNonPayable = 0x02, // ether value sent to non-payable function
UnderOverflow = 0x11, // arithmetic underflow or overflow
DivisionByZero = 0x12, // division or modulo by zero
EnumConversionError = 0x21, // enum conversion error