aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-11-14 19:58:04 +0800
committerchriseth <chris@ethereum.org>2018-01-19 23:27:44 +0800
commit6807010dc7864500d89a833e4f6e7f338e58b948 (patch)
tree90fa3b3d59ae85a752dc611b6a32e24fe91e9efb /test/libsolidity
parent33723c457a99213a545006162112b55351da5fe4 (diff)
downloaddexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar.gz
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar.bz2
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar.lz
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar.xz
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.tar.zst
dexon-solidity-6807010dc7864500d89a833e4f6e7f338e58b948.zip
Prevent libraries from being called.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index f5f7e64a..5b98d979 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3543,6 +3543,39 @@ BOOST_AUTO_TEST_CASE(library_call_in_homestead)
ABI_CHECK(callContractFunction("sender()"), encodeArgs(u160(m_sender)));
}
+BOOST_AUTO_TEST_CASE(library_call_protection)
+{
+ // This tests code that reverts a call if it is a direct call to a library
+ // as opposed to a delegatecall.
+ char const* sourceCode = R"(
+ library Lib {
+ struct S { uint x; }
+ // a direct call to this should revert
+ function np(S storage s) public returns (address) { s.x = 3; return msg.sender; }
+ // a direct call to this is fine
+ function v(S storage) public view returns (address) { return msg.sender; }
+ // a direct call to this is fine
+ function pu() public pure returns (uint) { return 2; }
+ }
+ contract Test {
+ Lib.S public s;
+ function np() public returns (address) { return Lib.np(s); }
+ function v() public view returns (address) { return Lib.v(s); }
+ function pu() public pure returns (uint) { return Lib.pu(); }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ ABI_CHECK(callContractFunction("np(Lib.S storage)"), encodeArgs());
+ ABI_CHECK(callContractFunction("v(Lib.S storage)"), encodeArgs(u160(m_sender)));
+ ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("s()"), encodeArgs(0));
+ ABI_CHECK(callContractFunction("np()"), encodeArgs(u160(m_sender)));
+ ABI_CHECK(callContractFunction("s()"), encodeArgs(3));
+ ABI_CHECK(callContractFunction("v()"), encodeArgs(u160(m_sender)));
+ ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
+}
+
BOOST_AUTO_TEST_CASE(store_bytes)
{
// this test just checks that the copy loop does not mess up the stack