Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e8c7992
shnorr to ecdsa
catmcgee Mar 22, 2025
ba2442e
simpleprivatevoting artifact
catmcgee Mar 23, 2025
0d12155
token contract
catmcgee Mar 23, 2025
c77195e
blah
catmcgee Mar 26, 2025
2494d96
cleaned some things up
catmcgee Mar 27, 2025
9c9ea5e
fees
catmcgee Mar 27, 2025
6cac912
fees
catmcgee Mar 27, 2025
aba5b3d
Merge branch 'master' into playground-updates
catmcgee Mar 27, 2025
5adbf02
Merge remote-tracking branch 'origin/master' into playground-updates
catmcgee Apr 1, 2025
c67b550
sfpm
catmcgee Apr 1, 2025
6b3a163
design
catmcgee Apr 1, 2025
2aa25e2
Merge remote-tracking branch 'origin/master' into playground-updates
catmcgee Apr 3, 2025
480a890
Merge remote-tracking branch 'origin/master' into playground-updates
catmcgee Apr 5, 2025
566eb09
deisgn
catmcgee Apr 5, 2025
244092f
contract changes
catmcgee Apr 6, 2025
3aa7e24
touches
catmcgee Apr 6, 2025
fcd8bd9
account deployments
catmcgee Apr 7, 2025
b4425e5
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Apr 8, 2025
73e0ffc
deps
Thunkar Apr 8, 2025
b38254b
esau script
catmcgee Apr 8, 2025
ab03203
Merge branch 'playground-updates' of github.com:AztecProtocol/aztec-p…
Thunkar Apr 9, 2025
4f5a31f
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Apr 9, 2025
a7c2aa2
revert internal changes, added new styling
Thunkar Apr 9, 2025
fce9dfa
contracts
Thunkar Apr 9, 2025
50215fe
back to working
Thunkar Apr 9, 2025
eafa9f9
sponsored deployments and ecdsa contracts
Thunkar Apr 9, 2025
629b0a1
more cleanup
Thunkar Apr 9, 2025
ca8a9e0
contract section refactor
Thunkar Apr 10, 2025
4810205
more cleanup, handling deployments with fees
Thunkar Apr 10, 2025
cbdf2c3
deleted unused script
Thunkar Apr 10, 2025
4123e37
smaller build, cleaner stuff
Thunkar Apr 10, 2025
3154e96
tweaks and fixes
Thunkar Apr 10, 2025
7af929b
more fixes
Thunkar Apr 10, 2025
d52f135
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Apr 10, 2025
6a69171
ensure registration, increase pxe block batch
Thunkar Apr 10, 2025
83ce534
now working
Thunkar Apr 10, 2025
b4a6118
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Apr 11, 2025
420383e
fix deployments
Thunkar Apr 11, 2025
bf5c23b
authwit management
Thunkar Apr 11, 2025
ee93aad
fixes
Thunkar Apr 11, 2025
a85d754
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Apr 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"contracts/app/token_bridge_contract",
"contracts/app/token_contract",
"contracts/app/uniswap_contract",
"contracts/app/simple_token_playground",
"contracts/docs/docs_example_contract",
"contracts/fees/fpc_contract",
"contracts/fees/sponsored_fpc_contract",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "simple_token_playground"
authors = [""]
compiler_version = ">=0.25.0"
type = "contract"

