Move hash collisions checks.

This commit is contained in:
chriseth 2018-11-29 18:33:54 +01:00
parent 6d1644e55c
commit 4f992298c6
3 changed files with 18 additions and 13 deletions

View File

@ -43,6 +43,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
checkConstructor(_contract);
checkFallbackFunction(_contract);
checkExternalTypeClashes(_contract);
checkHashCollisions(_contract);
return Error::containsOnlyWarnings(m_errorReporter.errors());
}
@ -420,3 +421,18 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
"Function overload clash during conversion to external types for arguments."
);
}
void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contract)
{
set<FixedHash<4>> hashes;
for (auto const& it: _contract.interfaceFunctionList())
{
FixedHash<4> const& hash = it.first;
if (hashes.count(hash))
m_errorReporter.typeError(
_contract.location(),
string("Function signature hash collision for ") + it.second->externalSignature()
);
hashes.insert(hash);
}
}

View File

@ -75,6 +75,8 @@ private:
/// Checks that different functions with external visibility end up having different
/// external argument types (i.e. different signature).
void checkExternalTypeClashes(ContractDefinition const& _contract);
/// Checks for hash collisions in external function signatures.
void checkHashCollisions(ContractDefinition const& _contract);
langutil::ErrorReporter& m_errorReporter;
};

View File

@ -93,19 +93,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
for (auto const& n: _contract.subNodes())
n->accept(*this);
// check for hash collisions in function signatures
set<FixedHash<4>> hashes;
for (auto const& it: _contract.interfaceFunctionList())
{
FixedHash<4> const& hash = it.first;
if (hashes.count(hash))
m_errorReporter.typeError(
_contract.location(),
string("Function signature hash collision for ") + it.second->externalSignature()
);
hashes.insert(hash);
}
if (_contract.isLibrary())
checkLibraryRequirements(_contract);