Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merkle list and token account update iterator #1398

Merged
merged 59 commits into from
Feb 12, 2024

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Feb 1, 2024

This PR introduces several provable types to represent dynamic-sized data structures (on which we perform a fixed number of operations)

  • MerkleList<T> represents a list which supports push() and pop() (if you pop an empty list, it returns a dummy)
  • MerkleListIterator<T> exposes the functionality of popping through the elements of a Merkle list, but without removing them from the list. Main method: next(), which returns a dummy if we're past the end of the list
  • AccountUpdateForest is built up from Merkle lists recursively to represent a forest of account updates -- i.e., the children of another account update
    • uses the Merkle list hash that is compatible with how the protocol hashes trees of account updates
    • so, as we iterate through an AccountUpdateForest, we will be given nodes (account updates) along with their child account updates, which are a Merkle list themselves
  • TokenAccountUpdateIterator pulls it all together: It iterates deeply through an AccountUpdateForest, stepping down in the tree after every new account update with children is encountered, and stepping up once a layer is done. Since this will be used by token contracts, it supports skipping "inaccessible subtrees", i.e. it skips the children of an update that already doesn't inherit token permissions itself. Assuming that no subtree is skipped, the iteration will return every update in the tree exactly once, in depth-first order. After the full tree has been processed, it returns dummies.
    • the logic is heavily indebted to @mrmr1993's token contract example.
    • there is an exhaustive new unit test for TokenAccountUpdateIterator. It also tests flat iteration through a Merkle list

@mitschabaude mitschabaude requested a review from a team as a code owner February 1, 2024 10:31
@mitschabaude mitschabaude changed the title Merkle list and call forest iterator Merkle list and token account update iterator Feb 1, 2024
Base automatically changed from feature/hashed-provable to main February 1, 2024 11:46
@@ -31,6 +30,7 @@ export {
provable,
provablePure,
Struct,
Unconstrained,
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a fixup - Unconstrained was announced in a previous release but not exported

@@ -66,6 +66,17 @@ const Poseidon = {
return MlFieldArray.from(newState) as [Field, Field, Field];
},

hashWithPrefix(prefix: string, input: Field[]) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm exporting this since I wanted to use this in dogfooding already as well

src/lib/mina.ts Outdated Show resolved Hide resolved
Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

lgtm

src/lib/provable-types/merkle-list.ts Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
@mitschabaude mitschabaude merged commit 8624f44 into main Feb 12, 2024
13 checks passed
@mitschabaude mitschabaude deleted the feature/call-forest-iterator branch February 12, 2024 15:21
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.

None yet

3 participants