Skip to content

Commit

Permalink
feat(noir): use #[aztec(private)] and #[aztec(public) attributes …
Browse files Browse the repository at this point in the history
…(#1735)

## Overview

Now that noir-lang/noir#2403 has been merged
into noir and released under the `aztec` tag. This PR now builds!

This cleans up the syntax for noir programs, making them less verbose
and easier to get started with.
For example what originally was:
```rust
    fn mint(
        inputs: PrivateContextInputs,
        amount: Field, 
        owner: Field
    ) -> distinct pub abi::PrivateCircuitPublicInputs {
        let storage = Storage::init();
        let mut context = PrivateContext::new(inputs, abi::hash_args([amount, owner]));

        // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call.
        let owner_balance = storage.balances.at(owner);
        send_note(&mut context, owner_balance, amount, owner);
        emit_unencrypted_log(&mut context, "Coins minted");

        // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel..
        context.finish()
    }
```
can instead be written as:
```rust
   #[aztec(private)]
    fn mint(
        amount: Field, 
        owner: Field
    )  {
        let storage = Storage::init();

        // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call.
        let owner_balance = storage.balances.at(owner);
        send_note(&mut context, owner_balance, amount, owner);
        emit_unencrypted_log(&mut context, "Coins minted");
    }
```
  • Loading branch information
superstar0402 committed Aug 29, 2023
1 parent aad25c6 commit 496bf6b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions yarn-project/noir-libs/noir-aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,30 @@ impl PublicCircuitPublicInputs {
}
}

struct Hasher {
fields: [Field],
}

impl Hasher {
fn new()-> Self {
Self { fields: [] }
}

fn add(&mut self, field: Field) {
self.fields = self.fields.push_back(field);
}

fn add_multiple<N>(&mut self, fields: [Field; N]) {
for i in 0..N {
self.fields = self.fields.push_back(fields[i]);
}
}

fn hash(self) -> Field {
hash_args(self.fields)
}
}

global ARGS_HASH_CHUNK_LENGTH: u32 = 32;
global ARGS_HASH_CHUNK_COUNT: u32 = 16;

Expand Down

0 comments on commit 496bf6b

Please sign in to comment.