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 nested struct array rule generation #915

Merged
merged 7 commits into from
Dec 16, 2024

Conversation

palinatolmach
Copy link
Collaborator

@palinatolmach palinatolmach commented Dec 13, 2024

Follow up to #830.

This PR ensures that the elements of nested structs up to an arbitrary depth all have _{i} indices appended to their names if they correspond to an array element. It also factors out the processing of tuple array components into a separate function process_tuple_array.

This PR also adds a test that exercises the previously missing edge case, which manifested in variables on the LHS and in the ensures clause of the #abiCalldata rule in contract.k not having proper indexes (..._0) set.

Please note that this test branches on the possible length of dynamically sized strings in the calldata, so it is meant to test kontrol build and is not run during the kontrol prove stage:

// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.13;

import "forge-std/Test.sol";

interface ProjectConfig {
    struct ChainEnv {
        string chainName;
        string chainIndex;
    }

    struct Vault {
        string tokenName;
        address oracle;
        uint256 allowedToTrade;
        InputData params;
        uint256 reserves;
    }

    struct InputData {
        uint256 ltv;
        uint256 rate;
        uint256 exchangeRate;
        uint256 utilization;
    }

    struct AssetAddresses {
        address cToken;
        address dToken;
    }

    struct VaultWithAddresses {
        Vault vault;
        AssetAddresses addresses;
    }
}

contract NestedStructArrayTest is Test, ProjectConfig {
    // this test branches on dynamically sized calldata and not run in CI; it is only meant to test `kontrol build`
    function testVaultSignature(ChainEnv calldata environment, VaultWithAddresses[] memory listings) external { 
        assert(listings.length == 1);
    }
}

@palinatolmach palinatolmach changed the title Fix nested struct arrays Fix nested struct array rule generation Dec 13, 2024
@ehildenb
Copy link
Member

😍 nice refactoring!

@palinatolmach palinatolmach self-assigned this Dec 13, 2024
@palinatolmach palinatolmach added bug Something isn't working engagement labels Dec 13, 2024
Copy link
Contributor

@anvacaru anvacaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I was able to build my project using this fix

@automergerpr-permission-manager automergerpr-permission-manager bot merged commit 812743c into master Dec 16, 2024
12 checks passed
@automergerpr-permission-manager automergerpr-permission-manager bot deleted the fix-nested-struct-arrays branch December 16, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge bug Something isn't working engagement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants