Skip to content

Commit 7938402

Browse files
authored
refactor!: nuking no-longer necessary ValueNote utils (#17059)
Fixes #16879 We had utils in the `value_note` package that through time and all the API refactors just became unnecessary: they were used only in our testing contracts and I don't think it was a good place for those in the first place. For this reason I nuke those in this PR. This is admittedly a very low-priority task but I had a bit of spare time so decided to just tackle that.
2 parents 3295cd5 + 21cecb4 commit 7938402

File tree

8 files changed

+63
-126
lines changed

8 files changed

+63
-126
lines changed

docs/docs/migration_notes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ This naming change resulted in quite a few changes and if you've access private
2222
+ let header = context.get_anchor_block_header();
2323
```
2424

25+
### Removed ValueNote utils
26+
27+
The `value_note::utils` module has been removed because it was incorrect to have those in the value note package.
28+
29+
For the increment function you can easily just insert the note:
30+
31+
```diff
32+
- use value_note::utils;
33+
- utils::increment(storage.notes.at(owner), value, owner, sender);
34+
+ let note = ValueNote::new(value, owner);
35+
+ storage.notes.at(owner).insert(note).emit(&mut context, owner, MessageDelivery.CONSTRAINED_ONCHAIN);
36+
```
37+
2538
### PrivateMutable: replace / initialize_or_replace behaviour change
2639

2740
**Motivation:**

noir-projects/aztec-nr/value-note/src/balance_utils.nr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ use dep::aztec::{
33
context::UtilityContext, note::note_viewer_options::NoteViewerOptions, state_vars::PrivateSet,
44
};
55

6+
// DEPRECATED: Having this functionality in the value note package is incorrect and will be removed in the future.
67
pub unconstrained fn get_balance(set: PrivateSet<ValueNote, UtilityContext>) -> Field {
78
get_balance_with_offset(set, 0)
89
}
910

11+
// DEPRECATED: Having this functionality in the value note package is incorrect and will be removed in the future.
1012
pub unconstrained fn get_balance_with_offset(
1113
set: PrivateSet<ValueNote, UtilityContext>,
1214
offset: u32,

noir-projects/aztec-nr/value-note/src/filter.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use aztec::{
66
},
77
};
88

9+
// DEPRECATED: Having this functionality in the value note package is incorrect and will be removed in the future.
910
pub fn filter_notes_min_sum(
1011
notes: [Option<RetrievedNote<ValueNote>>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL],
1112
min_sum: Field,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod balance_utils;
22
pub mod filter;
3-
pub mod utils;
43
pub mod value_note;

noir-projects/aztec-nr/value-note/src/utils.nr

Lines changed: 0 additions & 85 deletions
This file was deleted.

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
// would alter the metrics we're capturing in the benchmarks, and we want to keep the
44
// subject being tested as unmodified as possible so we can detect metric changes that
55

6-
use dep::aztec::macros::aztec;
6+
use aztec::macros::aztec;
77

88
#[aztec]
99
pub contract Benchmarking {
10-
use dep::aztec::{
10+
use aztec::{
11+
macros::{functions::{private, public}, storage::storage},
12+
messages::message_delivery::MessageDelivery,
1113
note::note_getter_options::NoteGetterOptions,
1214
protocol_types::address::AztecAddress,
1315
state_vars::{Map, PrivateSet, PublicMutable},
1416
};
15-
use dep::value_note::{utils::increment, value_note::ValueNote};
16-
17-
use dep::aztec::macros::{functions::{private, public}, storage::storage};
17+
use value_note::value_note::ValueNote;
1818

1919
#[storage]
2020
struct Storage<Context> {
@@ -25,9 +25,12 @@ pub contract Benchmarking {
2525
// Creates a new value note for the target owner. Use this method to seed an initial set of notes.
2626
#[private]
2727
fn create_note(owner: AztecAddress, value: Field) {
28-
// docs:start:increment_valuenote
29-
increment(storage.notes.at(owner), value, owner);
30-
// docs:end:increment_valuenote
28+
let note = ValueNote::new(value, owner);
29+
storage.notes.at(owner).insert(note).emit(
30+
&mut context,
31+
owner,
32+
MessageDelivery.CONSTRAINED_ONCHAIN,
33+
);
3134
}
3235
// Deletes a note at a specific index in the set and creates a new one with the same value.
3336
// We explicitly pass in the note index so we can ensure we consume different notes when sending
@@ -40,7 +43,7 @@ pub contract Benchmarking {
4043
let mut getter_options = NoteGetterOptions::new();
4144
let notes = owner_notes.pop_notes(getter_options.set_limit(1).set_offset(index));
4245
let note = notes.get(0);
43-
increment(owner_notes, note.value(), owner);
46+
owner_notes.insert(note).emit(&mut context, owner, MessageDelivery.CONSTRAINED_ONCHAIN);
4447
}
4548

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

noir-projects/noir-contracts/contracts/test/stateful_test_contract/src/main.nr

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
// A contract used for testing a random hodgepodge of small features from simulator and end-to-end tests.
2-
use dep::aztec::macros::aztec;
2+
use aztec::macros::aztec;
33

44
#[aztec]
55
pub contract StatefulTest {
6-
use dep::aztec::macros::{
6+
use aztec::macros::{
77
functions::{
88
initialization_utils::assert_is_initialized_private, initializer, noinitcheck, private,
99
public, utility, view,
1010
},
1111
storage::storage,
1212
};
13-
use dep::aztec::{
13+
use aztec::{
14+
messages::message_delivery::MessageDelivery,
15+
note::note_getter_options::NoteGetterOptions,
1416
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
1517
state_vars::{Map, PrivateSet, PublicMutable},
1618
};
17-
use dep::value_note::{balance_utils, utils::{decrement, increment}, value_note::ValueNote};
19+
use value_note::{balance_utils, value_note::ValueNote};
1820

1921
#[storage]
2022
struct Storage<Context> {
@@ -49,7 +51,8 @@ pub contract StatefulTest {
4951
fn create_note(owner: AztecAddress, value: Field) {
5052
if (value != 0) {
5153
let loc = storage.notes.at(owner);
52-
increment(loc, value, owner);
54+
let note = ValueNote::new(value, owner);
55+
loc.insert(note).emit(&mut context, owner, MessageDelivery.CONSTRAINED_ONCHAIN);
5356
}
5457
}
5558

@@ -58,32 +61,39 @@ pub contract StatefulTest {
5861
fn create_note_no_init_check(owner: AztecAddress, value: Field) {
5962
if (value != 0) {
6063
let loc = storage.notes.at(owner);
61-
increment(loc, value, owner);
64+
let note = ValueNote::new(value, owner);
65+
loc.insert(note).emit(&mut context, owner, MessageDelivery.CONSTRAINED_ONCHAIN);
6266
}
6367
}
6468

6569
#[private]
66-
fn destroy_and_create(recipient: AztecAddress, amount: Field) {
70+
fn destroy_and_create(recipient: AztecAddress) {
6771
assert_is_initialized_private(&mut context);
6872
let sender = context.msg_sender();
6973

7074
let sender_notes = storage.notes.at(sender);
71-
decrement(sender_notes, amount, sender);
75+
let _ = sender_notes.pop_notes(NoteGetterOptions::new().set_limit(2));
7276

73-
let recipient_notes = storage.notes.at(recipient);
74-
increment(recipient_notes, amount, recipient);
77+
storage.notes.at(recipient).insert(ValueNote::new(92, recipient)).emit(
78+
&mut context,
79+
recipient,
80+
MessageDelivery.CONSTRAINED_ONCHAIN,
81+
);
7582
}
7683

7784
#[private]
7885
#[noinitcheck]
79-
fn destroy_and_create_no_init_check(recipient: AztecAddress, amount: Field) {
86+
fn destroy_and_create_no_init_check(recipient: AztecAddress) {
8087
let sender = context.msg_sender();
8188

8289
let sender_notes = storage.notes.at(sender);
83-
decrement(sender_notes, amount, sender);
90+
let _ = sender_notes.pop_notes(NoteGetterOptions::new().set_limit(2));
8491

85-
let recipient_notes = storage.notes.at(recipient);
86-
increment(recipient_notes, amount, recipient);
92+
storage.notes.at(recipient).insert(ValueNote::new(92, recipient)).emit(
93+
&mut context,
94+
recipient,
95+
MessageDelivery.CONSTRAINED_ONCHAIN,
96+
);
8797
}
8898

8999
#[public]

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.test.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ describe('Private Execution test suite', () => {
442442
});
443443

444444
it('should run the destroy_and_create function', async () => {
445-
const amountToTransfer = 100n;
446-
447445
const storageSlot = await deriveStorageSlotInMap(StatefulTestContractArtifact.storageLayout['notes'].slot, owner);
448446
const recipientStorageSlot = await deriveStorageSlotInMap(
449447
StatefulTestContractArtifact.storageLayout['notes'].slot,
@@ -466,7 +464,7 @@ describe('Private Execution test suite', () => {
466464

467465
await insertLeaves(consumedNotes);
468466

469-
const args = [recipient, amountToTransfer];
467+
const args = [recipient];
470468
const { entrypoint: result } = await runSimulator({
471469
args,
472470
artifact: StatefulTestContractArtifact,
@@ -480,25 +478,22 @@ describe('Private Execution test suite', () => {
480478
const nullifiers = result.publicInputs.nullifiers;
481479
expect(nullifiers.claimedLength).toBe(consumedNotes.length);
482480

483-
expect(result.newNotes).toHaveLength(2);
484-
const [changeNote, recipientNote] = result.newNotes;
481+
expect(result.newNotes).toHaveLength(1);
482+
const [recipientNote] = result.newNotes;
485483
expect(recipientNote.storageSlot).toEqual(recipientStorageSlot);
484+
expect(recipientNote.note.items[0]).toEqual(new Fr(92n));
486485

487486
const noteHashes = result.publicInputs.noteHashes;
488-
expect(noteHashes.claimedLength).toBe(2);
489-
490-
expect(recipientNote.note.items[0]).toEqual(new Fr(amountToTransfer));
491-
expect(changeNote.note.items[0]).toEqual(new Fr(40n));
487+
expect(noteHashes.claimedLength).toBe(1);
492488

493489
const privateLogs = result.publicInputs.privateLogs;
494-
expect(privateLogs.claimedLength).toBe(2);
490+
expect(privateLogs.claimedLength).toBe(1);
495491

496492
const readRequests = result.publicInputs.noteHashReadRequests;
497493
expect(readRequests.claimedLength).toBe(consumedNotes.length);
498494
});
499495

500496
it('should be able to destroy_and_create with dummy notes', async () => {
501-
const amountToTransfer = 100n;
502497
const balance = 160n;
503498

504499
const storageSlot = await deriveStorageSlotInMap(new Fr(1n), owner);
@@ -516,7 +511,7 @@ describe('Private Execution test suite', () => {
516511

517512
await insertLeaves(consumedNotes);
518513

519-
const args = [recipient, amountToTransfer];
514+
const args = [recipient];
520515
const { entrypoint: result } = await runSimulator({
521516
args,
522517
artifact: StatefulTestContractArtifact,
@@ -528,13 +523,12 @@ describe('Private Execution test suite', () => {
528523
const nullifiers = result.publicInputs.nullifiers;
529524
expect(nullifiers.claimedLength).toBe(consumedNotes.length);
530525

531-
expect(result.newNotes).toHaveLength(2);
532-
const [changeNote, recipientNote] = result.newNotes;
533-
expect(recipientNote.note.items[0]).toEqual(new Fr(amountToTransfer));
534-
expect(changeNote.note.items[0]).toEqual(new Fr(balance - amountToTransfer));
526+
// We've inserted just one note for recipient with hardcoded value 92
527+
expect(result.newNotes).toHaveLength(1);
528+
expect(result.newNotes[0].note.items[0]).toEqual(new Fr(92n));
535529

536530
const privateLogs = result.publicInputs.privateLogs;
537-
expect(privateLogs.claimedLength).toBe(2);
531+
expect(privateLogs.claimedLength).toBe(1);
538532
});
539533
});
540534

0 commit comments

Comments
 (0)