mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prevent libraries from being called.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user