diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-15 18:24:53 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-18 01:23:35 +0800 |
commit | ceeb8f4a2b20a54c38792c7451969b660b144246 (patch) | |
tree | af10548952be7dd39b03ba8e5d0064d1f22b5ef0 /libsolidity/codegen | |
parent | b46a14f4a8e128c08336763abf8bbf7c111f464d (diff) | |
download | dexon-solidity-ceeb8f4a2b20a54c38792c7451969b660b144246.tar.gz dexon-solidity-ceeb8f4a2b20a54c38792c7451969b660b144246.tar.zst dexon-solidity-ceeb8f4a2b20a54c38792c7451969b660b144246.zip |
Add payable check for constructor in codegen
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 2e3f5d7f..03296cb2 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -137,6 +137,12 @@ void ContractCompiler::appendInitAndConstructorCode(ContractDefinition const& _c appendConstructor(*constructor); else if (auto c = m_context.nextConstructor(_contract)) appendBaseConstructor(*c); + else + { + // Throw if function is not payable but call contained ether. + m_context << Instruction::CALLVALUE; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } } size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _contract) @@ -184,6 +190,12 @@ void ContractCompiler::appendBaseConstructor(FunctionDefinition const& _construc void ContractCompiler::appendConstructor(FunctionDefinition const& _constructor) { CompilerContext::LocationSetter locationSetter(m_context, _constructor); + if (!_constructor.isPayable()) + { + // Throw if function is not payable but call contained ether. + m_context << Instruction::CALLVALUE; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } // copy constructor arguments from code to memory and then to stack, they are supplied after the actual program if (!_constructor.parameters().empty()) { |