-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
166 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
This file is part of solidity. | ||
solidity is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
solidity is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
/** | ||
* Component that verifies overloads, abstract contracts, function clashes and others | ||
* checks at contract or function level. | ||
*/ | ||
|
||
#include <libsolidity/analysis/PostTypeContractLevelChecker.h> | ||
|
||
#include <libsolidity/ast/AST.h> | ||
#include <libsolutil/FunctionSelector.h> | ||
#include <liblangutil/ErrorReporter.h> | ||
|
||
using namespace std; | ||
using namespace solidity; | ||
using namespace solidity::langutil; | ||
using namespace solidity::frontend; | ||
|
||
bool PostTypeContractLevelChecker::check(SourceUnit const& _sourceUnit) | ||
{ | ||
bool noErrors = true; | ||
for (auto* contract: ASTNode::filteredNodes<ContractDefinition>(_sourceUnit.nodes())) | ||
if (!check(*contract)) | ||
noErrors = false; | ||
return noErrors; | ||
} | ||
|
||
bool PostTypeContractLevelChecker::check(ContractDefinition const& _contract) | ||
{ | ||
solAssert( | ||
_contract.annotation().creationCallGraph.set() && | ||
_contract.annotation().deployedCallGraph.set(), | ||
"" ); | ||
|
||
map<uint32_t, map<string, SourceLocation>> errorHashes; | ||
for (ErrorDefinition const* error: _contract.interfaceErrors()) | ||
{ | ||
string signature = error->functionType(true)->externalSignature(); | ||
uint32_t hash = selectorFromSignature32(signature); | ||
if (!errorHashes[hash].empty() && !errorHashes[hash].count(signature)) | ||
{ | ||
SourceLocation& otherLocation = errorHashes[hash].begin()->second; | ||
m_errorReporter.typeError( | ||
4883_error, | ||
error->nameLocation(), | ||
SecondarySourceLocation{}.append("This error has a different signature but the same hash: ", otherLocation), | ||
string("Error signature hash collision for ") + error->functionType(true)->externalSignature() | ||
); | ||
} | ||
else | ||
errorHashes[hash][signature] = error->location(); | ||
} | ||
|
||
return Error::containsOnlyWarnings(m_errorReporter.errors()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
This file is part of solidity. | ||
solidity is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
solidity is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
/** | ||
* Component that verifies properties at contract level, after the type checker has run. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <libsolidity/ast/ASTForward.h> | ||
|
||
namespace solidity::langutil | ||
{ | ||
class ErrorReporter; | ||
} | ||
|
||
namespace solidity::frontend | ||
{ | ||
|
||
/** | ||
* Component that verifies properties at contract level, after the type checker has run. | ||
*/ | ||
class PostTypeContractLevelChecker | ||
{ | ||
public: | ||
explicit PostTypeContractLevelChecker(langutil::ErrorReporter& _errorReporter): | ||
m_errorReporter(_errorReporter) | ||
{} | ||
|
||
/// Performs checks on the given source ast. | ||
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings | ||
bool check(SourceUnit const& _sourceUnit); | ||
|
||
private: | ||
/// Performs checks on the given contract. | ||
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings | ||
bool check(ContractDefinition const& _contract); | ||
|
||
langutil::ErrorReporter& m_errorReporter; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/libsolidity/syntaxTests/errors/hash_collision_external.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
library L { | ||
error gsf(); | ||
} | ||
contract test { | ||
error tgeo(); | ||
function f(bool a) public { | ||
if (a) | ||
revert L.gsf(); | ||
else | ||
revert tgeo(); | ||
} | ||
} | ||
// ---- | ||
// TypeError 4883: (57-61): Error signature hash collision for tgeo() |