-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Top level objects in files without contracts are not included in the compilation artifacts #1646
Comments
I think this is expected behavior - if there is no library and no contract, then what do you want from the compilation artifacts? Free standing functions are not included in the ABI. |
exactly, solc only emits a I've though about this after @mds1 brought it up, we could generate an empty artifact with only the AST set for files like this, but I'm not a fan of that tbh. it's potentially unsound because the general assumption is I'm not sure why slither expects a file to begin with, judging from the logs, it parses the ast and maps that to a file structure: I will investigate this |
The issue is that with forge's compilation artifacts structure the data associated with top-level objects are missing (unless the top level objects are in a file that has a contract). In this example, when I run "/tmp/tests_foundry/src/top_level.sol": {
"lastModificationDate": 1653035419629,
"contentHash": "6e6c34f5c3278ef99f3777de8ddf2601",
"sourceName": "src/top_level.sol",
"solcConfig": {
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"bytecodeHash": "ipfs"
},
"outputSelection": {
"*": {
"": [
"ast"
],
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc"
]
}
},
"evmVersion": "london"
}
},
"imports": [],
"versionRequirement": null,
"artifacts": {}
}, So I would expect to have access to the ast/devdoc/userdoc of the content in It's also unexpected imho that the top-level object artifacts are available if the objects are in a file with a contract, and are not available otherwise. I think that anything that can generate Solidity artifacts (ast/doc/etc ..) should be available in some format in the compilation artifacts. |
For info, the way hardhat handles it, is that it will create, per compilation unit, a |
I get it now, thanks. this should be an easy fix and I'm on it now. |
@montyly can you check if this works now on latest |
closing this as we emit artifacts for sol files without contract definitions now |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
No response
What command(s) is the bug in?
No response
Operating System
No response
Describe the bug
Hey,
If a foundry codebase has a file that contains only top-level objects without contract, foundry does not generate their compilation artifacts.
For example: (after
foundry init
):Running
forge build
will not generate a json file inout/free.sol/
.However by adding an empty contract to
top_level.sol
:Running
forge build
will generate a json file inout/free.sol/T.json
.This prevent third-party tools (such as Slither) to work on such codebase.
Related: crytic/crytic-compile#271
The text was updated successfully, but these errors were encountered: