Skip to content

chore: Use old poseidon wrapper for tree operations on v1 registry#767

Open
Kemperino wants to merge 4 commits into
ps/reduce-poseidon2-gasfrom
kempy/poseidon2-v1
Open

chore: Use old poseidon wrapper for tree operations on v1 registry#767
Kemperino wants to merge 4 commits into
ps/reduce-poseidon2-gasfrom
kempy/poseidon2-v1

Conversation

@Kemperino
Copy link
Copy Markdown
Contributor

@Kemperino Kemperino commented Jun 1, 2026

contract size: 21,242

  public internal linked tree + internal
fs update leaf 0 427,473 395,557 (-7.5%) 399,194(-6.6%)
fs update leaf 500 427,574 395,658 (-7.5%) 399,248 (-6.6%)
fs update leaf 999 423,458 391,542 (-7.5%) 395,132 (-6.7%)

❯ jq '.bytecode.linkReferences' out/WorldIDRegistryV2Unreleased.sol/WorldIDRegistryV2.json
{
  "src/core/libraries/FullStorageBinaryIMT.sol": {
    "FullStorageBinaryIMT": [
      {
        "start": 2417,
        "length": 20
      },
      {
        "start": 5885,
        "length": 20
      },
      {
        "start": 10505,
        "length": 20
      },
      {
        "start": 17188,
        "length": 20
      }
    ]
  },
  "src/core/libraries/PackedAccountData.sol": {
    "PackedAccountData": [
      {
        "start": 4339,
        "length": 20
      },
      {
        "start": 7714,
        "length": 20
      },
      {
        "start": 11454,
        "length": 20
      },
      {
        "start": 12630,
        "length": 20
      },
      {
        "start": 13664,
        "length": 20
      },
      {
        "start": 15887,
        "length": 20
      },
      {
        "start": 16808,
        "length": 20
      },
      {
        "start": 17402,
        "length": 20
      }
    ]
  }
}


Note

Medium Risk
Changes how Merkle roots are computed on V1 write paths; a mismatch with deployed behavior would break proof validity, though the intent is bytecode-level compatibility with the original public Poseidon call pattern.

Overview
Splits V1 registry Merkle writes from the shared FullStorageBinaryIMT helpers so they always hash through a V1-style public Poseidon2T2V1 library call, matching how the original registry built roots.

WorldIDRegistry now routes insert/update/batch insert via virtual _insertLeaf, _insertManyLeaves, and _updateLeafAndRecord that delegate to new WorldIDRegistryV1Tree (logic copied from the IMT library, using Poseidon2T2V1). FullStorageBinaryIMT widens _key / _getNode to internal so that library can reuse node lookups. WorldIDRegistryV2 overrides those hooks to keep using FullStorageBinaryIMT with the current internal Poseidon2T2 path for post-upgrade behavior.

Reviewed by Cursor Bugbot for commit 9339ab4. Configure here.

@Kemperino Kemperino requested a review from a team as a code owner June 1, 2026 12:53
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.

1 participant