Skip to content

Commit

Permalink
feat: update to latest noir and update noir compiler (#3696)
Browse files Browse the repository at this point in the history
This PR updates aztec-packages to use latest noir.

- Regarding noir_wasm, providing the solved sources directly to
`node_wasm` eliminates the need for `source-resolver`, which has been
completely removed from the repository.
 - Added required pub in return values
 - Updated return_type
 - Pulled latest noir
  • Loading branch information
Thunkar authored and Maddiaa0 committed Jan 8, 2024
1 parent 3fe955c commit a7d0ba1
Show file tree
Hide file tree
Showing 1,042 changed files with 22,103 additions and 19,613 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mirror_noir_subrepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Push to branch
run: |
SUBREPO_PATH=noir
BRANCH=aztec
BRANCH=aztec-packages
# identify ourselves, needed to commit
git config --global user.name AztecBot
git config --global user.email [email protected]
Expand All @@ -57,4 +57,4 @@ jobs:
pr_title: 'feat: aztec-packages'
pr_body: 'Development from Aztec.'
destination_branch: 'master'
source_branch: 'aztec'
source_branch: 'aztec-packages'
2 changes: 1 addition & 1 deletion .github/workflows/protocol-circuits-gate-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: TomAFrench/noir-gates-diff@e7cf131b7e7f044c01615f93f0b855f65ddc02d4
with:
report: protocol_circuits_report.json
summaryQuantile: 1 # Display any diff in gate count
summaryQuantile: 0 # Display any diff in gate count

- name: Add gates diff to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
Expand Down
13 changes: 8 additions & 5 deletions boxes/blank/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ contract Blank {
fn constructor() {}

#[aztec(private)]
fn getPublicKey(
address: Field,
) -> [Field; 2]{
fn getPublicKey(address: Field) -> [Field; 2] {
let pub_key = get_public_key(address);

[pub_key.x, pub_key.y]
}

// A function which needs to be implemented by every contract working with storage. Replace it's content with your
// own logic once you start working with private storage.
// TODO: Remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> [Field; 4] {
unconstrained fn compute_note_hash_and_nullifier(
contract_address: Field,
nonce: Field,
storage_slot: Field,
serialized_note: [Field; 0]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
}
101 changes: 25 additions & 76 deletions boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ contract Token {

// docs:start:set_admin
#[aztec(public)]
fn set_admin(
new_admin: AztecAddress,
) {
fn set_admin(new_admin: AztecAddress) {
assert(storage.admin.read().eq(AztecAddress::new(context.msg_sender())), "caller is not admin");
// docs:start:write_admin
storage.admin.write(new_admin);
Expand All @@ -140,10 +138,7 @@ contract Token {

// docs:start:set_minter
#[aztec(public)]
fn set_minter(
minter: AztecAddress,
approve: bool,
) {
fn set_minter(minter: AztecAddress, approve: bool) {
// docs:start:read_admin
assert(storage.admin.read().eq(AztecAddress::new(context.msg_sender())), "caller is not admin");
// docs:end:read_admin
Expand All @@ -155,10 +150,7 @@ contract Token {

// docs:start:mint_public
#[aztec(public)]
fn mint_public(
to: AztecAddress,
amount: Field,
) -> Field {
fn mint_public(to: AztecAddress, amount: Field) -> Field {
// docs:start:read_minter
assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter");
// docs:end:read_minter
Expand All @@ -174,10 +166,7 @@ contract Token {

// docs:start:mint_private
#[aztec(public)]
fn mint_private(
amount: Field,
secret_hash: Field,
) -> Field {
fn mint_private(amount: Field, secret_hash: Field) -> Field {
assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter");
let pending_shields = storage.pending_shields;
let mut note = TransparentNote::new(amount, secret_hash);
Expand All @@ -193,12 +182,7 @@ contract Token {

// docs:start:shield
#[aztec(public)]
fn shield(
from: AztecAddress,
amount: Field,
secret_hash: Field,
nonce: Field,
) -> Field {
fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
// The redeem is only spendable once, so we need to ensure that you cannot insert multiple shields from the same message.
assert_current_call_valid_authwit_public(&mut context, from);
Expand All @@ -220,12 +204,7 @@ contract Token {

// docs:start:transfer_public
#[aztec(public)]
fn transfer_public(
from: AztecAddress,
to: AztecAddress,
amount: Field,
nonce: Field,
) -> Field {
fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
assert_current_call_valid_authwit_public(&mut context, from);
} else {
Expand All @@ -245,11 +224,7 @@ contract Token {

// docs:start:burn_public
#[aztec(public)]
fn burn_public(
from: AztecAddress,
amount: Field,
nonce: Field,
) -> Field {
fn burn_public(from: AztecAddress, amount: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
assert_current_call_valid_authwit_public(&mut context, from);
} else {
Expand All @@ -269,11 +244,7 @@ contract Token {

// docs:start:redeem_shield
#[aztec(private)]
fn redeem_shield(
to: AztecAddress,
amount: Field,
secret: Field,
) -> Field {
fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) -> Field {
let pending_shields = storage.pending_shields;
let secret_hash = compute_secret_hash(secret);
let options = NoteGetterOptions::new().select(0, amount).select(1, secret_hash).set_limit(1);
Expand All @@ -289,12 +260,7 @@ contract Token {

// docs:start:unshield
#[aztec(private)]
fn unshield(
from: AztecAddress,
to: AztecAddress,
amount: Field,
nonce: Field,
) -> Field {
fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
assert_current_call_valid_authwit(&mut context, from);
} else {
Expand All @@ -312,12 +278,7 @@ contract Token {

// docs:start:transfer
#[aztec(private)]
fn transfer(
from: AztecAddress,
to: AztecAddress,
amount: Field,
nonce: Field,
) -> Field {
fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
assert_current_call_valid_authwit(&mut context, from);
} else {
Expand All @@ -334,11 +295,7 @@ contract Token {

// docs:start:burn
#[aztec(private)]
fn burn(
from: AztecAddress,
amount: Field,
nonce: Field,
) -> Field {
fn burn(from: AztecAddress, amount: Field, nonce: Field) -> Field {
if (from.address != context.msg_sender()) {
assert_current_call_valid_authwit(&mut context, from);
} else {
Expand All @@ -356,9 +313,7 @@ contract Token {

// docs:start:initialize
#[aztec(public)]
internal fn _initialize(
new_admin: AztecAddress,
) {
internal fn _initialize(new_admin: AztecAddress) {
storage.admin.write(new_admin);
storage.minters.at(new_admin.address).write(true);
}
Expand All @@ -368,20 +323,15 @@ contract Token {
// docs:start:increase_public_balance
#[aztec(public)]
internal fn _increase_public_balance(
to: AztecAddress,
amount: Field,
) {
internal fn _increase_public_balance(to: AztecAddress, amount: Field) {
let new_balance = storage.public_balances.at(to.address).read().add(SafeU120::new(amount));
storage.public_balances.at(to.address).write(new_balance);
}
// docs:end:increase_public_balance

// docs:start:reduce_total_supply
#[aztec(public)]
internal fn _reduce_total_supply(
amount: Field,
) {
internal fn _reduce_total_supply(amount: Field) {
// Only to be called from burn.
let new_supply = storage.total_supply.read().sub(SafeU120::new(amount));
storage.total_supply.write(new_supply);
Expand All @@ -391,37 +341,31 @@ contract Token {
/// Unconstrained ///
// docs:start:admin
unconstrained fn admin() -> Field {
unconstrained fn admin() -> pub Field {
storage.admin.read().address
}
// docs:end:admin

// docs:start:is_minter
unconstrained fn is_minter(
minter: AztecAddress,
) -> bool {
unconstrained fn is_minter(minter: AztecAddress) -> pub bool {
storage.minters.at(minter.address).read()
}
// docs:end:is_minter

// docs:start:total_supply
unconstrained fn total_supply() -> u120 {
unconstrained fn total_supply() -> pub u120 {
storage.total_supply.read().value
}
// docs:end:total_supply

// docs:start:balance_of_private
unconstrained fn balance_of_private(
owner: AztecAddress,
) -> u120 {
unconstrained fn balance_of_private(owner: AztecAddress) -> pub u120 {
storage.balances.at(owner).balance_of().value
}
// docs:end:balance_of_private

// docs:start:balance_of_public
unconstrained fn balance_of_public(
owner: AztecAddress,
) -> u120 {
unconstrained fn balance_of_public(owner: AztecAddress) -> pub u120 {
storage.public_balances.at(owner.address).read().value
}
// docs:end:balance_of_public
Expand All @@ -433,7 +377,12 @@ contract Token {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; TOKEN_NOTE_LEN]) -> [Field; 4] {
unconstrained fn compute_note_hash_and_nullifier(
contract_address: Field,
nonce: Field,
storage_slot: Field,
serialized_note: [Field; TOKEN_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
if (storage_slot == 5) {
note_utils::compute_note_hash_and_nullifier(TransparentNoteMethods, note_header, serialized_note)
Expand Down
6 changes: 1 addition & 5 deletions noir/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ packages
**/node_modules
**/outputs

# Source resolver
compiler/source-resolver/lib
compiler/source-resolver/lib-node

# Noir.js
tooling/noir_js/lib

Expand All @@ -19,4 +15,4 @@ compiler/wasm/nodejs
compiler/wasm/web
tooling/noirc_abi_wasm/nodejs
tooling/noirc_abi_wasm/web
tooling/noir_js/lib
tooling/noir_js/lib
5 changes: 5 additions & 0 deletions noir/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
Expand Down
12 changes: 6 additions & 6 deletions noir/.github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ description: Installs the workspace's yarn dependencies and caches them
runs:
using: composite
steps:
- name: Cache
uses: actions/cache@v3
id: cache
- uses: actions/setup-node@v3
id: node
with:
path: "**/node_modules"
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
node-version: 18.17.1
cache: 'yarn'
cache-dependency-path: 'yarn.lock'

- name: Install
run: yarn --immutable
shell: bash
if: steps.cache.outputs.cache-hit != 'true'
Loading

0 comments on commit a7d0ba1

Please sign in to comment.