Skip to content

Add values from tuple elements into the dictionary#1406

Merged
elopez merged 7 commits intocrytic:masterfrom
gustavo-grieco:dev-tuple-dicts
Aug 7, 2025
Merged

Add values from tuple elements into the dictionary#1406
elopez merged 7 commits intocrytic:masterfrom
gustavo-grieco:dev-tuple-dicts

Conversation

@gustavo-grieco
Copy link
Copy Markdown
Collaborator

This should allow echidna to solve this:

pragma solidity ^0.8.0;

contract Marketplace {
    uint256 internal currentKey = 1375566;
    struct Item {
        uint16 useless;
        uint256 keyId;
        bytes32 data;
    }

    mapping(uint256 => Item) public items;

    function addItem(bytes32 _data) public returns (Item memory) {
    currentKey += 174; 

        // Store the item
        items[currentKey] = Item({
            useless: 16,
            keyId: currentKey,
            data: _data
        });
    return items[currentKey];
    }

    function getItem(uint256 _keyId) public view returns (Item memory) {
        assert(items[_keyId].keyId == 0);
    }
}

We need to add this into a test.

@gustavo-grieco gustavo-grieco requested a review from arcz as a code owner July 26, 2025 08:37
gustavo-grieco and others added 2 commits July 29, 2025 07:54
Co-authored-by: Emilio López <[email protected]>
Co-authored-by: Emilio López <[email protected]>
if isTuple type'
then Just $ Map.fromListWith Set.union
[ (abiValueType val, Set.singleton val)
| val <- V.toList $ getTupleVector abiValue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should these be filtered so no cheatCode makes its way into the dictionary?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let me fix that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should we move the cheat code detection deeper into the dictionary handling to avoid duplication?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is done, even at the cost of duplicating the logic a bit

@elopez elopez merged commit b23878f into crytic:master Aug 7, 2025
21 of 22 checks passed
@gustavo-grieco gustavo-grieco deleted the dev-tuple-dicts branch September 14, 2025 17:27
datradito pushed a commit to datradito/echidna-mcp that referenced this pull request Dec 29, 2025
* add values from tuple elements into the dictionary

* added test

* avoid adding cheatcode into dictionary
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