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

Echidna printer: improve constant function detection #437

Merged
merged 9 commits into from
Apr 17, 2020

Conversation

montyly
Copy link
Member

@montyly montyly commented Apr 10, 2020

Heuristic:

montyly added 7 commits April 10, 2020 13:58
Fix incorrect compiler version access
Remove dupplicate constant values
- Add types to constant
- Convert the type in case of explicit type conversion (ex: address(0x41))
- Add constructors info
- Add impacts/is_impacted_by info
@montyly
Copy link
Member Author

montyly commented Apr 14, 2020

In addition, this PR adds:

  • The type for the constant used. If there is an explicit type conversion (ex : address(0x41)) , the constant is the destination's type (ex : 0x41, address ):
    "constants_used": {
        "Ownable": {
            "transferOwnership(address)": [
                [
                    {
                        "value": 0,
                        "type": "address"
                    }
                ]
            ]
        },
  • The constructor of each contract
    "constructors": {
        "Ownable": "Ownable()",
        "BasicToken": "Ownable()",
  • The list of functions impacted by a function (if f write a state variable read by g, then f impacts g). The output contains both impacts and is_impacted_by to simplify lookup for third-parties tools.
            "approve(address,uint256)": {
                "impacts": [
                    "transferFrom(address,address,uint256)",
                    "approve(address,uint256)",
                    "allowance(address,address)"
                ],
                "is_impacted_by": [
                    "transferFrom(address,address,uint256)",
                    "approve(address,uint256)",
                ]
            },

@montyly
Copy link
Member Author

montyly commented Apr 14, 2020

I added two additional info:

  • have_external_calls: list of functions that call external contracts
  • call_a_parameter: if a parameter is directly use as an external call.

Example:

contract C{
    function test() public;
}

contract D{
    C c;

    function f() public{
        c.test();
    }

    function f2(address addr) public{
        C(addr).test();
    }

}

Will give

    "have_external_calls": {
        "D": [
            "f()",
            "f2(address)"
        ]
    },
    "call_a_parameter": {
        "D": [
            {
                "function": "f2(address)",
                "parameter_idx": 0,
                "signature": "test()"
            }
        ]

Note: "signature" will be null for low level calls

@montyly
Copy link
Member Author

montyly commented Apr 14, 2020

Added:

  • use_balance: list of functions using balance
contract C{

    function test() public{
        address(this).balance;
    }
}
    "use_balance": {
        "C": [
            "test()"
        ]
    }

Given the number of new features of this printer, the json must be documented.

@montyly montyly merged commit ce2199a into dev Apr 17, 2020
@montyly montyly deleted the dev-echidna-printer-improvements branch April 17, 2020 11:11
@montyly montyly restored the dev-echidna-printer-improvements branch April 17, 2020 11:12
@montyly montyly deleted the dev-echidna-printer-improvements branch April 17, 2020 11:12
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

Successfully merging this pull request may close these issues.

2 participants