-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Absolute paths in contract metadata #4119
Comments
@gnidan, @haltman-at, @eggplantzzz would you be up for a call with Solidity team on this topic? We're very interested in solving this problem and would like to hear if there are any obstacles and how we could help. |
@cameel getting on a call sounds great. How should I reach out to schedule this? |
We could discuss details on the #solc-tooling channel. Everyone is there from our side and any others from your team are welcome too :) |
Here's my summary from the call. Sorry if I missed something. My notes were a bit chaotic unfortunately so please correct me if something's not right. The main takeaways are in bold.
|
So, as to how this could actually be done -- we actually already do something very similar with Vyper! When compiling Vyper, we remove the contracts directory, and treat it as the root directory. (This is for technical reasons involving how Vyper handles imports that I'm going to skip going into right now.) Specifically, this happens in the collectSources function here; this is used for both Solidity and Vyper, but that third argument, So, this should be a fairly simple change. Say we rename the variable from So yay, we already mostly have machinery for this! |
Appreciate the excellent notes @cameel 🙇 |
OK, closing this now that the "project:/" fix is out. (We changed it from double-slash to single-slash in #4157 as double-slash was causing problems.) Let us know if there's more to do here. |
Thanks! I did some testing to see if it handles all paths correctly and found a few issues. I think all of these are relatively minor problems:
Another one I did not report: the way |
Fantastic, this makes verification so much easier, assuming the buidler is using the latest truffle version including the |
@aaronmboyd Yes, note we ultimately changed it to |
Issue
When compiling a Solidity project, Truffle gives the compiler absolute paths of all source files. Relative paths are used only for source located in libraries found by the resolver (e.g. when importing from
node_modules/
) but thefs
module of the resolver sometimes creates absolute paths too.The use of absolute paths to refer to Solidity source files makes it harder to reproduce the same bytecode on different machines because they are included in contract metadata,the hash of which is always appended at the end of the bytecode. It also potentially leaks user's local information (the name of the home directory if the contract is stored there).
Truffle uses Standard JSON, which gives it complete control over paths in compiler's VFS. The only real constraint is that they should match imports. Using relative paths for files from main project directory should be completely doable according to my knowledge.
There are two potential problems:
I see several ways to deal with them, depending on how backwards-compatible this change needs to be:
Context
We're also currently working on solving this problem in the Solidity compiler (ethereum/solidity#11408, ethereum/solidity#11409, ethereum/solidity#11410). Unfortunately this will only help people who use the CLI. Truffle's use of Standard JSON mode isolates it from such changes as it's the path resolver that determines paths here.
This problem is also a direct cause of #1621 (and trufflesuite/truffle-compile#77).
Steps to Reproduce
Expected Behavior
/tmp/path-test/contracts/C.sol
should not be present anywhere in metadata.contracts/C.sol
should be there instead.@openzeppelin/contracts/utils/Arrays.sol
instead. Otherwise it's possible for the same file to end up under two different names in the JSON input.node_modules/@openzeppelin/contracts/utils/Arrays.sol
because that's how the compiler would resolve../node_modules/@openzeppelin/contracts/utils/Arrays.sol
(which is a special, relative import).Actual Results
Absolute paths present in metadata.
Environment
The text was updated successfully, but these errors were encountered: