Merge pull request #6042 from ethereum/fixEventSignatureInLibraries

Fix event signature in libraries
This commit is contained in:
chriseth 2019-02-20 14:59:21 +01:00 committed by GitHub
commit 03b8fcd7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -13,6 +13,7 @@ Bugfixes:
* ABIEncoderV2: Fix internal error related to bare delegatecall.
* ABIEncoderV2: Fix internal error related to ecrecover.
* ABIEncoderV2: Fix internal error related to mappings as library parameters.
* ABIEncoderV2: Fix invalid signature for events containing structs emitted in libraries.
* Inline Assembly: Proper error message for missing variables.
* SMTChecker: Fixed crash when used with fixed-sized arrays.
* Yul: Properly detect name clashes with functions before their declaration.

View File

@ -3062,7 +3062,8 @@ string FunctionType::externalSignature() const
solAssert(false, "Invalid function type for requesting external signature.");
}
bool const inLibrary = dynamic_cast<ContractDefinition const&>(*m_declaration->scope()).isLibrary();
// "inLibrary" is only relevant if this is not an event.
bool const inLibrary = kind() != Kind::Event && dynamic_cast<ContractDefinition const&>(*m_declaration->scope()).isLibrary();
FunctionTypePointer external = interfaceFunctionType();
solAssert(!!external, "External function type requested.");
auto parameterTypes = external->parameterTypes();

View File

@ -444,6 +444,7 @@ BOOST_AUTO_TEST_CASE(structs)
);
BOOST_CHECK(callContractFunction("f()") == encoded);
REQUIRE_LOG_DATA(encoded);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("e(uint16,(uint16,uint16,(uint64[2])[],uint16))")));
)
}

View File

@ -14097,6 +14097,35 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_arrayOfStrings)
BOOST_CHECK_EQUAL(m_logs[0].topics[1], dev::keccak256(asString(arrayEncoding)));
}
BOOST_AUTO_TEST_CASE(event_signature_in_library)
{
// This tests a bug that was present where the "internal signature"
// for structs was also used for events.
char const* sourceCode = R"(
pragma experimental ABIEncoderV2;
library L {
struct S {
uint8 a;
int16 b;
}
event E(S indexed, S);
function f() internal {
S memory s;
emit E(s, s);
}
}
contract C {
constructor() public {
L.f();
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 2);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E((uint8,int16),(uint8,int16))")));
}
BOOST_AUTO_TEST_CASE(abi_encode_with_selector)
{
char const* sourceCode = R"(