Skip to content

Commit 3a2de80

Browse files
author
Esau
committed
add
fix
1 parent 486aa01 commit 3a2de80

28 files changed

+13785
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
target
1+
target
2+
node_modules
3+
.DS_Store

note-send-proof/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
target
3+
codegenCache.json
4+
artifacts
5+
dist
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "circuits"
3+
type = "bin"
4+
authors = [""]
5+
6+
[dependencies]
7+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.87.9", directory = "noir-projects/aztec-nr/aztec" }
8+
uint_note = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.87.9", directory = "noir-projects/aztec-nr/uint-note" }
9+
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
settled_note_hash: "0x109ebaffd4e6aa4e4c305606addd352dd432d37fd5541b67e86e7310cdf80053"
2+
contract_address: "0x0f140443f51fe2a1b9ca04b279cda12e2bbdd073efb6b09aed79a6a4315957d0"
3+
recipient: "0x116586dbcc81434e8b0727cbe282be01271886275e347489947af5d1b94618a4"
4+
randomness: "0x0000000000000000000000000000000000000000000000000000000000001b39",
5+
value: 69,
6+
storage_slot: "0x134f661dca40dad62341c230269bbed01da64b506e8a0e6e0a452a9262023012"
7+
note_nonce: "0x0fe225cdf1421a3266faf50f46025b73bb57858d10f7cd62875b47e988c64edd"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use dep::aztec::protocol_types::{
2+
address::AztecAddress,
3+
constants::{GENERATOR_INDEX__SILOED_NOTE_HASH, GENERATOR_INDEX__UNIQUE_NOTE_HASH},
4+
traits::FromField,
5+
};
6+
use dep::aztec::note::note_interface::NoteHash;
7+
use dep::poseidon;
8+
9+
use uint_note::uint_note::UintNote;
10+
11+
fn main(
12+
settled_note_hash: pub Field,
13+
contract_address: pub Field,
14+
recipient: pub Field,
15+
randomness: Field,
16+
value: pub u128,
17+
storage_slot: Field,
18+
note_nonce: Field,
19+
) {
20+
let note = UintNote { value, randomness, owner: AztecAddress::from_field(recipient) };
21+
let note_hash = note.compute_note_hash(storage_slot);
22+
23+
let siloed_note_hash = poseidon::poseidon2::Poseidon2::hash([GENERATOR_INDEX__SILOED_NOTE_HASH as Field, contract_address, note_hash], 3);
24+
let unique_note_hash = poseidon::poseidon2::Poseidon2::hash([GENERATOR_INDEX__UNIQUE_NOTE_HASH as Field, note_nonce, siloed_note_hash], 3);
25+
26+
assert_eq(settled_note_hash, unique_note_hash);
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "getting_started_contract"
3+
authors = [""]
4+
compiler_version = ">=1.0.0"
5+
type = "contract"
6+
7+
[dependencies]
8+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.87.9", directory = "noir-projects/aztec-nr/aztec" }
9+
uint_note = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.87.9", directory = "noir-projects/aztec-nr/uint-note" }
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use aztec::macros::aztec;
2+
3+
#[aztec]
4+
pub contract GettingStarted {
5+
use aztec::{
6+
state_vars::{private_mutable::PrivateMutable, private_set::PrivateSet, public_mutable::PublicMutable, map::Map},
7+
messages::logs::note::encode_and_encrypt_note_unconstrained,
8+
note::{constants::MAX_NOTES_PER_PAGE, note_viewer_options::NoteViewerOptions},
9+
10+
macros::{
11+
functions::{initializer, private, public, utility, internal},
12+
storage::storage,
13+
},
14+
protocol_types::{
15+
address::AztecAddress,
16+
},
17+
};
18+
19+
use uint_note::uint_note::UintNote;
20+
21+
#[storage]
22+
struct Storage<Context> {
23+
contract_private_state: PrivateMutable<UintNote, Context>,
24+
user_private_state: Map<AztecAddress, PrivateSet<UintNote, Context>, Context>,
25+
contract_public_state: PublicMutable<u128, Context>,
26+
user_public_state: Map<AztecAddress, PublicMutable<u128, Context>, Context>,
27+
owner: PublicMutable<AztecAddress, Context>,
28+
}
29+
30+
#[initializer]
31+
#[public]
32+
fn setup() {
33+
storage.owner.write(context.msg_sender());
34+
}
35+
36+
#[private]
37+
fn create_note_for_user(value: u128) {
38+
let note_owner = context.msg_sender();
39+
storage.user_private_state.at(note_owner)
40+
// randomness should actually be random, but is a workaround because we can't recover it now
41+
.insert(UintNote { value, owner: note_owner, randomness: 6969 })
42+
.emit(encode_and_encrypt_note_unconstrained(&mut context, note_owner, note_owner));
43+
}
44+
45+
#[public]
46+
fn modify_public_state_for_user(value: u128) {
47+
storage.user_public_state.at(context.msg_sender()).write(value);
48+
}
49+
50+
#[private]
51+
fn modify_private_state_for_contract(value: u128) {
52+
let maybe_contract_owner = context.msg_sender();
53+
54+
storage.contract_private_state.initialize_or_replace(UintNote::new(value, maybe_contract_owner))
55+
.emit(encode_and_encrypt_note_unconstrained(&mut context, maybe_contract_owner, maybe_contract_owner));
56+
57+
GettingStarted::at(context.this_address())._assert_is_owner(maybe_contract_owner).enqueue(&mut context);
58+
}
59+
60+
#[public]
61+
#[internal]
62+
fn _assert_is_owner(maybe_owner: AztecAddress) {
63+
assert_eq(maybe_owner, storage.owner.read());
64+
}
65+
66+
#[public]
67+
fn modify_public_state_for_contract(value: u128) {
68+
let maybe_contract_owner = context.msg_sender();
69+
70+
GettingStarted::at(context.this_address())._assert_is_owner(maybe_contract_owner).call(&mut context);
71+
72+
storage.user_public_state.at(context.msg_sender()).write(value);
73+
}
74+
75+
#[utility]
76+
unconstrained fn view_created_notes(owner: AztecAddress) -> BoundedVec<UintNote, MAX_NOTES_PER_PAGE> {
77+
storage.user_private_state.at(owner).view_notes(NoteViewerOptions::new())
78+
}
79+
}

0 commit comments

Comments
 (0)