Skip to content

Commit

Permalink
chore: declare global types (#10206)
Browse files Browse the repository at this point in the history
We're now enforcing that all globals must declare their type. This PR
updates all aztec-packages code to conform with this.
  • Loading branch information
TomAFrench authored Nov 27, 2024
1 parent 49b4a6c commit 7b2e343
Show file tree
Hide file tree
Showing 43 changed files with 142 additions and 129 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ use dep::aztec::protocol_types::{
* chain to avoid a case where the same message could be used across multiple chains.
*/

global IS_VALID_SELECTOR = 0x47dacd73; // 4 last bytes of poseidon2_hash_bytes("IS_VALID()")
global IS_VALID_SELECTOR: Field = 0x47dacd73; // 4 last bytes of poseidon2_hash_bytes("IS_VALID()")

/**
* Assert that `on_behalf_of` have authorized the current call with a valid authentication witness
Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/generators.nr
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
use dep::protocol_types::point::Point;

// A set of generators generated with `derive_generators(...)` function from noir::std
pub global Ga1 = Point {
pub global Ga1: Point = Point {
x: 0x30426e64aee30e998c13c8ceecda3a77807dbead52bc2f3bf0eae851b4b710c1,
y: 0x113156a068f603023240c96b4da5474667db3b8711c521c748212a15bc034ea6,
is_infinite: false,
};
pub global Ga2 = Point {
pub global Ga2: Point = Point {
x: 0x2825c79cc6a5cbbeef7d6a8f1b6a12b312aa338440aefeb4396148c89147c049,
y: 0x129bfd1da54b7062d6b544e7e36b90736350f6fba01228c41c72099509f5701e,
is_infinite: false,
};
pub global Ga3 = Point {
pub global Ga3: Point = Point {
x: 0x0edb1e293c3ce91bfc04e3ceaa50d2c541fa9d091c72eb403efb1cfa2cb3357f,
y: 0x1341d675fa030ece3113ad53ca34fd13b19b6e9762046734f414824c4d6ade35,
is_infinite: false,
};
pub global Ga4 = Point {
pub global Ga4: Point = Point {
x: 0x0e0dad2250583f2a9f0acb04ededf1701b85b0393cae753fe7e14b88af81cb52,
y: 0x0973b02c5caac339ee4ad5dab51329920f7bf1b6a07e1dabe5df67040b300962,
is_infinite: false,
};
pub global Ga5 = Point {
pub global Ga5: Point = Point {
x: 0x2f3342e900e8c488a28931aae68970738fdc68afde2910de7b320c00c902087d,
y: 0x1bf958dc63cb09d59230603a0269ae86d6f92494da244910351f1132df20fc08,
is_infinite: false,
};
// If you change this update `G_SLOT` in `yarn-project/simulator/src/client/test_utils.ts` as well
pub global G_slot = Point {
pub global G_slot: Point = Point {
x: 0x041223147b680850dc82e8a55a952d4df20256fe0593d949a9541ca00f0abf15,
y: 0x0a8c72e60d0e60f5d804549d48f3044d06140b98ed717a9b532af630c1530791,
is_infinite: false,
Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/keys/constants.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use dep::protocol_types::constants::{
GENERATOR_INDEX__TSK_M,
};

pub global NULLIFIER_INDEX = 0;
pub global INCOMING_INDEX = 1;
pub global OUTGOING_INDEX = 2;
pub global TAGGING_INDEX = 3;
pub global NULLIFIER_INDEX: Field = 0;
pub global INCOMING_INDEX: Field = 1;
pub global OUTGOING_INDEX: Field = 2;
pub global TAGGING_INDEX: Field = 3;

pub global NUM_KEY_TYPES = 4;
pub global NUM_KEY_TYPES: u32 = 4;

pub global sk_generators = [
pub global sk_generators: [Field; 4] = [
GENERATOR_INDEX__NSK_M as Field,
GENERATOR_INDEX__IVSK_M as Field,
GENERATOR_INDEX__OVSK_M as Field,
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/keys/getters/test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::keys::getters::get_public_keys;
use crate::test::helpers::{cheatcodes, test_environment::TestEnvironment, utils::TestAccount};
use dep::std::test::OracleMock;

global KEY_ORACLE_RESPONSE_LENGTH = 13; // 12 fields for the keys, one field for the partial address
global KEY_ORACLE_RESPONSE_LENGTH: u32 = 13; // 12 fields for the keys, one field for the partial address

unconstrained fn setup() -> TestAccount {
let _ = TestEnvironment::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub comptime fn stub_fn(f: FunctionDefinition) -> Quoted {
let fn_parameters_list =
fn_parameters.map(|(name, typ): (Quoted, Type)| quote { $name: $typ }).join(quote {,});

let fn_name_str = fn_name.as_str_quote();
let (fn_name_str, _) = fn_name.as_str_quote();

let fn_name_len: u32 = unquote!(quote { $fn_name_str.as_bytes().len()});

Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
meta::{typ::fresh_type_variable, type_of, unquote},
};

comptime global NOTE_HEADER_TYPE = type_of(NoteHeader::empty());
comptime global NOTE_HEADER_TYPE: Type = type_of(NoteHeader::empty());

/// A map from note type to (note_struct_definition, serialized_note_length, note_type_id, fields).
/// `fields` is an array of tuples where each tuple contains the name of the field/struct member (e.g. `amount`
Expand All @@ -22,7 +22,7 @@ pub comptime mut global NOTES: UHashMap<Type, (StructDefinition, u32, Field, [(Q
/// Computes a note type id by hashing a note name (e.g. `TokenNote`), getting the first 4 bytes of the hash
/// and returning it as a `Field`.
comptime fn compute_note_type_id(name: Quoted) -> Field {
let name_as_str_quote = name.as_str_quote();
let (name_as_str_quote, _) = name.as_str_quote();

unquote!(
quote {
Expand Down Expand Up @@ -267,7 +267,7 @@ pub(crate) comptime fn generate_note_export(
let hash = hasher.finish() as u32;
let global_export_name = f"{name}_{hash}_EXPORTS".quoted_contents();
let note_fields_name = f"{name}Fields_{hash}".quoted_contents();
let note_name_as_str = name.as_str_quote();
let (note_name_as_str, _) = name.as_str_quote();
let note_name_str_len = unquote!(quote { $note_name_as_str.as_bytes().len() });

let mut note_fields = &[];
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub comptime fn storage(s: StructDefinition) -> Quoted {
let module = s.module();
let module_name = module.name();
let storage_layout_name = f"STORAGE_LAYOUT_{module_name}".quoted_contents();
let module_name_str = module_name.as_str_quote();
let (module_name_str, module_name_len) = module_name.as_str_quote();
STORAGE_LAYOUT_NAME.insert(module, storage_layout_name);

quote {
Expand All @@ -79,7 +79,7 @@ pub comptime fn storage(s: StructDefinition) -> Quoted {
}

#[abi(storage)]
pub global $storage_layout_name = StorageLayout {
pub global $storage_layout_name: StorageLayout<$module_name_len> = StorageLayout {
contract_name: $module_name_str,
fields: StorageLayoutFields { $storage_layout_constructors }
};
Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/macros/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ comptime fn signature_of_type(typ: Type) -> Quoted {
}

trait AsStrQuote {
fn as_str_quote(self) -> Self;
fn as_str_quote(self) -> (Self, u32);
}

impl<let N: u32, Env> AsStrQuote for Quoted {
// Used to convert an arbirary quoted type into a quoted string, removing whitespace between tokens
comptime fn as_str_quote(self) -> Quoted {
// Used to convert an arbitrary quoted type into a quoted string, removing whitespace between tokens
comptime fn as_str_quote(self) -> (Quoted, u32) {
let tokens = self.tokens();
let mut acc: [u8] = &[];
let mut total_len: u32 = 0;
Expand All @@ -166,7 +166,7 @@ impl<let N: u32, Env> AsStrQuote for Quoted {
signature_as_array.as_str_unchecked()
},
);
quote { $result }
(quote { $result }, total_len)
}
}

Expand All @@ -181,7 +181,7 @@ pub(crate) comptime fn compute_fn_selector(f: FunctionDefinition) -> Field {
let args_signatures =
f.parameters().map(|(_, typ): (Quoted, Type)| signature_of_type(typ)).join(quote {,});
let signature_quote = quote { $fn_name($args_signatures) };
let signature_str_quote = signature_quote.as_str_quote();
let (signature_str_quote, _) = signature_quote.as_str_quote();

let computation_quote = quote {
protocol_types::abis::function_selector::FunctionSelector::from_signature($signature_str_quote).to_field()
Expand All @@ -207,7 +207,7 @@ pub(crate) comptime fn compute_event_selector(s: StructDefinition) -> Field {
})
.join(quote {,});
let signature_quote = quote { $event_name($args_signatures) };
let signature_str_quote = signature_quote.as_str_quote();
let (signature_str_quote, _) = signature_quote.as_str_quote();

let computation_quote = quote {
protocol_types::abis::event_selector::EventSelector::from_signature($signature_str_quote).to_field()
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct SortOrderEnum {
pub ASC: u8,
}

pub global SortOrder = SortOrderEnum { DESC: 1, ASC: 2 };
pub global SortOrder: SortOrderEnum = SortOrderEnum { DESC: 1, ASC: 2 };

pub struct Sort {
pub(crate) property_selector: PropertySelector,
Expand All @@ -45,7 +45,7 @@ pub struct NoteStatusEnum {
pub ACTIVE_OR_NULLIFIED: u8,
}

pub global NoteStatus = NoteStatusEnum {
pub global NoteStatus: NoteStatusEnum = NoteStatusEnum {
ACTIVE: 1,
ACTIVE_OR_NULLIFIED: 2,
// TODO 4217: add 'NULLIFIED'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use dep::protocol_types::{
utils::arr_copy_slice,
};

global NOTE_HASH_TREE_ID = 1;
global ARCHIVE_TREE_ID = 4;
global NOTE_HASH_TREE_ID: Field = 1;
global ARCHIVE_TREE_ID: Field = 4;

// Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to
// do it is to set M here and then set type of the return param, e.g.:
Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/oracle/storage.nr
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ mod tests {
use crate::test::mocks::mock_struct::MockStruct;
use std::test::OracleMock;

global address = AztecAddress::from_field(29);
global slot = 7;
global block_number = 17;
global address: AztecAddress = AztecAddress::from_field(29);
global slot: Field = 7;
global block_number: u32 = 17;

#[test]
unconstrained fn test_raw_storage_read() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use crate::test::{helpers::test_environment::TestEnvironment, mocks::mock_note::MockNote};
use std::test::OracleMock;

global storage_slot = 17;
global storage_slot: Field = 17;

unconstrained fn setup() -> TestEnvironment {
let mut env = TestEnvironment::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::{

use dep::std::{mem::zeroed, test::OracleMock};

global new_value = 17;
global new_value: Field = 17;

global new_delay = 20;
global new_delay: u32 = 20;

global storage_slot = 47;
global storage_slot: Field = 47;

global TEST_INITIAL_DELAY: u32 = 32;

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<let N: u32, let M: u32> Deployer<N, M> {
}

// Keys length + address
global TEST_ACCOUNT_LENGTH = PUBLIC_KEYS_LENGTH + 1;
global TEST_ACCOUNT_LENGTH: u32 = PUBLIC_KEYS_LENGTH + 1;

pub struct TestAccount {
pub address: AztecAddress,
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/utils/comparison.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ struct ComparatorEnum {
pub GTE: u8,
}

pub global Comparator = ComparatorEnum { EQ: 1, NEQ: 2, LT: 3, LTE: 4, GT: 5, GTE: 6 };
pub global Comparator: ComparatorEnum =
ComparatorEnum { EQ: 1, NEQ: 2, LT: 3, LTE: 4, GT: 5, GTE: 6 };

pub fn compare(lhs: Field, operation: u8, rhs: Field) -> bool {
// Values are computed ahead of time because circuits evaluate all branches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ contract AppSubscription {
fee_juice_limit_per_tx: PublicImmutable<Field, Context>,
}

global SUBSCRIPTION_DURATION_IN_BLOCKS = 5;
global SUBSCRIPTION_TXS = 5;
global SUBSCRIPTION_DURATION_IN_BLOCKS: Field = 5;
global SUBSCRIPTION_TXS: Field = 5;

#[private]
fn entrypoint(payload: DAppPayload, user_address: AztecAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::test::utils;

use dep::aztec::prelude::AztecAddress;

global CHANGE_AUTHORIZED_DELAY_BLOCKS = 5;
global CHANGE_AUTHORIZED_DELAY_BLOCKS: u32 = 5;

// TODO (#8588): These were ported over directly from e2e tests. Refactor these in the correct TXe style.
#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Deck<UnconstrainedContext> {
}
}

global PACK_CARDS = 3; // Limited by number of write requests (max 4)
global PACK_CARDS: u32 = 3; // Limited by number of write requests (max 4)

pub fn get_pack_cards(
seed: Field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract TestLog {
}

// EXAMPLE_EVENT_0_BYTES_LEN + 16
global EXAMPLE_EVENT_0_CIPHERTEXT_BYTES_LEN = 144;
global EXAMPLE_EVENT_0_CIPHERTEXT_BYTES_LEN: Field = 144;

#[private]
fn emit_encrypted_events(other: AztecAddress, randomness: [Field; 2], preimages: [Field; 4]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use dep::types::{
constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX},
};

global ALLOWED_PREVIOUS_CIRCUITS =
global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] =
[PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX];

pub struct PrivateKernelInnerCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use dep::types::{
PrivateKernelCircuitPublicInputs,
};

global ALLOWED_PREVIOUS_CIRCUITS =
global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] =
[PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX];

pub struct PrivateKernelResetHints<let NH_RR_PENDING: u32, let NH_RR_SETTLED: u32, let NLL_RR_PENDING: u32, let NLL_RR_SETTLED: u32, let KEY_VALIDATION_REQUESTS: u32, let TRANSIENT_DATA_AMOUNT: u32> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use dep::types::{
PrivateKernelCircuitPublicInputs,
};

global ALLOWED_PREVIOUS_CIRCUITS =
global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] =
[PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX];

pub struct PrivateKernelTailCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use dep::types::{
PrivateKernelCircuitPublicInputs,
};

global ALLOWED_PREVIOUS_CIRCUITS =
global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] =
[PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX];

pub struct PrivateKernelTailToPublicCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use dep::types::{
};
use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs;

global NOTE_HASH_PENDING_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64
global NOTE_HASH_SETTLED_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
global NULLIFIER_PENDING_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 64
global NULLIFIER_SETTLED_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX;
global NULLIFIER_KEYS = MAX_KEY_VALIDATION_REQUESTS_PER_TX; // 64
global TRANSIENT_DATA_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64
global NOTE_HASH_SILOING_AMOUNT = MAX_NOTE_HASHES_PER_TX; // 64
global NULLIFIER_SILOING_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64
global ENCRYPTED_LOG_SILOING_AMOUNT = MAX_ENCRYPTED_LOGS_PER_TX; // 8
global NOTE_HASH_PENDING_AMOUNT: u32 = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64
global NOTE_HASH_SETTLED_AMOUNT: u32 = MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
global NULLIFIER_PENDING_AMOUNT: u32 = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 64
global NULLIFIER_SETTLED_AMOUNT: u32 = MAX_NULLIFIER_READ_REQUESTS_PER_TX;
global NULLIFIER_KEYS: u32 = MAX_KEY_VALIDATION_REQUESTS_PER_TX; // 64
global TRANSIENT_DATA_AMOUNT: u32 = MAX_NULLIFIERS_PER_TX; // 64
global NOTE_HASH_SILOING_AMOUNT: u32 = MAX_NOTE_HASHES_PER_TX; // 64
global NULLIFIER_SILOING_AMOUNT: u32 = MAX_NULLIFIERS_PER_TX; // 64
global ENCRYPTED_LOG_SILOING_AMOUNT: u32 = MAX_ENCRYPTED_LOGS_PER_TX; // 8

unconstrained fn main(
previous_kernel: PrivateKernelDataWithoutPublicInputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use dep::types::{
};
use types::abis::private_kernel_data::PrivateKernelDataWithoutPublicInputs;

global NOTE_HASH_PENDING_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64
global NOTE_HASH_SETTLED_AMOUNT = MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
global NULLIFIER_PENDING_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 64
global NULLIFIER_SETTLED_AMOUNT = MAX_NULLIFIER_READ_REQUESTS_PER_TX;
global NULLIFIER_KEYS = MAX_KEY_VALIDATION_REQUESTS_PER_TX; // 64
global TRANSIENT_DATA_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64
global NOTE_HASH_SILOING_AMOUNT = MAX_NOTE_HASHES_PER_TX; // 64
global NULLIFIER_SILOING_AMOUNT = MAX_NULLIFIERS_PER_TX; // 64
global ENCRYPTED_LOG_SILOING_AMOUNT = MAX_ENCRYPTED_LOGS_PER_TX; // 8
global NOTE_HASH_PENDING_AMOUNT: u32 = MAX_NOTE_HASH_READ_REQUESTS_PER_TX; // 64
global NOTE_HASH_SETTLED_AMOUNT: u32 = MAX_NOTE_HASH_READ_REQUESTS_PER_TX;
global NULLIFIER_PENDING_AMOUNT: u32 = MAX_NULLIFIER_READ_REQUESTS_PER_TX; // 64
global NULLIFIER_SETTLED_AMOUNT: u32 = MAX_NULLIFIER_READ_REQUESTS_PER_TX;
global NULLIFIER_KEYS: u32 = MAX_KEY_VALIDATION_REQUESTS_PER_TX; // 64
global TRANSIENT_DATA_AMOUNT: u32 = MAX_NULLIFIERS_PER_TX; // 64
global NOTE_HASH_SILOING_AMOUNT: u32 = MAX_NOTE_HASHES_PER_TX; // 64
global NULLIFIER_SILOING_AMOUNT: u32 = MAX_NULLIFIERS_PER_TX; // 64
global ENCRYPTED_LOG_SILOING_AMOUNT: u32 = MAX_ENCRYPTED_LOGS_PER_TX; // 8

fn main(
previous_kernel: PrivateKernelDataWithoutPublicInputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub struct ReadRequestStateEnum {
pub SETTLED: u8,
}

pub global ReadRequestState = ReadRequestStateEnum { NADA: 0, PENDING: 1, SETTLED: 2 };
pub global ReadRequestState: ReadRequestStateEnum =
ReadRequestStateEnum { NADA: 0, PENDING: 1, SETTLED: 2 };

pub struct ReadRequestStatus {
pub state: u8,
Expand Down
Loading

0 comments on commit 7b2e343

Please sign in to comment.