[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
uint_note = { path = "../../../../aztec-nr/uint-note" }
compressed_string = { path = "../../../../aztec-nr/compressed-string" }
authwit = { path = "../../../../aztec-nr/authwit" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,367 @@
mod types;

use dep::aztec::macros::aztec;

// Minimal token contract. Do not use
// For demonstration purposes in playground only
// If you change the names of these functions, please also update them in playground/src/components/contract/contract.ts

#[aztec]
pub contract SimpleToken {
use std::{meta::derive, ops::{Add, Sub}};

use dep::compressed_string::FieldCompressedString;

use dep::aztec::{
context::{PrivateCallInterface, PrivateContext},
encrypted_logs::log_assembly_strategies::default_aes128::{
event::encode_and_encrypt_event_unconstrained,
note::{encode_and_encrypt_note, encode_and_encrypt_note_unconstrained},
},
event::event_interface::EventInterface,
macros::{
events::event,
functions::{initializer, internal, private, public, utility, view},
storage::storage,
},
prelude::{AztecAddress, Map, PublicContext, PublicImmutable, PublicMutable},
protocol_types::traits::Serialize,
};

use dep::uint_note::uint_note::{PartialUintNote, UintNote};
use aztec::protocol_types::traits::ToField;

use dep::authwit::auth::{
assert_current_call_valid_authwit, assert_current_call_valid_authwit_public,
compute_authwit_nullifier,
};

use crate::types::balance_set::BalanceSet;

global INITIAL_TRANSFER_CALL_MAX_NOTES: u32 = 2;
global RECURSIVE_TRANSFER_CALL_MAX_NOTES: u32 = 8;

#[derive(Serialize)]
#[event]
struct Transfer {
from: AztecAddress,
to: AztecAddress,
amount: u128,
}

#[storage]
struct Storage<Context> {
balances: Map<AztecAddress, BalanceSet<Context>, Context>,
total_supply: PublicMutable<u128, Context>,
public_balances: Map<AztecAddress, PublicMutable<u128, Context>, Context>,
symbol: PublicImmutable<FieldCompressedString, Context>,
name: PublicImmutable<FieldCompressedString, Context>,
decimals: PublicImmutable<u8, Context>,
}

#[public]
#[initializer]
fn constructor(name: str<31>, symbol: str<31>, decimals: u8) {
storage.name.initialize(FieldCompressedString::from_string(name));
storage.symbol.initialize(FieldCompressedString::from_string(symbol));
storage.decimals.initialize(decimals);
}

#[public]
#[view]
fn public_get_name() -> FieldCompressedString {
storage.name.read()
}

#[public]
#[view]
fn public_get_symbol() -> pub FieldCompressedString {
storage.symbol.read()
}

#[public]
#[view]
fn public_get_decimals() -> pub u8 {
storage.decimals.read()
}

#[public]
#[view]
fn public_total_supply() -> u128 {
storage.total_supply.read()
}

#[public]
#[view]
fn public_balance_of(owner: AztecAddress) -> u128 {
storage.public_balances.at(owner).read()
}

#[utility]
pub(crate) unconstrained fn private_balance_of(owner: AztecAddress) -> u128 {
storage.balances.at(owner).balance_of()
}

#[public]
fn mint_publicly(to: AztecAddress, amount: u128) {
let new_balance = storage.public_balances.at(to).read().add(amount);
let supply = storage.total_supply.read().add(amount);
storage.public_balances.at(to).write(new_balance);
storage.total_supply.write(supply);
}

#[public]
fn public_transfer(from: AztecAddress, to: AztecAddress, amount: u128, nonce: Field) {
if (!from.eq(context.msg_sender())) {
assert_current_call_valid_authwit_public(&mut context, from);
} else {
assert(nonce == 0, "invalid nonce");
}
let from_balance = storage.public_balances.at(from).read().sub(amount);
storage.public_balances.at(from).write(from_balance);
let to_balance = storage.public_balances.at(to).read().add(amount);
storage.public_balances.at(to).write(to_balance);
}

#[public]
fn burn_public(from: AztecAddress, amount: u128, nonce: Field) {
if (!from.eq(context.msg_sender())) {
assert_current_call_valid_authwit_public(&mut context, from);
} else {
assert(nonce == 0, "invalid nonce");
}
let from_balance = storage.public_balances.at(from).read().sub(amount);
storage.public_balances.at(from).write(from_balance);
let new_supply = storage.total_supply.read().sub(amount);
storage.total_supply.write(new_supply);
}

#[private]
fn transfer_from_private_to_public(
from: AztecAddress,
to: AztecAddress,
amount: u128,
nonce: Field,
) {
if (!from.eq(context.msg_sender())) {
assert_current_call_valid_authwit(&mut context, from);
} else {
assert(nonce == 0, "invalid nonce");
}

storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));
SimpleToken::at(context.this_address())._increase_public_balance(to, amount).enqueue(
&mut context,
);
}

#[private]
fn private_transfer(from: AztecAddress, to: AztecAddress, amount: u128, nonce: Field) {
if (!from.eq(context.msg_sender())) {
assert_current_call_valid_authwit(&mut context, from);
} else {
assert(nonce == 0, "invalid nonce");
}

storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));
storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note(&mut context, to, from));
}

#[private]
fn burn_private(from: AztecAddress, amount: u128, nonce: Field) {
if (!from.eq(context.msg_sender())) {
assert_current_call_valid_authwit(&mut context, from);
} else {
assert(nonce == 0, "invalid nonce");
}
storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note(
&mut context,
from,
from,
));
SimpleToken::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context);
}

#[private]
fn transfer_from_public_to_private(to: AztecAddress, amount: u128) {
let from = context.msg_sender();
let token = SimpleToken::at(context.this_address());

let partial_note = _prepare_private_balance_increase(from, to, &mut context, storage);
token._finalize_transfer_to_private_unsafe(from, amount, partial_note).enqueue(&mut context);
}

#[private]
fn prepare_private_balance_increase(to: AztecAddress, from: AztecAddress) -> PartialUintNote {
_prepare_private_balance_increase(from, to, &mut context, storage)
}

