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

fix: have inline fixed-length array arguments generate the appropriate SlithIR #26

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

gfeng-certik
Copy link

Notes

Rev1

When generating SlithIR for function calls with inline fixed-length array arguments, those arguments would be left as (python) lists instead of Variable objects. We would expect instead that a InitArray operation would be generated that initializes a temporary variable to that array, then have that temporary variable be the argument for the call.

A core issue was that these inline fixed-length array arguments were equivalent to tuples in slither. The solc AST also characterizes them as tuples, but includes an extra field isInlineArray that distinguishes the two. slither TupleExpressions did not keep this information, so they could not be handled accordingly during SlithIR generation.

This PR adds the isInlineArray information to the TupleExpression class and uses it to properly generate the described "correct" SlithIR when an inline fixed-length array is a call argument.

Testing

Run slither's slithir printer on the following code:

pragma solidity ^0.8.13;

contract Test {
    function take_arr(uint8[3] memory arr) internal returns (uint8[3] memory) {
        return [4,5,6];
    }
    function give_arr() external {
        take_arr([1, 2, 3]);
    }

    function take_bool_arr(bool[2] memory arr) internal {}
    function give_bool_arr() external {
        take_bool_arr([true, false]);
    }

    function take_not_arr(uint x, uint y) internal {}
    function give_not_arr() external {
        uint x = 1;
        take_not_arr(x, 2);
    }
}

Ensure that the expected SlithIR is generated. That is, the SlithIR of the calls to take_arr and take_bool_arr now have temporary variable arguments that were initialized to the arrays given, and that the call to take_not_arr is still correct. Note as well that the expressions are also printed properly, using square brackets instead of parens for the array arguments.

Related Issue

https://github.com/CertiKProject/slither-task/issues/212

@kevinclancy kevinclancy merged commit 048c0d7 into certik Jan 30, 2023
@duckki duckki mentioned this pull request Apr 8, 2023
@chenhuitao chenhuitao deleted the inline-array-args branch March 18, 2024 10:40
whonore pushed a commit that referenced this pull request May 24, 2024
…e array and generate SlithIR accordingly (#26)

CertiKProject/slither-task#212
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