Aztec
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
###### tags: `aztec3-speccing-book` :::info PROPOSAL Author: Zac ::: TODO: put together some data structure that allows contracts to check for the non-existence of data (e.g. a blacklist) **IMPORTANT: this document is supplemented by a Discourse conversation [here](https://discourse.aztec.network/t/utxo-syntax-1-explicitly-specifying-the-utxo-owner/45)** # UTXOs and Private State Semantics (in Smart Contracts) Defining semantics to manipulate private state comes with unique difficulties due to its encrypted nature and the fact that private state is UTXO based. ## The UTXO problem Unlike in Aztec 2, we cannot anticipate the data *type* of the state value. If it is a simple numeric type, the contract developer may wish to have a private state slot represent an aggregateable value. It may be aggregateable but only depending on conditional logic. If it is a struct, perhaps the developer may wish to aggregate subsets of the struct into a single value for a given decryption key. There will be other usage patterns for UTXOs that develop over time that we cannot predict. UTXOs add significant complexity to developing and managing a private dapp. Question is: who pays? 1. Protocol developers (hide UTXO nature from contract devs and app devs) 2. Contract developers (hide UTXO nature from app devs) 3. App developers (App devs need to understand state is UTXO based and write aggregation functions like we do in the Aztec Connect SDK) The proposal is that we place the complexity burden on **contract developers** as far as is possible. They are the entity that understand the requirements of their contract and its logic. The protocol's resposibility is to provide clean, easy to express semantics to manipulate UTXOs such that their nature can be abstracted away from app developers. These are the two 'win' conditions we must hit under this proposal: > **All contract state required by a dapp can be accessed via contract getter functions.** > **UTXO commitments are *never* passed in as input parameters to an external-facing contract function** As an example of what *not* to aim for; in Aztec Connect the user must directly supply input/output note commitments to the join-split function. ## Definition of a private state commitment A private state commitment is defined by the following: 1. contract address 2. storage slot 3. decryption key 5. state value (probably 32 bytes. TODO: define size) 6. nonce 7. salt ### Contract representation Private state variables can be represented in one of two forms: 1. Singleton `mapping(address => Object)` 2. Unbounded Array `mapping(address => UArray(Object))` TODO: How do we initialize singleton variables? (i.e. cannot use patter "pull old value out of the state tree and nullify it, there is no old value") For a singleton variable, the explicit assumption here is that only the user will be making modifications (e.g. the Object type could be a struct, may, dynamic array etc.) The `Object` is the type of the storage variable itself (e.g. `u64`). If it does not fit into a single state commitmet, the variable is split across multiple state commitments (and storage slots). ### Unbounded Array-based UTXOs Simulating arrays is difficult because we need to enable users who are *not* the array owner to be able to *insert* objects into the array. Beause of this, we cannot track an array length (without leaking information, as everybody would need to know it to perform an `insert`) Without an array length, we cannot index specific array elements (the user may not know at which index they are inserting into). #### What *can* be done with unbounded arrays? * Anyone can `insert` into the array * Array owners can `remove` array elements * Array owners can `replace` array elements (syntactic sugar that removes an array element and inserts another in its place) #### How can we access unbounded array elements A contract function can request a fixed number of elements from the unbounded array. We can use rust-style Option semantics to represent the fact that the array elements may be either 'real' or 'gibberish' notes. ### Unbounded array access semantics (pseudocode) ``` function get(uint number, function SortFunction, function FilterFunction) returns [Option<ObjectType>; number] ``` The returned array elements are wrapped in a form of Option type with `is_some, is_none` methods that return boolean values depending on whether the element exists. The `SortFunction` defines the ordering used. The function declaration is (pseudocode): ``` SortFunction(ObjectType left, ObjectType right) returns bool ``` Function returns `true` if `left` is ordered before `right`. The `FilterFunction` acts similarly to the `SortFunction` and is used to omit UTXOs from the returned array: ``` FilterFunction(ObjectType v) returns bool ``` e.g. can be used to omit zero-valued notes. If no sort/filter functions are provided, default behaviour is to return notes ordered by their position in the state tree. Q: Is `sort`, `filter` sufficient to build up higher-level abstractions like `map`, `reduce`? Q: Is it too confusing for `SortFunction` and `FilterFunction` to add constraints? The constraint conditions is weaker than the conditions that apply when operating natively (could call them `SortDirective`, `FilterDirective` to make their functions clearer) ### Sort/Filter semantics The sort/filter functions generate constraints to ensure that the supplied UTXO objects match the criteria. However we cannot ensure that UTXOs that *would* have passed the checks have been ommitted. e.g: > Alice has UTXO's with values [0, 1, 2]. > The contract has a getter function that gets 2 UTXOs that are sorted from lowest to largest. > All of `[0, 1]`, `[1, 2]`, `[0, 2]` can be supplied as witnesses that satisfy the constraint checks. It is impossible to enforce sort/filter logic across all UTXOs without iterating over all UTXOs in-circuit, which is not practical. We need to be able to express these limitations clearly to devs as this is a potential security footgun. ### Access methods for getter functions We want to be able to support the creation of 'getter' methods that can be used by apps to extract required contract data (e.g. a user's balance of a shielded token). This requires a method that can get *all* of a user's notes for a given variable. We can do this by supporting *simulated* functions in Noir. These are functions that, when compiled, produce ACIR++, but *are not compiled into constraints*. i.e. you cannot 'call' these functions in a real transaction. Simulated functions are not bounded by some Noir rules such as no unbounded loops (this requires extra ACIR++ opcodes that are only valid in a simulated context e.g. conditional branching) Simulated functions can also access a get-all method on storage variables that returns a vector/dynamic array ``` get_all(function SortFunction, function FilterFunction) returns Vec<ObjectType> ``` ## Example: re-creating the Join-Split transaction TODO: use Noir syntax! This uses Solidity-style pseudocode (with rust's Option syntax grafted on...) ```solidity private mapping(address => bool) blackList; function private addToBlackList() { blackList[msg.sender] = true; } function private checkNotOnBlackList() { bool isOnBlackList = blackList[msg.sender]; require(isOnBlackList == false); } private mapping(address => UnboundedArray<uint256>) _notes; private antiset(address) _badPeople; bool thing_init = false; function private addBadPerson(address baddie) { _badPeople.insert(baddie); } function private checkNotBad() { require(_badPeople.notPresent(msg.sender)); } function private gimmeThing() { _thing[msg.sender] = 10; checkInit(); } function public checkInit() { require(thing_init == false); thing_init = true; } o /** * combines the user's 2 highest-valued notes into a single note. */ function consolidate() { [Option<uint256>; 2] storage notes = _notes[msg.sender].get(2, sortNotes, filterNote); require(notes[0].is_some() && notes[1].is_some(), "not enough notes to consolidate"); notes[0].replace(notes[0].unwrap() + notes[1].unwrap()); // 2 output notes. Could call 'remove' to produce only 1 ouput note. notes[1].replace(0); } /** * creates a j-s transaction that gives a note to 'to' worth 'value' * * Will throw if 2 largest notes are insufficiently large * * N.B. we could conditionally consolidate notes here if needed but would increase tx costs */ function privateSend(address to, uint256 value) { [Option<uint256>; 2] storage notes = _notes[msg.sender].get(2, sortNotes, filterNote); uint256 valueSum = notes[0].unwrap_or(0) + notes[1].unwrap_or(0); require(valueSum >= value, "insufficient note values. May need to consolidate"); notes[0].replace(valueSum - value); // TODO: might need to create a specific option type for an optional-storage var instead of Option. Would be good to have a direct `remove` method on the option that produces a gibberish nullifier if the UTXO is gibberish notes[1].remove(); // TODO: define syntax that declares the msg seder is not expected to know the viewing key to _notes[to] (e.g. some 'unknown' keyword) _notes[to].insert(value); } /** * Returns the user's shielded balance. * Is a simulate-only function that cannot be executed as part of a tx **/ function getShieldedBalance() simulated returns (uint256) { // can only call get_all in simulated functions uint256[] storage notes = _notes[msg.sender].get_all(sortNotes, filterNote); uint256 balance = 0; // can have unbounded loops in simulated functions for (uint256 i = 0; i < notes.length; ++i) { balance += notes[i]; } return balance; } /** * Computes number of note consolidations required before a user can send a note worth `target`. * Is a simulate-only function that cannot be executed as part of a tx **/ function numConsolidationsForSend(uint256 target) simulated returns (uint256) { uint256[] storage notes = _notes@self.get_all(sortNotes, filterNote); // uint256[] storage notes = _notes[msg.sender].get_all(sortNotes, filterNote); require(notes.length > 0, "insufficient balance"); uint256 count = 0; uint256 consolidatedValue = notes[0]; for (uint256 i = 1; i < notes.length; ++i) { if (notes[i] + consolidatedValue >= target) { return count; } consolidatedValue += notes[i]; count++; } require(false, "insufficient balance"); } ``` ## ACIR++ Changes The `get` method used to extract state adds a significant complexity to ACIR++; the algorithm that is executed during the *simulation* is different to the algorithm that is constrained when generating a circuit. ### Simulated `get` * Recover *all* UTXOs linked to a given storage key/user * Iterate over all UTXOs and apply the `sortFunction` and `filterFunction` functions * If the sorted/filtered UTXOs are less than `number`, add sufficient fake UTXOs * Return a `number`-sized array ### Circuit `get` * Present `number` of UTXO objects as witnesses * Iterate over the UTXOs and apply the `sortFunction` and `filterFunction` functions ## Performing Non-Membership Checks (TODO: should be moved to protocol architecture spec) If we want the Noir++ to support 'antisets', datasets where users can prove the non-existence of a key. We can expose a nullifier set as a basic primitive, but *secure* non-membership checks require specific a pattern is followed due to the following security requirement: **A unique nullifier can only produce *one* non-membership check** Non-membership checks are performed by exposing nullifiers to the rollup provider, who then performs the non-membership check into a nullifier set (to avoid race conditions. TODO link to a nullifiers primer) Repeated exposure of the *same* nullifier reveals part of the transaction graph; that nullifier can becomes an identifier. ### Secure non-membership checks Each antiset is assigned a state slot $slot_s$ and a nullifier slot $slot_n$ An antiset nullifier for a key $k \in \mathbb{F}$ requires a nullifier $nonce_k$ and is defined as: $$ H(k, nonce_k, slot_n, contract) $$ (contract = contract address) #### Adding to the antiset The initial nullifier for a given key $k$ uses a nonce value of $0$ i.e. the following nullifier is added: $$ H(k, 0, slot_n, contract) $$ (as with all nullifier insertions, the inserted nullifier must also pass a non membersihp check) #### Proving non-membership of the antiset For an input key $k$ and $nonce_k$, the circuit requires a non-membership check over the nullifier $H(k, nonce_k, slot_n, contract)$ If $n > 0$ the circuit must *also* prove the *existence* of a leaf in the **state tree** whose value is $$ H(k, nonce_k, slot_s, contract) $$ The circuit **adds** the following leaf to the state tree: $$ H(k, nonce_k + 1, slot_s, contract) $$ The circuit **adds** the following nullifier to the nullifier set: $$ H(k, nonce_k + 1, slot_n, contract) $$ #### Costs of non-membership checks A non-membership check requires adding 1 note to the state tree and 1 note to the nullifier set i.e. not read-only! ### Privacy considerations for non-membership checks If Alice wishes to add Bob to an antiset, she must choose a nullifier key $k$ that corresponds to Bob's identity. This is not hiding. [TODO explain how hiding can be done in a semitrusted setting] ## Non-membership check contract semantics

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully