Skip to content

Commit

Permalink
fix: capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 22, 2023
1 parent 22496ab commit d0d8b40
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions docs/docs/dev_docs/testing/cheat_codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ The baseSlot is specified in the Aztec.nr contract.

```rust
struct Storage {
balances: Map<PublicState<Field, FIELD_serializeD_LEN>>,
balances: Map<PublicState<Field, FIELD_SERIALIZED_LEN>>,
}

impl Storage {
Expand Down Expand Up @@ -496,7 +496,7 @@ Note: One Field element occupies a storage slot. Hence, structs with multiple fi

```rust
struct Storage {
balances: Map<PublicState<Field, FIELD_serializeD_LEN>>,
balances: Map<PublicState<Field, FIELD_SERIALIZED_LEN>>,
}

impl Storage {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/tutorials/writing_token_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Below the dependencies, paste the following Storage struct:

Reading through the storage variables:

- `admin` a single Field value stored in public state. `FIELD_serializeD_LEN` indicates the length of the variable, which is 1 in this case because it's a single Field element. A `Field` is basically an unsigned integer with a maximum value determined by the underlying cryptographic curve.
- `admin` a single Field value stored in public state. `FIELD_SERIALIZED_LEN` indicates the length of the variable, which is 1 in this case because it's a single Field element. 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.
- `total_supply` is a Field value stored in public state and represents the total number of tokens minted.
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/account.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::entrypoint::EntrypointPayload;
use crate::context::{PrivateContext, PublicContext, Context};
use crate::oracle::compute_selector::compute_selector;
use crate::state_vars::{map::Map, public_state::PublicState};
use crate::types::type_serialisation::bool_serialisation::{BoolSerialisationMethods,BOOL_serializeD_LEN};
use crate::types::type_serialisation::bool_serialisation::{BoolSerialisationMethods,BOOL_SERIALIZED_LEN};
use crate::auth::IS_VALID_SELECTOR;

struct AccountActions {
context: Context,
is_valid_impl: fn(&mut PrivateContext, Field) -> bool,
approved_action: Map<PublicState<bool, BOOL_serializeD_LEN>>,
approved_action: Map<PublicState<bool, BOOL_SERIALIZED_LEN>>,
}

impl AccountActions {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec-nr/aztec/src/state_vars/public_state.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::oracle::storage::storage_write;
use crate::types::type_serialisation::TypeSerialisationInterface;
use dep::std::option::Option;

struct PublicState<T, T_serializeD_LEN> {
struct PublicState<T, T_SERIALIZED_LEN> {
storage_slot: Field,
serialisation_methods: TypeSerialisationInterface<T, T_serializeD_LEN>,
serialisation_methods: TypeSerialisationInterface<T, T_SERIALIZED_LEN>,
}

impl<T, T_serializeD_LEN> PublicState<T, T_serializeD_LEN> {
impl<T, T_SERIALIZED_LEN> PublicState<T, T_SERIALIZED_LEN> {
fn new(
// Note: Passing the contexts to new(...) just to have an interface compatible with a Map.
_: Context,
storage_slot: Field,
serialisation_methods: TypeSerialisationInterface<T, T_serializeD_LEN>,
serialisation_methods: TypeSerialisationInterface<T, T_SERIALIZED_LEN>,
) -> Self {
assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1.");
PublicState {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-nr/aztec/src/types/point.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ impl Point {
}
}

global POINT_serializeD_LEN: Field = 2;
global POINT_SERIALIZED_LEN: Field = 2;

fn deserializePoint(fields: [Field; POINT_serializeD_LEN]) -> Point {
fn deserializePoint(fields: [Field; POINT_SERIALIZED_LEN]) -> Point {
Point {
x: fields[0],
y: fields[1],
}
}

fn serializePoint(point: Point) -> [Field; POINT_serializeD_LEN] {
fn serializePoint(point: Point) -> [Field; POINT_SERIALIZED_LEN] {
[point.x, point.y]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::types::type_serialisation::TypeSerialisationInterface;

global BOOL_serializeD_LEN: Field = 1;
global BOOL_SERIALIZED_LEN: Field = 1;

fn deserializeBool(fields: [Field; BOOL_serializeD_LEN]) -> bool {
fn deserializeBool(fields: [Field; BOOL_SERIALIZED_LEN]) -> bool {
fields[0] as bool
}

fn serializeBool(value: bool) -> [Field; BOOL_serializeD_LEN] {
fn serializeBool(value: bool) -> [Field; BOOL_SERIALIZED_LEN] {
[value as Field]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::types::type_serialisation::TypeSerialisationInterface;

global FIELD_serializeD_LEN: Field = 1;
global FIELD_SERIALIZED_LEN: Field = 1;

fn deserializeField(fields: [Field; FIELD_serializeD_LEN]) -> Field {
fn deserializeField(fields: [Field; FIELD_SERIALIZED_LEN]) -> Field {
fields[0]
}

fn serializeField(value: Field) -> [Field; FIELD_serializeD_LEN] {
fn serializeField(value: Field) -> [Field; FIELD_SERIALIZED_LEN] {
[value]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::types::type_serialisation::TypeSerialisationInterface;

global U32_serializeD_LEN: Field = 1;
global U32_SERIALIZED_LEN: Field = 1;

fn deserializeU32(fields: [Field; U32_serializeD_LEN]) -> u32 {
fn deserializeU32(fields: [Field; U32_SERIALIZED_LEN]) -> u32 {
fields[0] as u32
}

fn serializeU32(value: u32) -> [Field; U32_serializeD_LEN] {
fn serializeU32(value: u32) -> [Field; U32_SERIALIZED_LEN] {
[value as Field]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ struct Game {
current_round: u32,
}

global GAME_serializeD_LEN: Field = 15;
global GAME_SERIALIZED_LEN: Field = 15;

fn deserializeGame(fields: [Field; GAME_serializeD_LEN]) -> Game {
fn deserializeGame(fields: [Field; GAME_SERIALIZED_LEN]) -> Game {
let players = [
PlayerEntry {
address: fields[0],
Expand Down Expand Up @@ -58,7 +58,7 @@ fn deserializeGame(fields: [Field; GAME_serializeD_LEN]) -> Game {
}
}

fn serializeGame(game: Game) -> [Field; GAME_serializeD_LEN] {
fn serializeGame(game: Game) -> [Field; GAME_SERIALIZED_LEN] {
[
game.players[0].address,
game.players[0].deck_strength as Field,
Expand All @@ -79,7 +79,7 @@ fn serializeGame(game: Game) -> [Field; GAME_serializeD_LEN] {
}

impl Game {
fn serialize(self: Self) -> [Field; GAME_serializeD_LEN] {
fn serialize(self: Self) -> [Field; GAME_SERIALIZED_LEN] {
serializeGame(self)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use dep::aztec::{
use dep::std::option::Option;

use cards::{Deck};
use game::{Game, GameSerialisationMethods, GAME_serializeD_LEN};
use game::{Game, GameSerialisationMethods, GAME_SERIALIZED_LEN};

struct Storage {
collections: Map<Deck>,
game_decks: Map<Map<Deck>>,
games: Map<PublicState<Game, GAME_serializeD_LEN>>,
games: Map<PublicState<Game, GAME_SERIALIZED_LEN>>,
}

impl Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ contract Child {
compute_selector::compute_selector,
},
state_vars::public_state::PublicState,
types::type_serialisation::field_serialisation::{FieldSerialisationMethods, FIELD_serializeD_LEN},
types::type_serialisation::field_serialisation::{FieldSerialisationMethods, FIELD_SERIALIZED_LEN},
};

struct Storage {
current_value: PublicState<Field, FIELD_serializeD_LEN>,
current_value: PublicState<Field, FIELD_SERIALIZED_LEN>,
}

impl Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@ use dep::aztec::state_vars::{
immutable_singleton::ImmutableSingleton, map::Map, public_state::PublicState, set::Set,
singleton::Singleton,
};
use dep::aztec::types::type_serialisation::bool_serialisation::BOOL_serializeD_LEN;
use dep::aztec::types::type_serialisation::bool_serialisation::BOOL_SERIALIZED_LEN;
use dep::std::option::Option;

use crate::types::{
card_note::{CardNote, CARD_NOTE_LEN},
profile_note::{ProfileNote, PROFILE_NOTE_LEN},
queen::{Queen, QUEEN_serializeD_LEN},
queen::{Queen, QUEEN_SERIALIZED_LEN},
rules_note::{RulesNote, RULES_NOTE_LEN},
};

// docs:start:state_vars-PublicStateRead
fn is_locked(state_var: PublicState<bool, BOOL_serializeD_LEN>) -> bool {
fn is_locked(state_var: PublicState<bool, BOOL_SERIALIZED_LEN>) -> bool {
state_var.read()
}
// docs:end:state_vars-PublicStateRead

// docs:start:state_vars-PublicStateWrite
fn lock(state_var: PublicState<bool, BOOL_serializeD_LEN>) {
fn lock(state_var: PublicState<bool, BOOL_SERIALIZED_LEN>) {
state_var.write(true);
}
// docs:end:state_vars-PublicStateWrite

fn unlock(state_var: PublicState<bool, BOOL_serializeD_LEN>) {
fn unlock(state_var: PublicState<bool, BOOL_SERIALIZED_LEN>) {
state_var.write(false);
}

// docs:start:state_vars-PublicStateReadCustom
fn get_current_queen(state_var: PublicState<Queen, QUEEN_serializeD_LEN>) -> Queen {
fn get_current_queen(state_var: PublicState<Queen, QUEEN_SERIALIZED_LEN>) -> Queen {
state_var.read()
}
// docs:end:state_vars-PublicStateReadCustom

fn can_replace_queen(
state_var: PublicState<Queen, QUEEN_serializeD_LEN>,
state_var: PublicState<Queen, QUEEN_SERIALIZED_LEN>,
new_queen: Queen,
) -> bool {
let current_queen = get_current_queen(state_var);
new_queen.points > current_queen.points
}

// docs:start:state_vars-PublicStateWriteCustom
fn replace_queen(state_var: PublicState<Queen, QUEEN_serializeD_LEN>, new_queen: Queen) {
fn replace_queen(state_var: PublicState<Queen, QUEEN_SERIALIZED_LEN>, new_queen: Queen) {
state_var.write(new_queen);
}
// docs:end:state_vars-PublicStateWriteCustom

// docs:start:state_vars-PublicStateReadWriteCustom
fn add_points_to_queen(state_var: PublicState<Queen, QUEEN_serializeD_LEN>, new_points: u8) {
fn add_points_to_queen(state_var: PublicState<Queen, QUEEN_SERIALIZED_LEN>, new_points: u8) {
let mut queen = state_var.read();
queen.points += new_points;
state_var.write(queen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract DocsExample {
};
// docs:start:state_vars-PublicStateBoolImport
use dep::aztec::types::type_serialisation::bool_serialisation::{
BoolSerialisationMethods, BOOL_serializeD_LEN,
BoolSerialisationMethods, BOOL_SERIALIZED_LEN,
};
// docs:end:state_vars-PublicStateBoolImport
use crate::account_contract_interface::AccountContractInterface;
Expand All @@ -23,14 +23,14 @@ contract DocsExample {
use crate::types::{
card_note::{CardNote, CardNoteMethods, CARD_NOTE_LEN},
profile_note::{ProfileNote, ProfileNoteMethods, PROFILE_NOTE_LEN},
queen::{Queen, QueenSerialisationMethods, QUEEN_serializeD_LEN},
queen::{Queen, QueenSerialisationMethods, QUEEN_SERIALIZED_LEN},
rules_note::{RulesNote, RulesNoteMethods, RULES_NOTE_LEN},
};

// docs:start:storage-struct-declaration
struct Storage {
locked: PublicState<bool, BOOL_serializeD_LEN>,
queen: PublicState<Queen, QUEEN_serializeD_LEN>,
locked: PublicState<bool, BOOL_SERIALIZED_LEN>,
queen: PublicState<Queen, QUEEN_SERIALIZED_LEN>,
game_rules: ImmutableSingleton<RulesNote, RULES_NOTE_LEN>,
legendary_card: Singleton<CardNote, CARD_NOTE_LEN>,
cards: Set<CardNote, CARD_NOTE_LEN>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ struct Queen {
// docs:end:state_vars-CustomStruct

// docs:start:state_vars-PublicStateCustomStruct
global QUEEN_serializeD_LEN: Field = 2;
global QUEEN_SERIALIZED_LEN: Field = 2;

fn deserialize(fields: [Field; QUEEN_serializeD_LEN]) -> Queen {
fn deserialize(fields: [Field; QUEEN_SERIALIZED_LEN]) -> Queen {
Queen {
account: fields[0],
points: fields[1] as u8,
}
}

fn serialize(queen: Queen) -> [Field; QUEEN_serializeD_LEN] {
fn serialize(queen: Queen) -> [Field; QUEEN_SERIALIZED_LEN] {
[queen.account, queen.points as Field]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ struct Asset {
oracle_address: Field,
}

global ASSET_serializeD_LEN: Field = 4;
global ASSET_SERIALIZED_LEN: Field = 4;

// Right now we are wasting so many writes. If changing last_updated_ts
// we will end up rewriting all of them, wasting writes.
fn deserializeAsset(fields: [Field; ASSET_serializeD_LEN]) -> Asset {
fn deserializeAsset(fields: [Field; ASSET_SERIALIZED_LEN]) -> Asset {
Asset {
interest_accumulator: fields[0] as u120,
last_updated_ts: fields[1] as u120,
Expand All @@ -25,7 +25,7 @@ fn deserializeAsset(fields: [Field; ASSET_serializeD_LEN]) -> Asset {
}
}

fn serializeAsset(asset: Asset) -> [Field; ASSET_serializeD_LEN] {
fn serializeAsset(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] {
[
asset.interest_accumulator as Field,
asset.last_updated_ts as Field,
Expand All @@ -35,7 +35,7 @@ fn serializeAsset(asset: Asset) -> [Field; ASSET_serializeD_LEN] {
}

impl Asset {
fn serialize(self: Self) -> [Field; ASSET_serializeD_LEN] {
fn serialize(self: Self) -> [Field; ASSET_SERIALIZED_LEN] {
serializeAsset(self)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ contract Lending {
public_state::PublicState,
},
types::type_serialisation::{
field_serialisation::{FieldSerialisationMethods, FIELD_serializeD_LEN},
field_serialisation::{FieldSerialisationMethods, FIELD_SERIALIZED_LEN},
TypeSerialisationInterface,
},
};
use crate::asset::{ASSET_serializeD_LEN, Asset, AssetSerialisationMethods};
use crate::asset::{ASSET_SERIALIZED_LEN, Asset, AssetSerialisationMethods};
use crate::interest_math::compute_multiplier;
use crate::helpers::{covered_by_collateral, DebtReturn, debt_updates, debt_value, compute_identifier};
use crate::interfaces::{Token, Lending, PriceFeed};
Expand All @@ -34,9 +34,9 @@ contract Lending {
struct Storage {
collateral_asset: PublicState<Field, 1>,
stable_coin: PublicState<Field, 1>,
assets: Map<PublicState<Asset, ASSET_serializeD_LEN>>,
collateral: Map<PublicState<Field, FIELD_serializeD_LEN>>,
static_debt: Map<PublicState<Field, FIELD_serializeD_LEN>>, // abusing keys very heavily
assets: Map<PublicState<Asset, ASSET_SERIALIZED_LEN>>,
collateral: Map<PublicState<Field, FIELD_SERIALIZED_LEN>>,
static_debt: Map<PublicState<Field, FIELD_SERIALIZED_LEN>>, // abusing keys very heavily
}

impl Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ contract NonNativeToken {
oracle::compute_selector::compute_selector,
state_vars::{map::Map, public_state::PublicState, set::Set},
types::type_serialisation::field_serialisation::{
FieldSerialisationMethods, FIELD_serializeD_LEN,
FieldSerialisationMethods, FIELD_SERIALIZED_LEN,
},
};

struct Storage {
balances: Map<Set<ValueNote, VALUE_NOTE_LEN>>,
pending_shields: Set<TransparentNote, TRANSPARENT_NOTE_LEN>,
public_balances: Map<PublicState<Field, FIELD_serializeD_LEN>>,
public_balances: Map<PublicState<Field, FIELD_SERIALIZED_LEN>>,
}

impl Storage {
Expand Down
Loading

0 comments on commit d0d8b40

Please sign in to comment.