Skip to content

Commit

Permalink
feat(docs): Document slow update tree (#3416)
Browse files Browse the repository at this point in the history
Closes AztecProtocol/aztec-packages#3374

Documents the slow update tree - how, when, why

Explanation in concepts & how-to in syntax page
# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [x] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: josh crites <[email protected]>
Co-authored-by: Rahul Kothari <[email protected]>
  • Loading branch information
3 people authored and AztecBot committed Dec 2, 2023
1 parent 3d2aba3 commit 2588c88
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions slow-updates-tree/src/slow_map.nr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct SlowUpdateInner<N> {
sibling_path: [Field; N],
}

// docs:start:slow_update_proof
// The slow update proof. Containing two merkle paths
// One for the before and one for the after trees.
// M = 2 * N + 4
Expand All @@ -52,6 +53,7 @@ struct SlowUpdateProof<N, M> {
before: SlowUpdateInner<N>,
after: SlowUpdateInner<N>,
}
// docs:end:slow_update_proof

pub fn deserialize_slow_update_proof<N, M>(serialized: [Field; M]) -> SlowUpdateProof<N, M> {
SlowUpdateProof::deserialize(serialized)
Expand Down Expand Up @@ -142,11 +144,14 @@ impl<N,M> SlowMap<N,M> {
}
}

// docs:start:read_leaf_at
pub fn read_leaf_at(self: Self, key: Field) -> Leaf {
let derived_storage_slot = pedersen_hash([self.storage_slot, key]);
storage_read(derived_storage_slot, deserialize_leaf)
}
// docs:end:read_leaf_at

// docs:start:read_at
// Reads the "CURRENT" value of the leaf
pub fn read_at(self: Self, key: Field) -> Field {
let time = self.context.public.unwrap().timestamp() as u120;
Expand All @@ -157,6 +162,7 @@ impl<N,M> SlowMap<N,M> {
leaf.after
}
}
// docs:end:read_at

// Will update values in the "AFTER" tree
// - updates the leaf and root to follow current values, moving from after to before if
Expand Down

0 comments on commit 2588c88

Please sign in to comment.