From a915f78d5fc6c649da8384a88fb8a6cfb201cb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Tue, 23 Apr 2024 15:04:37 +0000 Subject: [PATCH 1/3] Delete field note --- docs/docs/developers/contracts/main.md | 2 +- docs/docs/misc/migration_notes.md | 6 ++++++ noir-projects/aztec-nr/Nargo.toml | 1 - noir-projects/aztec-nr/field-note/Nargo.toml | 8 -------- noir-projects/aztec-nr/field-note/src/lib.nr | 1 - .../import_test_contract/src/main.nr | 1 - .../contracts/test_contract/Nargo.toml | 1 - .../contracts/test_contract/src/main.nr | 19 ++++++++++--------- .../contracts/test_contract/src/test_note.nr} | 18 +++++++++--------- .../token_blacklist_contract/Nargo.toml | 1 - .../token_blacklist_contract/src/main.nr | 2 -- 11 files changed, 26 insertions(+), 34 deletions(-) delete mode 100644 noir-projects/aztec-nr/field-note/Nargo.toml delete mode 100644 noir-projects/aztec-nr/field-note/src/lib.nr rename noir-projects/{aztec-nr/field-note/src/field_note.nr => noir-contracts/contracts/test_contract/src/test_note.nr} (63%) diff --git a/docs/docs/developers/contracts/main.md b/docs/docs/developers/contracts/main.md index 2507154c6ba..b2ac8781286 100644 --- a/docs/docs/developers/contracts/main.md +++ b/docs/docs/developers/contracts/main.md @@ -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). diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index 731f78a774e..13891c0a2cb 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -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. + ## [Aztec.nr & js] Portal addresses Deployments have been modified. No longer are portal addresses treated as a special class, being immutably set on creation of a contract. They are no longer passed in differently compared to the other variables and instead should be implemented using usual storage by those who require it. One should use the storage that matches the usecase - likely shared storage to support private and public. diff --git a/noir-projects/aztec-nr/Nargo.toml b/noir-projects/aztec-nr/Nargo.toml index 94e4674f336..bd7bbc074c1 100644 --- a/noir-projects/aztec-nr/Nargo.toml +++ b/noir-projects/aztec-nr/Nargo.toml @@ -5,7 +5,6 @@ members = [ "aztec", "compressed-string", "easy-private-state", - "field-note", "slow-updates-tree", "value-note", "tests", diff --git a/noir-projects/aztec-nr/field-note/Nargo.toml b/noir-projects/aztec-nr/field-note/Nargo.toml deleted file mode 100644 index 908a532b295..00000000000 --- a/noir-projects/aztec-nr/field-note/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "field_note" -authors = ["aztec-labs"] -compiler_version = ">=0.18.0" -type = "lib" - -[dependencies] -aztec = { path = "../aztec" } \ No newline at end of file diff --git a/noir-projects/aztec-nr/field-note/src/lib.nr b/noir-projects/aztec-nr/field-note/src/lib.nr deleted file mode 100644 index 71523fc462b..00000000000 --- a/noir-projects/aztec-nr/field-note/src/lib.nr +++ /dev/null @@ -1 +0,0 @@ -mod field_note; diff --git a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr index 9224c0c2a3e..92636928014 100644 --- a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr @@ -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 diff --git a/noir-projects/noir-contracts/contracts/test_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test_contract/Nargo.toml index c1e9abeb6a9..8ddc423b451 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/test_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index a7e897ad564..f7a40cf41a8 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -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 @@ -25,9 +28,10 @@ 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, @@ -35,8 +39,8 @@ contract Test { #[aztec(storage)] struct Storage { - example_constant: PrivateImmutable, - example_set: PrivateSet, + example_constant: PrivateImmutable, + example_set: PrivateSet, } #[aztec(private)] @@ -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" ); @@ -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); } @@ -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); diff --git a/noir-projects/aztec-nr/field-note/src/field_note.nr b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr similarity index 63% rename from noir-projects/aztec-nr/field-note/src/field_note.nr rename to noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr index f6350ddd613..cc554679c2d 100644 --- a/noir-projects/aztec-nr/field-note/src/field_note.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr @@ -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 for FieldNote { +impl NoteInterface 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. @@ -27,14 +28,13 @@ impl NoteInterface 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() } } } - diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/token_blacklist_contract/Nargo.toml index 54bc420b804..5c61a519f96 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/Nargo.toml @@ -6,6 +6,5 @@ type = "contract" [dependencies] aztec = { path = "../../../aztec-nr/aztec" } -field_note = { path = "../../../aztec-nr/field-note" } authwit = { path = "../../../aztec-nr/authwit" } slow_tree = { path = "../slow_tree_contract" } \ No newline at end of file diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index ddb115c721e..426a270c03e 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -19,8 +19,6 @@ contract TokenBlacklist { hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, 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}; From 9eb13a3461c7f501bf41174a7bef52648ce48aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Tue, 23 Apr 2024 15:21:30 +0000 Subject: [PATCH 2/3] Remove usage in e2e test --- yarn-project/end-to-end/src/e2e_non_contract_account.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 100ad4c7646..8b08c8fa4fc 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -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; @@ -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); From 053a094dac525a5d87021cea8cacec70a0e780ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Tue, 23 Apr 2024 15:22:14 +0000 Subject: [PATCH 3/3] Fix capitalization --- .../noir-contracts/contracts/test_contract/src/test_note.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr index cc554679c2d..17f2d2d244d 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr @@ -3,7 +3,7 @@ use dep::aztec::{ context::PrivateContext }; -global Test_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 @@ -14,7 +14,7 @@ struct TestNote { value: Field, } -impl NoteInterface for TestNote { +impl NoteInterface 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.