-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify contracts using Solc standard JSON input #416
Merged
alcuadrado
merged 7 commits into
NomicFoundation:development
from
DeepitAG:verify-using-solc-input
Apr 1, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9687f40
Add fixture project and test to show flattened source with name clash
35cf88a
Increase timeout in plugin tests to handle testnet slow response times
2e0cdc5
Add load/save functions for Solc standard JSON input
09c95df
Remove only filter used for debug from test section
97277d7
Get the Solc input from Buidler cache
3695e1c
Add support for Etherscan full contract name
ed8d5d0
Merge branch 'development' of github.com:nomiclabs/buidler into verif…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions
1
packages/buidler-core/test/fixture-projects/contracts-nameclash-project/buidler.config.js
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 @@ | ||
module.exports = {}; |
3 changes: 3 additions & 0 deletions
3
packages/buidler-core/test/fixture-projects/contracts-nameclash-project/contracts/A.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,3 @@ | ||
pragma solidity ^0.5.1 | ||
import "./B.sol"; | ||
contract A {} |
3 changes: 3 additions & 0 deletions
3
packages/buidler-core/test/fixture-projects/contracts-nameclash-project/contracts/B.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,3 @@ | ||
pragma solidity ^0.5.1 | ||
import "./C.sol"; | ||
contract B {} |
2 changes: 2 additions & 0 deletions
2
packages/buidler-core/test/fixture-projects/contracts-nameclash-project/contracts/C.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,2 @@ | ||
pragma solidity ^0.5.1 | ||
contract C {}; |
2 changes: 2 additions & 0 deletions
2
...ges/buidler-core/test/fixture-projects/contracts-nameclash-project/contracts/folder/C.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,2 @@ | ||
pragma solidity ^0.5.1 | ||
contract C {}; |
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
16 changes: 16 additions & 0 deletions
16
packages/buidler-etherscan/test/buidler-project/contracts/ReentrancyGuard.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,16 @@ | ||
pragma solidity 0.5.15; | ||
|
||
contract ReentrancyGuard { | ||
uint256 public guardCounter; | ||
|
||
constructor() internal { | ||
guardCounter = 1; | ||
} | ||
|
||
modifier nonReentrant() { | ||
guardCounter += 1; | ||
uint256 localCounter = guardCounter; | ||
_; | ||
require(localCounter == guardCounter, "re-entered"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/buidler-etherscan/test/buidler-project/contracts/TestContract.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
2 changes: 1 addition & 1 deletion
2
packages/buidler-etherscan/test/buidler-project/contracts/TestContract1.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pragma solidity 0.5.1; | ||
pragma solidity 0.5.15; | ||
|
||
contract TestContract1 { | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
packages/buidler-etherscan/test/buidler-project/contracts/TestReentrancyGuardImported.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,10 @@ | ||
pragma solidity 0.5.15; | ||
|
||
import "./imported/ReentrancyGuard.sol"; | ||
|
||
contract TestReentrancyGuardImported is ReentrancyGuard { | ||
|
||
function foo() public nonReentrant returns(uint) { | ||
return 0; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/buidler-etherscan/test/buidler-project/contracts/TestReentrancyGuardLocal.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,10 @@ | ||
pragma solidity 0.5.15; | ||
|
||
import "./ReentrancyGuard.sol"; | ||
|
||
contract TestReentrancyGuardLocal is ReentrancyGuard { | ||
|
||
function foo() public nonReentrant returns(uint) { | ||
return 1; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/buidler-etherscan/test/buidler-project/contracts/imported/ReentrancyGuard.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,32 @@ | ||
pragma solidity 0.5.15; | ||
|
||
/** | ||
* @title Helps contracts guard against reentrancy attacks. | ||
* @author Remco Bloemen <remco@2π.com>, Eenae <alexey@mixbytes.io> | ||
* @dev If you mark a function `nonReentrant`, you should also | ||
* mark it `external`. | ||
*/ | ||
contract ReentrancyGuard { | ||
/// @dev counter to allow mutex lock with only one SSTORE operation | ||
uint256 private _guardCounter; | ||
|
||
constructor() internal { | ||
// The counter starts at one to prevent changing it from zero to a non-zero | ||
// value, which is a more expensive operation. | ||
_guardCounter = 1; | ||
} | ||
|
||
/** | ||
* @dev Prevents a contract from calling itself, directly or indirectly. | ||
* Calling a `nonReentrant` function from another `nonReentrant` | ||
* function is not supported. It is possible to prevent this from happening | ||
* by making the `nonReentrant` function external, and make it call a | ||
* `private` function that does the actual work. | ||
*/ | ||
modifier nonReentrant() { | ||
_guardCounter += 1; | ||
uint256 localCounter = _guardCounter; | ||
_; | ||
require(localCounter == _guardCounter, "re-entered"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/buidler-etherscan/test/buidler-project/contracts/libraries/SafeMath.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pragma solidity 0.5.1; | ||
pragma solidity 0.5.15; | ||
|
||
|
||
library SafeMath { | ||
|
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/artifacts | ||
/cache |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is the only problematic thing I can see, as it imposes the same names for files and contracts.
This could be fixed by doing something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're absolutely right, it's a limitation of this PR.
An idea for handling any use case is extending the
verify-contract
task arguments to accept an optionalcontractFilePath
argument (e.g. contracts/A.sol) to build the complete contract name as${taskArgs.contractFilePath}:${taskArgs.contractName}
; when thecontractFilePath
is not given, the default simplified namecontracts/${taskArgs.contractName}.sol:${taskArgs.contractName}
will be used.Another option could be changing the
contractName
argument of theverify-contract
task to become the full contract name, specified exactly as expected by Etherscan API${contractFilePath}:${contractName}
(e.g. contracts/A.sol:B.sol).IMHO the latter option is slightly preferable even if it changes a bit the semantic of the
contractName
argument of theverify-contract
task.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alcuadrado Does this issue gate merging? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcowgill this issue has been resolved in last commit 3695e1c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@canepat Great, thanks. I thought so but I wanted to confirm that