Skip to content

Commit

Permalink
feat!: delete field note (#5959)
Browse files Browse the repository at this point in the history
`TestContract` was its sole user, so I just created `TestNote` inside
that crate to replace it.

Closes #5932
  • Loading branch information
nventuro authored Apr 23, 2024
1 parent 8f73f18 commit ae18396
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/docs/developers/contracts/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Smart Contracts
---

This section is a collection of how-to guides and references for building smart contracts with Aztec.nr.
This section is a collection of how-to guides and references for building smart contracts with Aztec.nr.

If you are looking for an overview of how smart contracts work, head to the [Concepts section](../../learn/concepts/smart_contracts/main.md).

Expand Down
6 changes: 6 additions & 0 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Aztec is in full-speed development. Literally every version breaks compatibility

## 0.36.0

## `FieldNote` removed

`FieldNote` only existed for testing purposes, and was not a note type that should be used in any real application. Its name unfortunately led users to think that it was a note type suitable to store a `Field` value, which it wasn't.

If using `FieldNote`, you most likely want to use `ValueNote` instead, which has both randomness for privacy and an owner for proper nullification.

## `SlowUpdatesTree` replaced for `SharedMutable`

The old `SlowUpdatesTree` contract and libraries have been removed from the codebase, use the new `SharedMutable` library instead. This will require that you add a global variable specifying a delay in blocks for updates, and replace the slow updates tree state variable with `SharedMutable` variables.
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"aztec",
"compressed-string",
"easy-private-state",
"field-note",
"value-note",
"tests",
]
8 changes: 0 additions & 8 deletions noir-projects/aztec-nr/field-note/Nargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion noir-projects/aztec-nr/field-note/src/lib.nr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ contract ImportTest {

use dep::test::{Test, Test::DeepStruct, Test::DummyNote};

use dep::test::Test::FieldNote;
use dep::test::Test::ValueNote;

// Calls the test_code_gen on the Test contract at the target address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
field_note = { path = "../../../aztec-nr/field-note" }
value_note = { path = "../../../aztec-nr/value-note" }
token_portal_content_hash_lib = { path = "../token_portal_content_hash_lib" }
19 changes: 10 additions & 9 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod test_note;

// A contract used for testing a random hodgepodge of small features from simulator and end-to-end tests.
contract Test {

use dep::aztec::prelude::{
AztecAddress, EthAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
PrivateContext, PrivateImmutable, PrivateSet, SharedImmutable
Expand All @@ -25,18 +28,19 @@ contract Test {
oracle::{get_public_key::get_public_key as get_public_key_oracle, unsafe_rand::unsafe_rand}
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
use dep::field_note::field_note::FieldNote;
use dep::value_note::value_note::ValueNote;

use crate::test_note::TestNote;

#[aztec(event)]
struct ExampleEvent {
value: Field,
}

#[aztec(storage)]
struct Storage {
example_constant: PrivateImmutable<FieldNote>,
example_set: PrivateSet<FieldNote>,
example_constant: PrivateImmutable<TestNote>,
example_set: PrivateSet<TestNote>,
}

#[aztec(private)]
Expand Down Expand Up @@ -122,10 +126,7 @@ contract Test {
opt_notes[0].unwrap().value
}

unconstrained fn call_view_notes_many(
storage_slot: Field,
active_or_nullified: bool
) -> pub [Field; 2] {
unconstrained fn call_view_notes_many(storage_slot: Field, active_or_nullified: bool) -> pub [Field; 2] {
assert(
storage_slot != storage.example_constant.get_storage_slot(), "this storage slot is reserved for example_constant"
);
Expand Down Expand Up @@ -298,7 +299,7 @@ contract Test {

#[aztec(private)]
fn set_constant(value: Field) {
let mut note = FieldNote::new(value);
let mut note = TestNote::new(value);
storage.example_constant.initialize(&mut note, false);
}

Expand Down Expand Up @@ -352,7 +353,7 @@ contract Test {
let notes_set = storage.example_set;
let secret_hash = compute_secret_hash(secret);
let mut options = NoteGetterOptions::new();
options = options.select(FieldNote::properties().value, secret_hash, Option::none()).set_limit(1);
options = options.select(TestNote::properties().value, secret_hash, Option::none()).set_limit(1);
let notes = notes_set.get_notes(options);
let note = notes[0].unwrap_unchecked();
notes_set.remove(note);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use dep::aztec::{
context::PrivateContext
};

global FIELD_NOTE_LEN: Field = 1;
global TEST_NOTE_LEN: Field = 1;

// A note which stores a field and is expected to be passed around using the `addNote` function.
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform serialized_note
// attack on it.
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform
// serialized_note attack on it. This note has been developed purely for testing purposes so that it can easily be
// manually added to PXE. Do not use for real applications.
#[aztec(note)]
struct FieldNote {
struct TestNote {
value: Field,
}

impl NoteInterface<FIELD_NOTE_LEN> for FieldNote {
impl NoteInterface<TEST_NOTE_LEN> for TestNote {

fn compute_nullifier(self, _context: &mut PrivateContext) -> Field {
// This note is expected to be shared between users and for this reason can't be nullified using a secret.
Expand All @@ -27,14 +28,13 @@ impl NoteInterface<FIELD_NOTE_LEN> for FieldNote {

fn broadcast(self, context: &mut PrivateContext, slot: Field) {
assert(
false, "FieldNote does not support broadcast. Add it to PXE directly using the `.addNote` function."
false, "TestNote does not support broadcast. Add it to PXE directly using the `.addNote` function."
);
}
}

impl FieldNote {
impl TestNote {
pub fn new(value: Field) -> Self {
FieldNote { value, header: NoteHeader::empty() }
TestNote { value, header: NoteHeader::empty() }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
field_note = { path = "../../../aztec-nr/field-note" }
authwit = { path = "../../../aztec-nr/authwit" }
authwit = { path = "../../../aztec-nr/authwit" }
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ contract TokenBlacklist {
state_vars::{Map, PublicMutable, PrivateSet, SharedMutable, SharedImmutable}
};

use dep::field_note::field_note::FieldNote;

use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}};

use crate::types::{transparent_note::TransparentNote, token_note::TokenNote, balances_map::BalancesMap, roles::UserFlags};
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('e2e_non_contract_account', () => {
}, 120_000);

// Note: This test doesn't really belong here as it doesn't have anything to do with non-contract accounts. I needed
// to test the FieldNote functionality and it doesn't really fit anywhere else. Creating a separate e2e test for this
// to test the TestNote functionality and it doesn't really fit anywhere else. Creating a separate e2e test for this
// seems wasteful. Move this test if a better place is found.
it('can set and get a constant', async () => {
const value = 123n;
Expand All @@ -86,7 +86,7 @@ describe('e2e_non_contract_account', () => {
wallet.getCompleteAddress().address,
contract.address,
TestContract.storage.example_constant.slot,
TestContract.notes.FieldNote.id,
TestContract.notes.TestNote.id,
txHash,
);
await wallet.addNote(extendedNote);
Expand Down

0 comments on commit ae18396

Please sign in to comment.