Skip to content

Incorrect SSA for indirect call to function modifying global state #434

Open
@aaronyoo

Description

@aaronyoo

SSA doesn't track global state modification through indirect call. Consider the following two test cases, one performs the correct behavior but the other doesn't. I have attached screenshots of the resulting SSA IR in graph form

Correct:

pragma solidity >=0.4.16 <0.7.0;
contract Contract {
    int public a;
    function f() public {
        e();
        a += 1;
    }

    function e() public {
        a -= 1;
    }
}

correct

Incorrect:

pragma solidity >=0.4.16 <0.7.0;
pragma solidity >=0.4.16 <0.7.0;
contract Contract {
    int public a;
    function f() public {
        g();
        a += 1;
    }

    function e() public {
        a -= 1;
    }

    function g() public {
        e();
    }
}

image


The correct version uses a phi node to track the alteration to global state through the function call. However, when we add one more layer of indirection, it no longer tracks that alteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingir

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions