From 8aa8299d775350705daace99bfaaa14e71c072e7 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Tue, 23 Jan 2024 15:50:36 +0000 Subject: [PATCH] chore: rename singletons to leaky because they leak privacy --- .../dev_docs/contracts/syntax/storage/main.md | 74 +++++++++---------- yarn-project/aztec-nr/aztec/src/state_vars.nr | 4 +- ...gleton.nr => leaky_immutable_singleton.nr} | 6 +- .../{singleton.nr => leaky_singleton.nr} | 6 +- .../end-to-end/src/e2e_singleton.test.ts | 20 ++--- .../docs_example_contract/src/main.nr | 47 ++++++------ .../ecdsa_account_contract/src/main.nr | 6 +- .../schnorr_account_contract/src/main.nr | 6 +- .../contracts/test_contract/src/main.nr | 6 +- .../token_blacklist_contract/src/main.nr | 6 +- 10 files changed, 92 insertions(+), 89 deletions(-) rename yarn-project/aztec-nr/aztec/src/state_vars/{immutable_singleton.nr => leaky_immutable_singleton.nr} (95%) rename yarn-project/aztec-nr/aztec/src/state_vars/{singleton.nr => leaky_singleton.nr} (97%) diff --git a/docs/docs/dev_docs/contracts/syntax/storage/main.md b/docs/docs/dev_docs/contracts/syntax/storage/main.md index b774ee0c6825..3a4cdb4aa463 100644 --- a/docs/docs/dev_docs/contracts/syntax/storage/main.md +++ b/docs/docs/dev_docs/contracts/syntax/storage/main.md @@ -8,13 +8,13 @@ You control this storage in Aztec using the `Storage` struct. This struct serves These state variables come in two forms: public and private. Public variables are visible to anyone, and private variables remain hidden within the contract. -Aztec.nr has a few abstractions to help define the type of data your contract holds. These include Singletons, ImmutableSingletons, Set, and Map. +Aztec.nr has a few abstractions to help define the type of data your contract holds. These include LeakySingletons, LeakyImmutableSingletons, Set, and Map. On this page, you’ll learn: - How to manage a smart contract's storage structure - The distinctions and applications of public and private state variables -- How to use Singleton, ImmutableSingleton, Set, and Map +- How to use LeakySingleton, LeakyImmutableSingleton, Set, and Map - An overview of 'notes' and the UTXO model - Practical implications of Storage in real smart contracts In an Aztec.nr contract, storage is to be defined as a single struct, that contains both public and private state variables. @@ -85,15 +85,15 @@ We will see examples of map constructors for public and private variables in lat #### As private storage -When declaring a mapping in private storage, we have to specify which type of Note to use. In the example below, we are specifying that we want to use the `Singleton` note type. See the [Singleton](#singletonnotetype) section for more information. +When declaring a mapping in private storage, we have to specify which type of Note to use. In the example below, we are specifying that we want to use the `LeakySingleton` note type. See the [LeakySingleton](#leakysingletonnotetype) section for more information. In the Storage struct: -#include_code storage-map-singleton-declaration /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust +#include_code storage-map-leaky-singleton-declaration /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust In the `Storage::init` function: -#include_code state_vars-MapSingleton /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust +#include_code state-vars-map-leaky-singleton /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust #### Public Example @@ -226,8 +226,8 @@ Aztec private state follows a utxo-based model. That is, a private state's curre To greatly simplify the experience of writing private state, Aztec.nr provides three different types of private state variable: -- [Singleton](#singletonnotetype) -- [ImmutableSingleton](#immutablesingletonnotetype) +- [LeakySingleton](#leakysingletonnotetype) +- [LeakyImmutableSingleton](#leakyimmutablesingletonnotetype) - [Set](#setnotetype) These three structs abstract-away many of Aztec's protocol complexities, by providing intuitive methods to modify notes in the utxo tree in a privacy-preserving way. @@ -248,19 +248,19 @@ A note should conform to the following interface: The interplay between a private state variable and its notes can be confusing. Here's a summary to aid intuition: -A private state variable (of type `Singleton`, `ImmutableSingleton` or `Set`) may be declared in storage. +A private state variable (of type `LeakySingleton`, `LeakyImmutableSingleton` or `Set`) may be declared in storage. Every note contains (as a 'header') the contract address and storage slot of the state variable to which it "belongs". A note is said to "belong" to a private state if the storage slot of the private state matches the storage slot contained in the note's header. The header provides information that helps the user interpret the note's data. Without it the user would have to figure out where it belongs by brute-forcing the address and contract space. -Management of this 'header' is abstracted-away from developers who use the `ImmutableSingleton`, `Singleton` and `Set` types. +Management of this 'header' is abstracted-away from developers who use the `LeakyImmutableSingleton`, `LeakySingleton` and `Set` types. A private state variable is colloquially said to "point" to one or many notes (depending on the type), if those note(s) all "belong" to that private state, and those note(s) haven't-yet been nullified. -An `ImmutableSingleton` will point to _one_ note over the lifetime of the contract. ("One", hence "Singleton"). This note is a struct of information that is persisted forever. +An `LeakyImmutableSingleton` will point to _one_ note over the lifetime of the contract. ("One", hence "Singleton"). This note is a struct of information that is persisted forever. -A `Singleton` may point to _one_ note at a time. ("One", hence "Singleton"). But since it's not "immutable", the note that it points to may be [replaced](#replace) by functions of the contract, over time. The "current value" of a `Singleton` is interpreted as the one note which has not-yet been nullified. The act of 'replacing' a Singleton's note is how a `Singleton` state may be modified by functions. +A `LeakySingleton` may point to _one_ note at a time. ("One", hence "Singleton"). But since it's not "immutable", the note that it points to may be [replaced](#replace) by functions of the contract, over time. The "current value" of a `LEakySingleton` is interpreted as the one note which has not-yet been nullified. The act of 'replacing' a LeakySingleton's note is how a `LeakySingleton` state may be modified by functions. -`Singleton` is a useful type when declaring a private state which may only ever be modified by those who are privy to the current value of that state. +`LeakySingleton` is a useful type when declaring a private state which may only ever be modified by those who are privy to the current value of that state. A `Set` may point to _multiple_ notes at a time. The "current value" of a private state variable of type `Set` is some 'accumulation' of all not-yet nullified notes which "belong" to the `Set`. The term "some accumulation" is intentionally vague. The interpretation of the "current value" of a `Set` must be expressed by the smart contract developer. A common use case for a `Set` is to represent the sum of a collection of values (in which case 'accumulation' is 'summation'). @@ -268,29 +268,27 @@ Think of a ZCash balance (or even a Bitcoin balance). The "current value" of a u Interestingly, if a developer requires a private state to be modifiable by users who _aren't_ privy to the value of that state, a `Set` is a very useful type. The `insert` method allows new notes to be added to the `Set` without knowing any of the other notes in the set! (Like posting an envelope into a post box, you don't know what else is in there!). -## `Singleton` +## `LeakySingleton` -Singleton is a private state variable that is unique in a way. When a Singleton is initialized, a note is created to represent its value. And the way to update the value is to destroy the current note, and create a new one with the updated value. +LeakySingleton is a private state variable that is unique in a way. When a LeakySingleton is initialized it will nullify its storage slot to ensure it cannot be initialized more than once. Since this leaks some information about the state, it's called a LeakySingleton. Furthermore, a note is created to represent its value and the way to update the value is to destroy the current note, and create a new one with the updated value. -Like for public state, we define the struct to have context, a storage slot and `note_interface` specifying how the note should be constructed and manipulated. You can view the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr). +Like for public state, we define the struct to have context, a storage slot and `note_interface` specifying how the note should be constructed and manipulated. You can view the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/state_vars/leaky_singleton.nr). -An example of singleton usage in the account contracts is keeping track of public keys. The `Singleton` is added to the `Storage` struct as follows: +An example of singleton usage in the account contracts is keeping track of public keys. The `LeakySingleton` is added to the `Storage` struct as follows: -#include_code storage-singleton-declaration /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust +#include_code storage-leaky-singleton-declaration /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust ### `new` -As part of the initialization of the `Storage` struct, the `Singleton` is created as follows, here at the specified storage slot and with the `NoteInterface` for `CardNote`. +As part of the initialization of the `LeakyStorage` struct, the `LeakySingleton` is created as follows, here at the specified storage slot and with the `NoteInterface` for `CardNote`. -#include_code start_vars_singleton /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust +#include_code state-vars-leaky-singleton /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust ### `initialize` -As mentioned, the Singleton is initialized to create the first note and value. +As mentioned, the LeakySingleton is initialized to create the first note and value. When this function is called, a nullifier of the storage slot is created, preventing this LeakySingleton from being initialized again. -When this function is called, a nullifier of the storage slot is created, preventing this Singleton from being initialized again. If an `owner` is specified, the nullifier will be hashed with the owner's secret key. It's crucial to provide an owner if the Singleton is associated with an account. Initializing it without an owner may inadvertently reveal important information about the owner's intention. - -Unlike public states, which have a default initial value of `0` (or many zeros, in the case of a struct, array or map), a private state (of type `Singleton`, `ImmutableSingleton` or `Set`) does not have a default initial value. The `initialize` method (or `insert`, in the case of a `Set`) must be called. +Unlike public states, which have a default initial value of `0` (or many zeros, in the case of a struct, array or map), a private state (of type `LeakySingleton`, `LeakyImmutableSingleton` or `Set`) does not have a default initial value. The `initialize` method (or `insert`, in the case of a `Set`) must be called. :::info Extend on what happens if you try to use non-initialized state. @@ -298,21 +296,21 @@ Extend on what happens if you try to use non-initialized state. ### `is_initialized` -An unconstrained method to check whether the Singleton has been initialized or not. It takes an optional owner and returns a boolean. You can view the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr). +An unconstrained method to check whether the LeakySingleton has been initialized or not. It takes an optional owner and returns a boolean. You can view the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/state_vars/leaky_singleton.nr). ### `replace` -To update the value of a `Singleton`, we can use the `replace` method. The method takes a new note as input, and replaces the current note with the new one. It emits a nullifier for the old value, and inserts the new note into the data tree. +To update the value of a `LeakySingleton`, we can use the `replace` method. The method takes a new note as input, and replaces the current note with the new one. It emits a nullifier for the old value, and inserts the new note into the data tree. An example of this is seen in a example card game, where we create a new note (a `CardNote`) containing some new data, and replace the current note with it: #include_code state_vars-SingletonReplace /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust -If two people are trying to modify the Singleton at the same time, only one will succeed as we don't allow duplicate nullifiers! Developers should put in place appropriate access controls to avoid race conditions (unless a race is intended!). +If two people are trying to modify the LeakySingleton at the same time, only one will succeed as we don't allow duplicate nullifiers! Developers should put in place appropriate access controls to avoid race conditions (unless a race is intended!). ### `get_note` -This function allows us to get the note of a Singleton, essentially reading the value. +This function allows us to get the note of a LeakySingleton, essentially reading the value. #include_code state_vars-SingletonGet /yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr rust @@ -324,11 +322,11 @@ It's possible that at the time this function is called, the system hasn't synced Functionally similar to [`get_note`](#get_note), but executed in unconstrained functions and can be used by the wallet to fetch notes for use by front-ends etc. -## `ImmutableSingleton` +## `LeakyImmutableSingleton` -ImmutableSingleton represents a unique private state variable that, as the name suggests, is immutable. Once initialized, its value cannot be altered. +LeakyImmutableSingleton represents a unique private state variable that, as the name suggests, is immutable. Once initialized, its value cannot be altered. -#include_code struct /yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr rust +#include_code struct /yarn-project/aztec-nr/aztec/src/state_vars/leaky_immutable_singleton.nr rust ### `new` @@ -338,29 +336,29 @@ As part of the initialization of the `Storage` struct, the `Singleton` is create ### `initialize` -When this function is invoked, it creates a nullifier for the storage slot, ensuring that the ImmutableSingleton cannot be initialized again. If an owner is specified, the nullifier will be hashed with the owner's secret key. It is crucial to provide an owner if the ImmutableSingleton is linked to an account; initializing it without one may inadvertently disclose sensitive information about the owner's intent. +When this function is invoked, it creates a nullifier for the storage slot, ensuring that the LeakyImmutableSingleton cannot be initialized again. -Set the value of an ImmutableSingleton by calling the `initialize` method: +Set the value of an LeakyImmutableSingleton by calling the `initialize` method: #include_code initialize /yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr rust -Once initialized, an ImmutableSingleton's value remains unchangeable. This method can only be called once. +Once initialized, an LeakyImmutableSingleton's value remains unchangeable. This method can only be called once. ### `is_initialized` -An unconstrained method to check if the ImmutableSingleton has been initialized. Takes an optional owner and returns a boolean. You can find the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master//yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr). +An unconstrained method to check if the LeakyImmutableSingleton has been initialized. Takes an optional owner and returns a boolean. You can find the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/state_vars/leaky_immutable_singleton.nr). ### `get_note` -Similar to the `Singleton`, we can use the `get_note` method to read the value of an ImmutableSingleton. +Similar to the `LeakySingleton`, we can use the `get_note` method to read the value of an LeakyImmutableSingleton. -Use this method to retrieve the value of an initialized ImmutableSingleton. +Use this method to retrieve the value of an initialized LeakyImmutableSingleton. #include_code get_note /yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr rust -Unlike a `Singleton`, the `get_note` function for an ImmutableSingleton doesn't destroy the current note in the background. This means that multiple accounts can concurrently call this function to read the value. +Unlike a `LeakySingleton`, the `get_note` function for an LeakyImmutableSingleton doesn't destroy the current note in the background. This means that multiple accounts can concurrently call this function to read the value. -This function will throw if the ImmutableSingleton hasn't been initialized. +This function will throw if the LeakyImmutableSingleton hasn't been initialized. ### `view_note` diff --git a/yarn-project/aztec-nr/aztec/src/state_vars.nr b/yarn-project/aztec-nr/aztec/src/state_vars.nr index e1e813891ffb..6710ddca283f 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars.nr @@ -1,5 +1,5 @@ -mod immutable_singleton; +mod leaky_immutable_singleton; mod map; mod public_state; mod set; -mod singleton; +mod leaky_singleton; diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/leaky_immutable_singleton.nr similarity index 95% rename from yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr rename to yarn-project/aztec-nr/aztec/src/state_vars/leaky_immutable_singleton.nr index 9178f2010ac4..a79aee78f218 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/leaky_immutable_singleton.nr @@ -17,14 +17,14 @@ use crate::note::{ use crate::oracle::notes::check_nullifier_exists; // docs:start:struct -struct ImmutableSingleton { +struct LeakyImmutableSingleton { context: Option<&mut PrivateContext>, storage_slot: Field, note_interface: NoteInterface, } // docs:end:struct -impl ImmutableSingleton { +impl LeakyImmutableSingleton { // docs:start:new pub fn new( context: Context, @@ -32,7 +32,7 @@ impl ImmutableSingleton { note_interface: NoteInterface, ) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); - ImmutableSingleton { + Self { context: context.private, storage_slot, note_interface, diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/leaky_singleton.nr similarity index 97% rename from yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr rename to yarn-project/aztec-nr/aztec/src/state_vars/leaky_singleton.nr index 59472add9975..21b9a2f5578b 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/leaky_singleton.nr @@ -21,14 +21,14 @@ use crate::oracle::{ }; // docs:start:struct -struct Singleton { +struct LeakySingleton { context: Option<&mut PrivateContext>, storage_slot: Field, note_interface: NoteInterface, } // docs:end:struct -impl Singleton { +impl LeakySingleton { // docs:start:new pub fn new( context: Context, @@ -36,7 +36,7 @@ impl Singleton { note_interface: NoteInterface, ) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); - Singleton { + Self { context: context.private, storage_slot, note_interface, diff --git a/yarn-project/end-to-end/src/e2e_singleton.test.ts b/yarn-project/end-to-end/src/e2e_singleton.test.ts index 6c1407ef053d..0a2b2d0fbfe0 100644 --- a/yarn-project/end-to-end/src/e2e_singleton.test.ts +++ b/yarn-project/end-to-end/src/e2e_singleton.test.ts @@ -3,7 +3,7 @@ import { DocsExampleContract } from '@aztec/noir-contracts'; import { setup } from './fixtures/utils.js'; -describe('e2e_singleton', () => { +describe('e2e_singletons', () => { let wallet: Wallet; let teardown: () => Promise; @@ -19,13 +19,13 @@ describe('e2e_singleton', () => { afterAll(() => teardown()); - describe('Singleton', () => { - it('fail to read uninitialized singleton', async () => { + describe('LeakySingleton', () => { + it('fail to read uninitialized leakySingleton', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(false); await expect(contract.methods.get_legendary_card().view()).rejects.toThrowError(); }); - it('initialize singleton', async () => { + it('initialize leakySingleton', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(false); const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); @@ -43,7 +43,7 @@ describe('e2e_singleton', () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); }); - it('read initialized singleton', async () => { + it('read initialized leakySingleton', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const { points, randomness } = await contract.methods.get_legendary_card().view(); expect(points).toEqual(POINTS); @@ -73,7 +73,7 @@ describe('e2e_singleton', () => { expect(noteBefore.header.nonce).not.toEqual(noteAfter.header.nonce); }); - it('replace singleton with other values', async () => { + it('replace leakySingleton with other values', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const receipt = await contract.methods .update_legendary_card(RANDOMNESS + 2n, POINTS + 1n) @@ -90,7 +90,7 @@ describe('e2e_singleton', () => { expect(randomness).toEqual(RANDOMNESS + 2n); }); - it('replace singleton dependent on prior value', async () => { + it('replace leakySingleton dependent on prior value', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().view(); const receipt = await contract.methods.increase_legendary_points().send().wait(); @@ -107,12 +107,12 @@ describe('e2e_singleton', () => { }); describe('Immutable Singleton', () => { - it('fail to read uninitialized singleton', async () => { + it('fail to read uninitialized leakySingleton', async () => { expect(await contract.methods.is_imm_initialized().view()).toEqual(false); await expect(contract.methods.get_imm_card().view()).rejects.toThrowError(); }); - it('initialize singleton', async () => { + it('initialize leakySingleton', async () => { expect(await contract.methods.is_imm_initialized().view()).toEqual(false); const receipt = await contract.methods.initialize_immutable_singleton(RANDOMNESS, POINTS).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); @@ -132,7 +132,7 @@ describe('e2e_singleton', () => { expect(await contract.methods.is_imm_initialized().view()).toEqual(true); }); - it('read initialized singleton', async () => { + it('read initialized leakySingleton', async () => { expect(await contract.methods.is_imm_initialized().view()).toEqual(true); const { points, randomness } = await contract.methods.get_imm_card().view(); expect(points).toEqual(POINTS); diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr index e7c9befa319f..ac4684049b92 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -1,15 +1,15 @@ mod options; mod types; -// Following is a very simple game to show case use of singleton in as minimalistic way as possible -// It also serves as an e2e test that you can read and then replace the singleton in the same call +// Following is a very simple game to show case use of LeakySingleton in as minimalistic way as possible +// It also serves as an e2e test that you can read and then replace the LeakySingleton in the same call // (tests ordering in the circuit) -// you have a card (singleton). Anyone can create a bigger card. Whoever is bigger will be the leader. -// it also has dummy methods and other examples used for documentation e.g. +// You have a card (LeakySingleton). If you get a new card that have more points, you can replace it as the leader. +// It also has dummy methods and other examples used for documentation e.g. // how to create custom notes, a custom struct for public state, a custom note that may be unencrypted // also has `options.nr` which shows various ways of using `NoteGetterOptions` to query notes -// it also shows what our macros do behind the scenes! +// It also shows what our macros do behind the scenes! contract DocsExample { // how to import dependencies defined in your workspace @@ -23,7 +23,12 @@ contract DocsExample { utils as note_utils, }, context::{PrivateContext, PublicContext, Context}, - state_vars::{map::Map, public_state::PublicState,singleton::Singleton, immutable_singleton::ImmutableSingleton}, + state_vars::{ + map::Map, + public_state::PublicState, + leaky_singleton::LeakySingleton, + leaky_immutable_singleton::LeakyImmutableSingleton + }, }; // how to import methods from other files/folders within your workspace use crate::options::create_account_card_getter_options; @@ -35,14 +40,14 @@ contract DocsExample { struct Storage { // Shows how to create a custom struct in Public leader: PublicState, - // docs:start:storage-singleton-declaration - legendary_card: Singleton, - // docs:end:storage-singleton-declaration - // just used for docs example to show how to create a singleton map. - // docs:start:storage-map-singleton-declaration - profiles: Map>, - // docs:end:storage-map-singleton-declaration - imm_singleton: ImmutableSingleton, + // docs:start:storage-leaky-singleton-declaration + legendary_card: LeakySingleton, + // docs:end:storage-leaky-singleton-declaration + // just used for docs example to show how to create a LeakySingleton map. + // docs:start:storage-map-leaky-singleton-declaration + profiles: Map>, + // docs:end:storage-map-leaky-singleton-declaration + imm_singleton: LeakyImmutableSingleton, } impl Storage { @@ -53,20 +58,20 @@ contract DocsExample { 1, LeaderSerializationMethods, ), - // docs:start:start_vars_singleton - legendary_card: Singleton::new(context, 2, CardNoteMethods), - // docs:end:start_vars_singleton + // docs:start:state-vars-leaky-singleton + legendary_card: LeakySingleton::new(context, 2, CardNoteMethods), + // docs:end:state-vars-leaky-singleton // just used for docs example (not for game play): - // docs:start:state_vars-MapSingleton + // docs:start:state-vars-map-leaky-singleton profiles: Map::new( context, 3, |context, slot| { - Singleton::new(context, slot, CardNoteMethods) + LeakySingleton::new(context, slot, CardNoteMethods) }, ), - // docs:end:state_vars-MapSingleton - imm_singleton: ImmutableSingleton::new(context, 4, CardNoteMethods), + // docs:end:state-vars-map-leaky-singleton + imm_singleton: LeakyImmutableSingleton::new(context, 4, CardNoteMethods), } } } diff --git a/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/main.nr b/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/main.nr index da730b23c32f..eec3f5b3e94a 100644 --- a/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/main.nr @@ -14,7 +14,7 @@ contract EcdsaAccount { utils as note_utils, }, oracle::get_public_key::get_public_key, - state_vars::immutable_singleton::ImmutableSingleton, + state_vars::leaky_immutable_singleton::LeakyImmutableSingleton, }; use dep::authwit:: { entrypoint::{ EntrypointPayload, ENTRYPOINT_PAYLOAD_SIZE }, @@ -27,13 +27,13 @@ contract EcdsaAccount { }; struct Storage { - public_key: ImmutableSingleton, + public_key: LeakyImmutableSingleton, } impl Storage { fn init(context: Context) -> Self { Storage { - public_key: ImmutableSingleton::new(context, 1, EcdsaPublicKeyNoteInterface), + public_key: LeakyImmutableSingleton::new(context, 1, EcdsaPublicKeyNoteInterface), } } } diff --git a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr index 001437e9c9df..88f811d87aa1 100644 --- a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/main.nr @@ -12,7 +12,7 @@ contract SchnorrAccount { context::{PrivateContext, Context}, note::{ note_header::NoteHeader, utils as note_utils }, oracle::get_public_key::get_public_key, - state_vars::immutable_singleton::ImmutableSingleton, + state_vars::leaky_immutable_singleton::LeakyImmutableSingleton, }; use dep::authwit:: { entrypoint::{ EntrypointPayload, ENTRYPOINT_PAYLOAD_SIZE }, @@ -24,7 +24,7 @@ contract SchnorrAccount { struct Storage { // docs:start:storage - signing_public_key: ImmutableSingleton, + signing_public_key: LeakyImmutableSingleton, // docs:end:storage } @@ -32,7 +32,7 @@ contract SchnorrAccount { fn init(context: Context) -> Self { Storage { // docs:start:storage_init - signing_public_key: ImmutableSingleton::new(context, 1, PublicKeyNoteMethods), + signing_public_key: LeakyImmutableSingleton::new(context, 1, PublicKeyNoteMethods), // docs:end:storage_init } } diff --git a/yarn-project/noir-contracts/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/contracts/test_contract/src/main.nr index 6402ec444e81..d4c5d19996e8 100644 --- a/yarn-project/noir-contracts/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/test_contract/src/main.nr @@ -29,7 +29,7 @@ contract Test { context::get_portal_address, rand::rand }, - state_vars::immutable_singleton::ImmutableSingleton, + state_vars::leaky_immutable_singleton::LeakyImmutableSingleton, log::emit_unencrypted_log_from_private, types::vec::BoundedVec, }; @@ -42,13 +42,13 @@ contract Test { } struct Storage { - example_constant: ImmutableSingleton, + example_constant: LeakyImmutableSingleton, } impl Storage { fn init(context: Context) -> Self { Storage { - example_constant: ImmutableSingleton::new(context, 1, FieldNoteMethods), + example_constant: LeakyImmutableSingleton::new(context, 1, FieldNoteMethods), } } } diff --git a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/main.nr index 46ff827b00c9..1ac16043b73b 100644 --- a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -29,7 +29,7 @@ contract TokenBlacklist { }, context::{PrivateContext, PublicContext, Context}, hash::{compute_secret_hash}, - state_vars::{map::Map, public_state::PublicState, set::Set, immutable_singleton::ImmutableSingleton}, + state_vars::{map::Map, public_state::PublicState, set::Set, leaky_immutable_singleton::LeakyImmutableSingleton}, types::type_serialization::{ field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN}, bool_serialization::{BoolSerializationMethods, BOOL_SERIALIZED_LEN}, @@ -63,7 +63,7 @@ contract TokenBlacklist { total_supply: PublicState, pending_shields: Set, public_balances: Map>, - slow_update: ImmutableSingleton, + slow_update: LeakyImmutableSingleton, public_slow_update: PublicState, } @@ -95,7 +95,7 @@ contract TokenBlacklist { ), // Below is an abomination to have same value in private and public (immutable in solidity). // docs:start:slow_updates_storage - slow_update: ImmutableSingleton::new(context, 7, FieldNoteMethods), + slow_update: LeakyImmutableSingleton::new(context, 7, FieldNoteMethods), public_slow_update: PublicState::new( context, 8,