Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 3, 2025
1 parent fb58c16 commit a7c1f0f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ where
compute_payload(context, note, recipient, sender)
}

// This function seems to be affected by the following Noir bug:
// https://github.com/noir-lang/noir/issues/5771
// If you get weird behavior it might be because of it.
pub fn encode_and_encrypt_note<Note, let N: u32>(
context: &mut PrivateContext,
recipient: AztecAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use dep::aztec::macros::aztec;
contract TokenBlacklist {
// Libs
use dep::aztec::{
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_unconstrained,
encrypted_logs::encrypted_note_emission::{
encode_and_encrypt_note, encode_and_encrypt_note_unconstrained,
},
hash::compute_secret_hash,
macros::{functions::{initializer, internal, private, public, view}, storage::storage},
prelude::{AztecAddress, Map, NoteGetterOptions, PrivateSet, PublicMutable, SharedMutable},
Expand Down Expand Up @@ -186,11 +188,11 @@ contract TokenBlacklist {
assert(notes.len() == 1, "note not popped");

// Add the token note to user's balances set
// TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.add(to, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, to, context.msg_sender()),
);
storage.balances.add(to, U128::from_integer(amount)).emit(encode_and_encrypt_note(
&mut context,
to,
context.msg_sender(),
));
}

#[private]
Expand All @@ -206,11 +208,11 @@ contract TokenBlacklist {
assert(nonce == 0, "invalid nonce");
}

// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from, from),
);
storage.balances.sub(from, U128::from_integer(amount)).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));

TokenBlacklist::at(context.this_address())._increase_public_balance(to, amount).enqueue(
&mut context,
Expand Down Expand Up @@ -255,11 +257,11 @@ contract TokenBlacklist {
assert(nonce == 0, "invalid nonce");
}

// TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from, from),
);
storage.balances.sub(from, U128::from_integer(amount)).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));

TokenBlacklist::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context);
}
Expand Down
24 changes: 7 additions & 17 deletions noir-projects/noir-contracts/contracts/token_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ contract Token {
context::{PrivateCallInterface, PrivateContext},
encrypted_logs::{
encrypted_event_emission::encode_and_encrypt_event_unconstrained,
encrypted_note_emission::encode_and_encrypt_note_unconstrained,
encrypted_note_emission::{
encode_and_encrypt_note, encode_and_encrypt_note_unconstrained,
},
},
macros::{
events::event,
Expand Down Expand Up @@ -250,10 +252,8 @@ contract Token {
assert(nonce == 0, "invalid nonce");
}

// TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.at(from).sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from, from),
encode_and_encrypt_note(&mut context, from, from),
);
Token::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context);
}
Expand Down Expand Up @@ -376,22 +376,14 @@ contract Token {
let amount = U128::from_integer(amount);
// docs:start:increase_private_balance
// docs:start:encrypted
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note_unconstrained(
storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));
// docs:end:encrypted
// docs:end:increase_private_balance
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note_unconstrained(
&mut context,
to,
from,
));
storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note(&mut context, to, from));
}
// docs:end:transfer_in_private

Expand All @@ -403,10 +395,8 @@ contract Token {
} else {
assert(nonce == 0, "invalid nonce");
}
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.at(from).sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from, from),
encode_and_encrypt_note(&mut context, from, from),
);
Token::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
import { Fr, GrumpkinScalar, type PXE, createLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js';

import { jest } from '@jest/globals';
import { format } from 'util';

// docs:end:imports
Expand All @@ -64,6 +65,8 @@ import { deployToken, mintTokensToPrivate } from '../fixtures/token_utils.js';
const { PXE_URL = 'http://localhost:8080' } = process.env;

describe('e2e_sandbox_example', () => {
jest.setTimeout(60_000);

it('sandbox example works', async () => {
// docs:start:setup
////////////// CREATE THE CLIENT INTERFACE AND CONTACT THE SANDBOX //////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer_in_private(badAccount.address, accounts[1].address, 0, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrow(
"Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'",
);
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Assertion failed: Message not authorized by account');
});
});
});
4 changes: 4 additions & 0 deletions yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { TestContract } from '@aztec/noir-contracts.js/Test';
// docs:end:import_contract
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import { jest } from '@jest/globals';

import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { mintTokensToPrivate } from '../fixtures/token_utils.js';

const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env;

describe('guides/dapp/testing', () => {
jest.setTimeout(60_000);

describe('on local sandbox', () => {
beforeAll(async () => {
// docs:start:create_pxe_client
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/src/guides/up_quick_start.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { createAztecNodeClient, waitForNode } from '@aztec/aztec.js';

import { jest } from '@jest/globals';
import { execSync } from 'child_process';

const { AZTEC_NODE_URL = '' } = process.env;

// Entrypoint for running the up-quick-start script on the CI
describe('guides/up_quick_start', () => {
jest.setTimeout(60_000);

// TODO: update to not use CLI
it('works', async () => {
await waitForNode(createAztecNodeClient(AZTEC_NODE_URL));
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/src/shared/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as AztecJs from '@aztec/aztec.js';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { contractArtifactToBuffer } from '@aztec/types/abi';

import { jest } from '@jest/globals';
import getPort from 'get-port';
import { type Server } from 'http';
import Koa from 'koa';
Expand Down Expand Up @@ -55,6 +56,8 @@ export const browserTestSuite = (
pageLogger: AztecJs.Logger,
) =>
describe('e2e_aztec.js_browser', () => {
jest.setTimeout(60_000);

const initialBalance = 33n;
const transferAmount = 3n;

Expand Down

0 comments on commit a7c1f0f

Please sign in to comment.