Skip to content
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

Can't analysis import contained contracts #1708

Open
ahmedrafat880 opened this issue Nov 23, 2022 · 4 comments
Open

Can't analysis import contained contracts #1708

ahmedrafat880 opened this issue Nov 23, 2022 · 4 comments

Comments

@ahmedrafat880
Copy link

I followed this tutorial : https://mythril-classic.readthedocs.io/en/develop/tutorial.html

and I use the following command :

myth analyze contract01 --solc-json json.json

but I get a python error.

Here's json.json content:

{ "remappings": [ "@openzeppelin/contracts/token/PRC20/=node_modules/PRC20" ], }
Here's contract01 content:

`
import "@openzeppelin/contracts/token/PRC20/PRC20.sol";

contract Nothing is PRC20{
string x_0 = "";

bytes3 x_1 = "A";

bytes5 x_2 = "E";

bytes5 x_3 = "";

bytes3 x_4 = "I";

bytes3 x_5 = "U";

bytes3 x_6 = "O";

bytes3 x_7 = "0";

bytes3 x_8 = "U";

bytes3 x_9 = "U";
function stringCompare(string memory a, string memory b) internal pure returns (bool) {
    if(bytes(a).length != bytes(b).length) {
        return false;
    } else {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

function nothing(string memory g_0, bytes3 g_1, bytes5 g_2, bytes5 g_3, bytes3 g_4, bytes3 g_5, bytes3 g_6, bytes3 g_7, bytes3 g_8, bytes3 g_9, bytes3 g_10, bytes3 g_11) public view returns (bool){
    if (!stringCompare(g_0, x_0)) return false;

    if (g_1 != x_1) return false;

    if (g_2 != x_2) return false;

    if (g_3 != x_3) return false;

    if (g_4 != x_4) return false;

    if (g_5 != x_5) return false;

    if (g_6 != x_6) return false;

    if (g_7 != x_7) return false;

    if (g_8 != x_8) return false;

    if (g_9 != x_9) return false;

    if (g_10 != x_9) return false;

    if (g_11 != x_9) return false;

    return true;

}

}
`

Here's error I get :

File "/usr/local/lib/python3.8/dist-packages/mythril/interfaces/cli.py", line 938, in parse_args_and_execute address = load_code(disassembler, args) File "/usr/local/lib/python3.8/dist-packages/mythril/interfaces/cli.py", line 693, in load_code address, _ = disassembler.load_from_solidity( File "/usr/local/lib/python3.8/dist-packages/mythril/mythril/mythril_disassembler.py", line 175, in load_from_solidity self.sigs.import_solidity_file( File "/usr/local/lib/python3.8/dist-packages/mythril/support/signatures.py", line 245, in import_solidity_file solc_json = get_solc_json(file_path, solc_binary, solc_settings_json) File "/usr/local/lib/python3.8/dist-packages/mythril/ethereum/util.py", line 56, in get_solc_json settings = json.load(f) File "/usr/lib/python3.8/json/__init__.py", line 293, in load return loads(fp.read(), File "/usr/lib/python3.8/json/__init__.py", line 357, in loads return _default_decoder.decode(s) File "/usr/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.8/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 1 (char 79)

@norhh
Copy link
Collaborator

norhh commented Nov 23, 2022

Nice catch! You'll have to remove the comma at the end. It should be

{
"remappings": [ "@openzeppelin/contracts/token/PRC20/=node_modules/PRC20/" ]
}

Make sure that the file PRC20.sol is in your remapped directory (i.e. node_modules/PRC20/)

@ahmedrafat880
Copy link
Author

I already removed the , but tells that node_modules/PRC20PRC20.sol is not there

@ahmedrafat880
Copy link
Author

I also installed npm i @openzeppelin/contracts

But get me this error : ParserError: Source "/node_modules/PRC20PRC20.sol" not found: File not found. Searched the following locations: "".

@norhh
Copy link
Collaborator

norhh commented Nov 24, 2022

There is no library named PRC20. It's just a spoof of ERC20. You likely missed a / at the end of the remapping :
"remappings": [ "@openzeppelin/contracts/token/PRC20/=node_modules/PRC20/" ].
You can change it to some existing import in openzeppelin or your own custom import and then run the file. I'll add a new example to the tutorial meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants