OpenZeppelin / OpenZeppelin/openzeppelin-upgrades

Add support of packing / unpacking structure during storage layout verification.

Open
#431 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

storage-checks
Dominant language
TypeScript
Stars
658
Forks
286
PR merge metrics
No merged PRs in 30d

Description

Let's say we have an ERC20Votes contract. This contract contains 3 consecutive slots dedicated to the voting logic:

    mapping(address => address) private _delegates;
    mapping(address => Checkpoint[]) private _checkpoints;
    Checkpoint[] private _totalSupplyCheckpoints;

This storage and the associated logic would benefit from being abstracted away, so it can be reused for ERC721 voting or ERC1155 voting (for example).

This is what this structure proposes. You'll note that, at a low level, the storage is consistent. It is however hidden in structs.

    struct Checkpoint {
        uint32 index;
        uint224 value;
    }

    struct History {
        Checkpoint[] _checkpoints;
    }

    struct Votes {
        mapping(address => address) _delegation;
        mapping(address => History) _userCheckpoints;
        History                     _totalCheckpoints;
    }

I believe that it would be a great improvement if the plugin was able to flatten the structure so that this would trigger a rename error, but not replace/delete/insert errors.

This branch include tests for such a feature

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the storage examples in ERC20Votes.sol and Voting.sol, then inspect the tests on the referenced feature/pack-unpackstorage branch. Determine how the plugin currently verifies storage layouts and compare the expected behavior for packed structures. Done means the linked test cases pass while detecting renames without reporting replacement, deletion, or insertion errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity, typescript
Domain
blockchain, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.