Skip to content

fix: avoid collision in PartialAccountTree#2598

Open
igamigo wants to merge 2 commits intorelease/v0.14.0-betafrom
igamigo-fix-partial-smt
Open

fix: avoid collision in PartialAccountTree#2598
igamigo wants to merge 2 commits intorelease/v0.14.0-betafrom
igamigo-fix-partial-smt

Conversation

@igamigo
Copy link
Collaborator

@igamigo igamigo commented Mar 12, 2026

PartialSmt::get_leaf returns Ok(SmtLeaf::Empty) for a provably empty space, which was causing errors in the node. Seems this changed with the recent migration to plonky 3 (noticed here) but track_account was not rewritten to account for this.

Seems like the original change was reviewed here.

This PR basically uses the same pattern that insert() uses for catching real collision cases. A (maybe more correct) alternative could be to add something like PartialSmt::has_explicit_leaf(&key) but that requires crypto changes.

@igamigo igamigo changed the title fix: avoid collision fix: avoid collision in PartialAccountTree Mar 12, 2026
@igamigo igamigo force-pushed the igamigo-fix-partial-smt branch from 2acc5bc to ac28f6a Compare March 13, 2026 17:59
@igamigo igamigo force-pushed the igamigo-fix-partial-smt branch from ac28f6a to 49519f3 Compare March 13, 2026 18:00
@igamigo igamigo marked this pull request as ready for review March 13, 2026 18:50
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the fix!

Comment on lines +125 to 129
if let Ok(SmtLeaf::Single((existing_key, _))) = self.smt.get_leaf(&id_key)
&& id_key != existing_key
{
return Err(AccountTreeError::DuplicateIdPrefix { duplicate_prefix: id_prefix });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud: This allows adding the same account witness twice, but that should be fine. Since PartialSmt::add_proof will error if a root mismatch occurs, the only allowed case is if the previously added account witness is the same as the current one, so we could technically return early if id_key == existing_key. Though, I'd leave things as is to avoid introducing special logic that needs to be tested, etc.

Comment on lines +306 to +307
let mut partial_tree = PartialAccountTree::with_witnesses([witness0, witness1, witness2])?;

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a partial_tree.track_account(witness1) here just to have a code path that adds the same witness twice (to make sure this does not error)?

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.

3 participants