Skip to content

Implement rehashing for dirty BMTs in StateValue#95

Open
ysh-red wants to merge 1 commit intomidnightntwrk:mainfrom
zoniqx:fix/ledger-state
Open

Implement rehashing for dirty BMTs in StateValue#95
ysh-red wants to merge 1 commit intomidnightntwrk:mainfrom
zoniqx:fix/ledger-state

Conversation

@ysh-red
Copy link
Copy Markdown

@ysh-red ysh-red commented Mar 17, 2026

Trigger: Any export circuit that performs MerkleTree.checkRoot() (a read) followed by MerkleTree.insert() (a write) — even on the same tree, even in the same queryLedgerState call.
Panic message:

Error: invalid operation for type: attempted to take root of non-rehashed bmt (this should not be possible!)
  at partitionTranscripts (...)
  at partitionTranscript (.../compact-js/.../ContractExecutable.js)

Minimal Reproducing example :

export ledger tree: MerkleTree<10, Bytes<32>>;

witness get_path(cm: Bytes<32>): Maybe<MerkleTreePath<10, Bytes<32>>>;
witness get_a(): Bytes<32>;
witness get_b(): Bytes<32>;

export circuit transfer(): [] {
  const cm = get_a();
  const p = get_path(cm);
  // READ: checkRoot — passes fine in isolation
  assert(tree.checkRoot(disclose(merkleTreePathRoot<10, Bytes<32>>(p.value))), "bad root");
  // WRITE: insert — causes partitionTranscripts to panic
  tree.insert(disclose(get_a()));
  tree.insert(disclose(get_b()));
}

Signed-off-by: ysh-red <yreddy@zoniqx.com>
@ysh-red ysh-red requested a review from a team as a code owner March 17, 2026 11:24
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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