Skip to content

fix(subgraph): fix(subgraph): update Merkle tree depth when adding me… - #1109

Open
zjuncal wants to merge 1 commit into
semaphore-protocol:mainfrom
zjuncal:main
Open

zjuncal wants to merge 1 commit into
semaphore-protocol:mainfrom
zjuncal:main

Conversation

@zjuncal

@zjuncal zjuncal commented Nov 12, 2026

Copy link
Copy Markdown

Description

Fix an indexed Merkle tree depth that stays at 0 after members are added. For example, adding three leaves currently produces size 3 and depth 0; the correct LeanIMT depth is 2.

Add a shared integer-based helper and recompute depth from the updated size in both addMember() and addMembers(). The calculation returns 0 for an empty or single-leaf tree and ceil(log2(size)) for larger trees.

Extend the existing assertions and add isolated regression tests covering individual additions through nine leaves, batch additions across multiple depth levels, and preservation of size and depth after member updates and removals. This is a bug fix with no schema or contract changes.

Related Issue(s)

Fixes #1108

Other information

Validation:

  • Before the mapping fix, the extended suite failed four tests with incorrect depth values, including depth 0 instead of 1 for two leaves and depth 0 instead of 2 for three leaves.
  • After the fix, yarn test:subgraph passes all 10 tests using the repository's pinned Matchstick binary 0.5.0.
  • yarn workspace @semaphore-protocol/utils build, yarn build:subgraph, and yarn build:libraries pass.
  • yarn format passes.
  • yarn lint passes after building the workspace libraries. Solhint reports 27 warnings in unchanged Solidity files; ESLint reports no errors.
  • ESLint and Prettier pass for all three changed files.

Existing indexed data needs reindexing/replaying events to correct all affected groups and historical results. A subsequent member-add event recomputes the current depth for that group, but groups without further additions retain the previously stored value.

The unit-test verification covers the subgraph suite; unrelated test suites were not run.

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run yarn format and yarn lint without getting any errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Important

We do not accept pull requests for minor grammatical fixes (e.g., correcting typos, rewording sentences) or for fixing broken links, unless they significantly improve clarity or functionality. These contributions, while appreciated, are not a priority for merging. If you notice any of these issues, please create a GitHub Issue to report them so they can be properly tracked and addressed.

…mbers

Fix an indexed Merkle tree depth that stays at `0` after members are added. For example, adding
three leaves currently produces size `3` and depth `0`; the correct LeanIMT depth is `2`.

re semaphore-protocol#1108
@zjuncal
zjuncal requested a review from a team as a code owner November 12, 2026 03:55

This branch has not been deployed

No deployments
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.

Subgraph Merkle tree depth remains zero after adding members

1 participant