diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index e010b8efe..6af4fff6e 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -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) diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index b80e892da..2e58c1ac4 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -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() { () } + })"); + tmpl("panic", m_utils.panicFunction(PanicCode::EtherToNonPayable)); + return tmpl.render(); } string IRGenerator::dispatchRoutine(ContractDefinition const& _contract) diff --git a/libsolutil/ErrorCodes.h b/libsolutil/ErrorCodes.h index bc11041a6..f9ff9c69b 100644 --- a/libsolutil/ErrorCodes.h +++ b/libsolutil/ErrorCodes.h @@ -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