#[contract_library_method]
fn _prepare_private_balance_increase(
from: AztecAddress,
to: AztecAddress,
context: &mut PrivateContext,
storage: Storage<&mut PrivateContext>,
) -> PartialUintNote {
let partial_note = UintNote::partial(
to,
storage.balances.at(to).set.storage_slot,
context,
to,
from,
);

SimpleToken::at(context.this_address())
._store_balances_set_partial_note(partial_note)
.enqueue(context);

partial_note
}

#[public]
fn finalize_transfer_to_private(amount: u128, partial_note: PartialUintNote) {
let from = context.msg_sender();
_finalize_transfer_to_private(from, amount, partial_note, &mut context, storage);
}

#[public]
#[internal]
fn _finalize_transfer_to_private_unsafe(
from: AztecAddress,
amount: u128,
partial_note: PartialUintNote,
) {
_finalize_transfer_to_private(from, amount, partial_note, &mut context, storage);
}

#[contract_library_method]
fn _finalize_transfer_to_private(
from: AztecAddress,
amount: u128,
partial_note: PartialUintNote,
context: &mut PublicContext,
storage: Storage<&mut PublicContext>,
) {
let from_balance = storage.public_balances.at(from).read().sub(amount);
storage.public_balances.at(from).write(from_balance);

assert(context.storage_read(partial_note.commitment()), "Invalid partial note");
partial_note.complete(amount, context);
}

#[private]
fn mint_privately(from: AztecAddress, to: AztecAddress, amount: u128) {
let token = SimpleToken::at(context.this_address());
let partial_note = _prepare_private_balance_increase(from, to, &mut context, storage);
token._finalize_mint_to_private_unsafe(amount, partial_note).enqueue(&mut context);
}

#[public]
fn finalize_mint_to_private(amount: u128, partial_note: PartialUintNote) {
_finalize_mint_to_private(amount, partial_note, &mut context, storage);
}

#[public]
#[internal]
fn _finalize_mint_to_private_unsafe(amount: u128, partial_note: PartialUintNote) {
_finalize_mint_to_private(amount, partial_note, &mut context, storage);
}

#[contract_library_method]
fn _finalize_mint_to_private(
amount: u128,
partial_note: PartialUintNote,
context: &mut PublicContext,
storage: Storage<&mut PublicContext>,
) {
let supply = storage.total_supply.read().add(amount);
storage.total_supply.write(supply);

assert(context.storage_read(partial_note.commitment()), "Invalid partial note");
partial_note.complete(amount, context);
}

#[public]
#[internal]
fn _store_balances_set_partial_note(partial_note: PartialUintNote) {
context.storage_write(partial_note.commitment(), true);
}

#[public]
#[internal]
fn _increase_public_balance(to: AztecAddress, amount: u128) {
_increase_public_balance_inner(to, amount, storage);
}

#[contract_library_method]
fn _increase_public_balance_inner(
to: AztecAddress,
amount: u128,
storage: Storage<&mut PublicContext>,
) {
let new_balance = storage.public_balances.at(to).read().add(amount);
storage.public_balances.at(to).write(new_balance);
}

#[public]
#[internal]
fn _reduce_total_supply(amount: u128) {
let new_supply = storage.total_supply.read().sub(amount);
storage.total_supply.write(new_supply);
}

#[private]
fn cancel_authwit(inner_hash: Field) {
let on_behalf_of = context.msg_sender();
let nullifier = compute_authwit_nullifier(on_behalf_of, inner_hash);
context.push_nullifier(nullifier);
}

#[contract_library_method]
fn subtract_balance(
context: &mut PrivateContext,
storage: Storage<&mut PrivateContext>,
account: AztecAddress,
amount: u128,
max_notes: u32,
) -> u128 {
let subtracted = storage.balances.at(account).try_sub(amount, max_notes);
assert(subtracted > 0 as u128, "Balance too low");
if subtracted >= amount {
subtracted - amount
} else {
let remaining = amount - subtracted;
compute_recurse_subtract_balance_call(*context, account, remaining).call(context)
}
}

#[no_predicates]
#[contract_library_method]
fn compute_recurse_subtract_balance_call(
context: PrivateContext,
account: AztecAddress,
remaining: u128,
) -> PrivateCallInterface<25, u128> {
SimpleToken::at(context.this_address())._recurse_subtract_balance(account, remaining)
}

#[internal]
#[private]
fn _recurse_subtract_balance(account: AztecAddress, amount: u128) -> u128 {
subtract_balance(
&mut context,
storage,
account,
amount,
RECURSIVE_TRANSFER_CALL_MAX_NOTES,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod balance_set;
Loading
Loading