Remove low-level log functions.

This commit is contained in:
chriseth
2020-10-22 17:50:14 +02:00
parent c20beaf2c9
commit bfc8e26007
15 changed files with 61 additions and 295 deletions
+31 -134
View File
@@ -1177,139 +1177,6 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
)
}
BOOST_AUTO_TEST_CASE(log0)
{
char const* sourceCode = R"(
contract test {
function a() public {
log0(bytes32(uint256(1)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
callContractFunction("a()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_CHECK_EQUAL(numLogTopics(0), 0);
)
}
BOOST_AUTO_TEST_CASE(log1)
{
char const* sourceCode = R"(
contract test {
function a() public {
log1(bytes32(uint256(1)), bytes32(uint256(2)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
callContractFunction("a()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 1);
BOOST_CHECK_EQUAL(logTopic(0, 0), h256(u256(2)));
)
}
BOOST_AUTO_TEST_CASE(log2)
{
char const* sourceCode = R"(
contract test {
function a() public {
log2(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
callContractFunction("a()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
for (unsigned i = 0; i < 2; ++i)
BOOST_CHECK_EQUAL(logTopic(0, i), h256(u256(i + 2)));
)
}
BOOST_AUTO_TEST_CASE(log3)
{
char const* sourceCode = R"(
contract test {
function a() public {
log3(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
callContractFunction("a()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 3);
for (unsigned i = 0; i < 3; ++i)
BOOST_CHECK_EQUAL(logTopic(0, i), h256(u256(i + 2)));
)
}
BOOST_AUTO_TEST_CASE(log4)
{
char const* sourceCode = R"(
contract test {
function a() public {
log4(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)), bytes32(uint256(5)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
callContractFunction("a()");
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 4);
for (unsigned i = 0; i < 4; ++i)
BOOST_CHECK_EQUAL(logTopic(0, i), h256(u256(i + 2)));
)
}
BOOST_AUTO_TEST_CASE(log_in_constructor)
{
char const* sourceCode = R"(
contract test {
constructor() {
log1(bytes32(uint256(1)), bytes32(uint256(2)));
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(1)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 1);
BOOST_CHECK_EQUAL(logTopic(0, 0), h256(u256(2)));
)
}
BOOST_AUTO_TEST_CASE(selfdestruct)
{
char const* sourceCode = R"(
@@ -1883,7 +1750,12 @@ BOOST_AUTO_TEST_CASE(event)
function deposit(bytes32 _id, bool _manually) public payable {
if (_manually) {
bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f;
log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id);
uint value = msg.value;
address sender = msg.sender;
assembly {
mstore(0, value)
log3(0, 0x20, s, sender, _id)
}
} else {
emit Deposit(msg.sender, _id, msg.value);
}
@@ -1937,6 +1809,31 @@ BOOST_AUTO_TEST_CASE(event_emit)
)
}
BOOST_AUTO_TEST_CASE(event_constructor)
{
char const* sourceCode = R"(
contract ClientReceipt {
event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
constructor() {
emit Deposit(msg.sender, bytes32("abc"), 7);
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
BOOST_REQUIRE_EQUAL(numLogs(), 1);
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(7)));
BOOST_REQUIRE_EQUAL(numLogTopics(0), 3);
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Deposit(address,bytes32,uint256)")));
BOOST_CHECK_EQUAL(logTopic(0, 1), h256(m_sender, h256::AlignRight));
BOOST_CHECK_EQUAL(logTopic(0, 2), h256(string{"abc"}, h256::FromBinary, h256::AlignLeft));
)
}
BOOST_AUTO_TEST_CASE(event_no_arguments)
{
char const* sourceCode = R"(
@@ -1,40 +0,0 @@
pragma experimental SMTChecker;
contract C {
function f() external {
bytes32 t1 = bytes32(uint256(0x1234));
log0(t1);
log1(t1, t1);
log2(t1, t1, t1);
log3(t1, t1, t1, t1);
log4(t1, t1, t1, t1, t1);
}
function g_data() pure internal returns (bytes32) {
assert(true);
return bytes32(uint256(0x5678));
}
function g() external {
// To test that the function call is actually visited.
log0(g_data());
log1(g_data(), g_data());
log2(g_data(), g_data(), g_data());
log3(g_data(), g_data(), g_data(), g_data());
log4(g_data(), g_data(), g_data(), g_data(), g_data());
}
bool x = true;
function h_data() view internal returns (bytes32) {
assert(x);
}
function h() external {
// To test that the function call is actually visited.
x = false;
log0(h_data());
log1(h_data(), h_data());
log2(h_data(), h_data(), h_data());
log3(h_data(), h_data(), h_data(), h_data());
log4(h_data(), h_data(), h_data(), h_data(), h_data());
}
}
// ----
// Warning 6321: (655-662): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
// Warning 6328: (668-677): CHC: Assertion violation happens here.
@@ -0,0 +1,15 @@
contract C {
function f() public {
log0;
log1;
log2;
log3;
log4;
}
}
// ----
// DeclarationError 7576: (38-42): Undeclared identifier.
// DeclarationError 7576: (46-50): Undeclared identifier.
// DeclarationError 7576: (54-58): Undeclared identifier.
// DeclarationError 7576: (62-66): Undeclared identifier.
// DeclarationError 7576: (70-74): Undeclared identifier.
@@ -6,4 +6,4 @@ contract c {
}
}
// ----
// DeclarationError 7576: (101-105): Undeclared identifier. Did you mean "log8", "log9", "log0", "log1", "log2", "log3" or "log4"?
// DeclarationError 7576: (101-105): Undeclared identifier. Did you mean "log8" or "log9"?
@@ -12,6 +12,6 @@ contract c {
// DeclarationError 7576: (52-53): Undeclared identifier.
// DeclarationError 7576: (56-60): Undeclared identifier. Did you mean "long"?
// DeclarationError 7576: (70-71): Undeclared identifier.
// DeclarationError 7576: (74-78): Undeclared identifier. Did you mean "long", "log0", "log1", "log2", "log3" or "log4"?
// DeclarationError 7576: (74-78): Undeclared identifier. Did you mean "long"?
// DeclarationError 7576: (88-89): Undeclared identifier.
// DeclarationError 7576: (92-96): Undeclared identifier. Did you mean "long"?
@@ -1,13 +1,13 @@
contract C {
function f() public pure {
(bool a,) = address(this).call(abi.encode(address(this).delegatecall, super));
(a,) = address(this).delegatecall(abi.encode(log0, tx, mulmod));
(a,) = address(this).delegatecall(abi.encode(block, tx, mulmod));
a;
}
}
// ----
// TypeError 2056: (94-120): This type cannot be encoded.
// TypeError 2056: (122-127): This type cannot be encoded.
// TypeError 2056: (184-188): This type cannot be encoded.
// TypeError 2056: (190-192): This type cannot be encoded.
// TypeError 2056: (194-200): This type cannot be encoded.
// TypeError 2056: (184-189): This type cannot be encoded.
// TypeError 2056: (191-193): This type cannot be encoded.
// TypeError 2056: (195-201): This type cannot be encoded.