-
Notifications
You must be signed in to change notification settings - Fork 607
feat(docs): document noir macros #2016
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
Changes from 2 commits
53a38e1
4e04bcb
c1965dc
464b3ae
2ab0f65
934604b
a6851f7
5ea83e3
6f324f6
319aada
2db1fba
b68ba49
9c20b42
3b571b7
65de5b3
801a7b3
b16f617
2aa2a91
7399b00
757634c
381c590
8e8b214
1cde337
398e70f
171f3f6
3ec0b0f
b2033dd
1d6561a
27dcb8b
2b02a14
57f42b4
c00bba6
8e04c5b
e8a0e21
18b0094
c76ab7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Overview of this page (change this title) | ||
|
|
||
| We want ot include some over arching details on what is included inside the context structure, and give an overview of what it actually is. | ||
|
|
||
| ## What is the context. | ||
| The context is a variable that is made available within every function in `Aztec.nr`. As mentioned in the KERNEL CIRCUIT SECTION. The application context is a structure that contains all of the infromation a function needs from the kernel circuit, as well as all the information the kernel needs after a function execution completes. | ||
|
|
||
| Behind the scenes, Aztec noir will pass data the kernel needs to and from a circuit, this is completely abstracted away from the developer. In an application developer's eyes; the context is a useful structure that allows access to anything on the aztec blockchain outside of the current circuit (REWORD THIS SECTION). | ||
|
|
||
| ## What is contained within the context. | ||
|
|
||
| The code snippet below shows what is currently contained within the private context. | ||
| #include_code functions-OpenFunction /yarn-project/noir-libs/noir-aztec/src/context.nr rust | ||
|
|
||
| ### Private Context Broken Down | ||
| #### Inputs | ||
| The context inputs includes all of the information that is passed from the kernel circuit into the application circuit. It contains the following values. | ||
|
|
||
| #include_code private-context-inputs /yarn-project/noir-libs/noir-aztec/src/abi.nr rust | ||
|
|
||
| As shown in the snippet, the application context is made up of 4 main structures. The call context, the block data, the contract deployment data and the private global variables. | ||
|
|
||
| First of all, the call context. | ||
|
|
||
| #include_code call-context /yarn-project/noir-libs/noir-aztec/src/abi.nr rust | ||
|
|
||
| The call context contains information about the current call being made:. | ||
| 1, Msg Sender | ||
| - The message sender is the account (Aztec Contract) that sent the message to the current context. In the first call of the kernel circuit (often the account contract call), this value will be empty. For all subsequent calls the value will be the previous call. | ||
|
Maddiaa0 marked this conversation as resolved.
|
||
|
|
||
| ( TODO: INCLUDE A DIAGRAM HERE SHOWING HOW IT GETS UPDATED ON CONTRACT CALLS ) | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
| 2. Storage contract address | ||
| - This value is the address of the current context's contract address. This value will be the value of the current contract that is being executed except for when the current call is a delegate call (TODO: INCLUDE A LINK TO ITS DOCUMENTATION). In this case the value will be that of the sending contract. | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
|
|
||
| - This value is important as it is the value that is used when siloing the storage values of a contract. ( TODO: DOES THIS NEED TO BE DIVED INTO MORE OR IS IT SOMETHING THTAT THERE IS A LINK TO). | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
| 3. Portal Contract Address | ||
| - This value stores the current contract's linked portal contract address. ( INCLUDE A LINK TO THE LITERATURE ). As a quick recap, this value is the value of the contracts related ethereum l1 contract address, and will be the recipient of any messages that are created by this contract. | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
| 4. Flags | ||
| - Furthermore there are a series of flags that are stored within the application context: | ||
| - is_delegate_call: Denotes whether the current call is a delegate call. If true, then the storage contract address will NOT be the current contract address. | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
| - is_static_call: (TODO: REFER TO EVM CODES TO FILL IN THIS SECTION) | ||
|
Maddiaa0 marked this conversation as resolved.
Outdated
|
||
| - is_contract_deployment: This will be set if and only if the current call is the contract's constructor. | ||
|
|
||
| ### Historic Block Data | ||
| Another structure that is contained within the context is the Historic Block Data object. This object is a special one as it contains all of the roots of Aztec's data trees. | ||
|
|
||
| #include_code historic-block-data /yarn-project/noir-libs/noir-aztec/src/abi.nr rust | ||
|
|
||
| ## TODO: gloss this up | ||
| Having these tree's on hand allows for a host of interesting use cases. If you can create a merkle proof which matches the root of these trees. Then you can prove that a value exists in the current state of the system. | ||
|
|
||
| ### Contract Deployment Data | ||
| Just like with the `is_contract_deployment` flag mentioned earlier. This flag will only be set to true when the current transaction is one in which a contract is being deployed. | ||
|
|
||
| #### TODO : WAT CONTAIN AND WAT DO | ||
|
|
||
|
|
||
| ### Private Global Variables | ||
| TODO: | ||
| - include in this section how the global variabels can be accessed and what they contain | ||
|
|
||
|
|
||
|
|
||
|
|
||
| ## Args Hash | ||
|
|
||
|
|
||
|
|
||
| <!-- args_hash : Field, | ||
| return_values : BoundedVec<Field, RETURN_VALUES_LENGTH>, | ||
|
|
||
| read_requests: BoundedVec<Field, MAX_READ_REQUESTS_PER_CALL>, | ||
|
|
||
| new_commitments: BoundedVec<Field, MAX_NEW_COMMITMENTS_PER_CALL>, | ||
| new_nullifiers: BoundedVec<Field, MAX_NEW_NULLIFIERS_PER_CALL>, | ||
| nullified_commitments: BoundedVec<Field, MAX_NEW_NULLIFIERS_PER_CALL>, | ||
|
|
||
| private_call_stack : BoundedVec<Field, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL>, | ||
| public_call_stack : BoundedVec<Field, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL>, | ||
| new_l2_to_l1_msgs : BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_CALL>, --> --> | ||
|
|
||
| ## Public Context Inputs | ||
| In the current version of the system, the public context is almost a clone of the private execution context. It contains the same call context data, access to the same historic tree roots, however it does NOT have access to contract deployment data, this is due to traditional contract deployments only currently being possible from private transactions. | ||
|
|
||
| #include_code public-context-inputs /yarn-project/noir-libs/noir-aztec/src/abi.nr rust | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,37 +110,14 @@ Access control on the L1 portal contract is essential to prevent consumption of | |
|
|
||
| As earlier, we can use a token bridge as an example. In this case, we are burning tokens on L2 and sending a message to the portal to free them on L1. | ||
|
|
||
| ```rust title="NonNativeTokenContract.nr" | ||
| // burns token and sends a message to the portal | ||
| fn withdraw( | ||
| amount: Field, | ||
| sender: Field, | ||
| recipient: Field, | ||
| callerOnL1: Field, | ||
| ) -> distinct pub abi::PrivateCircuitPublicInputs { | ||
| ... | ||
| let sender_balance = storage.balances.at(sender); | ||
| spend_notes(&mut context, sender_balance, amount, sender); | ||
|
|
||
| let content = get_withdraw_content_hash(amount, recipient, callerOnL1); | ||
| context.message_portal(content); | ||
| ... | ||
| } | ||
| ``` | ||
| #include_code send_to_portal /yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr rust | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be updated along with #2177. Adding a comment here for reference. |
||
|
|
||
| When the transaction is included in a rollup block the message will be inserted into the `Outbox`, where the recipient portal can consume it from. When consuming, the `msg.sender` must match the `recipient` meaning that only portal can actually consume the message. | ||
|
|
||
| ```solidity title="IOutbox.sol" | ||
| struct L2ToL1Msg { | ||
| DataStructures.L2Actor sender; | ||
| DataStructures.L1Actor recipient; | ||
| bytes32 content; | ||
| } | ||
| <!-- TODO: the rest of these docs should have code snippets updates --> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an issue, or should it be fixed in this pr?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did it in this pr, will revert in this one |
||
| #include_code l1_to_l2_message_struct /l1-contracts/src/core/libraries/DataStructures.sol solidity | ||
|
|
||
| function consume(DataStructures.L2ToL1Msg memory _message) | ||
| external | ||
| returns (bytes32 entryKey); | ||
| ``` | ||
| #include_code consume_interface /l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol solidity | ||
|
|
||
| As noted earlier, the portal contract should check that the sender is as expected. In the example below, we support only one sender contract (stored in `l2TokenAddress`) so we can just pass it as the sender, that way we will only be able to consume messages from that contract. If multiple senders are supported, you could use a have `mapping(address => bool) allowed` and check that `allowed[msg.sender]` is `true`. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Aztec.nr Syntax | ||
|
|
||
| [Noir](https://noir-lang.org/) is a language which is agnostic to proof systems and use cases. Rather than baking Aztec-specific keywords and smart contract types directly into Noir (which would break this agnosticism), we have developed a library -- written in Noir -- whose types and methods provide rich smart contract semantics. | ||
| [Noir](https://noir-lang.org/) is a language which is agnostic to proof systems and use cases. Rather than baking Aztec-specific keywords and smart contract types directly into Noir (which would break this agnosticism), we have developed a framework -- written in Noir -- whose types and methods provide rich smart contract semantics. | ||
|
|
||
| On top of [Noir's stdlib](https://noir-lang.org/standard_library/array_methods), we provide [Aztec.nr](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-libs) for writing contracts on Aztec. | ||
|
|
||
|
|
@@ -16,4 +16,15 @@ Aztec.nr contains abstractions which remove the need to understand the low-level | |
|
|
||
| To import Aztec.nr into your Aztec contract project, simply include it as a dependency. | ||
|
|
||
| #include_code importing-aztec /yarn-project/noir-contracts/src/contracts/private_token_contract/Nargo.toml toml | ||
| ```toml | ||
| [package] | ||
| name = "my_noir_contract" | ||
| authors = [""] | ||
| compiler_version = "0.10.0" | ||
| type = "contract" | ||
|
|
||
| [dependencies] | ||
| aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/noir-aztec" } | ||
| ``` | ||
|
|
||
| Note: currently the dependency name ***MUST*** be `aztec`. The framework expects this namespace to be available when compiling into contracts. This limitation may be removed in the future. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would probably be better to make this a larger note os one of the |
||
Uh oh!
There was an error while loading. Please reload this page.