Skip to content

Commit

Permalink
docs: Update storage doc (#3212)
Browse files Browse the repository at this point in the history
This PR removes the implementation references in the Storage and Authwit
pages, removes some unnecessary text and adds some examples.

closes #2662
closes #3209

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] 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).
  • Loading branch information
critesjosh authored Nov 3, 2023
1 parent 9f71c5d commit d707d4e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 122 deletions.
6 changes: 3 additions & 3 deletions docs/docs/dev_docs/contracts/portals/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ Computing the `content` must be done manually in its current form, as we are sti
#include_code claim_public /yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr rust

:::info
The `content_hash` is a sha256 truncated to a field element (~ 254 bits). In Aztec-nr, you can use our `sha256_to_field()` to do a sha256 hash which fits in one field element:
The `content_hash` is a sha256 truncated to a field element (~ 254 bits). In Aztec-nr, you can use our `sha256_to_field()` to do a sha256 hash which fits in one field element
:::

#include_code mint_public_content_hash_nr /yarn-project/noir-contracts/src/contracts/token_portal_content_hash_lib/src/lib.nr rust

In solidity, you can use our `Hash.sha256ToField()` method:
In Solidity, you can use our `Hash.sha256ToField()` method:

#include_code content_hash_sol_import l1-contracts/test/portals/TokenPortal.sol solidity

#include_code deposit_public l1-contracts/test/portals/TokenPortal.sol solidity

The `secret_hash` uses the pederson hash which fits in a field element. You can use the utility method `computeMessageSecretHash()`in `@aztec/aztec.js` npm package to generate a secret and its corresponding hash.
:::

After the transaction has been mined, the message is consumed, a nullifier is emitted and the tokens have been minted on Aztec and are ready for claiming.

Expand Down
24 changes: 11 additions & 13 deletions docs/docs/dev_docs/contracts/resources/common_patterns/authwit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
title: Authentication Witness
description: Developer Documentation to use Authentication Witness for authentication actions on Aztec.
---

## Prerequisite reading

- [Authwit from Foundational Concepts](./../../../../concepts/foundation/accounts/authwit.md)

## Introduction
Expand Down Expand Up @@ -86,41 +88,37 @@ For our purposes here (not building a wallet), the most important part of the li

### General utilities

The primary general utility is the `compute_authwit_message_hash` function which computes the action hash from its components. This is useful for when you need to generate a hash that is not for the current call, such as when you want to update a public approval state value that is later used for [authentication in public](#updating-approval-state-in-noir).

#include_code compute_authwit_message_hash /yarn-project/aztec-nr/authwit/src/auth.nr rust
The primary general utility is the `compute_authwit_message_hash` function which computes the action hash from its components. This is useful for when you need to generate a hash that is not for the current call, such as when you want to update a public approval state value that is later used for [authentication in public](#updating-approval-state-in-noir). You can view the implementation of this function [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/authwit/src/auth.nr).

#### TypeScript utilities

To make it convenient to compute the message hashes in TypeScript, the `aztec.js` package includes a `computeAuthWitMessageHash` function that you can use.
To make it convenient to compute the message hashes in TypeScript, the `aztec.js` package includes a `computeAuthWitMessageHash` function that you can use. Implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec.js/src/utils/authwit.ts).

#include_code authwit_computeAuthWitMessageHash /yarn-project/aztec.js/src/utils/authwit.ts typescript

As you can see above, this function takes a `caller` and a `request`. So let's quickly see how we can get those. Luckily for us, the `request` can be easily prepared similarly to how we are making contract calls from TypeScript.
As you can see above, this function takes a `caller` and a `request`. The `request` can be easily prepared similarly to how we are making contract calls from TypeScript.

#include_code authwit_computeAuthWitMessageHash /yarn-project/end-to-end/src/e2e_token_contract.test.ts typescript

### Utilities for private calls

For private calls where we allow execution on behalf of others, we generally want to check if the current call is authenticated by `on_behalf_of`. To easily do so, we can use the `assert_current_call_valid_authwit` which fetches information from the current context without us needing to provide much beyond the `on_behalf_of`.

#include_code assert_current_call_valid_authwit /yarn-project/aztec-nr/authwit/src/auth.nr rust

As seen above, we mainly compute the message hash, and then forward the call to the more generic `assert_valid_authwit`. This validating function will then:
This function computes the message hash, and then forwards the call to the more generic `assert_valid_authwit`. This validating function will then:

- make a call to `on_behalf_of` to validate that the call is authenticated
- emit a nullifier for the action to prevent replay attacks
- throw if the action is not authenticated by `on_behalf_of`

#include_code assert_valid_authwit /yarn-project/aztec-nr/authwit/src/auth.nr rust
#### Example

#include_code assert_current_call_valid_authwit /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust

### Utilities for public calls

Very similar to above, we have variations that work in the public domain. These functions are wrapped to give a similar flow for both cases, but behind the scenes the logic of the account contracts is slightly different since they cannot use the oracle as they are not in the private domain.

#include_code assert_current_call_valid_authwit_public /yarn-project/aztec-nr/authwit/src/auth.nr rust
#### Example

#include_code assert_valid_authwit_public /yarn-project/aztec-nr/authwit/src/auth.nr rust
#include_code assert_current_call_valid_authwit_public /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust

## Usage

Expand Down
Loading

0 comments on commit d707d4e

Please sign in to comment.