Skip to content

Commit 60fe5f7

Browse files
author
sklppy88
committed
init
1 parent c3f9087 commit 60fe5f7

File tree

16 files changed

+132
-43
lines changed

16 files changed

+132
-43
lines changed

noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr

+24-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn compute_payload_and_hash<Event, let N: u32>(
1212
ovsk_app: Field,
1313
ovpk: OvpkM,
1414
recipient: AztecAddress,
15+
sender: AztecAddress,
1516
) -> ([u8; 384 + N * 32], Field)
1617
where
1718
Event: EventInterface<N>,
@@ -25,6 +26,7 @@ where
2526
ovsk_app,
2627
ovpk,
2728
recipient,
29+
sender,
2830
plaintext,
2931
false,
3032
);
@@ -38,19 +40,29 @@ unconstrained fn compute_payload_and_hash_unconstrained<Event, let N: u32>(
3840
randomness: Field,
3941
ovpk: OvpkM,
4042
recipient: AztecAddress,
43+
sender: AztecAddress,
4144
) -> ([u8; 384 + N * 32], Field)
4245
where
4346
Event: EventInterface<N>,
4447
{
4548
let ovsk_app = get_ovsk_app(ovpk.hash());
46-
compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, recipient)
49+
compute_payload_and_hash(
50+
context,
51+
event,
52+
randomness,
53+
ovsk_app,
54+
ovpk,
55+
recipient,
56+
sender,
57+
)
4758
}
4859

4960
pub fn encode_and_encrypt_event<Event, let N: u32>(
5061
context: &mut PrivateContext,
5162
ovpk: OvpkM,
5263
recipient: AztecAddress,
53-
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
64+
sender: AztecAddress,
65+
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
5466
where
5567
Event: EventInterface<N>,
5668
{
@@ -62,7 +74,7 @@ where
6274
let randomness = unsafe { random() };
6375
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
6476
let (encrypted_log, log_hash) =
65-
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
77+
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender);
6678
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
6779
}
6880
}
@@ -71,7 +83,8 @@ pub fn encode_and_encrypt_event_unconstrained<Event, let N: u32>(
7183
context: &mut PrivateContext,
7284
ovpk: OvpkM,
7385
recipient: AztecAddress,
74-
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
86+
sender: AztecAddress,
87+
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
7588
where
7689
Event: EventInterface<N>,
7790
{
@@ -82,7 +95,7 @@ where
8295
// value generation.
8396
let randomness = unsafe { random() };
8497
let (encrypted_log, log_hash) = unsafe {
85-
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
98+
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender)
8699
};
87100
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
88101
}
@@ -96,14 +109,15 @@ pub fn encode_and_encrypt_event_with_randomness<Event, let N: u32>(
96109
randomness: Field,
97110
ovpk: OvpkM,
98111
recipient: AztecAddress,
99-
) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress)](Event) -> ()
112+
sender: AztecAddress,
113+
) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress, AztecAddress)](Event) -> ()
100114
where
101115
Event: EventInterface<N>,
102116
{
103117
|e: Event| {
104118
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
105119
let (encrypted_log, log_hash) =
106-
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
120+
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender);
107121
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
108122
}
109123
}
@@ -113,7 +127,8 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained<Event, let N: u32>
113127
randomness: Field,
114128
ovpk: OvpkM,
115129
recipient: AztecAddress,
116-
) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress)](Event) -> ()
130+
sender: AztecAddress,
131+
) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
117132
where
118133
Event: EventInterface<N>,
119134
{
@@ -133,7 +148,7 @@ where
133148
// return the log from this function to the app, otherwise it could try to do stuff with it and then that might
134149
// be wrong.
135150
let (encrypted_log, log_hash) = unsafe {
136-
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
151+
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender)
137152
};
138153
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
139154
}

noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr

+22-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn compute_payload_and_hash<Note, let N: u32>(
1515
ovsk_app: Field,
1616
ovpk: OvpkM,
1717
recipient: AztecAddress,
18+
sender: AztecAddress,
1819
) -> (u32, [u8; 385 + N * 32], Field)
1920
where
2021
Note: NoteInterface<N>,
@@ -32,8 +33,15 @@ where
3233
let plaintext = note.to_be_bytes(storage_slot);
3334

3435
// For note logs we always include public values prefix
35-
let encrypted_log: [u8; 385 + N * 32] =
36-
compute_private_log_payload(contract_address, ovsk_app, ovpk, recipient, plaintext, true);
36+
let encrypted_log: [u8; 385 + N * 32] = compute_private_log_payload(
37+
contract_address,
38+
ovsk_app,
39+
ovpk,
40+
recipient,
41+
sender,
42+
plaintext,
43+
true,
44+
);
3745
let log_hash = sha256_to_field(encrypted_log);
3846

