File outside of allowed directories issue
I have zeppelin as a submodule, and I am trying to import a solidity contract from inside of the zeppelin submodule. solc is throwing and error when trying to compile though. File outside of allowed directories.\nimport 'zeppelin-solidity/contracts/ownership/Ownable.sol any idea what's causing this?
Here is my repository https://github.com/aleitner/MineableToken
Current state:
The following works on linux, but not on windows:
# pwd
/tmp
# cat a/b/c/d/a.sol
import "../../x/y/r.sol";
# cat a/b/c/x/y/r.sol
# (empty)
# solc --allow-paths . a/b/c/d/a.sol
Trying to load a/b/x/y/r.sol (boost: "a/b/x/y/r.sol" canonical: "/tmp/a/b/x/y/r.sol" )
Allowed directory: ""
Is allowed: 1
# (compilation successful)
@aleitner I'm having a similar issue when editing a .sol file in <prj-root>/contracts, trying to import from <prj-root>/node_modules/
How did you resolve this?
It was happening when I was trying to include a file that was a git submodule. When I just added the code to the project in a folder rather than as a submodule, the problem went away
@aleitner Did the pathname then exist when it didn't before? I created a symlink and its not working :(
I didn't look too far into how git submodules work, but I reopened the issues because it's still a problem that needs to be addressed.
Solidity checks the canonical path and does not allow symlinks.
The same behaviour occurs even without symlinks, as shown here.
Also when running from inside the node_modules directory:
$ solc ../contracts/CapitalCoin.sol
../contracts/CapitalCoin.sol:2:1: Error: Source "zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.
import 'zeppelin-solidity/contracts/token/StandardToken.sol';
^-----------------------------------------------------------^
$ pwd
/home/ravi/repo/erc20/coin/node_modules
$ readlink -f 'zeppelin-solidity/contracts/token/StandardToken.sol'
/home/ravi/repo/erc20/coin/node_modules/zeppelin-solidity/contracts/token/StandardToken.sol
$
readlink -f shows that there are no symlinks in this case.
import 'zeppelin-solidity/contracts/token/StandardToken.sol' is importing from an absolute path, i.e. from /zeppelin-solidity/contracts/token/StandardToken.sol. Does it work if you change it to relative?
If I prepend ./, I get a different issue:
$ pwd
/home/ravi/repo/erc20/coin/node_modules
$ cat ../contracts/testImport.sol
pragma solidity ^0.4.15;
import './zeppelin-solidity/contracts/token/StandardToken.sol';
$ solc ../contracts/testImport.sol
../contracts/testImport.sol:2:1: Error: Source "../contracts/zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.
import './zeppelin-solidity/contracts/token/StandardToken.sol';
^-------------------------------------------------------------^
$
It's not using the $PWD working directory as ., but rather ../contracts, so it won't find ../contracts/zeppelin-solidity.
What is the design decision behind not allowing a fundamental feature of POSIX filesystems, namely symlinks?
@chriseth I guess there may be a typo. Here import path is preparing for comparison: https://github.com/ethereum/solidity/blob/dc154b4e5661945ca9c98720e097e84729a528be/solc/CommandLineInterface.cpp#L672
And here one of allow-paths is preparing for append: https://github.com/ethereum/solidity/blob/dc154b4e5661945ca9c98720e097e84729a528be/solc/CommandLineInterface.cpp#L713
I suggest to change boost::filesystem::path(path); into boost::filesystem::canonical(path); in the second fragment.
Do you accept?
@ekpyron I think all of these were sorted?
I'm still seeing errors and my setup is like @HaleTom (using node_modules). Given that, and that the issue is still marked as open, I presume it is not yet fixed?
Issue is still present in 0.4.24 compiler version. Can we expect fixing this error?
@Talvish @JuliusBrain could you please explain your set up a little more in detail? The issue is still open because it is not clear whether this is a bug or what the expectation is.
import_remappings will fix this error
compiled_sol = compile_source(contract_source_code, import_remappings=['=./pathDirectory', '-'])
Compiled source code
You can use -rmp on the cmd to remap the path to node_modules:
python oyente.py -rmp openzeppelin-solidity=/full/path/to/node_modules/openzeppelin-solidity -s someContract.sol
If you import other files (e. g. stuff you wrote via import '../../blah') in your code you can use -ap to allow other paths, like:
python oyente.py -ap /full/path/to/the/dir/from/where/you/want/to/import/a/module -s someContract.sol
Ofc, you can also combine both.
I'm following this tutorial! but got error -> "TokenCreate has not been deployed to detected network (network/artifact mismatch)"
while running command =>TokenCreate.deployed().then(inst => { crowdsale = inst } )
is any idea to resolve it ?
@HaleTom @chriseth try this => import "../../node_modules/zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "../../node_modules/zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol";
I hope it'll work for you!
@chriseth When I'm using solc to compile a contract which uses contracts from openzeppelin, I get Error: Source "openzeppelin-solidity/contracts/math/SafeMath.sol" not found: File outside of allowed directories.
@JuliusBrain use solc --allow-paths
what should I put in the --allow-paths to make it work? My project have typical truffle structure.