From 2588c88e940f8c64be8a561da1a34b2f781828fa Mon Sep 17 00:00:00 2001
From: Cat McGee <helloworld@mcgee.cat>
Date: Fri, 1 Dec 2023 09:41:14 +0000
Subject: [PATCH] feat(docs): Document slow update tree (#3416)

Closes https://github.com/AztecProtocol/aztec-packages/issues/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 <critesjosh@gmail.com>
Co-authored-by: Rahul Kothari <rahul.kothari.201@gmail.com>
---
 slow-updates-tree/src/slow_map.nr | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/slow-updates-tree/src/slow_map.nr b/slow-updates-tree/src/slow_map.nr
index f36d9f79..d2dc5c67 100644
--- a/slow-updates-tree/src/slow_map.nr
+++ b/slow-updates-tree/src/slow_map.nr
@@ -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
@@ -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)
@@ -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;
@@ -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