sbip-sg / solc-json-parser

A Powerful AST Parser for Solidity
12 stars 1 forks source link

Fail to parse the program with `solc` < 0.4.12 #57

Closed thanhtoantnt closed 1 year ago

thanhtoantnt commented 1 year ago

Program

pragma solidity ^0.4.2;

contract SimpleDAO { mapping (address => uint) public credit;

function donate(address to) payable { credit[to] += msg.value; }

function withdraw(uint amount) { if (credit[msg.sender]>= amount) { // REENTRANCY bool res = msg.sender.call.value(amount)(); credit[msg.sender]-=amount; } }

function queryCredit(address to) returns (uint){ return credit[to]; } }



# Command 
- Running the program in `Smart-Fuzz`
- `python main.py simple_dao.sol  -t 20000 -r --enable-abstract-rewriting --use-dependency-graph --rust-evm -q -j4 --reentrancy --reentrancy-high-sensitive`
YoHoSo commented 1 year ago

SolcAST depends on solcx package, which supports solidity>=0.4.11. In our SolcAST, if version is not specified, given this line, we will treat pragma solidity ^0.4.2; as 0.4.2, thus causing the failure.

thanhtoantnt commented 1 year ago

@YoungHS-NUS Do you have any suggestions for dealing with solidity < 0.4.11? We may get these contracts in some old benchmarks.

YoHoSo commented 1 year ago

For the moment, I don't have any good suggestions. Maybe Chan Li has some insight on this issue.

minhhn2910 commented 1 year ago

Arguments passed to the lib print(" SolidityAst: Received args ", contract_source_path, version, retry_num, solc_options)

pragma solidity ^0.4.2;
contract SimpleDAO {
....
}
 0.4.11 None {}
Traceback (most recent call last):
    ast = SolidityAst(flatten_source, solc_version, solc_options=solc_options)
  File "/home/minh/Documents/github/solc-json-parser/solc_json_parser/parser.py", line 260, in __init__
    self.contracts_dict: Dict = self._parse()
  File "/home/minh/Documents/github/solc-json-parser/solc_json_parser/parser.py", line 502, in _parse
    self.exported_symbols = symbols_to_ids_from_ast_v7(self.solc_json_ast)
  File "/home/minh/Documents/github/solc-json-parser/solc_json_parser/parser.py", line 157, in symbols_to_ids_from_ast_v7
    syms = [c['ast']['attributes']['exportedSymbols'] for c in ast.values()]
  File "/home/minh/Documents/github/solc-json-parser/solc_json_parser/parser.py", line 157, in <listcomp>
    syms = [c['ast']['attributes']['exportedSymbols'] for c in ast.values()]
KeyError: 'attributes'

The bugs is in other parts of solc_json_parser not the unsupported version . The correct solc version is already passed to this library. @thanhtoantnt When you post an issue, it's better to post the call stacks and error message so people know what is wrong, you post it's too general Fail to parse the program nobody can guess what is the exact problem .

minhhn2910 commented 1 year ago

@YoungHS-NUS can you test with SolidityAst version=0.4.11 to see if the bug can be reproduced ?

YoHoSo commented 1 year ago

No problem, will test it later in afternoon

YoHoSo commented 1 year ago

I have reproduced the error. On the first look, it might come from the compatibility problem from different versions. This part of the code is not written by me, but I will see what I can do to fix it.

YoHoSo commented 1 year ago

For this issue, compiler 0.4.11 output can't support our functionality, 0.4.12 will work in this case. In my experience, I suggest using 0.4.23 to avoid some problems.

minhhn2910 commented 1 year ago

We can force the compiling function from our side to start from 0.4.12 @cl2089

cassc commented 1 year ago

to be handled by updating the compiler version selection strategy in smart-fuzz (https://github.com/sbip-sg/smart-fuzz/issues/182), closing this here.