Skip to content

Commit

Permalink
chore: remove hardcoded storage slot values (AztecProtocol#4398)
Browse files Browse the repository at this point in the history
This uses the storage slot getter introduced in
AztecProtocol#4200 to remove some
intances were we were still hardcoding storage slot values. I did not
find any other such cases.
  • Loading branch information
nventuro authored Feb 5, 2024
1 parent 341b0a1 commit d2294a4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions yarn-project/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ contract Test {

#[aztec(private)]
fn call_create_note(value: Field, owner: AztecAddress, storage_slot: Field) {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let mut note = ValueNote::new(value, owner);
create_note(&mut context, storage_slot, &mut note, true);
}

#[aztec(private)]
fn call_get_notes(storage_slot: Field, active_or_nullified: bool) {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let mut options = NoteGetterOptions::new();
if (active_or_nullified) {
Expand All @@ -112,7 +116,9 @@ contract Test {

#[aztec(private)]
fn call_get_notes_many(storage_slot: Field, active_or_nullified: bool) {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let mut options = NoteGetterOptions::new();
if (active_or_nullified) {
Expand All @@ -128,7 +134,9 @@ contract Test {
}

unconstrained fn call_view_notes(storage_slot: Field, active_or_nullified: bool) -> pub Field {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let mut options = NoteViewerOptions::new();
if (active_or_nullified) {
Expand All @@ -144,7 +152,9 @@ contract Test {
storage_slot: Field,
active_or_nullified: bool
) -> pub [Field; 2] {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let mut options = NoteViewerOptions::new();
if (active_or_nullified) {
Expand All @@ -158,7 +168,9 @@ contract Test {

#[aztec(private)]
fn call_destroy_note(storage_slot: Field) {
assert(storage_slot != 1, "storage slot 1 is reserved for example_constant");
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);

let options = NoteGetterOptions::new();
let opt_notes: [Option<ValueNote>; MAX_READ_REQUESTS_PER_CALL] = get_notes(&mut context, storage_slot, options);
Expand Down

0 comments on commit d2294a4

Please sign in to comment.