Skip to content

Conversation

@PhilippGackstatter
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter commented Mar 28, 2025

Adds strongly typed wrapper around Smt for AccountTree and PartialAccountTree.

Adds a test to check that foreign accounts whose commitment is stale results in an error.

Added two tests that check the subtleties of the implementation.

Docs do not need to be updated after this change. The PR fixes an incorrect image link in the docs however.

closes #1157
closes #1158

@PhilippGackstatter
Copy link
Contributor Author

@igamigo This should be a breaking change for the client - should I wait for anything before merging it?

@igamigo
Copy link
Collaborator

igamigo commented Apr 4, 2025

I think we can go ahead and merge this. We have not migrated to next yet, but also, not sure this is a breaking change from the client's perspective.

EDIT: The node's changes will very likely be breaking, maybe that's what you were referring to

@PhilippGackstatter
Copy link
Contributor Author

EDIT: The node's changes will very likely be breaking, maybe that's what you were referring to

I was thinking that the account proof format changing and how it is fetched would be a breaking change, but maybe this is all abstracted away. If that's the case then all the better.

@PhilippGackstatter
Copy link
Contributor Author

I thought I could finish this PR today but I would still like to add more tests and refactor the AccountWitness according to this comment: 0xMiden/miden-node#783 (comment). This will take a bit more time and so I'll pause this PR here and work on #1261 first.

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 reviewed pretty much all non-test code and left some comments inline.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does AccountTree need to be in miden-base? Given that the NullifierTree is in miden-node, I think it would be more consistent to put the AccountTree there too. We could of course move the NullifierTree here too, but it seems like miden-node may be a more appropriate place for these structs (not a strong preference though).

Copy link
Contributor Author

@PhilippGackstatter PhilippGackstatter Apr 17, 2025

Choose a reason for hiding this comment

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

Thanks for raising this point. The main reason I wanted AccountTree in miden-base is so we can use it in MockChain. For the same reason, I'd like to move NullifierTree and ideally also Blockchain from the node to base. Otherwise, we're forced to reimplement those structures for mock chain and then we're more likely to have drifting implementations. For example, in the mock chain we currently have to reimplement low-level details like the nullifier layout:

https://github.com/0xPolygonMiden/miden-base/blob/7aeeb96f71a459b3209f956e47dd6521356044da/crates/miden-tx/src/testing/mock_chain/mod.rs#L849-L852

Or for Blockchain, we should be able to deduplicate some code as well, e.g.:

It also means users who use MockChain have the same API, types and guarantees on those data structures as when interacting with the client or node. That's why having those core protocol data structures in miden-base is best, I think.

If we do this, then we'd have all of these consistently in miden-base:

  • AccountTree and PartialAccountTree
  • NullifierTree and PartialNullifierTree
  • Blockchain and PartialBlockchain (if we rename ChainMmr).

I'm happy to open an issue to move the NullifierTree and Blockchain to base if you agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Let's move NullifierTree and Blockchain here in a separate PR.

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 comment which can be addressed in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Let's move NullifierTree and Blockchain here in a separate PR.

Comment on lines +80 to +91
for (leaf_idx, leaf) in smt.leaves() {
if leaf.num_entries() >= 2 {
// SAFETY: Since we only inserted account IDs into the SMT, it is guaranteed that
// the leaf_idx is a valid Felt as well as a valid account ID prefix.
return Err(AccountTreeError::DuplicateIdPrefix {
duplicate_prefix: AccountIdPrefix::new_unchecked(
Felt::try_from(leaf_idx.value())
.expect("leaf index should be a valid felt"),
),
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could check if the number of leaves is different from the number of passed in accounts before iterating over the leaves. This way, we'd iterate over leaves only if we know there was an issue.

Let's make this change in a follow-up PR.

@bobbinth bobbinth merged commit acaf77c into next Apr 18, 2025
16 checks passed
@bobbinth bobbinth deleted the pgackst-account-tree branch April 18, 2025 05:06
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