Skip to content

feat: add generic <S> to NullifierTree enabling LargeSmt support#2091

Merged
drahnr merged 9 commits intonextfrom
bernhard-1353-largesmt-for-nullifier-tree
Nov 25, 2025
Merged

feat: add generic <S> to NullifierTree enabling LargeSmt support#2091
drahnr merged 9 commits intonextfrom
bernhard-1353-largesmt-for-nullifier-tree

Conversation

@drahnr
Copy link
Contributor

@drahnr drahnr commented Nov 12, 2025

Allows seting up the NullifierTree with LargeSmt by means of adding an additional trait ala AccountTreeBackend for the nullifier tree: NullifierTreeBackend.

Part of 0xMiden/node#1353

@drahnr drahnr force-pushed the bernhard-1353-largesmt-for-nullifier-tree branch from 1710b9b to f6bf8ae Compare November 12, 2025 17:49
@drahnr drahnr changed the title feat: add generic <S> to NullifierTree enablign LargeSmt support feat: add generic <S> to NullifierTree enabling LargeSmt support Nov 12, 2025
@drahnr drahnr marked this pull request as ready for review November 12, 2025 20:01
Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

Minor naming/nits; I did check the impls but I'll defer approval to @PhilippGackstatter

@drahnr drahnr force-pushed the bernhard-1353-largesmt-for-nullifier-tree branch 3 times, most recently from 348dc16 to 1556b91 Compare November 18, 2025 12:17
- Add NullifierTreeBackend trait to abstract over Smt and LargeSmt
- Make NullifierTree generic over the SMT backend
- Implement backend trait for both Smt and LargeSmt<Backend>
- Add comprehensive tests for LargeSmt backend
- Update partial_nullifier_tree to use free helper functions
- Maintain backward compatibility with default Smt backend
@drahnr drahnr force-pushed the bernhard-1353-largesmt-for-nullifier-tree branch from 1556b91 to 7f0d754 Compare November 18, 2025 17:57
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!

I left a few comments. The two main ones I think are whether the free function must be public and the panicking in num_entries.

Comment on lines +134 to +136
#[cfg(feature = "std")]
impl<Backend> NullifierTreeBackend for LargeSmt<Backend>
where
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: My impression was that we want to eventually move LargeSmt out of miden crypto into a separate crate, and then, I think it would be great to move the implementation impl<Backend> NullifierTreeBackend for LargeSmt<Backend> out of miden-base, to avoid having the rocksdb dependency here, where we don't actually need it. Is that still the plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the priority is to move the RocksDB SmtStore implementation out of miden-crypto, moving LargeSmt is still an open discussion point iiuc.
However, we only incur a dependency on RocksDB iff we enable the feature rocksdb, which we do not by default (not here, not in the node (yet, see 0xMiden/node#1352 ) ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense. I erroneously assumed rocks db and large smt meant the same thing. Makes sense to move rocks DB out of crypto I think.

I wonder if it would still make sense to keep the backend implementation for large SMT closer to where it is used with rocks DB, primarily to lower the chances of the error handling assumptions going out of sync. E.g. we currently assume storage operations are panicky (and the issue #2010 is already closed - is that intentional?) and this seems to be with rocks DB in mind. But the impl here is more general, e.g. it implements NullifierTreeBackend for any SmtStorage. So, keeping rocks DB usage + large SMT backed impl closer together (e.g. node) would be better in my mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#2010 re-opened and added some more context.

I am not quite sold on keeping the trait SmtStore, struct LargeSmt and the relevant impl SmtStores all in one place, the proximity might not be as useful, but it also depends on the path forward re multi-monorepo, which is still an open discussion point.

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! I left a couple of comments inline.

drahnr added a commit that referenced this pull request Nov 24, 2025
- Rename generic parameter S to Backend for better clarity
- Rename new() to new_unchecked() to indicate lack of invariant validation
- Add SAFETY comments explaining unwrap() usage in LargeSmt implementation
- Clarify trait documentation regarding Default requirement
- Update all call sites to use new_unchecked()

Addresses feedback from PR #2091
@drahnr drahnr force-pushed the bernhard-1353-largesmt-for-nullifier-tree branch from 81de654 to 0d6a53d Compare November 24, 2025 15:59
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! I left one small question inline.

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 to me! Thank you for updating the error panic and the docs!

Left some minor comments.

@drahnr drahnr merged commit 5a0c6f8 into next Nov 25, 2025
17 checks passed
@drahnr drahnr deleted the bernhard-1353-largesmt-for-nullifier-tree branch November 25, 2025 12:31
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.

4 participants