You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: create verifiable Standard JSON for projects with external files (#36)
- Resolvesfoundry-rs/foundry#5307
Currently, Foundry projects containing Solidity files outside the
project root directory face contract verification failures on block
explorers. This issue occurs from the Standard JSON including unusable
source paths for external files, represented as full absolute paths in
their host file systems.
This PR addresses the issue by improving the path conversion process.
For files not located under the project root directory, relative parent
directory paths (`..`) are used, enabling the compiler to find the files
within the json.
Steps to reproduce the issue are detailed in the linked issue above.
Additionally, a test case representing that scenario has been added.
With this change, the json created in the reproduction scenario will
appear as follows:
```json
{
"language": "Solidity",
"sources": {
"src/Counter.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n\nimport \"@remapped/Parent.sol\";\n\ncontract Counter {\n uint256 public number;\n\n function setNumber(uint256 newNumber) public {\n number = newNumber;\n }\n\n function increment() public {\n number++;\n }\n}\n"
},
"../remapped/Parent.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\nimport \"./Child.sol\";\n"
},
"../remapped/Child.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n"
}
},
"settings": {
"remappings": [
"@remapped/=../remapped/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"": [
"ast"
],
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
]
}
},
"evmVersion": "paris",
"libraries": {}
}
}
```
The source path is now aligned with the project root.
I have successfully deployed and verified the contract on Etherscan
using this change.
`forge create --rpc-url "wss://ethereum-holesky.publicnode.com" --verify
--verifier-url "https://api-holesky.etherscan.io/api"
--etherscan-api-key "..." --private-key "..." src/Counter.sol:Counter`
https://holesky.etherscan.io/address/0xe08c332706185521fc8bc2b224f67adf814b1880#code
0 commit comments