3947
(note_hash_counter, encrypted_log, log_hash)
@@ -44,12 +52,13 @@ unconstrained fn compute_payload_and_hash_unconstrained<Note, let N: u32>(
4452
note: Note,
4553
ovpk: OvpkM,
4654
recipient: AztecAddress,
55+
sender: AztecAddress,
4756
) -> (u32, [u8; 385 + N * 32], Field)
4857
where
4958
Note: NoteInterface<N>,
5059
{
5160
let ovsk_app = get_ovsk_app(ovpk.hash());
52-
compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient)
61+
compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient, sender)
5362
}
5463

5564
// This function seems to be affected by the following Noir bug:
@@ -59,15 +68,17 @@ pub fn encode_and_encrypt_note<Note, let N: u32>(
5968
context: &mut PrivateContext,
6069
ovpk: OvpkM,
6170
recipient: AztecAddress,
62-
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
71+
// TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address?
72+
sender: AztecAddress,
73+
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
6374
where
6475
Note: NoteInterface<N>,
6576
{
6677
|e: NoteEmission<Note>| {
6778
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
6879

6980
let (note_hash_counter, encrypted_log, log_hash) =
70-
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient);
81+
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient, sender);
7182
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
7283
}
7384
}
@@ -76,7 +87,9 @@ pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
7687
context: &mut PrivateContext,
7788
ovpk: OvpkM,
7889
recipient: AztecAddress,
79-
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
90+
// TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address?
91+
sender: AztecAddress,
92+
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
8093
where
8194
Note: NoteInterface<N>,
8295
{
@@ -100,8 +113,9 @@ where
100113
// for the log to be deleted when it shouldn't have (which is fine - they can already make the content be
101114
// whatever), or cause for the log to not be deleted when it should have (which is also fine - it'll be a log
102115
// for a note that doesn't exist).
103-
let (note_hash_counter, encrypted_log, log_hash) =
104-
unsafe { compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient) };
116+
let (note_hash_counter, encrypted_log, log_hash) = unsafe {
117+
compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient, sender)
118+
};
105119
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
106120
}
107121
}

noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn compute_private_log_payload<let P: u32, let M: u32>(
1919
ovsk_app: Field,
2020
ovpk: OvpkM,
2121
recipient: AztecAddress,
22+
sender: AztecAddress,
2223
plaintext: [u8; P],
2324
include_public_values_prefix: bool,
2425
) -> [u8; M] {
@@ -206,11 +207,16 @@ mod test {
206207
0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c,
207208
);
208209

210+
let sender = AztecAddress::from_field(
211+
0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c,
212+
);
213+
209214
let log = compute_private_log_payload(
210215
contract_address,
211216
ovsk_app,
212217
ovpk_m,
213218
recipient,
219+
sender,
214220
plaintext,
215221
false,
216222
);

noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,15 @@ comptime fn generate_setup_payload(
463463
}
464464
}
465465

