diff options
author | chriseth <c@ethdev.com> | 2015-10-07 22:41:49 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-07 22:41:49 +0800 |
commit | 8644ad686674edfd2205fb9624521692362d6bfa (patch) | |
tree | 934629f1cd51be7e4c89f57a8ee6b9390d1de08f | |
parent | 5053e153ece086ce3b5e4d9a3324a526306a1579 (diff) | |
parent | 0297a213feeec8b27dcfc107b29228676489f21b (diff) | |
download | dexon-solidity-8644ad686674edfd2205fb9624521692362d6bfa.tar.gz dexon-solidity-8644ad686674edfd2205fb9624521692362d6bfa.tar.zst dexon-solidity-8644ad686674edfd2205fb9624521692362d6bfa.zip |
Merge pull request #118 from chriseth/rejectEtherSentToLibrary
Reject ether sent to library.
-rw-r--r-- | libsolidity/Compiler.cpp | 3 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 6fb09def..7ce2121e 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -260,6 +260,9 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract) m_context << returnTag; appendReturnValuePacker(FunctionType(*fallback).returnParameterTypes(), _contract.isLibrary()); } + else if (_contract.isLibrary()) + // Reject invalid library calls and ether sent to a library. + m_context.appendJumpTo(m_context.errorTag()); else m_context << eth::Instruction::STOP; // function not found diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a17a3be5..56061b0b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5578,6 +5578,29 @@ BOOST_AUTO_TEST_CASE(version_stamp_for_libraries) BOOST_CHECK_EQUAL(runtimeCode[7], int(eth::Instruction::POP)); } +BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) +{ + char const* sourceCode = R"( + library lib {} + contract c { + function f(address x) returns (bool) { + return x.send(1); + } + } + )"; + compileAndRun(sourceCode, 0, "lib"); + Address libraryAddress = m_contractAddress; + compileAndRun(sourceCode, 10, "c"); + BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 10); + BOOST_CHECK_EQUAL(m_state.balance(libraryAddress), 0); + BOOST_CHECK(callContractFunction("f(address)", encodeArgs(u160(libraryAddress))) == encodeArgs(false)); + BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 10); + BOOST_CHECK_EQUAL(m_state.balance(libraryAddress), 0); + BOOST_CHECK(callContractFunction("f(address)", encodeArgs(u160(m_contractAddress))) == encodeArgs(true)); + BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 10); + BOOST_CHECK_EQUAL(m_state.balance(libraryAddress), 0); +} + BOOST_AUTO_TEST_SUITE_END() } |