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

[Draft] SSA IR Fix Phi Handling #1715

Closed
wants to merge 9 commits into from
Closed

[Draft] SSA IR Fix Phi Handling #1715

wants to merge 9 commits into from

Conversation

bsamuels453
Copy link
Contributor

@bsamuels453 bsamuels453 commented Mar 6, 2023

Derived from #1102

This PR changes Phi handling so that Phis are injected at dominance frontiers.

The current implementation adds empty Phi nodes which are later removed and cause variable instances to be missing a definition.

Linked issues:

These changes also improves the ArbitrarySendErc20 detector, which can now detect test case bad2:

function bad2(address from, address to, uint256 am) public {
int_transferFrom(from, to, am);
}

This PR also fixes a previously unknown issue where the existence of a Phi node is incorrectly interpreted as a variable write when variables_written is constructed. This bug introduced some small false positives, so their unit tests needed to be updated.

@bsamuels453 bsamuels453 marked this pull request as draft March 6, 2023 16:10
@0xalpharush
Copy link
Contributor

0xalpharush commented Mar 7, 2023

These changes also improves the ArbitrarySendErc20 detector, which can now detect test case bad2:

I'm not sure it fixed this as the data dependency tests are failing.

@bsamuels453
Copy link
Contributor Author

I'm about go to on a project for a month, so if anyone wants to adopt this PR in the meantime, feel free.

Right now it's failing the data dependency tests; specifically the one for tracking data dependencies through function args.

contract PropagateThroughArguments {
    uint var_tainted;
    uint var_not_tainted;
    uint var_dependant;

    function f(uint user_input) public {
        f2(user_input, 4);
        var_dependant = var_tainted;
    }

    function f2(uint x, uint y) internal {
        uint z = x + 1;
        var_tainted = z;
        var_not_tainted = y;
    }
}

generates:

        Function PropagateThroughArguments.f2(uint256,uint256)
                Expression: z = x + 1
                IRs:
                        TMP_1(uint256) = x_0 + 1
                        z_1(uint256) := TMP_1(uint256)

The ssa IR is missing a phi statement for x_0 = phi(user_input_0)

Normally I believe fix_phi would create these phi statements, so I was trying to port that over for the new SSA generation but running into infinite loop issues.

@0xalpharush 0xalpharush closed this Aug 3, 2023
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