466-
fn encrypt_log(self, context: &mut PrivateContext, ovpk: aztec::protocol_types::public_keys::OvpkM, recipient: aztec::protocol_types::address::AztecAddress) -> [Field; $encrypted_log_field_length] {
466+
fn encrypt_log(self, context: &mut PrivateContext, ovpk: aztec::protocol_types::public_keys::OvpkM, recipient: aztec::protocol_types::address::AztecAddress, sender: aztec::protocol_types::address::AztecAddress) -> [Field; $encrypted_log_field_length] {
467467
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
468468

469469
let encrypted_log_bytes: [u8; $encrypted_log_byte_length] = aztec::encrypted_logs::payload::compute_private_log_payload(
470470
context.this_address(),
471471
ovsk_app,
472472
ovpk,
473473
recipient,
474+
sender,
474475
self.log_plaintext,
475476
true
476477
);

noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ impl<Context> EasyPrivateUint<Context> {
2222

2323
impl EasyPrivateUint<&mut PrivateContext> {
2424
// Very similar to `value_note::utils::increment`.
25-
pub fn add(self, addend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: AztecAddress) {
25+
pub fn add(
26+
self,
27+
addend: u64,
28+
owner: AztecAddress,
29+
outgoing_viewer: AztecAddress,
30+
sender: AztecAddress,
31+
) {
2632
let outgoing_viewer_keys = get_public_keys(outgoing_viewer);
2733
// Creates new note for the owner.
2834
let mut addend_note = ValueNote::new(addend as Field, owner);
@@ -39,7 +45,13 @@ impl EasyPrivateUint<&mut PrivateContext> {
3945
}
4046

4147
// Very similar to `value_note::utils::decrement`.
42-
pub fn sub(self, subtrahend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: AztecAddress) {
48+
pub fn sub(
49+
self,
50+
subtrahend: u64,
51+
owner: AztecAddress,
52+
outgoing_viewer: AztecAddress,
53+
sender: AztecAddress,
54+
) {
4355
let outgoing_viewer_keys = get_public_keys(outgoing_viewer);
4456

4557
// docs:start:pop_notes

noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ contract AppSubscription {
117117
let mut subscription_note =
118118
SubscriptionNote::new(subscriber, expiry_block_number, tx_count);
119119
storage.subscriptions.at(subscriber).initialize_or_replace(&mut subscription_note).emit(
120-
encode_and_encrypt_note(&mut context, msg_sender_ovpk_m, subscriber, context.msg_sender()),
120+
encode_and_encrypt_note(
121+
&mut context,
122+
msg_sender_ovpk_m,
123+
subscriber,
124+
context.msg_sender(),
125+
),
121126
);
122127
}
123128

noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ contract Benchmarking {
2222
#[private]
2323
fn create_note(owner: AztecAddress, outgoing_viewer: AztecAddress, value: Field) {
2424
// docs:start:increment_valuenote
25-
increment(storage.notes.at(owner), value, owner, outgoing_viewer);
25+
increment(
26+
storage.notes.at(owner),
27+
value,
28+
owner,
29+
outgoing_viewer,
30+
outgoing_viewer,
31+
);
2632
// docs:end:increment_valuenote
2733
}
2834
// Deletes a note at a specific index in the set and creates a new one with the same value.
@@ -36,7 +42,13 @@ contract Benchmarking {
3642
let mut getter_options = NoteGetterOptions::new();
3743
let notes = owner_notes.pop_notes(getter_options.set_limit(1).set_offset(index));
3844
let note = notes.get(0);
39-
increment(owner_notes, note.value, owner, outgoing_viewer);
45+
increment(
46+
owner_notes,
47+
note.value,
48+
owner,
49+
outgoing_viewer,
50+
outgoing_viewer,
51+
);
4052
}
4153

4254
// Reads and writes to public storage and enqueues a call to another public function.

noir-projects/noir-contracts/contracts/counter_contract/src/main.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ contract Counter {
2424
// We can name our initializer anything we want as long as it's marked as aztec(initializer)
2525
fn initialize(headstart: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) {
2626
let counters = storage.counters;
27-
counters.at(owner).add(headstart, owner, outgoing_viewer);
27+
counters.at(owner).add(headstart, owner, outgoing_viewer, context.msg_sender());
2828
}
2929
// docs:end:constructor
3030

@@ -38,7 +38,7 @@ contract Counter {
3838
);
3939
}
4040
let counters = storage.counters;
41-
counters.at(owner).add(1, owner, outgoing_viewer);
41+
counters.at(owner).add(1, owner, outgoing_viewer, context.msg_sender());
4242
}
4343
// docs:end:increment
4444
// docs:start:get_counter

noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ contract EasyPrivateToken {
2121
fn constructor(initial_supply: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) {
2222
let balances = storage.balances;
2323

24-
balances.at(owner).add(initial_supply, owner, outgoing_viewer);
24+
balances.at(owner).add(initial_supply, owner, outgoing_viewer, context.msg_sender());
2525
}
2626

2727
// Mints `amount` of tokens to `owner`.
2828
#[private]
2929
fn mint(amount: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) {
3030
let balances = storage.balances;
3131

32-
balances.at(owner).add(amount, owner, outgoing_viewer);
32+
balances.at(owner).add(amount, owner, outgoing_viewer, context.msg_sender());
3333
}
3434

3535
// Transfers `amount` of tokens from `sender` to a `recipient`.
@@ -42,8 +42,8 @@ contract EasyPrivateToken {
4242
) {
4343
let balances = storage.balances;
4444

45-
balances.at(sender).sub(amount, sender, outgoing_viewer);
46-
balances.at(recipient).add(amount, recipient, outgoing_viewer);
45+
balances.at(sender).sub(amount, sender, outgoing_viewer, sender);
46+
balances.at(recipient).add(amount, recipient, outgoing_viewer, sender);
4747
}
4848

4949
// Helper function to get the balance of a user ("unconstrained" is a Noir alternative of Solidity's "view" function).

noir-projects/noir-contracts/contracts/nft_contract/src/main.nr

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ contract NFT {
188188

189189
// We set the ovpk to the message sender's ovpk and we encrypt the log.
190190
let from_ovpk = get_public_keys(context.msg_sender()).ovpk_m;
191-
let setup_log = note_setup_payload.encrypt_log(context, from_ovpk, to);
191+
let setup_log =
192+
note_setup_payload.encrypt_log(context, from_ovpk, to, context.msg_sender());
192193

193194
// Using the x-coordinate as a hiding point slot is safe against someone else interfering with it because
194195
// we have a guarantee that the public functions of the transaction are executed right after the private ones

noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr

+12-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,20 @@ contract PendingNoteHashes {
139139
// Insert note
140140
let emission = owner_balance.insert(&mut note);
141141

142-
emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner, context.msg_sender()));
142+
emission.emit(encode_and_encrypt_note(
143+
&mut context,
144+
outgoing_viewer_ovpk_m,
145+
owner,
146+
context.msg_sender(),
147+
));
143148

144149
// Emit note again
145-
emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner, context.msg_sender()));
150+
emission.emit(encode_and_encrypt_note(
151+
&mut context,
152+
outgoing_viewer_ovpk_m,
153+
owner,
154+
context.msg_sender(),
155+
));
146156
}
147157

148158
// Nested/inner function to get a note and confirm it matches the expected value

0 commit comments

Comments
 (0)