Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: renamings of state var wrappers #4739

Merged
merged 32 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4b9c532
refactor: renamings of state var wrappers
benesjan Feb 23, 2024
5c8c139
SharedImmutable
benesjan Feb 23, 2024
a79338b
fix
benesjan Feb 23, 2024
4cbd515
private immutable
benesjan Feb 23, 2024
bebe505
singleton
benesjan Feb 23, 2024
0f30d99
WIP
benesjan Feb 26, 2024
26308ec
WIP
benesjan Feb 26, 2024
cfc97fc
Enforcing 1 time initialization
benesjan Feb 26, 2024
336414f
using re-exports
benesjan Feb 26, 2024
dc7cd83
SharedImmutable fix
benesjan Feb 26, 2024
6f23109
double initialization test
benesjan Feb 26, 2024
c09bc54
migration notes
benesjan Feb 26, 2024
218a234
linking issues
benesjan Feb 26, 2024
1cf4c81
fixes + diff cleanup
benesjan Feb 26, 2024
03f0759
docs fix
benesjan Feb 26, 2024
6e6f5b5
Set -> PrivateSet
benesjan Feb 26, 2024
b36f8ef
stale docs fix
benesjan Feb 26, 2024
5f9dda5
stale docs fix 2
benesjan Feb 26, 2024
4045039
revert incorrect change
benesjan Feb 26, 2024
ec9ff0d
updated comment
benesjan Feb 26, 2024
9865806
import cleanup
benesjan Feb 26, 2024
c2ccbf1
assert_deployment -> is_deployment
benesjan Feb 26, 2024
9c6d668
efficiently assigning initialization slot
benesjan Feb 26, 2024
f507e72
simpler approach of computing initialization slot
benesjan Feb 26, 2024
5d5f2b7
fix
benesjan Feb 26, 2024
b84b263
doc fix
benesjan Feb 26, 2024
f9e831c
import cleanup
benesjan Feb 26, 2024
a025a6d
documenting INITIALIZATION_SLOT_SEPARATOR
benesjan Feb 26, 2024
1baf757
link fix
benesjan Feb 26, 2024
4f734ff
increasing INITIALIZATION_SLOT_SEPARATOR constant
benesjan Feb 27, 2024
ac481d8
improved docs
benesjan Feb 27, 2024
0af3f03
updated slither
benesjan Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
contract BoxReact {
use dep::aztec::{
protocol_types::address::AztecAddress,
state_vars::{singleton::Singleton, map::Map},
note::{
utils as note_utils,
note_interface::NoteInterface,
note_header::NoteHeader,
},
protocol_types::address::AztecAddress, state_vars::{PrivateMutable, Map},
benesjan marked this conversation as resolved.
Show resolved Hide resolved
note::{utils as note_utils, note_interface::NoteInterface, note_header::NoteHeader}
};

use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

struct Storage {
numbers: Map<AztecAddress, Singleton<ValueNote>>,
numbers: Map<AztecAddress, PrivateMutable<ValueNote>>,
}

#[aztec(private)]
fn constructor(number: Field, owner: AztecAddress) {
let numbers = storage.numbers;
Expand Down
13 changes: 4 additions & 9 deletions boxes/vanilla-js/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
contract Vanilla {
use dep::aztec::{
protocol_types::address::AztecAddress,
state_vars::{singleton::Singleton, map::Map},
note::{
utils as note_utils,
note_interface::NoteInterface,
note_header::NoteHeader,
},
protocol_types::address::AztecAddress, state_vars::{PrivateMutable, Map},
note::{utils as note_utils, note_interface::NoteInterface, note_header::NoteHeader}
};

use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

struct Storage {
numbers: Map<AztecAddress, Singleton<ValueNote>>,
numbers: Map<AztecAddress, PrivateMutable<ValueNote>>,
}

#[aztec(private)]
fn constructor(number: Field, owner: AztecAddress) {
let numbers = storage.numbers;
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/developers/contracts/references/storage/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ Reading through the storage variables:

- `admin` a single Field value stored in public state. A `Field` is basically an unsigned integer with a maximum value determined by the underlying cryptographic curve.
- `minters` is a mapping of Fields in public state. This will store whether an account is an approved minter on the contract.
- `balances` is a mapping of private balances. Private balances are stored in a `Set` of `ValueNote`s. The balance is the sum of all of an account's `ValueNote`s.
- `balances` is a mapping of private balances. Private balances are stored in a `PrivateSet` of `ValueNote`s. The balance is the sum of all of an account's `ValueNote`s.
- `total_supply` is a Field value stored in public state and represents the total number of tokens minted.
- `pending_shields` is a `Set` of `TransparentNote`s stored in private state. What is stored publicly is a set of commitments to `TransparentNote`s.
- `pending_shields` is a `PrivateSet` of `TransparentNote`s stored in private state. What is stored publicly is a set of commitments to `TransparentNote`s.
- `public_balances` is a mapping field elements in public state and represents the publicly viewable balances of accounts.

You can read more about it [here](../storage/main.md).
Expand Down Expand Up @@ -288,7 +288,7 @@ The function returns 1 to indicate successful execution.

This public function allows an account approved in the public `minters` mapping to create new private tokens that can be claimed by anyone that has the pre-image to the `secret_hash`.

First, public storage is initialized. Then it checks that the `msg_sender` is an approved minter. Then a new `TransparentNote` is created with the specified `amount` and `secret_hash`. You can read the details of the `TransparentNote` in the `types.nr` file [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-contracts/contracts/token_contract/src/types.nr#L61). The `amount` is added to the existing public `total_supply` and the storage value is updated. Then the new `TransparentNote` is added to the `pending_shields` using the `insert_from_public` function, which is accessible on the `Set` type. Then it's ready to be claimed by anyone with the `secret_hash` pre-image using the `redeem_shield` function. It returns `1` to indicate successful execution.
First, public storage is initialized. Then it checks that the `msg_sender` is an approved minter. Then a new `TransparentNote` is created with the specified `amount` and `secret_hash`. You can read the details of the `TransparentNote` in the `types.nr` file [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-contracts/contracts/token_contract/src/types.nr#L61). The `amount` is added to the existing public `total_supply` and the storage value is updated. Then the new `TransparentNote` is added to the `pending_shields` using the `insert_from_public` function, which is accessible on the `PrivateSet` type. Then it's ready to be claimed by anyone with the `secret_hash` pre-image using the `redeem_shield` function. It returns `1` to indicate successful execution.

#include_code mint_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust

Expand Down
Loading
Loading