Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 28, 2024
1 parent 70259b8 commit f9a8fb8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 160 deletions.
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/uint-note/src/uint_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ impl NoteInterface<UINT_NOTE_LEN, UINT_NOTE_BYTES_LEN> for UintNote {
impl UintNote {
// TODO: Merge this func with `compute_note_hiding_point`. I (benesjan) didn't do it in the initial PR to not have
// to modify macros and all the related funcs in it.
fn to_note_hiding_point(self) -> IntNoteHidingPoint {
IntNoteHidingPoint::new(self.compute_note_hiding_point())
fn to_note_hiding_point(self) -> UintNoteHidingPoint {
UintNoteHidingPoint::new(self.compute_note_hiding_point())
}
}

struct IntNoteHidingPoint {
struct UintNoteHidingPoint {
inner: Point
}

impl IntNoteHidingPoint {
impl UintNoteHidingPoint {
fn new(point: Point) -> Self {
Self { inner: point }
}
Expand All @@ -95,7 +95,7 @@ impl IntNoteHidingPoint {
}
}

impl Serialize<POINT_LENGTH> for IntNoteHidingPoint {
impl Serialize<POINT_LENGTH> for UintNoteHidingPoint {
fn serialize(self) -> [Field; POINT_LENGTH] {
self.inner.serialize()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ 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" }
24 changes: 11 additions & 13 deletions noir-projects/noir-contracts/contracts/token_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod test;
contract Token {
// Libs

use dep::uint_note::uint_note::{UintNote, UintNoteHidingPoint};
use dep::compressed_string::FieldCompressedString;

use dep::aztec::{
Expand All @@ -32,10 +33,7 @@ contract Token {
use dep::authwit::auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public, compute_authwit_nullifier};
// docs:end:import_authwit

use crate::types::{
transparent_note::TransparentNote,
token_note::{TokenNote, TOKEN_NOTE_LEN, TokenNoteHidingPoint}, balance_set::BalanceSet
};
use crate::types::{transparent_note::TransparentNote, balance_set::BalanceSet};
// docs:end::imports

// In the first transfer iteration we are computing a lot of additional information (validating inputs, retrieving
Expand Down Expand Up @@ -64,7 +62,7 @@ contract Token {
minters: Map<AztecAddress, PublicMutable<bool>>,
// docs:end:storage_minters
// docs:start:storage_balances
balances: Map<AztecAddress, BalanceSet<TokenNote>>,
balances: Map<AztecAddress, BalanceSet<UintNote>>,
// docs:end:storage_balances
total_supply: PublicMutable<U128>,
// docs:start:storage_pending_shields
Expand Down Expand Up @@ -536,25 +534,25 @@ contract Token {

// 4. We create the partial notes for the fee payer and the user.
// --> Called "partial" because they don't have the amount set yet (that will be done in `complete_refund(...)`).
let fee_payer_partial_note = TokenNote {
let fee_payer_partial_note = UintNote {
header: NoteHeader {
contract_address: AztecAddress::zero(),
nonce: 0,
storage_slot: storage.balances.at(fee_payer).set.storage_slot,
note_hash_counter: 0
},
amount: U128::zero(),
value: U128::zero(),
npk_m_hash: fee_payer_npk_m_hash,
randomness: fee_payer_randomness
};
let user_partial_note = TokenNote {
let user_partial_note = UintNote {
header: NoteHeader {
contract_address: AztecAddress::zero(),
nonce: 0,
storage_slot: storage.balances.at(user).set.storage_slot,
note_hash_counter: 0
},
amount: U128::zero(),
value: U128::zero(),
npk_m_hash: user_npk_m_hash,
randomness: user_randomness
};
Expand All @@ -580,10 +578,10 @@ contract Token {
#[aztec(internal)]
fn complete_refund(
// TODO(#7771): the following makes macros crash --> try getting it work once we migrate to metaprogramming
// mut fee_payer_point: TokenNoteHidingPoint,
// mut user_point: TokenNoteHidingPoint,
fee_payer_point_immutable: TokenNoteHidingPoint,
user_point_immutable: TokenNoteHidingPoint,
// mut fee_payer_point: UintNoteHidingPoint,
// mut user_point: UintNoteHidingPoint,
fee_payer_point_immutable: UintNoteHidingPoint,
user_point_immutable: UintNoteHidingPoint,
funded_amount: Field
) {
// TODO(#7771): nuke the following 2 lines once we have mutable args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::{test::utils, Token, types::token_note::TokenNote};
use crate::{test::utils, Token};

use dep::aztec::{
test::helpers::cheatcodes, oracle::unsafe_rand::unsafe_rand, hash::compute_secret_hash,
prelude::NoteHeader, protocol_types::storage::map::derive_storage_slot_in_map,
keys::getters::get_current_public_keys
};
use dep::authwit::cheatcodes as authwit_cheatcodes;
use dep::uint_note::uint_note::UintNote;

#[test]
unconstrained fn setup_refund_success() {
Expand Down Expand Up @@ -45,8 +46,8 @@ unconstrained fn setup_refund_success() {
// worth `funded_amount - transaction_fee`. We "know" the transaction fee was 1 (it is hardcoded in
// `executePublicFunction` TXE oracle) but we need to notify TXE of the note (preimage).
env.store_note_in_cache(
&mut TokenNote {
amount: U128::from_integer(funded_amount - 1),
&mut UintNote {
value: U128::from_integer(funded_amount - 1),
npk_m_hash: user_npk_m_hash,
randomness: user_randomness,
header: NoteHeader::empty()
Expand All @@ -55,8 +56,8 @@ unconstrained fn setup_refund_success() {
token_contract_address
);
env.store_note_in_cache(
&mut TokenNote {
amount: U128::from_integer(1),
&mut UintNote {
value: U128::from_integer(1),
npk_m_hash: fee_payer_npk_m_hash,
randomness: fee_payer_randomness,
header: NoteHeader::empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::aztec::{
oracle::{execution::{get_block_number, get_contract_address}, unsafe_rand::unsafe_rand, storage::storage_read}
};

use crate::{types::{token_note::TokenNote, transparent_note::TransparentNote}, Token};
use crate::{types::{transparent_note::TransparentNote}, Token};

pub fn setup(with_account_contracts: bool) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress) {
// Setup env, generate keys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod transparent_note;
mod balance_set;
mod token_note;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dep::aztec::{
note::{note_getter::view_notes, note_emission::{NoteEmission, OuterNoteEmission}},
keys::{getters::get_current_public_keys, public_keys::NpkM}
};
use crate::types::token_note::OwnedNote;
use dep::uint_note::uint_note::OwnedNote;

struct BalanceSet<T, Context> {
set: PrivateSet<T, Context>,
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_fees/private_refunds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('e2e_fees/private_refunds', () => {
t.aliceAddress,
token.address,
deriveStorageSlotInMap(TokenContract.storage.balances.slot, t.aliceAddress),
TokenContract.notes.TokenNote.id,
TokenContract.notes.IntNote.id,
txHash,
),
);
Expand All @@ -118,7 +118,7 @@ describe('e2e_fees/private_refunds', () => {
t.bobAddress,
token.address,
deriveStorageSlotInMap(TokenContract.storage.balances.slot, t.bobAddress),
TokenContract.notes.TokenNote.id,
TokenContract.notes.IntNote.id,
txHash,
),
);
Expand Down

0 comments on commit f9a8fb8

Please sign in to comment.