-
Notifications
You must be signed in to change notification settings - Fork 598
feat(docs): Historical trees docs #3895
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c267a9f
historical trees docs
catmcgee d52e9b1
Merge branch 'master' into historical-trees-docs
catmcgee 450d820
comment format
catmcgee a76b53c
Merge branch 'master' into historical-trees-docs
catmcgee 0cb603f
Merge branch 'master' into historical-trees-docs
catmcgee 65d4ba4
Merge branch 'master' into historical-trees-docs
catmcgee fe6f2d5
added concepts section
catmcgee c145f54
Merge branch 'master' into historical-trees-docs
catmcgee 37dba09
Apply suggestions from code review
catmcgee 54b21f1
diaxified
catmcgee 61d98da
Merge branch 'master' into historical-trees-docs
catmcgee 174fdea
suggestions
catmcgee b6caf92
fix build errors
catmcgee 2513fdb
Apply suggestions from code review
catmcgee c08ce22
timestamp -> minimum timestamp
catmcgee dc8435d
context -> content
catmcgee 9a08490
3 -> 4 parameters
catmcgee f1c6648
added some info about note hash
catmcgee 79f0a95
valuenotemethods includecode
catmcgee 3ecabb1
Merge branch 'master' into historical-trees-docs
catmcgee 15edd27
Merge branch 'master' into historical-trees-docs
catmcgee 154b9f2
history -> archival blockchain data
catmcgee ef6f481
update how-to title to avoid confusion with slow updates tree
catmcgee 8a3d516
update sidebar to match new title
catmcgee 906ffb0
Update docs/docs/concepts/advanced/data_structures/trees.md
catmcgee 4a990f7
Merge branch 'master' into historical-trees-docs
catmcgee 689dbbf
grammar nits
catmcgee 65b9517
fix broken link
catmcgee 3292b96
Merge branch 'master' into historical-trees-docs
catmcgee dbfa14c
fix broken link
catmcgee c281a0b
Merge branch 'historical-trees-docs' of https://github.com/AztecProto…
catmcgee 1ce48d1
jan suggestion
catmcgee f1022fd
Merge branch 'master' into historical-trees-docs
catmcgee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
docs/docs/dev_docs/contracts/syntax/historical_access/history_lib_reference.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| --- | ||
| title: History Reference | ||
| --- | ||
|
|
||
| <!-- Note: This will soon be moved into an Aztec.nr reference category under Aztec.nr smart contracts --> | ||
|
|
||
| ## Note inclusion | ||
|
|
||
| Note inclusion proves that a note existed (its hash was included in a note hash tree) at a specific block number. | ||
|
|
||
| ## prove_note_inclusion | ||
|
|
||
| `prove_note_inclusion` takes 4 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | note_interface | NoteInterface<Note, N> | Interface for the note with necessary functionality| | ||
| | note_with_header| Note | The note you are proving inclusion for | | ||
| | block_number | u32 | Block number for proving note's existence | | ||
| | context | PrivateContext | Private context | | ||
|
|
||
| ## prove_note_commitment_inclusion | ||
|
|
||
| A **commitment**, also referred to as a **note hash** is a public acknowledgment of the existence of a note without revealing the content of the note. You can learn more about how to compress a note to a note hash [here](../../../../concepts/advanced/data_structures/trees.md#example-note). | ||
|
|
||
| `prove_note_commitment_inclusion` takes 3 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | commitment | Field | Note commitment we are checking inclusion of | | ||
| | block_number | u32 | Block number for proving note's existence | | ||
| | context| PrivateContext | Private Context | | ||
|
|
||
| ## Note validity | ||
|
|
||
| This proves that a note exists and has not been nullified at a specified block. | ||
catmcgee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### prove_note_validity | ||
|
|
||
| `prove_note_validity` takes 4 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | note_interface | NoteInterface<Note, N> | Interface for the note with necessary functionality| | ||
| | note_with_header| Note | The note you are proving inclusion for | | ||
| | block_number | u32 | Block number for proving note's existence | | ||
| | context | PrivateContext | Private context | | ||
|
|
||
| ## Nullifier inclusion | ||
|
|
||
| This proves that a nullifier was included in a certain block (can be used to prove that a note had been nullified). | ||
|
|
||
| ### prove_nullifier_inclusion | ||
|
|
||
| `prove_nullifier_inclusion` takes 3 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | nullifier | Field | The nullifier you are proving inclusion for | | ||
| | block_number | u32 | Block number for proving note's existence | | ||
| | context | PrivateContext | Private context | | ||
|
|
||
| ## Nullifier non inclusion | ||
|
|
||
| This proves that a nullifier was not included in a certain block (can be used to prove that a note had not yet been nullified in a given block). | ||
|
|
||
| ### prove_nullifier_non_inclusion | ||
|
|
||
| `prove_nullifier_non_inclusion` takes 3 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | nullifier | Field | The nullifier you are proving inclusion for | | ||
| | block_number | u32 | Block number for proving note's existence | | ||
| | context | PrivateContext | Private context | | ||
rahul-kothari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ### note_not_nullified | ||
|
|
||
| Instead of passing the nullifier, you can check that a note has not been nullified by passing the note. | ||
|
|
||
| ## Public value inclusion | ||
|
|
||
| This proves that a public value exists at a certain block. | ||
|
|
||
| ### prove_public_value_inclusion | ||
|
|
||
| `prove_public_value_inclusion` takes 4 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------|------------------------|-----------------------------------------------------| | ||
| | value | Field | The public value you are proving inclusion for | | ||
| | storage_slot | Field | Storage slot the value exists in | | ||
| | block_number | u32 | Block number for proving value's existence | | ||
| | context | PrivateContext | Private context | | ||
|
|
||
| ## Contract inclusion | ||
|
|
||
| This proves that a contract exists in, ie had been deployed before or in, a certain block. | ||
|
|
||
| ### prove_contract_inclusion | ||
|
|
||
| `prove_contract_inclusion` takes 7 parameters: | ||
|
|
||
| | Name | Type | Description | | ||
| |---------------------------|-----------------|-------------------------------------------------------| | ||
| | deployer_public_key | GrumpkinPoint | Public key of the contract deployer | | ||
| | contract_address_salt | Field | Unique identifier for the contract's address | | ||
| | function_tree_root | Field | Root of the contract's function tree | | ||
| | constructor_hash | Field | Hash of the contract's constructor | | ||
| | portal_contract_address | EthAddress | Ethereum address of the associated portal contract | | ||
| | block_number | u32 | Block number for proof verification | | ||
| | context | PrivateContext | Private context | | ||
|
|
||
| If there is no associated portal contract, you can use a zero Ethereum address: | ||
|
|
||
| ```ts | ||
| new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES)); | ||
| ``` | ||
102 changes: 102 additions & 0 deletions
102
docs/docs/dev_docs/contracts/syntax/historical_access/how_to_prove_history.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| --- | ||
| title: How to prove existence of historical notes and nullifiers | ||
| --- | ||
|
|
||
| The Aztec Protocol uses an append-only Merkle tree to store hashes of the headers of all previous blocks in the chain as its leaves. This is known as an archive tree. You can learn more about how it works in the [concepts section](../../../../concepts/advanced/data_structures/trees.md#archive-tree). | ||
|
|
||
| # History library | ||
|
|
||
| The history library allows you to prove any of the following at a given block height before the current height: | ||
| * [Note inclusion](./history_lib_reference.md#note-inclusion) | ||
| * [Nullifier inclusion](./history_lib_reference.md#nullifier-inclusion) | ||
| * [Note validity](./history_lib_reference.md#note-validity) | ||
| * [Existence of public value](./history_lib_reference.md#public-value-inclusion) | ||
| * [Contract inclusion](./history_lib_reference.md#contract-inclusion) | ||
|
|
||
| Using this library, you can check that specific notes or nullifiers were part of Aztec network state at specific blocks. This can be useful for things such as: | ||
|
|
||
| * Verifying a minimum timestamp from a private context | ||
| * Checking eligibility based on historical events (e.g. for an airdrop by proving that you owned a note) | ||
| * Verifying historic ownership / relinquishing of assets | ||
| * Proving existence of a value in public data tree at a given contract slot | ||
| * Proving that a contract was deployed in a given block with some parameters | ||
|
|
||
| **In this guide you will learn how to** | ||
| * Prove a note was included in a specified block | ||
| * Create a nullifier and prove it was not included in a specified block | ||
|
|
||
| For a more extensive reference, go to [the reference page](./history_lib_reference.md). | ||
|
|
||
| ## 1. Import the `history` library from `aztec` | ||
|
|
||
| ```rust | ||
| aztec::{ | ||
| #include_code imports yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr raw | ||
| } | ||
| ``` | ||
|
|
||
| This imports all functions from the `history` library. You should only import the functions you will use in your contract. | ||
|
|
||
| ## 2. Create a note to prove inclusion of | ||
|
|
||
| In general you will likely have the note you want to prove inclusion of. But if you are just experimenting you can create a note with a function like below: | ||
|
|
||
| #include_code create_note yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| ## 3. Get the note from the PXE | ||
|
|
||
| Retrieve the note from the user's PXE. | ||
|
|
||
| #include_code get_note_from_pxe yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| In this example, the user's notes are stored in a map called `private_values`. We retrieve this map, then select 1 note from it with the value of `1`. | ||
|
|
||
| ## 4. Prove that a note was included in a specified block | ||
|
|
||
| To prove that a note existed in a specified block, call `prove_note_inclusion` as shown in this example: | ||
|
|
||
| #include_code prove_note_inclusion yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| This function takes in 4 arguments: | ||
|
|
||
| 1. The note interface (`ValueNoteMethods`) | ||
| 2. The note (`maybe_note.unwrap_unchecked()`). Here, `unwrap_unchecked()` returns the inner value without asserting `self.is_some()` | ||
| 3. The block number | ||
| 4. Private context | ||
|
|
||
| Note: for this to work, you will need to import `ValueNoteMethods` at the beginning of the contract: | ||
|
|
||
| #include_code value_note_imports yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| This will only prove the note existed, not whether or not the note has been nullified. You can prove that a note existed and had not been nullified in a specified block by using `prove_note_validity` which takes the same arguments: | ||
|
|
||
| #include_code prove_note_validity yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| ## 5. Create a nullifier to prove inclusion of | ||
|
|
||
| You can easily nullify a note like so: | ||
|
|
||
| #include_code nullify_note yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| This function gets a note from the PXE like we did in [step 3](#3-get-the-note-from-the-pxe) and nullifies it with `remove()`. | ||
|
|
||
| You can then compute this nullifier with `note.compute_nullifier(&mut context)`. | ||
|
|
||
| ## 6. Prove that a nullifier was included in a specified block | ||
|
|
||
| Call `prove_nullifier_inclusion` like so: | ||
|
|
||
| #include_code prove_nullifier_inclusion yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| This takes three arguments: | ||
| 1. The nullifier | ||
| 2. Block number | ||
| 3. Private context | ||
|
|
||
| You can also prove that a nullifier was not included in a specified block by using `prove_nullifier_non_inclusion` which takes the same arguments: | ||
|
|
||
| #include_code prove_nullifier_non_inclusion yarn-project/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust | ||
|
|
||
| ## Prove contract inclusion, public value inclusion, and note commitment inclusion | ||
|
|
||
| To see what else you can do with the `history` library, check out the [reference](./history_lib_reference.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.