@aztec/noir-test-contracts.js 2.0.3 → 2.1.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/avm_initializer_test_contract-AvmInitializerTest.json +4 -4
- package/artifacts/avm_test_contract-AvmTest.json +1 -1
- package/artifacts/counter_contract-Counter.json +39 -116
- package/artifacts/offchain_effect_contract-OffchainEffect.json +1 -1
- package/artifacts/public_immutable_contract-PublicImmutableContract.json +5 -5
- package/artifacts/state_vars_contract-StateVars.json +8 -8
- package/artifacts/static_parent_contract-StaticParent.json +1 -1
- package/dest/Counter.d.ts +0 -2
- package/dest/Counter.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Counter.ts +0 -3
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"bytecode": "JwACBAEoAAABBIBIJwAABAMnAgEEACcCAgQAHwoAAQACgEglAAAAPyUAAABjKAIAAQSASCcCAgQAOw4AAgABKACAQwQAAygAgEQBAAAoAIBFBAAAKACARgEAASgAgEcEAAEmJQAABX0eAgABAC0IAQInAgMEAwAIAQMBJwMCBAEAIgICAzYOAAEAAwABIgACgEcABC0LBAMnAgQEAgAqAgQGLQsGBRwKAwIABCoCBQYkAgADAAAAwScCAgQAPAYCAS0IAQInAgMEAwAIAQMBJwMCBAEAIgICAzYOAAEAAwIBIgACgEcAAy0LAwEAKgIEBS0LBQMcCgECAAQqAgMEJAIAAQAAARAnAgIEADwGAgEtCAEBJwICBAIACAECAScDAQQBACIBAgIfMIBHgEUAAgEiAAGARwADLQsDAhwKAgMEHAoDAQAtCAECAAABAgEnAwIEAQAiAgIDHzCARYBHAAMnAgMAAC0IAQUnAgcEBAAIAQcBJwMFBAEAIgUCBy0KBwgtDgMIACIIAggtDgMIACIIAggtDgMIKwIABwAAAAAAAAAAAwAAAAAAAAAALQgBCCcCCQQFAAgBCQEnAwgEAQAiCAIJLQoJCi0OAwoAIgo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aKAIAAQSATicCAgQAOw4AAgABKACAQwQAAygAgEQBAAAoAIBFBAAAKACARgAAACgAgEcBAAEoAIBIBAABKACASQAAASgAgEoEAAIoAIBLAAAGKwCATAAAAAAAAAAAAQAAAAAAAAAAJiUAAAQ/KQIAAgAX8SiICioBAgMkAgADAAAAuiMAAAEoJwICBAMtCAADAAgAAgAlAAAEaC0CAAAnAgMEACcCBQQDACoDBQQtCAECAAgBBAEnAwIEAQAiAgIELQ4DBAAiBAIELQ4DBCcCBAQDACoCBAMAIgICBS0LBQQnAgYEAgAqBQYDOw4ABAADIwAAASgpAgACAIQtoykKKgECAyQCAAMAAAFDIwAAAnMeAgACAB4CAAMAMyoAAgADAAQkAgAEAAABYiUAAAjVLQgBAicCAwQCAAgBAwEnAwIEAQAiAgIDLQoDBC4MgEkABC0IAQMnAgQEAgAIAQQBJwMDBAEAIgMCBC0KBAUuDIBLAAUnAgUEBi0IAAYtCgMHLQoCCAAIAAUAJQAACOctAgAALQoHBCcCAwQFLQgABS0KBAYuCIBKAAcuCIBEAAgACAADACUAAAkyLQIAAC0KBgIeAgADADMqAAIAAwAEJAIABAAAAg4lAAAK4S8IgEkAAicCBAQBJwIGBAMAKgQGBS0IAQMACAEFAScDAwQBACIDAgUtDgQFACIFAgUtDgQFJwIFBAMAKgMFBC0KBAUtDgIFACIDAgUtCwUEJwIGBAIAKgUGAjsOAAQAAiMAAAJzJwICAlUnAgMCbicCBAJrJwIFAm8nAgYCdycCBwIgJwIIAnMnAgkCZScCCgJsJwILAmMnAgwCdCcCDQJyJwIOAnsnAg8CfS0IARAnAhEEHAAIAREBJwMQBAEAIhACES0KERItDgISACISAhItDgMSACISAhItDgQSACISAhItDgMSACISAhItDgUSACISAhItDgYSACISAhItDgMSACISAhItDgcSACISAhItDggSACISAhItDgkSACISAhItDgoSACISAhItDgkSACISAhItDgsSACISAhItDgwSACISAhItDgUSACISAhItDg0SACISAhItDgcSACISAhItDg4SACISAhItDggSACISAhItDgkSACISAhItDgoSAC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0etvuXB/Ls50AKbeOaSvD/C3OJcdXI4v+s5KvJvK4WUNwROOSO3yThic4MY17nSIpXgeU6R2psSCtc50iP5GLH62qBGOnredXg5P9x4tmBcpUENj+8tX6NwPRD/YTr2uH4O6q+2cvuXvK8f5rOZPNjlusawufoRHhnS/4o8Ct9vP/0+PLqDxh8Z6mXx/vfnx7045/fnj8dvv363y/2jf0BhC8vnz89/PHt5YGV4q8g0D+/dMp0d8RfP9xV+gT0ifYU9Il/dvtLoU0zrc78MfO9tKukdebX71y1/wE="
|
|
356
356
|
},
|
|
357
357
|
{
|
|
358
358
|
"name": "read_storage_immutable",
|
|
@@ -384,7 +384,7 @@
|
|
|
384
384
|
}
|
|
385
385
|
},
|
|
386
386
|
"bytecode": "JwACBAEoAAABBIBFJwAABAMnAgEEACcCAgQAHwoAAQACgEQlAAAARSUAAABNLgIAAYBEKAIAAgSARCcCAwQBOw4AAwACKACAQwQAAyYlAAACdB4CAAIAHgIAAwAzKgACAAMABCcCAgEBJAIABAAAAHYlAAACnScCAwAAKwIABAAAAAAAAAAAAgAAAAAAAAAALQgBBScCBgQFAAgBBgEnAwUEAQAiBQIGLQoGBy0OAwcAIgcCBy0OAwcAIgcCBy0OAwcAIgcCBy0OBActCAEEAAABAgEtCAEGAAABAgEtCAEHAAABAgEtCAEIAAABAgEnAgkABicCCgABLQgBCycCDAQEAAgBDAEnAwsEAQAiCwIMLQoMDS0OCQ0AIg0CDS0OCg0AIg0CDS0OAw0tDgsELQ4FBicCAwQCLQ4DBycCAwEALQ4DCCcCAwQAJwIFBAEtCgMBIwAAAVgNIgABgEMAAyQCAAMAAAHoIwAAAW0tCwYBLQsBAwAiAwIDLQ4DAS0IAQMnAgkEBQAIAQkBJwMDBAEAIgECCScCCwQEACIDAgw/DwAJAAwtCwQBLQsHCS0OAQQtDgMGLQ4JBy0OAggAKgMFBC0LBAEeAgADADMqAAEAAwAEJAIABAAAAeElAAACry8KAAoAASYtCwcDDCoBAwkkAgAJAAAB/iMAAA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K43Y1oi6m3PVUEZqaXRDKcXdACjNUNIvhML/O5SU51XJ7VXJbQmR7BKSqelE6QQStal4INqwfhoIYDuQTpmzUFXgwrNAut4m0KlP5hRdgeXCh/xll3TqU5i8toQztzWorUEIqWpou41tjdTzo7iGSDzHoifMtUanQIWi50Moh7aGdGojedfQ02VWQPyi0KlPhOLFhRhKW6NTodqnfWEh3eYFZl9X3bbY1MBejSf0Lg6J5EYNnnuXnke3xSLgvUt/yoS2H9RrgBLP/a+Tj16NEs7lxTcpFPIiLynfpHB1rHG7NrCTT/3h4xVKVM5+QPl+OkuYl7VgO53d1iNxbj3ahpptI8JvHNH4Gwdbt5GW+VgSlHY09OOjLabfONu+fbC0V6arIdFj4RygnY9OocK5iUG8bKVfKjX2DvvA2ZupvsCE3EoIhZ5IOGc1BApNEegdLTHNIinm5tJ0O0jwYAre2IPYG0iR9NMu9lXhXi9XT+vd1Uv80aR269XjZqyXL4ft08Xo/u+7j/ifAO+7t6fx+bAbTen8T4B+3IG+hulZcm8v/naprmp12CVMo6SXfH80Z/4B"
|
|
388
388
|
},
|
|
389
389
|
{
|
|
390
390
|
"name": "sync_private_state",
|
|
@@ -827,7 +827,7 @@
|
|
|
827
827
|
},
|
|
828
828
|
"185": {
|
|
829
829
|
"path": "/home/aztec-dev/aztec-packages/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr",
|
|
830
|
-
"source": "use crate::{\n context::{PrivateContext, PublicContext, UtilityContext},\n state_vars::storage::HasStorageSlot,\n utils::with_hash::WithHash,\n};\nuse protocol_types::{\n constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::poseidon2_hash_with_separator,\n traits::Packable,\n};\n\n/// # PublicImmutable\n///\n/// PublicImmutable is a public state variable type for values that are set once\n/// during initialization and remain permanently unchanged.\n///\n/// You can declare a state variable of type PublicImmutable within your contract's\n/// #[storage] struct:\n///\n/// E.g.:\n/// `your_variable: PublicImmutable<T, Context>`\n///\n/// PublicImmutable stores an immutable value in public state which can be _read_\n/// from public, utility and even _private_ execution contexts.\n///\n/// The methods of PublicImmutable are:\n/// - `initialize`\n/// - `read`\n/// (see the methods' own doc comments for more info).\n///\n/// # Generic Parameters:\n///\n/// * `T` - The type of value stored (must implement Packable).\n/// * `Context` - The execution context (PublicContext, PrivateContext, or UtilityContext).\n///\n/// # Advanced\n///\n/// PublicImmutable leverages `WithHash<T>` to enable efficient private reads of\n/// public storage. The `WithHash` wrapper optimizes reads by hashing values that would\n/// be larger than a single field into a single field, then proving inclusion of only\n/// the hash in public storage.\n///\n/// This optimization is particularly valuable when T packs to multiple fields,\n/// as it maintains \"almost constant\" verification overhead regardless of the\n/// original data size.\n///\n/// ## Optimizing private reads in your contract\n/// Since reading T from public immutable storage in private contexts has \"almost\n/// constant\" constraint costs regardless of T's size, it's recommended to group\n/// multiple values into a single struct when they are to be read together. This is\n/// typically useful for configuration data set during contract initialization. E.g.:\n///\n/// ```noir\n/// use dep::aztec::protocol_types::{address::AztecAddress, traits::Packable};\n/// use std::meta::derive;\n///\n/// #[derive(Eq, Packable)]\n/// pub struct Config \\{\n/// pub address_1: AztecAddress,\n/// pub value_1: u128,\n/// pub value_2: u64,\n/// ...\n/// }\n/// ```\n///\n// docs:start:public_immutable_struct\npub struct PublicImmutable<T, Context> {\n context: Context,\n storage_slot: Field,\n}\n// docs:end:public_immutable_struct\n\n/// `WithHash<T>` stores both the packed value (using O fields) and its hash (1 field), requiring O = M + 1 total\n/// fields.\nimpl<T, Context, let M: u32, let O: u32> HasStorageSlot<O> for PublicImmutable<T, Context>\nwhere\n WithHash<T, M>: Packable<N = O>,\n{\n fn get_storage_slot(self) -> Field {\n self.storage_slot\n }\n}\n\nimpl<T, Context> PublicImmutable<T, Context> {\n /// Initializes a new PublicImmutable state variable.\n ///\n /// This function is usually automatically called within the #[storage] macro.\n /// You typically don't need to call this directly when writing smart contracts.\n ///\n /// # Arguments\n ///\n /// * `context` - One of `PublicContext`/`PrivateContext`/`UtilityContext`. The\n /// Context determines which methods of this struct will be made\n /// available to the calling smart contract function.\n /// * `storage_slot` - A unique identifier for this state variable within the\n /// contract. Usually, the #[storage] macro will determine an\n /// appropriate storage_slot automatically. A smart contract\n /// dev shouldn't have to worry about this, as it's managed\n /// behind the scenes.\n ///\n /// docs:start:public_immutable_struct_new\n pub fn new(\n // Note: Passing the contexts to new(...) just to have an interface compatible with a Map.\n context: Context,\n storage_slot: Field,\n ) -> Self {\n assert(storage_slot != 0, \"Storage slot 0 not allowed. Storage slots must start from 1.\");\n PublicImmutable { context, storage_slot }\n }\n // docs:end:public_immutable_struct_new\n\n pub fn compute_initialization_nullifier(self) -> Field {\n poseidon2_hash_with_separator(\n [self.storage_slot],\n GENERATOR_INDEX__INITIALIZATION_NULLIFIER,\n )\n }\n}\n\nimpl<T> PublicImmutable<T, &mut PublicContext> {\n /// Initializes a PublicImmutable state variable instance with a permanent value.\n ///\n /// This function sets the immutable value for this state variable. It can only\n /// be called once per PublicImmutable. Subsequent calls will fail because the\n /// initialization nullifier will already exist.\n ///\n /// # Arguments\n /// * `value` - The permanent value to store in this PublicImmutable.\n ///\n /// # Panics\n /// Panics if the value is already initialized.\n ///\n /// # Advanced\n ///\n /// This function performs the following operations:\n /// - Creates and emits an initialization nullifier to mark this storage slot\n /// as initialized. This prevents double-initialization.\n /// - Wraps the value in `WithHash<T>` for efficient private reads.\n /// - Stores the wrapped value in Aztec's public data tree.\n ///\n /// docs:start:public_immutable_struct_write\n pub fn initialize(self, value: T)\n where\n T: Packable + Eq,\n {\n // We emit an initialization nullifier to indicate that the struct is initialized. This also prevents\n // the value from being initialized again as a nullifier can be included only once.\n let nullifier = self.compute_initialization_nullifier();\n self.context.push_nullifier(nullifier);\n\n self.context.storage_write(self.storage_slot, WithHash::new(value));\n }\n // docs:end:public_immutable_struct_write\n\n /// Reads the permanent value stored in this PublicImmutable state variable.\n ///\n /// # Returns\n /// * `T` - The permanent value stored in this PublicImmutable.\n ///\n /// # Panics\n /// Panics if the value is not initialized.\n ///\n /// # Advanced\n ///\n /// This function performs the following operations:\n /// - Checks that the state variable has been initialized by verifying the\n /// initialization nullifier exists\n /// - Reads the `WithHash<T>` wrapper from public storage\n /// - Extracts and returns the original value T\n ///\n /// The function will panic if called on an uninitialized PublicImmutable.\n ///\n /// docs:start:public_immutable_struct_read\n pub fn read(self) -> T\n where\n T: Packable + Eq,\n {\n assert(self.is_initialized(), \"Trying to read from uninitialized PublicImmutable\");\n WithHash::public_storage_read(*self.context, self.storage_slot)\n }\n // docs:end:public_immutable_struct_read\n\n /// Reads the value stored in this PublicImmutable without checking if the value\n /// is initialized.\n ///\n /// This function bypasses the initialization check and directly reads from\n /// storage.\n /// If the PublicImmutable has not been initialized, this will return a\n /// zeroed value.\n /// However, if the variable is _known_ to be initialized, this is cheaper\n /// to call than `read`.\n ///\n /// # Returns\n ///\n /// * `T` - The value stored in this PublicImmutable, or empty/default values if\n /// uninitialized.\n ///\n pub fn read_unsafe(self) -> T\n where\n T: Packable + Eq,\n {\n WithHash::public_storage_read(*self.context, self.storage_slot)\n }\n\n fn is_initialized(self) -> bool {\n let nullifier = self.compute_initialization_nullifier();\n self.context.nullifier_exists(nullifier, self.context.this_address())\n }\n}\n\nimpl<T> PublicImmutable<T, UtilityContext> {\n /// Reads the permanent value stored in this PublicImmutable state variable.\n ///\n /// Notice that this function is executable only within a UtilityContext, which\n /// is an unconstrained environment on the user's local device.\n ///\n /// # Returns\n ///\n /// * `T` - The permanent value stored in this PublicImmutable.\n ///\n pub unconstrained fn read(self) -> T\n where\n T: Packable + Eq,\n {\n // TODO(#15703): this fn should fail if the variable is not initialized\n WithHash::utility_public_storage_read(self.context, self.storage_slot)\n }\n}\n\nimpl<T> PublicImmutable<T, &mut PrivateContext> {\n /// Reads the permanent value stored in this PublicImmutable from the anchor\n /// block.\n ///\n /// Private functions execute asynchronously and offchain. When a user begins\n /// private execution, their view of the chain 'branches off' from the current\n /// public state, since public state continues to advance while they execute\n /// privately. Therefore, private functions read from a historical snapshot of\n /// public state rather than the current state.\n ///\n /// # Returns\n ///\n /// * `T` - The permanent value stored in this PublicImmutable at the historical\n /// block referenced by the private context.\n ///\n /// # Advanced\n ///\n /// This function performs a historical read using the block header from the private\n /// context. The `WithHash` optimization is particularly valuable here because it\n /// reduces the number of required inclusion proofs by proving membership of\n /// only the hash instead of the full packed value.\n ///\n /// The historical read mechanism:\n /// - Uses an oracle to obtain the value from the historical block\n /// - Proves inclusion of the value's hash in the public data tree\n /// - Proves that the root of this public data tree is correct, relative to the\n /// historical block header that is being referenced by this private function.\n /// - Verifies that the oracle-provided value matches the stored hash\n ///\n pub fn read(self) -> T\n where\n T: Packable + Eq,\n {\n // TODO(#15703): this fn should fail if the variable is not initialized\n WithHash::historical_public_storage_read(\n self.context.get_block_header(),\n self.context.this_address(),\n self.storage_slot,\n )\n }\n}\n"
|
|
830
|
+
"source": "use crate::{\n context::{PrivateContext, PublicContext, UtilityContext},\n state_vars::storage::HasStorageSlot,\n utils::with_hash::WithHash,\n};\nuse protocol_types::{\n constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::poseidon2_hash_with_separator,\n traits::Packable,\n};\n\n/// # PublicImmutable\n///\n/// PublicImmutable is a public state variable type for values that are set once\n/// during initialization and remain permanently unchanged.\n///\n/// You can declare a state variable of type PublicImmutable within your contract's\n/// #[storage] struct:\n///\n/// E.g.:\n/// `your_variable: PublicImmutable<T, Context>`\n///\n/// PublicImmutable stores an immutable value in public state which can be _read_\n/// from public, utility and even _private_ execution contexts.\n///\n/// The methods of PublicImmutable are:\n/// - `initialize`\n/// - `read`\n/// (see the methods' own doc comments for more info).\n///\n/// # Generic Parameters:\n///\n/// * `T` - The type of value stored (must implement Packable).\n/// * `Context` - The execution context (PublicContext, PrivateContext, or UtilityContext).\n///\n/// # Advanced\n///\n/// PublicImmutable leverages `WithHash<T>` to enable efficient private reads of\n/// public storage. The `WithHash` wrapper optimizes reads by hashing values that would\n/// be larger than a single field into a single field, then proving inclusion of only\n/// the hash in public storage.\n///\n/// This optimization is particularly valuable when T packs to multiple fields,\n/// as it maintains \"almost constant\" verification overhead regardless of the\n/// original data size.\n///\n/// ## Optimizing private reads in your contract\n/// Since reading T from public immutable storage in private contexts has \"almost\n/// constant\" constraint costs regardless of T's size, it's recommended to group\n/// multiple values into a single struct when they are to be read together. This is\n/// typically useful for configuration data set during contract initialization. E.g.:\n///\n/// ```noir\n/// use dep::aztec::protocol_types::{address::AztecAddress, traits::Packable};\n/// use std::meta::derive;\n///\n/// #[derive(Eq, Packable)]\n/// pub struct Config \\{\n/// pub address_1: AztecAddress,\n/// pub value_1: u128,\n/// pub value_2: u64,\n/// ...\n/// }\n/// ```\n///\n// docs:start:public_immutable_struct\npub struct PublicImmutable<T, Context> {\n context: Context,\n storage_slot: Field,\n}\n// docs:end:public_immutable_struct\n\n/// `PublicImmutable` stores both the packed value (using M fields) and its hash (1 field), requiring M + 1 total\n/// fields.\nimpl<T, Context, let M: u32> HasStorageSlot<M + 1> for PublicImmutable<T, Context>\nwhere\n T: Packable<N = M>,\n{\n fn get_storage_slot(self) -> Field {\n self.storage_slot\n }\n}\n\nimpl<T, Context> PublicImmutable<T, Context> {\n /// Initializes a new PublicImmutable state variable.\n ///\n /// This function is usually automatically called within the #[storage] macro.\n /// You typically don't need to call this directly when writing smart contracts.\n ///\n /// # Arguments\n ///\n /// * `context` - One of `PublicContext`/`PrivateContext`/`UtilityContext`. The\n /// Context determines which methods of this struct will be made\n /// available to the calling smart contract function.\n /// * `storage_slot` - A unique identifier for this state variable within the\n /// contract. Usually, the #[storage] macro will determine an\n /// appropriate storage_slot automatically. A smart contract\n /// dev shouldn't have to worry about this, as it's managed\n /// behind the scenes.\n ///\n /// docs:start:public_immutable_struct_new\n pub fn new(\n // Note: Passing the contexts to new(...) just to have an interface compatible with a Map.\n context: Context,\n storage_slot: Field,\n ) -> Self {\n assert(storage_slot != 0, \"Storage slot 0 not allowed. Storage slots must start from 1.\");\n PublicImmutable { context, storage_slot }\n }\n // docs:end:public_immutable_struct_new\n\n pub fn compute_initialization_nullifier(self) -> Field {\n poseidon2_hash_with_separator(\n [self.storage_slot],\n GENERATOR_INDEX__INITIALIZATION_NULLIFIER,\n )\n }\n}\n\nimpl<T> PublicImmutable<T, &mut PublicContext> {\n /// Initializes a PublicImmutable state variable instance with a permanent value.\n ///\n /// This function sets the immutable value for this state variable. It can only\n /// be called once per PublicImmutable. Subsequent calls will fail because the\n /// initialization nullifier will already exist.\n ///\n /// # Arguments\n /// * `value` - The permanent value to store in this PublicImmutable.\n ///\n /// # Panics\n /// Panics if the value is already initialized.\n ///\n /// # Advanced\n ///\n /// This function performs the following operations:\n /// - Creates and emits an initialization nullifier to mark this storage slot\n /// as initialized. This prevents double-initialization.\n /// - Wraps the value in `WithHash<T>` for efficient private reads.\n /// - Stores the wrapped value in Aztec's public data tree.\n ///\n /// docs:start:public_immutable_struct_write\n pub fn initialize(self, value: T)\n where\n T: Packable + Eq,\n {\n // We emit an initialization nullifier to indicate that the struct is initialized. This also prevents\n // the value from being initialized again as a nullifier can be included only once.\n let nullifier = self.compute_initialization_nullifier();\n self.context.push_nullifier(nullifier);\n\n self.context.storage_write(self.storage_slot, WithHash::new(value));\n }\n // docs:end:public_immutable_struct_write\n\n /// Reads the permanent value stored in this PublicImmutable state variable.\n ///\n /// # Returns\n /// * `T` - The permanent value stored in this PublicImmutable.\n ///\n /// # Panics\n /// Panics if the value is not initialized.\n ///\n /// # Advanced\n ///\n /// This function performs the following operations:\n /// - Checks that the state variable has been initialized by verifying the\n /// initialization nullifier exists\n /// - Reads the `WithHash<T>` wrapper from public storage\n /// - Extracts and returns the original value T\n ///\n /// The function will panic if called on an uninitialized PublicImmutable.\n ///\n /// docs:start:public_immutable_struct_read\n pub fn read(self) -> T\n where\n T: Packable + Eq,\n {\n assert(self.is_initialized(), \"Trying to read from uninitialized PublicImmutable\");\n WithHash::public_storage_read(*self.context, self.storage_slot)\n }\n // docs:end:public_immutable_struct_read\n\n /// Reads the value stored in this PublicImmutable without checking if the value\n /// is initialized.\n ///\n /// This function bypasses the initialization check and directly reads from\n /// storage.\n /// If the PublicImmutable has not been initialized, this will return a\n /// zeroed value.\n /// However, if the variable is _known_ to be initialized, this is cheaper\n /// to call than `read`.\n ///\n /// # Returns\n ///\n /// * `T` - The value stored in this PublicImmutable, or empty/default values if\n /// uninitialized.\n ///\n pub fn read_unsafe(self) -> T\n where\n T: Packable + Eq,\n {\n WithHash::public_storage_read(*self.context, self.storage_slot)\n }\n\n fn is_initialized(self) -> bool {\n let nullifier = self.compute_initialization_nullifier();\n self.context.nullifier_exists(nullifier, self.context.this_address())\n }\n}\n\nimpl<T> PublicImmutable<T, UtilityContext> {\n /// Reads the permanent value stored in this PublicImmutable state variable.\n ///\n /// Notice that this function is executable only within a UtilityContext, which\n /// is an unconstrained environment on the user's local device.\n ///\n /// # Returns\n ///\n /// * `T` - The permanent value stored in this PublicImmutable.\n ///\n pub unconstrained fn read(self) -> T\n where\n T: Packable + Eq,\n {\n // TODO(#15703): this fn should fail if the variable is not initialized\n WithHash::utility_public_storage_read(self.context, self.storage_slot)\n }\n}\n\nimpl<T> PublicImmutable<T, &mut PrivateContext> {\n /// Reads the permanent value stored in this PublicImmutable from the anchor\n /// block.\n ///\n /// Private functions execute asynchronously and offchain. When a user begins\n /// private execution, their view of the chain 'branches off' from the current\n /// public state, since public state continues to advance while they execute\n /// privately. Therefore, private functions read from a historical snapshot of\n /// public state rather than the current state.\n ///\n /// # Returns\n ///\n /// * `T` - The permanent value stored in this PublicImmutable at the historical\n /// block referenced by the private context.\n ///\n /// # Advanced\n ///\n /// This function performs a historical read using the block header from the private\n /// context. The `WithHash` optimization is particularly valuable here because it\n /// reduces the number of required inclusion proofs by proving membership of\n /// only the hash instead of the full packed value.\n ///\n /// The historical read mechanism:\n /// - Uses an oracle to obtain the value from the historical block\n /// - Proves inclusion of the value's hash in the public data tree\n /// - Proves that the root of this public data tree is correct, relative to the\n /// historical block header that is being referenced by this private function.\n /// - Verifies that the oracle-provided value matches the stored hash\n ///\n pub fn read(self) -> T\n where\n T: Packable + Eq,\n {\n // TODO(#15703): this fn should fail if the variable is not initialized\n WithHash::historical_public_storage_read(\n self.context.get_block_header(),\n self.context.this_address(),\n self.storage_slot,\n )\n }\n}\n"
|
|
831
831
|
},
|
|
832
832
|
"19": {
|
|
833
833
|
"path": "std/hash/mod.nr",
|
|
@@ -7838,7 +7838,7 @@
|
|
|
7838
7838
|
},
|
|
7839
7839
|
"111": {
|
|
7840
7840
|
"path": "/home/aztec-dev/aztec-packages/noir-projects/aztec-nr/aztec/src/macros/utils.nr",
|
|
7841
|
-
"source": "use dep::protocol_types::meta::derive_serialize;\nuse std::meta::unquote;\n\npub(crate) comptime fn get_fn_visibility(f: FunctionDefinition) -> Quoted {\n if f.has_named_attribute(\"private\") {\n quote { private }\n } else if f.has_named_attribute(\"public\") {\n quote { public }\n } else {\n panic(f\"Function is neither private nor public\")\n }\n}\n\npub(crate) comptime fn is_fn_private(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"private\")\n}\n\npub(crate) comptime fn is_fn_public(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"public\")\n}\n\npub(crate) comptime fn is_fn_utility(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"utility\")\n}\n\npub(crate) comptime fn is_fn_contract_library_method(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"contract_library_method\")\n}\n\npub(crate) comptime fn is_fn_test(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"test\")\n}\n\npub(crate) comptime fn is_fn_view(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"view\")\n}\n\npub(crate) comptime fn is_fn_internal(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"internal\")\n}\n\npub(crate) comptime fn is_fn_initializer(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"initializer\")\n}\n\npub(crate) comptime fn fn_has_noinitcheck(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"noinitcheck\")\n}\n\npub(crate) comptime fn fn_has_authorize_once(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"authorize_once\")\n}\n\n/// Takes a function body as a collection of expressions, and alters it by prepending and appending quoted values.\npub(crate) comptime fn modify_fn_body(body: [Expr], prepend: Quoted, append: Quoted) -> Expr {\n // We need to quote the body before we can alter its contents, so we fold it by quoting each expression.\n let mut body_quote = body.fold(quote {}, |full_quote: Quoted, expr: Expr| {\n let expr_quote = expr.quoted();\n quote {\n $full_quote\n $expr_quote\n }\n });\n body_quote = quote {\n {\n $prepend\n $body_quote\n $append\n }\n };\n let body_expr = body_quote.as_expr();\n body_expr.expect(f\"Body is not an expression: {body_quote}\")\n}\n\n/// Adds a value to a field array. Structs and values inside arrays are required to implement the Serialize trait.\n///\n/// The function takes the name of the array, the index in the array where the value should be added, the name of the\n/// variable to be added, and the type of the variable. It returns a quoted expression that can be used in a function body.\n///\n/// The returned quoted expression will increment the `index_name` variable by the number of fields added to the array,\n/// which is typically 1 for simple types, but can be more for complex types like structs or arrays.\npub(crate) comptime fn add_to_field_array(\n array_name: Quoted,\n index_name: Quoted,\n name: Quoted,\n typ: Type,\n) -> Quoted {\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { \n $array_name[$index_name] = $name as Field;\n $index_name += 1;\n }\n } else if typ.as_data_type().is_some() {\n // We invoke serialize as a static trait function rather than calling $name.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote { \n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n } else if typ.as_array().is_some() {\n // We invoke serialize as a static trait function rather than calling x.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote {\n for i in 0..$name.len() {\n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name[i]);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n }\n } else if typ.as_str().is_some() {\n quote {\n let $serialized_name = $name.as_bytes();\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i] as Field;\n $index_name += 1;\n }\n }\n } else {\n panic(\n f\"Cannot add to slice: unsupported type {typ} variable {name}\",\n )\n }\n}\n\n/// Adds a value to a hash::ArgsHasher. Structs and values inside arrays are required to implement the Serialize trait.\npub(crate) comptime fn add_to_hasher(hasher_name: Quoted, name: Quoted, typ: Type) -> Quoted {\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { $hasher_name.add($name as Field); }\n } else if typ.as_data_type().is_some() {\n quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name)); }\n } else if typ.as_array().is_some() {\n let (element_type, _) = typ.as_array().unwrap();\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n quote {\n let $serialized_name = $name.map(|x: $element_type | dep::aztec::protocol_types::traits::Serialize::serialize(x));\n for i in 0..$name.len() {\n $hasher_name.add_multiple($serialized_name[i]);\n }\n }\n } else if typ.as_tuple().is_some() {\n let tuple_len = typ.as_tuple().unwrap().len();\n let mut tuple_quotes: [Quoted] = [];\n for i in 0..tuple_len {\n let element_quote = quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name.$i)); };\n tuple_quotes = tuple_quotes.push_back(element_quote);\n }\n tuple_quotes.join(quote {})\n } else if typ.as_str().is_some() {\n quote {\n $hasher_name.add_multiple($name.as_bytes().map(| byte: u8 | byte as Field));\n }\n } else {\n panic(\n f\"Cannot add to hasher: unsupported type {typ} of variable {name}\",\n )\n }\n}\n\ncomptime fn signature_of_type(typ: Type) -> Quoted {\n if typ.is_field() {\n quote {Field}\n } else if typ.as_integer().is_some() {\n let (is_signed, bit_size) = typ.as_integer().unwrap();\n if is_signed {\n f\"i{bit_size}\".quoted_contents()\n } else {\n f\"u{bit_size}\".quoted_contents()\n }\n } else if typ.is_bool() {\n quote {bool}\n } else if typ.as_str().is_some() {\n let str_len_typ = typ.as_str().unwrap();\n let str_len = str_len_typ.as_constant().unwrap();\n f\"str<{str_len}>\".quoted_contents()\n } else if typ.as_array().is_some() {\n let (element_type, array_len) = typ.as_array().unwrap();\n let array_len = if array_len.as_constant().is_some() {\n let const_len = array_len.as_constant().unwrap();\n f\"{const_len}\".quoted_contents()\n } else {\n // If array length is not a constant, chances are it's a numeric generic\n // This will make the signature of a type like Struct<N> be the same regardless\n // of the value of N, but at least this fn will not crash. It is up to the caller\n // to decide whether this is acceptable.\n f\"{array_len}\".quoted_contents()\n };\n\n let element_typ_quote = signature_of_type(element_type);\n f\"[{element_typ_quote};{array_len}]\".quoted_contents()\n } else if typ.as_data_type().is_some() {\n let (s, generics) = typ.as_data_type().unwrap();\n let field_signatures =\n s.fields(generics).map(|(_, typ, _)| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else if typ.as_tuple().is_some() {\n // Note that tuples are handled the same way as structs\n let types = typ.as_tuple().unwrap();\n let field_signatures = types.map(|typ: Type| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else {\n panic(f\"Unsupported type {typ}\")\n }\n}\n\npub trait AsStrQuote {\n fn as_str_quote(self) -> (Self, u32);\n}\n\nimpl<let N: u32, Env> AsStrQuote for Quoted {\n // Used to convert an arbitrary quoted type into a quoted string, removing whitespace between tokens\n comptime fn as_str_quote(self) -> (Quoted, u32) {\n let tokens = self.tokens();\n let mut acc: [u8] = &[];\n let mut total_len: u32 = 0;\n for token in tokens {\n let token_as_fmt_str = f\"{token}\";\n let token_as_str = unquote!(quote {$token_as_fmt_str});\n let token_len = unquote!(quote { $token_as_str.as_bytes().len() });\n let token_as_bytes = unquote!(quote { $token_as_str.as_bytes().as_slice() });\n total_len += token_len;\n acc = acc.append(token_as_bytes);\n }\n let result = unquote!(\n quote {\n let signature_as_array: [u8; $total_len] = $acc.as_array();\n signature_as_array.as_str_unchecked()\n },\n );\n (quote { $result }, total_len)\n }\n}\n\npub(crate) comptime fn compute_fn_selector(f: FunctionDefinition) -> Field {\n // The function selector is computed from the function signature, which is made up of the function name and types of\n // parameters, but not including the return type. For example, given:\n //\n // fn foo(a: Field, b: AztecAddress) -> Field\n //\n // The signature will be \"foo(Field,AztecAddress)\".\n let fn_name = f.name();\n let args_signatures = f.parameters().map(|(_, typ)| signature_of_type(typ)).join(quote {,});\n let signature_quote = quote { $fn_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field(protocol_types::abis::function_selector::FunctionSelector::from_signature($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\npub(crate) comptime fn compute_struct_selector(\n s: TypeDefinition,\n from_signature_fn: Quoted,\n) -> Field {\n // The struct selector is computed from the type signature, similar to how one might type\n // the constructor function. For example, given:\n //\n // struct Foo {\n // a: Field,\n // b: AztecAddress,\n // }\n //\n // The signature will be \"Foo(Field,AztecAddress)\".\n let struct_name = s.name();\n let args_signatures = s\n .fields_as_written()\n .map(|(_, typ, _)| {\n // signature_of_type can handle structs, so this supports nested structs\n // FIXME: Field generics are not handled here!\n signature_of_type(typ)\n })\n .join(quote {,});\n let signature_quote = quote { $struct_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field($from_signature_fn($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\n/// Returns how many storage slots a type needs to reserve for itself. State variables must implement the Storage trait\n/// for slots to be allocated for them.\npub(crate) comptime fn get_storage_size(typ: Type) -> u32 {\n // We create a type variable for the storage size. We can't simply read the value used in the implementation because\n // it may not be a constant (e.g. N + 1). We then bind it to the implementation of the Storage trait.\n let storage_size = std::meta::typ::fresh_type_variable();\n assert(\n typ.implements(quote { crate::state_vars::HasStorageSlot<$storage_size> }\n .as_trait_constraint()),\n f\"Attempted to fetch storage size, but {typ} does not implement the HasStorageSlot trait\",\n );\n\n storage_size.as_constant().unwrap()\n}\n\npub(crate) comptime fn module_has_storage(m: Module) -> bool {\n m.structs().any(|s: TypeDefinition| {\n s.has_named_attribute(\"storage\") | s.has_named_attribute(\"storage_no_init\")\n })\n}\n\npub(crate) comptime fn module_has_initializer(m: Module) -> bool {\n m.functions().any(|f: FunctionDefinition| is_fn_initializer(f))\n}\n\n/// Returns the typed expression of a trait method implementation.\n///\n/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,\n/// as direct inlining would result in missing import warnings in the generated code (specifically,\n/// warnings that the trait implementation is not in scope).\n///\n/// # Note\n/// A copy of this function exists in `noir-protocol-circuits/crates/types/src/meta/mod.nr`. We maintain separate\n/// copies because importing it here from there would cause the `target_trait` to be interpreted in the context\n/// of the protocol circuits types crate, making it impossible to compile code for traits from this crate\n/// (e.g. NoteType).\npub(crate) comptime fn get_trait_impl_method(\n typ: Type,\n target_trait: Quoted,\n target_method: Quoted,\n) -> TypedExpr {\n let trait_constraint = target_trait.as_trait_constraint();\n typ\n .get_trait_impl(trait_constraint)\n .expect(f\"Type does not implement trait\")\n .methods()\n .filter(|m| m.name() == target_method)[0]\n .as_typed_expr()\n}\n\npub comptime fn size_in_fields(typ: Type) -> u32 {\n array_size_in_fields(typ)\n .or_else(|| bool_size_in_fields(typ))\n .or_else(|| constant_size_in_fields(typ))\n .or_else(|| field_size_in_fields(typ))\n .or_else(|| int_size_in_fields(typ))\n .or_else(|| str_size_in_fields(typ))\n .or_else(|| struct_size_in_fields(typ))\n .or_else(|| tuple_size_in_fields(typ))\n .expect(f\"Can't determine size in fields of {typ}\")\n}\n\ncomptime fn array_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_array().and_then(|typ: (Type, Type)| {\n let (typ, element_size) = typ;\n element_size.as_constant().map(|x: u32| x * size_in_fields(typ))\n })\n}\n\ncomptime fn bool_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_bool() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn field_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_field() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn int_size_in_fields(typ: Type) -> Option<u32> {\n if typ.as_integer().is_some() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn constant_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_constant()\n}\n\ncomptime fn str_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_str().map(|typ| size_in_fields(typ))\n}\n\ncomptime fn struct_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_data_type().map(|typ: (TypeDefinition, [Type])| {\n let struct_type = typ.0;\n let generics = typ.1;\n let mut size = 0;\n for field in struct_type.fields(generics) {\n size += size_in_fields(field.1);\n }\n size\n })\n}\n\ncomptime fn tuple_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_tuple().map(|types: [Type]| {\n let mut size = 0;\n for typ in types {\n size += size_in_fields(typ);\n }\n size\n })\n}\n\n/// Generates a quote that implements `Serialize` for a given struct `s`.\n/// If the struct already implements `Serialize`, we return an empty quote.\npub comptime fn derive_serialize_if_not_implemented(s: TypeDefinition) -> Quoted {\n if s.as_type().implements(quote { crate::protocol_types::traits::Serialize }\n .as_trait_constraint()) {\n // We got some serialized length meaning that the struct implements `Serialize`. For this reason we return\n // an empty quote for the implementation.\n quote {}\n } else {\n // We didn't manage to get the serialized length which means the struct doesn't implement `Serialize`\n // so we derive it.\n derive_serialize(s)\n }\n}\n"
|
|
7841
|
+
"source": "use dep::protocol_types::meta::derive_serialize;\nuse std::meta::unquote;\n\npub(crate) comptime fn get_fn_visibility(f: FunctionDefinition) -> Quoted {\n if f.has_named_attribute(\"private\") {\n quote { private }\n } else if f.has_named_attribute(\"public\") {\n quote { public }\n } else {\n panic(f\"Function is neither private nor public\")\n }\n}\n\npub(crate) comptime fn is_fn_private(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"private\")\n}\n\npub(crate) comptime fn is_fn_public(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"public\")\n}\n\npub(crate) comptime fn is_fn_utility(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"utility\")\n}\n\npub(crate) comptime fn is_fn_contract_library_method(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"contract_library_method\")\n}\n\npub(crate) comptime fn is_fn_test(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"test\")\n}\n\npub(crate) comptime fn is_fn_view(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"view\")\n}\n\npub(crate) comptime fn is_fn_internal(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"internal\")\n}\n\npub(crate) comptime fn is_fn_initializer(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"initializer\")\n}\n\npub(crate) comptime fn fn_has_noinitcheck(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"noinitcheck\")\n}\n\npub(crate) comptime fn fn_has_authorize_once(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"authorize_once\")\n}\n\n/// Takes a function body as a collection of expressions, and alters it by prepending and appending quoted values.\npub(crate) comptime fn modify_fn_body(body: [Expr], prepend: Quoted, append: Quoted) -> Expr {\n // We need to quote the body before we can alter its contents, so we fold it by quoting each expression.\n let mut body_quote = body.fold(quote {}, |full_quote: Quoted, expr: Expr| {\n let expr_quote = expr.quoted();\n quote {\n $full_quote\n $expr_quote\n }\n });\n body_quote = quote {\n {\n $prepend\n $body_quote\n $append\n }\n };\n let body_expr = body_quote.as_expr();\n body_expr.expect(f\"Body is not an expression: {body_quote}\")\n}\n\n/// Adds a value to a field array. Structs and values inside arrays are required to implement the Serialize trait.\n///\n/// The function takes the name of the array, the index in the array where the value should be added, the name of the\n/// variable to be added, and the type of the variable. It returns a quoted expression that can be used in a function body.\n///\n/// The returned quoted expression will increment the `index_name` variable by the number of fields added to the array,\n/// which is typically 1 for simple types, but can be more for complex types like structs or arrays.\npub(crate) comptime fn add_to_field_array(\n array_name: Quoted,\n index_name: Quoted,\n name: Quoted,\n typ: Type,\n) -> Quoted {\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { \n $array_name[$index_name] = $name as Field;\n $index_name += 1;\n }\n } else if typ.as_data_type().is_some() {\n // We invoke serialize as a static trait function rather than calling $name.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote { \n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n } else if typ.as_array().is_some() {\n // We invoke serialize as a static trait function rather than calling x.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote {\n for i in 0..$name.len() {\n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name[i]);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n }\n } else if typ.as_str().is_some() {\n quote {\n let $serialized_name = $name.as_bytes();\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i] as Field;\n $index_name += 1;\n }\n }\n } else {\n panic(\n f\"Cannot add to slice: unsupported type {typ} variable {name}\",\n )\n }\n}\n\n/// Adds a value to a hash::ArgsHasher. Structs and values inside arrays are required to implement the Serialize trait.\npub(crate) comptime fn add_to_hasher(hasher_name: Quoted, name: Quoted, typ: Type) -> Quoted {\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { $hasher_name.add($name as Field); }\n } else if typ.as_data_type().is_some() {\n quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name)); }\n } else if typ.as_array().is_some() {\n let (element_type, _) = typ.as_array().unwrap();\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n quote {\n let $serialized_name = $name.map(|x: $element_type | dep::aztec::protocol_types::traits::Serialize::serialize(x));\n for i in 0..$name.len() {\n $hasher_name.add_multiple($serialized_name[i]);\n }\n }\n } else if typ.as_tuple().is_some() {\n let tuple_len = typ.as_tuple().unwrap().len();\n let mut tuple_quotes: [Quoted] = [];\n for i in 0..tuple_len {\n let element_quote = quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name.$i)); };\n tuple_quotes = tuple_quotes.push_back(element_quote);\n }\n tuple_quotes.join(quote {})\n } else if typ.as_str().is_some() {\n quote {\n $hasher_name.add_multiple($name.as_bytes().map(| byte: u8 | byte as Field));\n }\n } else {\n panic(\n f\"Cannot add to hasher: unsupported type {typ} of variable {name}\",\n )\n }\n}\n\ncomptime fn signature_of_type(typ: Type) -> Quoted {\n if typ.is_field() {\n quote {Field}\n } else if typ.as_integer().is_some() {\n let (is_signed, bit_size) = typ.as_integer().unwrap();\n if is_signed {\n f\"i{bit_size}\".quoted_contents()\n } else {\n f\"u{bit_size}\".quoted_contents()\n }\n } else if typ.is_bool() {\n quote {bool}\n } else if typ.as_str().is_some() {\n let str_len_typ = typ.as_str().unwrap();\n let str_len = str_len_typ.as_constant().unwrap();\n f\"str<{str_len}>\".quoted_contents()\n } else if typ.as_array().is_some() {\n let (element_type, array_len) = typ.as_array().unwrap();\n let array_len = if array_len.as_constant().is_some() {\n let const_len = array_len.as_constant().unwrap();\n f\"{const_len}\".quoted_contents()\n } else {\n // If array length is not a constant, chances are it's a numeric generic\n // This will make the signature of a type like Struct<N> be the same regardless\n // of the value of N, but at least this fn will not crash. It is up to the caller\n // to decide whether this is acceptable.\n f\"{array_len}\".quoted_contents()\n };\n\n let element_typ_quote = signature_of_type(element_type);\n f\"[{element_typ_quote};{array_len}]\".quoted_contents()\n } else if typ.as_data_type().is_some() {\n let (s, generics) = typ.as_data_type().unwrap();\n let field_signatures =\n s.fields(generics).map(|(_, typ, _)| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else if typ.as_tuple().is_some() {\n // Note that tuples are handled the same way as structs\n let types = typ.as_tuple().unwrap();\n let field_signatures = types.map(|typ: Type| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else {\n panic(f\"Unsupported type {typ}\")\n }\n}\n\npub trait AsStrQuote {\n fn as_str_quote(self) -> (Self, u32);\n}\n\nimpl AsStrQuote for Quoted {\n // Used to convert an arbitrary quoted type into a quoted string, removing whitespace between tokens\n comptime fn as_str_quote(self) -> (Quoted, u32) {\n let tokens = self.tokens();\n let mut acc: [u8] = &[];\n let mut total_len: u32 = 0;\n for token in tokens {\n let token_as_fmt_str = f\"{token}\";\n let token_as_str = unquote!(quote {$token_as_fmt_str});\n let token_len = unquote!(quote { $token_as_str.as_bytes().len() });\n let token_as_bytes = unquote!(quote { $token_as_str.as_bytes().as_slice() });\n total_len += token_len;\n acc = acc.append(token_as_bytes);\n }\n let result = unquote!(\n quote {\n let signature_as_array: [u8; $total_len] = $acc.as_array();\n signature_as_array.as_str_unchecked()\n },\n );\n (quote { $result }, total_len)\n }\n}\n\npub(crate) comptime fn compute_fn_selector(f: FunctionDefinition) -> Field {\n // The function selector is computed from the function signature, which is made up of the function name and types of\n // parameters, but not including the return type. For example, given:\n //\n // fn foo(a: Field, b: AztecAddress) -> Field\n //\n // The signature will be \"foo(Field,AztecAddress)\".\n let fn_name = f.name();\n let args_signatures = f.parameters().map(|(_, typ)| signature_of_type(typ)).join(quote {,});\n let signature_quote = quote { $fn_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field(protocol_types::abis::function_selector::FunctionSelector::from_signature($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\npub(crate) comptime fn compute_struct_selector(\n s: TypeDefinition,\n from_signature_fn: Quoted,\n) -> Field {\n // The struct selector is computed from the type signature, similar to how one might type\n // the constructor function. For example, given:\n //\n // struct Foo {\n // a: Field,\n // b: AztecAddress,\n // }\n //\n // The signature will be \"Foo(Field,AztecAddress)\".\n let struct_name = s.name();\n let args_signatures = s\n .fields_as_written()\n .map(|(_, typ, _)| {\n // signature_of_type can handle structs, so this supports nested structs\n // FIXME: Field generics are not handled here!\n signature_of_type(typ)\n })\n .join(quote {,});\n let signature_quote = quote { $struct_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field($from_signature_fn($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\n/// Returns how many storage slots a type needs to reserve for itself. State variables must implement the Storage trait\n/// for slots to be allocated for them.\npub(crate) comptime fn get_storage_size(typ: Type) -> u32 {\n // We create a type variable for the storage size. We can't simply read the value used in the implementation because\n // it may not be a constant (e.g. N + 1). We then bind it to the implementation of the Storage trait.\n let storage_size = std::meta::typ::fresh_type_variable();\n assert(\n typ.implements(quote { crate::state_vars::HasStorageSlot<$storage_size> }\n .as_trait_constraint()),\n f\"Attempted to fetch storage size, but {typ} does not implement the HasStorageSlot trait\",\n );\n\n storage_size.as_constant().unwrap()\n}\n\npub(crate) comptime fn module_has_storage(m: Module) -> bool {\n m.structs().any(|s: TypeDefinition| {\n s.has_named_attribute(\"storage\") | s.has_named_attribute(\"storage_no_init\")\n })\n}\n\npub(crate) comptime fn module_has_initializer(m: Module) -> bool {\n m.functions().any(|f: FunctionDefinition| is_fn_initializer(f))\n}\n\n/// Returns the typed expression of a trait method implementation.\n///\n/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,\n/// as direct inlining would result in missing import warnings in the generated code (specifically,\n/// warnings that the trait implementation is not in scope).\n///\n/// # Note\n/// A copy of this function exists in `noir-protocol-circuits/crates/types/src/meta/mod.nr`. We maintain separate\n/// copies because importing it here from there would cause the `target_trait` to be interpreted in the context\n/// of the protocol circuits types crate, making it impossible to compile code for traits from this crate\n/// (e.g. NoteType).\npub(crate) comptime fn get_trait_impl_method(\n typ: Type,\n target_trait: Quoted,\n target_method: Quoted,\n) -> TypedExpr {\n let trait_constraint = target_trait.as_trait_constraint();\n typ\n .get_trait_impl(trait_constraint)\n .expect(f\"Type does not implement trait\")\n .methods()\n .filter(|m| m.name() == target_method)[0]\n .as_typed_expr()\n}\n\npub comptime fn size_in_fields(typ: Type) -> u32 {\n array_size_in_fields(typ)\n .or_else(|| bool_size_in_fields(typ))\n .or_else(|| constant_size_in_fields(typ))\n .or_else(|| field_size_in_fields(typ))\n .or_else(|| int_size_in_fields(typ))\n .or_else(|| str_size_in_fields(typ))\n .or_else(|| struct_size_in_fields(typ))\n .or_else(|| tuple_size_in_fields(typ))\n .expect(f\"Can't determine size in fields of {typ}\")\n}\n\ncomptime fn array_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_array().and_then(|typ: (Type, Type)| {\n let (typ, element_size) = typ;\n element_size.as_constant().map(|x: u32| x * size_in_fields(typ))\n })\n}\n\ncomptime fn bool_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_bool() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn field_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_field() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn int_size_in_fields(typ: Type) -> Option<u32> {\n if typ.as_integer().is_some() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn constant_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_constant()\n}\n\ncomptime fn str_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_str().map(|typ| size_in_fields(typ))\n}\n\ncomptime fn struct_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_data_type().map(|typ: (TypeDefinition, [Type])| {\n let struct_type = typ.0;\n let generics = typ.1;\n let mut size = 0;\n for field in struct_type.fields(generics) {\n size += size_in_fields(field.1);\n }\n size\n })\n}\n\ncomptime fn tuple_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_tuple().map(|types: [Type]| {\n let mut size = 0;\n for typ in types {\n size += size_in_fields(typ);\n }\n size\n })\n}\n\n/// Generates a quote that implements `Serialize` for a given struct `s`.\n/// If the struct already implements `Serialize`, we return an empty quote.\npub comptime fn derive_serialize_if_not_implemented(s: TypeDefinition) -> Quoted {\n if s.as_type().implements(quote { crate::protocol_types::traits::Serialize }\n .as_trait_constraint()) {\n // We got some serialized length meaning that the struct implements `Serialize`. For this reason we return\n // an empty quote for the implementation.\n quote {}\n } else {\n // We didn't manage to get the serialized length which means the struct doesn't implement `Serialize`\n // so we derive it.\n derive_serialize(s)\n }\n}\n"
|
|
7842
7842
|
},
|
|
7843
7843
|
"112": {
|
|
7844
7844
|
"path": "/home/aztec-dev/aztec-packages/noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr",
|