Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 24, 2023
1 parent ecf6df2 commit 602c927
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 57 deletions.
7 changes: 7 additions & 0 deletions docs/docs/dev_docs/getting_started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ We can break this down as follows:

The Private Token Contract emits an unencrypted log message during construction:

:::danger

Emitting unencrypted events from private function is a significant privacy leak and it should be considered by the developer whether it is acceptable.
We have it as an example in private function because our public VM is unfinished and we wanted to demonstrate the use of unencrypted events.

:::

#include_code constructor /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust

We can retrieve this emitted log using the `getUnencryptedLogs()` api:
Expand Down
24 changes: 12 additions & 12 deletions yarn-project/aztec.js/src/abis/ecdsa_account_contract.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions yarn-project/aztec.js/src/abis/schnorr_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions yarn-project/end-to-end/src/e2e_public_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AztecAddress, Wallet } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { PublicTokenContract } from '@aztec/noir-contracts/types';
import { AztecRPC, CompleteAddress, L2BlockL2Logs, TxStatus } from '@aztec/types';
import { AztecRPC, CompleteAddress, TxStatus } from '@aztec/types';

import times from 'lodash.times';

import { setup } from './fixtures/utils.js';
import { expectUnencryptedLogsFromLastBlockToBe, setup } from './fixtures/utils.js';

describe('e2e_public_token_contract', () => {
let aztecNode: AztecNodeService | undefined;
Expand All @@ -26,15 +26,6 @@ describe('e2e_public_token_contract', () => {
return { contract, txReceipt };
};

const expectLogsFromLastBlockToBe = async (logMessages: string[]) => {
const l2BlockNum = await aztecRpcServer.getBlockNumber();
const unencryptedLogs = await aztecRpcServer.getUnencryptedLogs(l2BlockNum, 1);
const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs);
const asciiLogs = unrolledLogs.map(log => log.toString('ascii'));

expect(asciiLogs).toStrictEqual(logMessages);
};

beforeEach(async () => {
let accounts: CompleteAddress[];
({ aztecNode, aztecRpcServer, accounts, wallet, logger } = await setup());
Expand Down Expand Up @@ -68,7 +59,7 @@ describe('e2e_public_token_contract', () => {
const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient });
expect(balance).toBe(mintAmount);

await expectLogsFromLastBlockToBe(['Coins minted']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted']);
}, 45_000);

// Regression for https://github.com/AztecProtocol/aztec-packages/issues/640
Expand All @@ -91,6 +82,6 @@ describe('e2e_public_token_contract', () => {
const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient });
expect(balance).toBe(mintAmount * 3n);

await expectLogsFromLastBlockToBe(['Coins minted', 'Coins minted', 'Coins minted']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted', 'Coins minted', 'Coins minted']);
}, 60_000);
});
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PrivateTokenContract } from '@aztec/noir-contracts/types';

import { expectUnencryptedLogsFromLastBlockToBe } from './fixtures/utils.js';

const { SANDBOX_URL } = process.env;
const { SANDBOX_URL = 'http://localhost:8080' } = process.env;

describe('e2e_sandbox_example', () => {
// Note: this is a hack to make the docs use http://localhost:8080 and CI to use the SANDBOX_URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ contract EasyPrivateToken {
abi,
abi::PrivateContextInputs,
context::PrivateContext,
log::emit_unencrypted_log,
note::{
note_header::NoteHeader,
utils as note_utils,
Expand All @@ -39,8 +38,6 @@ contract EasyPrivateToken {

balances.at(owner).add(&mut context, initial_supply, owner);

emit_unencrypted_log(&mut context, "Balance set in constructor");

// 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()
}
Expand All @@ -60,8 +57,6 @@ contract EasyPrivateToken {

balances.at(owner).add(&mut context, 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()
}
Expand All @@ -83,8 +78,6 @@ contract EasyPrivateToken {
balances.at(sender).sub(&mut context, amount, sender);

balances.at(recipient).add(&mut context, amount, recipient);

emit_unencrypted_log(&mut context, "Coins transferred");

// 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ contract ExamplePublicStateIncrement {
PrivateContext,
PublicContext,
};
use dep::aztec::oracle::logs::emit_unencrypted_log;
use dep::aztec::types::point::Point;
use crate::storage::Storage;
use dep::aztec::state_vars::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract Lending {
PrivateContext,
PublicContext
};
use dep::aztec::oracle::{logs::emit_unencrypted_log};
use dep::aztec::public_call_stack_item::PublicCallStackItem;
use crate::storage::{Storage, Asset};
use crate::safe_math::SafeU120;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ contract PrivateTokenAirdrop {
let owner_balance = storage.balances.at(owner);
if (initial_supply != 0) {
send_note(&mut context, owner_balance, initial_supply, owner);
emit_unencrypted_log(&mut context, "Balance set in constructor");
}

// Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.
Expand All @@ -60,7 +59,6 @@ contract PrivateTokenAirdrop {
// 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()
Expand All @@ -86,8 +84,6 @@ contract PrivateTokenAirdrop {
// Creates new note for the recipient.
let recipient_balance = storage.balances.at(recipient);
send_note(&mut context, recipient_balance, amount, recipient);

emit_unencrypted_log(&mut context, "Coins transferred");

// 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()
Expand Down

0 comments on commit 602c927

Please sign in to comment.