diff --git a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr index 21137cc7e5a..6cd81a277cf 100644 --- a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr @@ -1,6 +1,7 @@ use dep::protocol_types::{ abis::{new_contract_data::NewContractData as ContractLeafPreimage}, - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, grumpkin_point::GrumpkinPoint + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, + grumpkin_point::GrumpkinPoint }; use dep::std::merkle::compute_merkle_root; diff --git a/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr b/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr index 4900f10e18b..05a9b645890 100644 --- a/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr +++ b/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr @@ -1,46 +1,4 @@ use dep::aztec::protocol_types::{utils::field::field_from_bytes, traits::{Serialize, Deserialize}}; -use dep::std; - -// A Fixedsize Compressed String. -// Essentially a special version of Compressed String for practical use. -struct FieldCompressedString{ - value: Field -} - -impl Serialize<1> for FieldCompressedString { - fn serialize(self) -> [Field; 1] { - [self.value] - } -} - -impl Deserialize<1> for FieldCompressedString { - fn deserialize(input: [Field; 1]) -> Self { - Self { value: input[0] } - } -} - -impl FieldCompressedString { - pub fn is_eq(self, other: FieldCompressedString) -> bool { - self.value == other.value - } - - pub fn from_field(input_field: Field) -> Self { - Self { value: input_field } - } - - pub fn from_string(input_string: str<31>) -> Self { - Self { value: field_from_bytes(input_string.as_bytes(), true) } - } - - pub fn to_bytes(self) -> [u8; 31] { - let mut result = [0; 31]; - let bytes = self.value.to_be_bytes(31); - for i in 0..31 { - result[i] = bytes[i]; - } - result - } -} // The general Compressed String. // Compresses M bytes into N fields. diff --git a/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr b/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr new file mode 100644 index 00000000000..cba01277dfd --- /dev/null +++ b/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr @@ -0,0 +1,42 @@ +use dep::aztec::protocol_types::{utils::field::field_from_bytes, traits::{Serialize, Deserialize}}; + +// A Fixedsize Compressed String. +// Essentially a special version of Compressed String for practical use. +struct FieldCompressedString{ + value: Field +} + +impl Serialize<1> for FieldCompressedString { + fn serialize(self) -> [Field; 1] { + [self.value] + } +} + +impl Deserialize<1> for FieldCompressedString { + fn deserialize(input: [Field; 1]) -> Self { + Self { value: input[0] } + } +} + +impl FieldCompressedString { + pub fn is_eq(self, other: FieldCompressedString) -> bool { + self.value == other.value + } + + pub fn from_field(input_field: Field) -> Self { + Self { value: input_field } + } + + pub fn from_string(input_string: str<31>) -> Self { + Self { value: field_from_bytes(input_string.as_bytes(), true) } + } + + pub fn to_bytes(self) -> [u8; 31] { + let mut result = [0; 31]; + let bytes = self.value.to_be_bytes(31); + for i in 0..31 { + result[i] = bytes[i]; + } + result + } +} diff --git a/noir-projects/aztec-nr/compressed-string/src/lib.nr b/noir-projects/aztec-nr/compressed-string/src/lib.nr index b441f622b40..76b5ba5a62b 100644 --- a/noir-projects/aztec-nr/compressed-string/src/lib.nr +++ b/noir-projects/aztec-nr/compressed-string/src/lib.nr @@ -1,4 +1,5 @@ mod compressed_string; +mod field_compressed_string; -use crate::compressed_string::{CompressedString}; -use crate::compressed_string::FieldCompressedString; +use crate::compressed_string::CompressedString; +use crate::field_compressed_string::FieldCompressedString; diff --git a/noir-projects/aztec-nr/easy-private-state/src/easy_private_state.nr b/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr similarity index 100% rename from noir-projects/aztec-nr/easy-private-state/src/easy_private_state.nr rename to noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr diff --git a/noir-projects/aztec-nr/easy-private-state/src/lib.nr b/noir-projects/aztec-nr/easy-private-state/src/lib.nr index 2a29ab85139..ad5150bfbb0 100644 --- a/noir-projects/aztec-nr/easy-private-state/src/lib.nr +++ b/noir-projects/aztec-nr/easy-private-state/src/lib.nr @@ -1 +1,3 @@ -mod easy_private_state; +mod easy_private_uint; + +use crate::easy_private_uint::EasyPrivateUint; diff --git a/noir-projects/aztec-nr/slow-updates-tree/src/leaf.nr b/noir-projects/aztec-nr/slow-updates-tree/src/leaf.nr new file mode 100644 index 00000000000..e5cda208efb --- /dev/null +++ b/noir-projects/aztec-nr/slow-updates-tree/src/leaf.nr @@ -0,0 +1,20 @@ +use dep::aztec::protocol_types::traits::{Serialize, Deserialize}; + +// A leaf in the tree. +struct Leaf { + next_change: Field, + before: Field, + after: Field, +} + +impl Serialize<3> for Leaf { + fn serialize(leaf: Leaf) -> [Field; 3] { + [leaf.next_change, leaf.before, leaf.after] + } +} + +impl Deserialize<3> for Leaf { + fn deserialize(serialized: [Field; 3]) -> Leaf { + Leaf { next_change: serialized[0], before: serialized[1], after: serialized[2] } + } +} diff --git a/noir-projects/aztec-nr/slow-updates-tree/src/lib.nr b/noir-projects/aztec-nr/slow-updates-tree/src/lib.nr index 72a8c1ad19f..b57ed505243 100644 --- a/noir-projects/aztec-nr/slow-updates-tree/src/lib.nr +++ b/noir-projects/aztec-nr/slow-updates-tree/src/lib.nr @@ -1 +1,8 @@ +mod leaf; mod slow_map; +mod slow_update_proof; + +use crate::leaf::Leaf; +use crate::slow_map::SlowMap; +use crate::slow_update_proof::{deserialize_slow_update_proof, SlowUpdateProof}; +use dep::std::merkle::compute_merkle_root; diff --git a/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr b/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr index 065ab009197..aee68bcb36e 100644 --- a/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr +++ b/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr @@ -1,9 +1,14 @@ -use dep::aztec::context::{PrivateContext, PublicContext, Context}; -use dep::aztec::oracle::storage::{storage_read, storage_write}; -use dep::aztec::protocol_types::traits::{Serialize, Deserialize}; +use crate::{ + leaf::Leaf, + slow_update_proof::SlowUpdateProof, +}; +use dep::aztec::{ + context::Context, + oracle::storage::{storage_read, storage_write}, + protocol_types::traits::{Serialize, Deserialize}, +}; use dep::std::hash::pedersen_hash; use dep::std::merkle::compute_merkle_root; -use dep::std::option::Option; // The epoch length is just a random number for now. global EPOCH_LENGTH: u120 = 100; @@ -12,86 +17,6 @@ fn compute_next_change(time: Field) -> Field { ((time as u120 / EPOCH_LENGTH + 1) * EPOCH_LENGTH) as Field } -// A leaf in the tree. -struct Leaf { - next_change: Field, - before: Field, - after: Field, -} - -impl Serialize<3> for Leaf { - fn serialize(leaf: Leaf) -> [Field; 3] { - [leaf.next_change, leaf.before, leaf.after] - } -} - -impl Deserialize<3> for Leaf { - fn deserialize(serialized: [Field; 3]) -> Leaf { - Leaf { next_change: serialized[0], before: serialized[1], after: serialized[2] } - } -} - -// Subset of the MembershipProof that is needed for the slow update. -struct SlowUpdateInner { - value: Field, // Value only really used for the private flow though :thinking: - sibling_path: [Field; N], -} - -// docs:start:slow_update_proof -// The slow update proof. Containing two merkle paths -// One for the before and one for the after trees. -// M = 2 * N + 4 -struct SlowUpdateProof { - index: Field, - new_value: Field, - before: SlowUpdateInner, - after: SlowUpdateInner, -} -// docs:end:slow_update_proof - -pub fn deserialize_slow_update_proof(serialized: [Field; M]) -> SlowUpdateProof { - SlowUpdateProof::deserialize(serialized) -} - -impl SlowUpdateProof { - pub fn serialize(self: Self) -> [Field; M] { - let mut serialized = [0; M]; - serialized[0] = self.index; - serialized[1] = self.new_value; - serialized[2] = self.before.value; - serialized[3 + N] = self.after.value; - - for i in 0..N { - serialized[3 + i] = self.before.sibling_path[i]; - serialized[4 + N + i] = self.after.sibling_path[i]; - } - serialized - } - - pub fn deserialize(serialized: [Field; M]) -> Self { - let mut before_sibling_path = [0; N]; - let mut after_sibling_path = [0; N]; - - for i in 0..N { - before_sibling_path[i] = serialized[3 + i]; - after_sibling_path[i] = serialized[4 + N + i]; - } - - Self { - index: serialized[0], - new_value: serialized[1], - before: SlowUpdateInner { - value: serialized[2], - sibling_path: before_sibling_path, - }, - after: SlowUpdateInner { - value: serialized[3 + N], - sibling_path: after_sibling_path, - }, - } - } -} - // The simple slow map which stores a sparse tree struct SlowMap { context: Context, diff --git a/noir-projects/aztec-nr/slow-updates-tree/src/slow_update_proof.nr b/noir-projects/aztec-nr/slow-updates-tree/src/slow_update_proof.nr new file mode 100644 index 00000000000..6f1b1d79a0f --- /dev/null +++ b/noir-projects/aztec-nr/slow-updates-tree/src/slow_update_proof.nr @@ -0,0 +1,52 @@ +// Subset of the MembershipProof that is needed for the slow update. +struct SlowUpdateInner { + value: Field, // Value only really used for the private flow though :thinking: + sibling_path: [Field; N], +} + +// The slow update proof. Containing two merkle paths +// One for the before and one for the after trees. +// M = 2 * N + 4 +struct SlowUpdateProof { + index: Field, + new_value: Field, + before: SlowUpdateInner, + after: SlowUpdateInner, +} + +pub fn deserialize_slow_update_proof(serialized: [Field; M]) -> SlowUpdateProof { + SlowUpdateProof::deserialize(serialized) +} + +impl SlowUpdateProof { + pub fn serialize(self: Self) -> [Field; M] { + let mut serialized = [0; M]; + serialized[0] = self.index; + serialized[1] = self.new_value; + serialized[2] = self.before.value; + serialized[3 + N] = self.after.value; + + for i in 0..N { + serialized[3 + i] = self.before.sibling_path[i]; + serialized[4 + N + i] = self.after.sibling_path[i]; + } + serialized + } + + pub fn deserialize(serialized: [Field; M]) -> Self { + let mut before_sibling_path = [0; N]; + let mut after_sibling_path = [0; N]; + + for i in 0..N { + before_sibling_path[i] = serialized[3 + i]; + after_sibling_path[i] = serialized[4 + N + i]; + } + + Self { + index: serialized[0], + new_value: serialized[1], + before: SlowUpdateInner { value: serialized[2], sibling_path: before_sibling_path }, + after: SlowUpdateInner { value: serialized[3 + N], sibling_path: after_sibling_path } + } + } +} diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/class_registered.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/class_registered.nr index 7fc4812ab61..9cf549d6c57 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/class_registered.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/class_registered.nr @@ -1,5 +1,5 @@ use dep::aztec::protocol_types::{ - contract_class::ContractClassId, + contract_class_id::ContractClassId, constants::{MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE}, traits::{Serialize} }; diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr index b68f15408a3..99092cf70e3 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr @@ -1,6 +1,6 @@ use dep::aztec::protocol_types; use dep::aztec::protocol_types::{ - contract_class::ContractClassId, abis::function_selector::FunctionSelector, + contract_class_id::ContractClassId, abis::function_selector::FunctionSelector, constants::{ FUNCTION_TREE_HEIGHT, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr index 39e2f79a5fb..aeaeaeaf627 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr @@ -1,6 +1,6 @@ use dep::aztec::protocol_types; use dep::aztec::protocol_types::{ - contract_class::ContractClassId, abis::function_selector::FunctionSelector, + contract_class_id::ContractClassId, abis::function_selector::FunctionSelector, constants::{ ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS, REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr index 1d0aed0116b..d54616558f1 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr @@ -3,7 +3,7 @@ mod events; contract ContractClassRegisterer { use dep::std::option::Option; use dep::aztec::protocol_types::{ - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, constants::{ ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, FUNCTION_TREE_HEIGHT, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/events/instance_deployed.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/events/instance_deployed.nr index b2f82d40d1e..1a01b992246 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/events/instance_deployed.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/events/instance_deployed.nr @@ -1,5 +1,5 @@ use dep::aztec::protocol_types::{ - contract_class::ContractClassId, + contract_class_id::ContractClassId, address::{AztecAddress, EthAddress, PublicKeysHash, PartialAddress}, constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, traits::{Serialize} }; diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr index 505de63b129..aceccc3ab11 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr @@ -4,8 +4,8 @@ contract ContractInstanceDeployer { use dep::std::option::Option; use dep::aztec::protocol_types::{ address::{AztecAddress, EthAddress, PublicKeysHash, PartialAddress}, - contract_class::ContractClassId, constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, - traits::{Serialize} + contract_class_id::ContractClassId, + constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, traits::{Serialize} }; use dep::aztec::log::{emit_unencrypted_log, emit_unencrypted_log_from_private}; diff --git a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr index a61f276d070..6cfad8ed21c 100644 --- a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr @@ -16,7 +16,7 @@ contract Counter { VALUE_NOTE_LEN, }, }; - use dep::easy_private_state::easy_private_state::EasyPrivateUint; + use dep::easy_private_state::EasyPrivateUint; // docs:end:imports // docs:start:storage_struct diff --git a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr index 336bae7e326..ed5091f485a 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr @@ -1,9 +1,7 @@ // docs:start:easy_private_token_contract contract EasyPrivateToken { use dep::aztec::protocol_types::address::AztecAddress; - use dep::std::option::Option; use dep::aztec::{ - context::{PrivateContext, PublicContext, Context}, note::{ note_header::NoteHeader, utils as note_utils, @@ -14,7 +12,7 @@ contract EasyPrivateToken { balance_utils, value_note::ValueNote, }; - use dep::easy_private_state::easy_private_state::EasyPrivateUint; + use dep::easy_private_state::EasyPrivateUint; struct Storage { balances: Map, diff --git a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr index eaaf052f99d..e737a47313c 100644 --- a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr @@ -2,7 +2,7 @@ contract InclusionProofs { use dep::aztec::protocol_types::{ abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}, - grumpkin_point::GrumpkinPoint, contract_class::ContractClassId + grumpkin_point::GrumpkinPoint, contract_class_id::ContractClassId }; use dep::aztec::{ state_vars::{map::Map, set::Set, public_state::PublicState}, context::Context, diff --git a/noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr b/noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr index 7950c230be8..5ae8795d957 100644 --- a/noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr @@ -15,7 +15,7 @@ contract SlowTree { state_vars::{map::Map, public_state::PublicState, set::Set}, protocol_types::type_serialization::FIELD_SERIALIZED_LEN }; - use dep::slow_updates_tree::slow_map::{SlowMap, Leaf, SlowUpdateProof, compute_merkle_root, deserialize_slow_update_proof}; + use dep::slow_updates_tree::{SlowMap, Leaf, SlowUpdateProof, compute_merkle_root, deserialize_slow_update_proof}; // docs:start:import_pop_capsule use crate::capsule::pop_capsule; diff --git a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr index 90a8c50c715..ba8476925e9 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr @@ -1,8 +1,8 @@ use dep::std; use dep::types::{ abis::{ - call_request::CallRequest, combined_accumulated_data::CombinedAccumulatedData, - function_data::FunctionData, kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputsBuilder, + call_request::CallRequest, accumulated_data::CombinedAccumulatedData, function_data::FunctionData, + kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputsBuilder, membership_witness::ReadRequestMembershipWitness, new_contract_data::NewContractData, nullifier_key_validation_request::NullifierKeyValidationRequestContext, private_circuit_public_inputs::PrivateCircuitPublicInputs, @@ -11,7 +11,7 @@ use dep::types::{ side_effect::{SideEffect, SideEffectLinkedToNoteHash} }, address::{AztecAddress, EthAddress, PartialAddress, compute_initialization_hash}, - contract_class::ContractClassId, contrakt::contract_deployment_data::ContractDeploymentData, + contract_class_id::ContractClassId, contrakt::contract_deployment_data::ContractDeploymentData, constants::{ MAX_NEW_NULLIFIERS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_COMMITMENTS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_READ_REQUESTS_PER_CALL, diff --git a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr index 837d6ee54fd..61828e9f813 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr @@ -1,7 +1,7 @@ use dep::types::{ abis::{ call_request::CallRequest, public_call_stack_item::PublicCallStackItem, - combined_accumulated_data::{CombinedAccumulatedData, CombinedAccumulatedDataBuilder}, + accumulated_data::{CombinedAccumulatedData, CombinedAccumulatedDataBuilder}, kernel_circuit_public_inputs::PublicKernelCircuitPublicInputsBuilder, new_contract_data::NewContractData, kernel_data::{PrivateKernelTailData, PublicKernelData}, public_call_data::PublicCallData, public_circuit_public_inputs::PublicCircuitPublicInputs, diff --git a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 47a1b941a94..9a656d26859 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -65,7 +65,7 @@ mod tests { public_data_update_request::PublicDataUpdateRequest, side_effect::{SideEffect, SideEffectLinkedToNoteHash} }, - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, hash::{compute_l2_to_l1_hash, compute_logs_hash, silo_commitment, silo_nullifier}, messaging::l2_to_l1_message::L2ToL1Message, tests::{kernel_data_builder::PreviousKernelDataBuilder, public_call_data_builder::PublicCallDataBuilder}, diff --git a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_setup.nr index 7dfedb0d237..d169e044db8 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -81,7 +81,7 @@ mod tests { new_contract_data::NewContractData, public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, public_call_data::PublicCallData }, - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, contrakt::storage_read::StorageRead, hash::compute_logs_hash, tests::{kernel_data_builder::PreviousKernelDataBuilder, public_call_data_builder::PublicCallDataBuilder}, utils::{arrays::{array_eq, array_length}} diff --git a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_teardown.nr index 56fd70fcf30..637f29c4771 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -69,7 +69,7 @@ mod tests { new_contract_data::NewContractData, public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest }, - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, contrakt::storage_read::StorageRead, hash::compute_logs_hash, tests::{kernel_data_builder::PreviousKernelDataBuilder, public_call_data_builder::PublicCallDataBuilder}, utils::{arrays::{array_eq, array_length}} diff --git a/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index 28cd26f8b02..d6f86134c40 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -15,8 +15,7 @@ use dep::types::{ }, nullifier_leaf_preimage::NullifierLeafPreimage, public_data_update_request::PublicDataUpdateRequest, public_data_read::PublicDataRead, kernel_data::PublicKernelData, - side_effect::{SideEffect, SideEffectLinkedToNoteHash}, - combined_accumulated_data::CombinedAccumulatedData + side_effect::{SideEffect, SideEffectLinkedToNoteHash}, accumulated_data::CombinedAccumulatedData }, constants::{ NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, @@ -569,7 +568,7 @@ mod tests { new_contract_data::NewContractData, nullifier_leaf_preimage::NullifierLeafPreimage, public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, kernel_data::PublicKernelData, side_effect::SideEffect, - combined_accumulated_data::CombinedAccumulatedData + accumulated_data::CombinedAccumulatedData }, address::{AztecAddress, EthAddress}, constants::{ @@ -581,7 +580,7 @@ mod tests { PUBLIC_DATA_TREE_HEIGHT, PUBLIC_DATA_SUBTREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, NUM_FIELDS_PER_SHA256 }, - contract_class::ContractClassId, partial_state_reference::PartialStateReference, + contract_class_id::ContractClassId, partial_state_reference::PartialStateReference, public_data_tree_leaf::PublicDataTreeLeaf, public_data_tree_leaf_preimage::PublicDataTreeLeafPreimage, tests::kernel_data_builder::PreviousKernelDataBuilder, diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis.nr index b1c37eb647e..e422dd6436d 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis.nr @@ -19,7 +19,7 @@ mod nullifier_key_validation_request; mod public_data_read; mod public_data_update_request; -mod combined_accumulated_data; +mod accumulated_data; mod private_kernel; mod kernel_circuit_public_inputs; @@ -29,6 +29,7 @@ mod call_request; mod private_call_stack_item; mod public_call_stack_item; mod call_context; +mod caller_context; mod public_call_data; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data.nr new file mode 100644 index 00000000000..fc606fc5abd --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data.nr @@ -0,0 +1,19 @@ +mod accumulated_non_revertible_data_builder; +mod accumulated_revertible_data_builder; +mod combined_accumulated_data; +mod combined_accumulated_data_builder; +mod private_accumulated_non_revertible_data; +mod private_accumulated_revertible_data; +mod public_accumulated_non_revertible_data; +mod public_accumulated_revertible_data; + +use crate::abis::accumulated_data::{ + combined_accumulated_data::CombinedAccumulatedData, + private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, + private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, + combined_accumulated_data_builder::CombinedAccumulatedDataBuilder, + public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData, + public_accumulated_revertible_data::PublicAccumulatedRevertibleData, + accumulated_non_revertible_data_builder::AccumulatedNonRevertibleDataBuilder, + accumulated_revertible_data_builder::AccumulatedRevertibleDataBuilder +}; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr new file mode 100644 index 00000000000..372a3f77eb6 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr @@ -0,0 +1,43 @@ +use crate::{ + abis::{ + accumulated_data::{ + private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, + public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData +}, + call_request::CallRequest, public_data_read::PublicDataRead, + public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX +}; + +struct AccumulatedNonRevertibleDataBuilder { + new_commitments: BoundedVec, + new_nullifiers: BoundedVec, + public_call_stack: BoundedVec, + public_data_update_requests: BoundedVec, + public_data_reads: BoundedVec, +} + +impl AccumulatedNonRevertibleDataBuilder { + pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData { + PrivateAccumulatedNonRevertibleData { + new_commitments: self.new_commitments.storage, + new_nullifiers: self.new_nullifiers.storage, + public_call_stack: self.public_call_stack.storage + } + } + pub fn to_public(self) -> PublicAccumulatedNonRevertibleData { + PublicAccumulatedNonRevertibleData { + new_commitments: self.new_commitments.storage, + new_nullifiers: self.new_nullifiers.storage, + public_call_stack: self.public_call_stack.storage, + public_data_update_requests: self.public_data_update_requests.storage, + public_data_reads: self.public_data_reads.storage + } + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr new file mode 100644 index 00000000000..8ee73738459 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr @@ -0,0 +1,80 @@ +use crate::{ + abis::{ + accumulated_data::{ + private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, + public_accumulated_revertible_data::PublicAccumulatedRevertibleData +}, + call_request::CallRequest, new_contract_data::NewContractData, + nullifier_key_validation_request::NullifierKeyValidationRequestContext, + public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, + NUM_FIELDS_PER_SHA256, MAX_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, + MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX +}; + +struct AccumulatedRevertibleDataBuilder { + read_requests: BoundedVec, + nullifier_key_validation_requests: BoundedVec, + + new_commitments: BoundedVec, + new_nullifiers: BoundedVec, + + private_call_stack: BoundedVec, + public_call_stack: BoundedVec, + new_l2_to_l1_msgs: BoundedVec, + + encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + + // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the + // variable-length data. + encrypted_log_preimages_length: Field, + unencrypted_log_preimages_length: Field, + + new_contracts: BoundedVec, + + public_data_update_requests: BoundedVec, + public_data_reads: BoundedVec, +} + +impl AccumulatedRevertibleDataBuilder { + pub fn to_private(self) -> PrivateAccumulatedRevertibleData { + PrivateAccumulatedRevertibleData { + new_commitments: self.new_commitments.storage, + new_nullifiers: self.new_nullifiers.storage, + private_call_stack: self.private_call_stack.storage, + public_call_stack: self.public_call_stack.storage, + new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, + encrypted_logs_hash: self.encrypted_logs_hash, + unencrypted_logs_hash: self.unencrypted_logs_hash, + encrypted_log_preimages_length: self.encrypted_log_preimages_length, + unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, + new_contracts: self.new_contracts.storage + } + } + + pub fn to_public(self) -> PublicAccumulatedRevertibleData { + PublicAccumulatedRevertibleData { + read_requests: self.read_requests.storage, + new_commitments: self.new_commitments.storage, + nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + new_nullifiers: self.new_nullifiers.storage, + private_call_stack: self.private_call_stack.storage, + public_call_stack: self.public_call_stack.storage, + new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, + encrypted_logs_hash: self.encrypted_logs_hash, + unencrypted_logs_hash: self.unencrypted_logs_hash, + encrypted_log_preimages_length: self.encrypted_log_preimages_length, + unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, + new_contracts: self.new_contracts.storage, + public_data_update_requests: self.public_data_update_requests.storage, + public_data_reads: self.public_data_reads.storage + } + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr new file mode 100644 index 00000000000..330e003ceb9 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -0,0 +1,176 @@ +use crate::{ + abis::{ + accumulated_data::{ + public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData, + public_accumulated_revertible_data::PublicAccumulatedRevertibleData +}, + call_request::CallRequest, caller_context::CallerContext, new_contract_data::NewContractData, + nullifier_key_validation_request::NullifierKeyValidationRequestContext, + public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, + MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX, + MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX +}; + +use dep::std::unsafe; +use crate::traits::is_empty; + +use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; + +struct CombinedAccumulatedData { + read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], + nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + + new_commitments: [SideEffect; MAX_NEW_COMMITMENTS_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], + + private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + + encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + + // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the + // variable-length data. + encrypted_log_preimages_length: Field, + unencrypted_log_preimages_length: Field, + + new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], + + public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + + public_data_reads: [PublicDataRead; MAX_PUBLIC_DATA_READS_PER_TX], +} + +impl CombinedAccumulatedData { + pub fn needs_app_logic(self) -> bool { + // if we have any enqueued revertible public calls, we need to run the public app logic circuit. + !self.public_call_stack[0].is_empty() + } + + pub fn recombine( + non_revertible: PublicAccumulatedNonRevertibleData, + revertible: PublicAccumulatedRevertibleData + ) -> CombinedAccumulatedData { + CombinedAccumulatedData { + read_requests: revertible.read_requests, + nullifier_key_validation_requests: revertible.nullifier_key_validation_requests, + new_commitments: array_concat(non_revertible.new_commitments, revertible.new_commitments), + new_nullifiers: array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers), + private_call_stack: revertible.private_call_stack, + public_call_stack: array_concat( + non_revertible.public_call_stack, + revertible.public_call_stack + ), + new_l2_to_l1_msgs: revertible.new_l2_to_l1_msgs, + encrypted_logs_hash: revertible.encrypted_logs_hash, + unencrypted_logs_hash: revertible.unencrypted_logs_hash, + encrypted_log_preimages_length: revertible.encrypted_log_preimages_length, + unencrypted_log_preimages_length: revertible.unencrypted_log_preimages_length, + new_contracts: revertible.new_contracts, + public_data_update_requests: array_concat( + non_revertible.public_data_update_requests, + revertible.public_data_update_requests + ), + public_data_reads: array_concat( + non_revertible.public_data_reads, + revertible.public_data_reads + ) + } + } +} + +mod tests { + use crate::abis::{ + accumulated_data::combined_accumulated_data_builder::CombinedAccumulatedDataBuilder, + call_request::CallRequest, caller_context::CallerContext, new_contract_data::NewContractData, + nullifier_key_validation_request::NullifierKeyValidationRequestContext, + public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} + }; + use crate::address::AztecAddress; + use crate::utils::arrays::array_eq; + use dep::std::unsafe; + + #[test] + unconstrained fn splits_revertible_and_non_revertible() { + let mut builder: CombinedAccumulatedDataBuilder = unsafe::zeroed(); + + let non_revertible_commitments = [ + SideEffect { value: 1, counter: 1 }, + SideEffect { value: 2, counter: 3 } + ]; + + let non_revertible_nullifiers = [ + SideEffectLinkedToNoteHash { value: 10, note_hash: 1, counter: 2 }, + SideEffectLinkedToNoteHash { value: 20, note_hash: 2, counter: 4 } + ]; + + let non_revertible_public_stack = [ + CallRequest { + hash: 1, + caller_contract_address: AztecAddress::from_field(1), + caller_context: CallerContext::empty(), + start_side_effect_counter: 5, + end_side_effect_counter: 0 + }, + CallRequest { + hash: 2, + caller_contract_address: AztecAddress::from_field(1), + caller_context: CallerContext::empty(), + start_side_effect_counter: 6, + end_side_effect_counter: 0 + } + ]; + + let revertible_commitments = [ + SideEffect { value: 3, counter: 7 }, + SideEffect { value: 4, counter: 10 } + ]; + + let revertible_nullifiers = [ + SideEffectLinkedToNoteHash { value: 30, note_hash: 3, counter: 8 }, + SideEffectLinkedToNoteHash { value: 40, note_hash: 4, counter: 11 } + ]; + + let revertible_public_call_stack = [ + CallRequest { + hash: 3, + caller_contract_address: AztecAddress::from_field(3), + caller_context: CallerContext::empty(), + start_side_effect_counter: 9, + end_side_effect_counter: 0 + } + ]; + + builder.new_commitments.extend_from_array(non_revertible_commitments); + builder.new_commitments.extend_from_array(revertible_commitments); + + builder.new_nullifiers.extend_from_array(non_revertible_nullifiers); + builder.new_nullifiers.extend_from_array(revertible_nullifiers); + + builder.public_call_stack.extend_from_array(non_revertible_public_stack); + builder.public_call_stack.extend_from_array(revertible_public_call_stack); + + let (non_revertible, revertible) = builder.split(7); + + assert(array_eq(non_revertible.new_commitments, non_revertible_commitments)); + assert(array_eq(non_revertible.new_nullifiers, non_revertible_nullifiers)); + assert(array_eq(non_revertible.public_call_stack, non_revertible_public_stack)); + + assert(array_eq(revertible.new_commitments, revertible_commitments)); + assert(array_eq(revertible.new_nullifiers, revertible_nullifiers)); + assert(array_eq(revertible.public_call_stack, revertible_public_call_stack)); + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr new file mode 100644 index 00000000000..69fc1ccffba --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr @@ -0,0 +1,203 @@ +use crate::{ + abis::{ + accumulated_data::{ + accumulated_non_revertible_data_builder::AccumulatedNonRevertibleDataBuilder, + accumulated_revertible_data_builder::AccumulatedRevertibleDataBuilder, + combined_accumulated_data::CombinedAccumulatedData, + private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, + private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, + public_accumulated_revertible_data::PublicAccumulatedRevertibleData, + public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData +}, + call_request::CallRequest, new_contract_data::NewContractData, + nullifier_key_validation_request::NullifierKeyValidationRequestContext, + public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, + MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX, + MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX +}; + +use dep::std::unsafe; +use crate::traits::is_empty; + +use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; + +struct CombinedAccumulatedDataBuilder { + read_requests: BoundedVec, + nullifier_key_validation_requests: BoundedVec, + + new_commitments: BoundedVec, + new_nullifiers: BoundedVec, + + private_call_stack: BoundedVec, + public_call_stack: BoundedVec, + new_l2_to_l1_msgs: BoundedVec, + + encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + + // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the + // variable-length data. + encrypted_log_preimages_length: Field, + unencrypted_log_preimages_length: Field, + + new_contracts: BoundedVec, + + public_data_update_requests: BoundedVec, + + public_data_reads: BoundedVec, +} + +impl CombinedAccumulatedDataBuilder { + pub fn recombine( + non_revertible: PublicAccumulatedNonRevertibleData, + revertible: PublicAccumulatedRevertibleData + ) -> CombinedAccumulatedDataBuilder { + CombinedAccumulatedDataBuilder { + read_requests: array_to_bounded_vec(revertible.read_requests), + nullifier_key_validation_requests: array_to_bounded_vec(revertible.nullifier_key_validation_requests), + new_commitments: array_to_bounded_vec(array_concat(non_revertible.new_commitments, revertible.new_commitments)), + new_nullifiers: array_to_bounded_vec(array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers)), + private_call_stack: array_to_bounded_vec(revertible.private_call_stack), + public_call_stack: array_to_bounded_vec( + array_concat( + non_revertible.public_call_stack, + revertible.public_call_stack + ) + ), + new_l2_to_l1_msgs: array_to_bounded_vec(revertible.new_l2_to_l1_msgs), + encrypted_logs_hash: revertible.encrypted_logs_hash, + unencrypted_logs_hash: revertible.unencrypted_logs_hash, + encrypted_log_preimages_length: revertible.encrypted_log_preimages_length, + unencrypted_log_preimages_length: revertible.unencrypted_log_preimages_length, + new_contracts: array_to_bounded_vec(revertible.new_contracts), + public_data_update_requests: array_to_bounded_vec( + array_concat( + non_revertible.public_data_update_requests, + revertible.public_data_update_requests + ) + ), + public_data_reads: array_to_bounded_vec( + array_concat( + non_revertible.public_data_reads, + revertible.public_data_reads + ) + ) + } + } + + pub fn finish(self) -> CombinedAccumulatedData { + CombinedAccumulatedData { + read_requests: self.read_requests.storage, + nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + new_commitments: self.new_commitments.storage, + new_nullifiers: self.new_nullifiers.storage, + private_call_stack: self.private_call_stack.storage, + public_call_stack: self.public_call_stack.storage, + new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, + encrypted_logs_hash: self.encrypted_logs_hash, + unencrypted_logs_hash: self.unencrypted_logs_hash, + encrypted_log_preimages_length: self.encrypted_log_preimages_length, + unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, + new_contracts: self.new_contracts.storage, + public_data_update_requests: self.public_data_update_requests.storage, + public_data_reads: self.public_data_reads.storage + } + } + + pub fn to_private_accumulated_revertible_data(self) -> PrivateAccumulatedRevertibleData { + PrivateAccumulatedRevertibleData { + new_commitments: array_cp(self.new_commitments.storage), + new_nullifiers: array_cp(self.new_nullifiers.storage), + private_call_stack: self.private_call_stack.storage, + public_call_stack: array_cp(self.public_call_stack.storage), + new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, + encrypted_logs_hash: self.encrypted_logs_hash, + unencrypted_logs_hash: self.unencrypted_logs_hash, + encrypted_log_preimages_length: self.encrypted_log_preimages_length, + unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, + new_contracts: self.new_contracts.storage + } + } + + pub fn to_public_accumulated_revertible_data(self) -> PublicAccumulatedRevertibleData { + PublicAccumulatedRevertibleData { + read_requests: self.read_requests.storage, + nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + new_commitments: array_cp(self.new_commitments.storage), + new_nullifiers: array_cp(self.new_nullifiers.storage), + private_call_stack: self.private_call_stack.storage, + public_call_stack: array_cp(self.public_call_stack.storage), + new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, + encrypted_logs_hash: self.encrypted_logs_hash, + unencrypted_logs_hash: self.unencrypted_logs_hash, + encrypted_log_preimages_length: self.encrypted_log_preimages_length, + unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, + new_contracts: self.new_contracts.storage, + public_data_update_requests: array_cp(self.public_data_update_requests.storage), + public_data_reads: array_cp(self.public_data_reads.storage) + } + } + + pub fn split( + self, + min_revertible_side_effect_counter: u32 + ) -> (PrivateAccumulatedNonRevertibleData, PrivateAccumulatedRevertibleData) { + let mut non_revertible_builder: AccumulatedNonRevertibleDataBuilder = unsafe::zeroed(); + let mut revertible_builder: AccumulatedRevertibleDataBuilder = unsafe::zeroed(); + + for i in 0..MAX_NEW_COMMITMENTS_PER_TX { + let commitment = self.new_commitments.storage[i]; + // TODO(fees) we shouldn't need to check is_empty here, + // but we do because new_commitments is bounded to MAX_REVERTIBLE_COMMITMENTS_PER_TX + if !is_empty(commitment) { + if commitment.counter < min_revertible_side_effect_counter { + non_revertible_builder.new_commitments.push(commitment); + } else { + revertible_builder.new_commitments.push(commitment); + } + } + } + for i in 0..MAX_NEW_NULLIFIERS_PER_TX { + let nullifier = self.new_nullifiers.storage[i]; + if !is_empty(nullifier) { + if nullifier.counter < min_revertible_side_effect_counter { + non_revertible_builder.new_nullifiers.push(nullifier); + } else { + revertible_builder.new_nullifiers.push(nullifier); + } + } + } + + for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { + let call_stack_item = self.public_call_stack.storage[i]; + if !is_empty(call_stack_item) { + if call_stack_item.start_side_effect_counter < min_revertible_side_effect_counter { + non_revertible_builder.public_call_stack.push(call_stack_item); + } else { + revertible_builder.public_call_stack.push(call_stack_item); + } + } + } + + revertible_builder.private_call_stack = self.private_call_stack; + revertible_builder.new_l2_to_l1_msgs = self.new_l2_to_l1_msgs; + revertible_builder.encrypted_logs_hash = self.encrypted_logs_hash; + revertible_builder.unencrypted_logs_hash = self.unencrypted_logs_hash; + revertible_builder.encrypted_log_preimages_length = self.encrypted_log_preimages_length; + revertible_builder.unencrypted_log_preimages_length= self.unencrypted_log_preimages_length; + revertible_builder.new_contracts = self.new_contracts; + + (non_revertible_builder.to_private(), revertible_builder.to_private()) + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr new file mode 100644 index 00000000000..8b61a1030f2 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr @@ -0,0 +1,26 @@ +use crate::{abis::{call_request::CallRequest, side_effect::{SideEffect, SideEffectLinkedToNoteHash}}}; +use crate::constants::{ + MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX +}; + +struct PrivateAccumulatedNonRevertibleData { + new_commitments: [SideEffect; MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], + public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], +} + +impl PrivateAccumulatedNonRevertibleData { + pub fn needs_setup(self) -> bool { + // By definition, the final non-revertible enqueued call is for teardown. + // since this is a stack, the teardown call would be the 0th element. + // So if we have more than one element, we need setup. + !self.public_call_stack[1].is_empty() + } + + pub fn needs_teardown(self) -> bool { + // By definition, the final non-revertible enqueued call is for teardown. + // since this is a stack, the teardown call would be the 0th element. + !self.public_call_stack[0].is_empty() + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr new file mode 100644 index 00000000000..739121715fb --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr @@ -0,0 +1,37 @@ +use crate::{ + abis::{ + call_request::CallRequest, new_contract_data::NewContractData, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, NUM_FIELDS_PER_SHA256, MAX_NEW_CONTRACTS_PER_TX +}; + +struct PrivateAccumulatedRevertibleData { + new_commitments: [SideEffect; MAX_REVERTIBLE_COMMITMENTS_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], + + private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], + new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + + encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + + // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the + // variable-length data. + encrypted_log_preimages_length: Field, + unencrypted_log_preimages_length: Field, + + new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], +} + +impl PrivateAccumulatedRevertibleData { + pub fn needs_app_logic(self) -> bool { + // if we have any enqueued revertible public calls, we need to run the public app logic circuit. + !self.public_call_stack[0].is_empty() + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr new file mode 100644 index 00000000000..bc0f8c5b98c --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr @@ -0,0 +1,40 @@ +use crate::{ + abis::{ + call_request::CallRequest, public_data_read::PublicDataRead, + public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, + MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX +}; + +use dep::std::unsafe; +use crate::traits::is_empty; + +use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; + +struct PublicAccumulatedNonRevertibleData { + new_commitments: [SideEffect; MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], + public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], + public_data_update_requests: [PublicDataUpdateRequest; MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_data_reads: [PublicDataRead; MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX], +} + +impl PublicAccumulatedNonRevertibleData { + pub fn needs_setup(self) -> bool { + // By definition, the final non-revertible enqueued call is for teardown. + // since this is a stack, the teardown call would be the 0th element. + // So if we have more than one element, we need setup. + !self.public_call_stack[1].is_empty() + } + + pub fn needs_teardown(self) -> bool { + // By definition, the final non-revertible enqueued call is for teardown. + // since this is a stack, the teardown call would be the 0th element. + !self.public_call_stack[0].is_empty() + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr new file mode 100644 index 00000000000..44b803e38b5 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr @@ -0,0 +1,47 @@ +use crate::{ + abis::{ + call_request::CallRequest, new_contract_data::NewContractData, + nullifier_key_validation_request::NullifierKeyValidationRequestContext, + public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, + side_effect::{SideEffect, SideEffectLinkedToNoteHash} +} +}; +use crate::constants::{ + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, NUM_FIELDS_PER_SHA256, MAX_NEW_CONTRACTS_PER_TX, + MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX +}; + +struct PublicAccumulatedRevertibleData { + read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], + nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + + new_commitments: [SideEffect; MAX_REVERTIBLE_COMMITMENTS_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], + + private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], + new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + + encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], + + // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the + // variable-length data. + encrypted_log_preimages_length: Field, + unencrypted_log_preimages_length: Field, + + new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], + + public_data_update_requests: [PublicDataUpdateRequest; MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_data_reads: [PublicDataRead; MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX], +} + +impl PublicAccumulatedRevertibleData { + pub fn needs_app_logic(self) -> bool { + // if we have any enqueued revertible public calls, we need to run the public app logic circuit. + !self.public_call_stack[0].is_empty() + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr index 9d6f71fa5dd..8eca6227d7c 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/call_request.nr @@ -1,33 +1,7 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; use crate::traits::Empty; - -struct CallerContext { - msg_sender: AztecAddress, - storage_contract_address: AztecAddress, -} - -impl Eq for CallerContext { - fn eq(self, caller_context: CallerContext) -> bool { - caller_context.msg_sender.eq(self.msg_sender) - & caller_context.storage_contract_address.eq(self.storage_contract_address) - } -} - -impl Empty for CallerContext { - fn empty() -> Self { - CallerContext { - msg_sender: AztecAddress::zero(), - storage_contract_address: AztecAddress::zero(), - } - } -} - -impl CallerContext { - pub fn is_empty(self) -> bool { - self.msg_sender.is_zero() & self.storage_contract_address.is_zero() - } -} +use crate::abis::caller_context::CallerContext; struct CallRequest { hash: Field, diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/caller_context.nr new file mode 100644 index 00000000000..829429e4e9e --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/caller_context.nr @@ -0,0 +1,30 @@ +use crate::address::AztecAddress; +use dep::std::cmp::Eq; +use crate::traits::Empty; + +struct CallerContext { + msg_sender: AztecAddress, + storage_contract_address: AztecAddress, +} + +impl Eq for CallerContext { + fn eq(self, caller_context: CallerContext) -> bool { + caller_context.msg_sender.eq(self.msg_sender) + & caller_context.storage_contract_address.eq(self.storage_contract_address) + } +} + +impl Empty for CallerContext { + fn empty() -> Self { + CallerContext { + msg_sender: AztecAddress::zero(), + storage_contract_address: AztecAddress::zero(), + } + } +} + +impl CallerContext { + pub fn is_empty(self) -> bool { + self.msg_sender.is_zero() & self.storage_contract_address.is_zero() + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr deleted file mode 100644 index 870b4b32505..00000000000 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr +++ /dev/null @@ -1,532 +0,0 @@ -use crate::{ - abis::{ - call_request::CallRequest, new_contract_data::NewContractData, - nullifier_key_validation_request::NullifierKeyValidationRequestContext, - public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ - MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, - MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, - MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, - MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX, - MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX -}; - -use dep::std::unsafe; -use crate::traits::is_empty; - -use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; - -struct CombinedAccumulatedData { - read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], - nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], - - new_commitments: [SideEffect; MAX_NEW_COMMITMENTS_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], - - private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], - new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], - - encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], - - public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - - public_data_reads: [PublicDataRead; MAX_PUBLIC_DATA_READS_PER_TX], -} - -impl CombinedAccumulatedData { - pub fn needs_app_logic(self) -> bool { - // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() - } - - pub fn recombine( - non_revertible: PublicAccumulatedNonRevertibleData, - revertible: PublicAccumulatedRevertibleData - ) -> CombinedAccumulatedData { - CombinedAccumulatedData { - read_requests: revertible.read_requests, - nullifier_key_validation_requests: revertible.nullifier_key_validation_requests, - new_commitments: array_concat(non_revertible.new_commitments, revertible.new_commitments), - new_nullifiers: array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers), - private_call_stack: revertible.private_call_stack, - public_call_stack: array_concat( - non_revertible.public_call_stack, - revertible.public_call_stack - ), - new_l2_to_l1_msgs: revertible.new_l2_to_l1_msgs, - encrypted_logs_hash: revertible.encrypted_logs_hash, - unencrypted_logs_hash: revertible.unencrypted_logs_hash, - encrypted_log_preimages_length: revertible.encrypted_log_preimages_length, - unencrypted_log_preimages_length: revertible.unencrypted_log_preimages_length, - new_contracts: revertible.new_contracts, - public_data_update_requests: array_concat( - non_revertible.public_data_update_requests, - revertible.public_data_update_requests - ), - public_data_reads: array_concat( - non_revertible.public_data_reads, - revertible.public_data_reads - ) - } - } -} - -struct PrivateAccumulatedRevertibleData { - new_commitments: [SideEffect; MAX_REVERTIBLE_COMMITMENTS_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], - - private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], - - encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], -} - -impl PrivateAccumulatedRevertibleData { - pub fn needs_app_logic(self) -> bool { - // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() - } -} - -struct PublicAccumulatedRevertibleData { - read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], - nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], - - new_commitments: [SideEffect; MAX_REVERTIBLE_COMMITMENTS_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], - - private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], - - encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], - - public_data_update_requests: [PublicDataUpdateRequest; MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - public_data_reads: [PublicDataRead; MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX], -} - -impl PublicAccumulatedRevertibleData { - pub fn needs_app_logic(self) -> bool { - // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() - } -} - -struct AccumulatedRevertibleDataBuilder { - read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, - - new_commitments: BoundedVec, - new_nullifiers: BoundedVec, - - private_call_stack: BoundedVec, - public_call_stack: BoundedVec, - new_l2_to_l1_msgs: BoundedVec, - - encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - new_contracts: BoundedVec, - - public_data_update_requests: BoundedVec, - public_data_reads: BoundedVec, -} - -impl AccumulatedRevertibleDataBuilder { - pub fn to_private(self) -> PrivateAccumulatedRevertibleData { - PrivateAccumulatedRevertibleData { - new_commitments: self.new_commitments.storage, - new_nullifiers: self.new_nullifiers.storage, - private_call_stack: self.private_call_stack.storage, - public_call_stack: self.public_call_stack.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - new_contracts: self.new_contracts.storage - } - } - - pub fn to_public(self) -> PublicAccumulatedRevertibleData { - PublicAccumulatedRevertibleData { - read_requests: self.read_requests.storage, - new_commitments: self.new_commitments.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, - new_nullifiers: self.new_nullifiers.storage, - private_call_stack: self.private_call_stack.storage, - public_call_stack: self.public_call_stack.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - new_contracts: self.new_contracts.storage, - public_data_update_requests: self.public_data_update_requests.storage, - public_data_reads: self.public_data_reads.storage - } - } -} - -struct PrivateAccumulatedNonRevertibleData { - new_commitments: [SideEffect; MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], - public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], -} - -impl PrivateAccumulatedNonRevertibleData { - pub fn needs_setup(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - // So if we have more than one element, we need setup. - !self.public_call_stack[1].is_empty() - } - - pub fn needs_teardown(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - !self.public_call_stack[0].is_empty() - } -} - -struct PublicAccumulatedNonRevertibleData { - new_commitments: [SideEffect; MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], - public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - public_data_update_requests: [PublicDataUpdateRequest; MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - public_data_reads: [PublicDataRead; MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX], -} - -impl PublicAccumulatedNonRevertibleData { - pub fn needs_setup(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - // So if we have more than one element, we need setup. - !self.public_call_stack[1].is_empty() - } - - pub fn needs_teardown(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - !self.public_call_stack[0].is_empty() - } -} - -struct AccumulatedNonRevertibleDataBuilder { - new_commitments: BoundedVec, - new_nullifiers: BoundedVec, - public_call_stack: BoundedVec, - public_data_update_requests: BoundedVec, - public_data_reads: BoundedVec, -} - -impl AccumulatedNonRevertibleDataBuilder { - pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData { - PrivateAccumulatedNonRevertibleData { - new_commitments: self.new_commitments.storage, - new_nullifiers: self.new_nullifiers.storage, - public_call_stack: self.public_call_stack.storage - } - } - pub fn to_public(self) -> PublicAccumulatedNonRevertibleData { - PublicAccumulatedNonRevertibleData { - new_commitments: self.new_commitments.storage, - new_nullifiers: self.new_nullifiers.storage, - public_call_stack: self.public_call_stack.storage, - public_data_update_requests: self.public_data_update_requests.storage, - public_data_reads: self.public_data_reads.storage - } - } -} - -struct CombinedAccumulatedDataBuilder { - read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, - - new_commitments: BoundedVec, - new_nullifiers: BoundedVec, - - private_call_stack: BoundedVec, - public_call_stack: BoundedVec, - new_l2_to_l1_msgs: BoundedVec, - - encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - new_contracts: BoundedVec, - - public_data_update_requests: BoundedVec, - - public_data_reads: BoundedVec, -} - -impl CombinedAccumulatedDataBuilder { - pub fn recombine( - non_revertible: PublicAccumulatedNonRevertibleData, - revertible: PublicAccumulatedRevertibleData - ) -> CombinedAccumulatedDataBuilder { - CombinedAccumulatedDataBuilder { - read_requests: array_to_bounded_vec(revertible.read_requests), - nullifier_key_validation_requests: array_to_bounded_vec(revertible.nullifier_key_validation_requests), - new_commitments: array_to_bounded_vec(array_concat(non_revertible.new_commitments, revertible.new_commitments)), - new_nullifiers: array_to_bounded_vec(array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers)), - private_call_stack: array_to_bounded_vec(revertible.private_call_stack), - public_call_stack: array_to_bounded_vec( - array_concat( - non_revertible.public_call_stack, - revertible.public_call_stack - ) - ), - new_l2_to_l1_msgs: array_to_bounded_vec(revertible.new_l2_to_l1_msgs), - encrypted_logs_hash: revertible.encrypted_logs_hash, - unencrypted_logs_hash: revertible.unencrypted_logs_hash, - encrypted_log_preimages_length: revertible.encrypted_log_preimages_length, - unencrypted_log_preimages_length: revertible.unencrypted_log_preimages_length, - new_contracts: array_to_bounded_vec(revertible.new_contracts), - public_data_update_requests: array_to_bounded_vec( - array_concat( - non_revertible.public_data_update_requests, - revertible.public_data_update_requests - ) - ), - public_data_reads: array_to_bounded_vec( - array_concat( - non_revertible.public_data_reads, - revertible.public_data_reads - ) - ) - } - } - - pub fn finish(self) -> CombinedAccumulatedData { - CombinedAccumulatedData { - read_requests: self.read_requests.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, - new_commitments: self.new_commitments.storage, - new_nullifiers: self.new_nullifiers.storage, - private_call_stack: self.private_call_stack.storage, - public_call_stack: self.public_call_stack.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - new_contracts: self.new_contracts.storage, - public_data_update_requests: self.public_data_update_requests.storage, - public_data_reads: self.public_data_reads.storage - } - } - - pub fn to_private_accumulated_revertible_data(self) -> PrivateAccumulatedRevertibleData { - PrivateAccumulatedRevertibleData { - new_commitments: array_cp(self.new_commitments.storage), - new_nullifiers: array_cp(self.new_nullifiers.storage), - private_call_stack: self.private_call_stack.storage, - public_call_stack: array_cp(self.public_call_stack.storage), - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - new_contracts: self.new_contracts.storage - } - } - - pub fn to_public_accumulated_revertible_data(self) -> PublicAccumulatedRevertibleData { - PublicAccumulatedRevertibleData { - read_requests: self.read_requests.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, - new_commitments: array_cp(self.new_commitments.storage), - new_nullifiers: array_cp(self.new_nullifiers.storage), - private_call_stack: self.private_call_stack.storage, - public_call_stack: array_cp(self.public_call_stack.storage), - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - new_contracts: self.new_contracts.storage, - public_data_update_requests: array_cp(self.public_data_update_requests.storage), - public_data_reads: array_cp(self.public_data_reads.storage) - } - } - - pub fn split( - self, - min_revertible_side_effect_counter: u32 - ) -> (PrivateAccumulatedNonRevertibleData, PrivateAccumulatedRevertibleData) { - let mut non_revertible_builder: AccumulatedNonRevertibleDataBuilder = unsafe::zeroed(); - let mut revertible_builder: AccumulatedRevertibleDataBuilder = unsafe::zeroed(); - - for i in 0..MAX_NEW_COMMITMENTS_PER_TX { - let commitment = self.new_commitments.storage[i]; - // TODO(fees) we shouldn't need to check is_empty here, - // but we do because new_commitments is bounded to MAX_REVERTIBLE_COMMITMENTS_PER_TX - if !is_empty(commitment) { - if commitment.counter < min_revertible_side_effect_counter { - non_revertible_builder.new_commitments.push(commitment); - } else { - revertible_builder.new_commitments.push(commitment); - } - } - } - for i in 0..MAX_NEW_NULLIFIERS_PER_TX { - let nullifier = self.new_nullifiers.storage[i]; - if !is_empty(nullifier) { - if nullifier.counter < min_revertible_side_effect_counter { - non_revertible_builder.new_nullifiers.push(nullifier); - } else { - revertible_builder.new_nullifiers.push(nullifier); - } - } - } - - for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { - let call_stack_item = self.public_call_stack.storage[i]; - if !is_empty(call_stack_item) { - if call_stack_item.start_side_effect_counter < min_revertible_side_effect_counter { - non_revertible_builder.public_call_stack.push(call_stack_item); - } else { - revertible_builder.public_call_stack.push(call_stack_item); - } - } - } - - revertible_builder.private_call_stack = self.private_call_stack; - revertible_builder.new_l2_to_l1_msgs = self.new_l2_to_l1_msgs; - revertible_builder.encrypted_logs_hash = self.encrypted_logs_hash; - revertible_builder.unencrypted_logs_hash = self.unencrypted_logs_hash; - revertible_builder.encrypted_log_preimages_length = self.encrypted_log_preimages_length; - revertible_builder.unencrypted_log_preimages_length= self.unencrypted_log_preimages_length; - revertible_builder.new_contracts = self.new_contracts; - - (non_revertible_builder.to_private(), revertible_builder.to_private()) - } -} - -mod tests { - use crate::abis::{ - combined_accumulated_data::CombinedAccumulatedDataBuilder, - call_request::{CallRequest, CallerContext}, new_contract_data::NewContractData, - nullifier_key_validation_request::NullifierKeyValidationRequestContext, - public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} - }; - use crate::address::AztecAddress; - use crate::utils::arrays::array_eq; - use dep::std::unsafe; - - #[test] - unconstrained fn splits_revertible_and_non_revertible() { - let mut builder: CombinedAccumulatedDataBuilder = unsafe::zeroed(); - - let non_revertible_commitments = [ - SideEffect { value: 1, counter: 1 }, - SideEffect { value: 2, counter: 3 } - ]; - - let non_revertible_nullifiers = [ - SideEffectLinkedToNoteHash { value: 10, note_hash: 1, counter: 2 }, - SideEffectLinkedToNoteHash { value: 20, note_hash: 2, counter: 4 } - ]; - - let non_revertible_public_stack = [ - CallRequest { - hash: 1, - caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), - start_side_effect_counter: 5, - end_side_effect_counter: 0 - }, - CallRequest { - hash: 2, - caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), - start_side_effect_counter: 6, - end_side_effect_counter: 0 - } - ]; - - let revertible_commitments = [ - SideEffect { value: 3, counter: 7 }, - SideEffect { value: 4, counter: 10 } - ]; - - let revertible_nullifiers = [ - SideEffectLinkedToNoteHash { value: 30, note_hash: 3, counter: 8 }, - SideEffectLinkedToNoteHash { value: 40, note_hash: 4, counter: 11 } - ]; - - let revertible_public_call_stack = [ - CallRequest { - hash: 3, - caller_contract_address: AztecAddress::from_field(3), - caller_context: CallerContext::empty(), - start_side_effect_counter: 9, - end_side_effect_counter: 0 - } - ]; - - builder.new_commitments.extend_from_array(non_revertible_commitments); - builder.new_commitments.extend_from_array(revertible_commitments); - - builder.new_nullifiers.extend_from_array(non_revertible_nullifiers); - builder.new_nullifiers.extend_from_array(revertible_nullifiers); - - builder.public_call_stack.extend_from_array(non_revertible_public_stack); - builder.public_call_stack.extend_from_array(revertible_public_call_stack); - - let (non_revertible, revertible) = builder.split(7); - - assert(array_eq(non_revertible.new_commitments, non_revertible_commitments)); - assert(array_eq(non_revertible.new_nullifiers, non_revertible_nullifiers)); - assert(array_eq(non_revertible.public_call_stack, non_revertible_public_stack)); - - assert(array_eq(revertible.new_commitments, revertible_commitments)); - assert(array_eq(revertible.new_nullifiers, revertible_nullifiers)); - assert(array_eq(revertible.public_call_stack, revertible_public_call_stack)); - } -} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs.nr index 59764ef6be1..4ea6274011e 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs.nr @@ -1,114 +1,17 @@ -use crate::abis::{ - combined_accumulated_data::{ - CombinedAccumulatedData, PrivateAccumulatedRevertibleData, PrivateAccumulatedNonRevertibleData, - CombinedAccumulatedDataBuilder, PublicAccumulatedNonRevertibleData, PublicAccumulatedRevertibleData, - AccumulatedNonRevertibleDataBuilder, AccumulatedRevertibleDataBuilder -}, - combined_constant_data::CombinedConstantData +mod private_kernel_circuit_public_inputs_builder; +mod private_kernel_inner_circuit_public_inputs; +mod private_kernel_tail_circuit_public_inputs; +mod public_kernel_circuit_public_inputs; +mod public_kernel_circuit_public_inputs_builder; +mod rollup_kernel_circuit_public_inputs; +mod rollup_kernel_circuit_public_inputs_builder; + +use crate::abis::kernel_circuit_public_inputs::{ + private_kernel_circuit_public_inputs_builder::PrivateKernelCircuitPublicInputsBuilder, + private_kernel_inner_circuit_public_inputs::PrivateKernelInnerCircuitPublicInputs, + private_kernel_tail_circuit_public_inputs::PrivateKernelTailCircuitPublicInputs, + public_kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, + public_kernel_circuit_public_inputs_builder::PublicKernelCircuitPublicInputsBuilder, + rollup_kernel_circuit_public_inputs::RollupKernelCircuitPublicInputs, + rollup_kernel_circuit_public_inputs_builder::RollupKernelCircuitPublicInputsBuilder }; -use dep::std::{unsafe}; -use crate::constants::{MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX}; - -use crate::mocked::AggregationObject; - -struct PrivateKernelInnerCircuitPublicInputs { - aggregation_object: AggregationObject, - min_revertible_side_effect_counter: u32, - end: CombinedAccumulatedData, - constants: CombinedConstantData, - is_private: bool, // TODO can we remove this? -} - -struct PrivateKernelTailCircuitPublicInputs { - aggregation_object: AggregationObject, - end_non_revertible: PrivateAccumulatedNonRevertibleData, - end: PrivateAccumulatedRevertibleData, - constants: CombinedConstantData, - needs_setup: bool, - needs_app_logic: bool, - needs_teardown: bool, -} - -struct PublicKernelCircuitPublicInputs { - aggregation_object: AggregationObject, - end_non_revertible: PublicAccumulatedNonRevertibleData, - end: PublicAccumulatedRevertibleData, - constants: CombinedConstantData, - needs_setup: bool, - needs_app_logic: bool, - needs_teardown: bool, -} - -struct RollupKernelCircuitPublicInputs { - aggregation_object: AggregationObject, - end: CombinedAccumulatedData, - constants: CombinedConstantData, -} - -struct RollupKernelCircuitPublicInputsBuilder { - aggregation_object: AggregationObject, - end: CombinedAccumulatedDataBuilder, - constants: CombinedConstantData, -} - -impl RollupKernelCircuitPublicInputsBuilder { - pub fn finish(self) -> RollupKernelCircuitPublicInputs { - RollupKernelCircuitPublicInputs { aggregation_object: self.aggregation_object, end: self.end.finish(), constants: self.constants } - } -} - -struct PrivateKernelCircuitPublicInputsBuilder { - aggregation_object: AggregationObject, - min_revertible_side_effect_counter: u32, - end: CombinedAccumulatedDataBuilder, - constants: CombinedConstantData, - is_private: bool, -} - -impl PrivateKernelCircuitPublicInputsBuilder { - pub fn to_inner(self) -> PrivateKernelInnerCircuitPublicInputs { - PrivateKernelInnerCircuitPublicInputs { - aggregation_object: self.aggregation_object, - min_revertible_side_effect_counter: self.min_revertible_side_effect_counter, - end: self.end.finish(), - constants: self.constants, - is_private: self.is_private - } - } - - pub fn to_tail(self) -> PrivateKernelTailCircuitPublicInputs { - let (end_non_revertible, end) = self.end.split(self.min_revertible_side_effect_counter); - PrivateKernelTailCircuitPublicInputs { - aggregation_object: self.aggregation_object, - end_non_revertible, - end, - constants: self.constants, - needs_setup: end_non_revertible.needs_setup(), - needs_app_logic: end.needs_app_logic(), - needs_teardown: end_non_revertible.needs_teardown() - } - } -} - -struct PublicKernelCircuitPublicInputsBuilder { - aggregation_object: AggregationObject, - end_non_revertible: AccumulatedNonRevertibleDataBuilder, - end: AccumulatedRevertibleDataBuilder, - constants: CombinedConstantData, -} - -impl PublicKernelCircuitPublicInputsBuilder { - pub fn to_inner(self) -> PublicKernelCircuitPublicInputs { - let end_non_revertible = self.end_non_revertible.to_public(); - let end = self.end.to_public(); - PublicKernelCircuitPublicInputs { - aggregation_object: self.aggregation_object, - end_non_revertible, - end, - constants: self.constants, - needs_setup: end_non_revertible.needs_setup(), - needs_app_logic: end.needs_app_logic(), - needs_teardown: end_non_revertible.needs_teardown() - } - } -} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr new file mode 100644 index 00000000000..39817c4e6c2 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr @@ -0,0 +1,42 @@ +use crate::abis::{ + accumulated_data::CombinedAccumulatedDataBuilder, combined_constant_data::CombinedConstantData, + kernel_circuit_public_inputs::{ + private_kernel_inner_circuit_public_inputs::PrivateKernelInnerCircuitPublicInputs, + private_kernel_tail_circuit_public_inputs::PrivateKernelTailCircuitPublicInputs +} +}; + +use crate::mocked::AggregationObject; + +struct PrivateKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject, + min_revertible_side_effect_counter: u32, + end: CombinedAccumulatedDataBuilder, + constants: CombinedConstantData, + is_private: bool, +} + +impl PrivateKernelCircuitPublicInputsBuilder { + pub fn to_inner(self) -> PrivateKernelInnerCircuitPublicInputs { + PrivateKernelInnerCircuitPublicInputs { + aggregation_object: self.aggregation_object, + min_revertible_side_effect_counter: self.min_revertible_side_effect_counter, + end: self.end.finish(), + constants: self.constants, + is_private: self.is_private + } + } + + pub fn to_tail(self) -> PrivateKernelTailCircuitPublicInputs { + let (end_non_revertible, end) = self.end.split(self.min_revertible_side_effect_counter); + PrivateKernelTailCircuitPublicInputs { + aggregation_object: self.aggregation_object, + end_non_revertible, + end, + constants: self.constants, + needs_setup: end_non_revertible.needs_setup(), + needs_app_logic: end.needs_app_logic(), + needs_teardown: end_non_revertible.needs_teardown() + } + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_inner_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_inner_circuit_public_inputs.nr new file mode 100644 index 00000000000..ce7eb302a4f --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_inner_circuit_public_inputs.nr @@ -0,0 +1,11 @@ +use crate::abis::{accumulated_data::CombinedAccumulatedData, combined_constant_data::CombinedConstantData}; + +use crate::mocked::AggregationObject; + +struct PrivateKernelInnerCircuitPublicInputs { + aggregation_object: AggregationObject, + min_revertible_side_effect_counter: u32, + end: CombinedAccumulatedData, + constants: CombinedConstantData, + is_private: bool, // TODO can we remove this? +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_tail_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_tail_circuit_public_inputs.nr new file mode 100644 index 00000000000..e1f11f18baa --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_tail_circuit_public_inputs.nr @@ -0,0 +1,16 @@ +use crate::abis::{ + accumulated_data::{PrivateAccumulatedNonRevertibleData, PrivateAccumulatedRevertibleData}, + combined_constant_data::CombinedConstantData +}; + +use crate::mocked::AggregationObject; + +struct PrivateKernelTailCircuitPublicInputs { + aggregation_object: AggregationObject, + end_non_revertible: PrivateAccumulatedNonRevertibleData, + end: PrivateAccumulatedRevertibleData, + constants: CombinedConstantData, + needs_setup: bool, + needs_app_logic: bool, + needs_teardown: bool, +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr new file mode 100644 index 00000000000..a581a992d19 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -0,0 +1,16 @@ +use crate::abis::{ + accumulated_data::{PublicAccumulatedNonRevertibleData, PublicAccumulatedRevertibleData}, + combined_constant_data::CombinedConstantData +}; + +use crate::mocked::AggregationObject; + +struct PublicKernelCircuitPublicInputs { + aggregation_object: AggregationObject, + end_non_revertible: PublicAccumulatedNonRevertibleData, + end: PublicAccumulatedRevertibleData, + constants: CombinedConstantData, + needs_setup: bool, + needs_app_logic: bool, + needs_teardown: bool, +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr new file mode 100644 index 00000000000..022d7bf7fc2 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -0,0 +1,30 @@ +use crate::abis::{ + accumulated_data::{AccumulatedNonRevertibleDataBuilder, AccumulatedRevertibleDataBuilder}, + combined_constant_data::CombinedConstantData, + kernel_circuit_public_inputs::public_kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs +}; + +use crate::mocked::AggregationObject; + +struct PublicKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject, + end_non_revertible: AccumulatedNonRevertibleDataBuilder, + end: AccumulatedRevertibleDataBuilder, + constants: CombinedConstantData, +} + +impl PublicKernelCircuitPublicInputsBuilder { + pub fn to_inner(self) -> PublicKernelCircuitPublicInputs { + let end_non_revertible = self.end_non_revertible.to_public(); + let end = self.end.to_public(); + PublicKernelCircuitPublicInputs { + aggregation_object: self.aggregation_object, + end_non_revertible, + end, + constants: self.constants, + needs_setup: end_non_revertible.needs_setup(), + needs_app_logic: end.needs_app_logic(), + needs_teardown: end_non_revertible.needs_teardown() + } + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs.nr new file mode 100644 index 00000000000..1e7711fc43e --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs.nr @@ -0,0 +1,9 @@ +use crate::abis::{accumulated_data::CombinedAccumulatedData, combined_constant_data::CombinedConstantData}; + +use crate::mocked::AggregationObject; + +struct RollupKernelCircuitPublicInputs { + aggregation_object: AggregationObject, + end: CombinedAccumulatedData, + constants: CombinedConstantData, +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs_builder.nr new file mode 100644 index 00000000000..9e5bd581700 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/kernel_circuit_public_inputs/rollup_kernel_circuit_public_inputs_builder.nr @@ -0,0 +1,18 @@ +use crate::abis::{ + accumulated_data::CombinedAccumulatedDataBuilder, combined_constant_data::CombinedConstantData, + kernel_circuit_public_inputs::rollup_kernel_circuit_public_inputs::RollupKernelCircuitPublicInputs +}; + +use crate::mocked::AggregationObject; + +struct RollupKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject, + end: CombinedAccumulatedDataBuilder, + constants: CombinedConstantData, +} + +impl RollupKernelCircuitPublicInputsBuilder { + pub fn finish(self) -> RollupKernelCircuitPublicInputs { + RollupKernelCircuitPublicInputs { aggregation_object: self.aggregation_object, end: self.end.finish(), constants: self.constants } + } +} diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr index 2f129dbdff8..e58de4329ce 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr @@ -1,5 +1,5 @@ use crate::address::{AztecAddress, EthAddress}; -use crate::contract_class::ContractClassId; +use crate::contract_class_id::ContractClassId; use crate::constants::{GENERATOR_INDEX__CONTRACT_LEAF, NEW_CONTRACT_DATA_LENGTH}; use dep::std::cmp::Eq; use crate::traits::{Empty, Serialize, Hash, Deserialize}; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_kernel/private_call_data.nr index 10647b0d3f3..e2bf6343ba8 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_kernel/private_call_data.nr @@ -3,7 +3,7 @@ use crate::abis::{ membership_witness::{ContractLeafMembershipWitness, FunctionLeafMembershipWitness, ReadRequestMembershipWitness} }; use crate::address::{SaltedInitializationHash, PublicKeysHash, EthAddress}; -use crate::contract_class::{ContractClassId}; +use crate::contract_class_id::ContractClassId; use crate::mocked::{Proof, VerificationKey}; use crate::constants::{ MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/address/aztec_address.nr index e407dbebb2b..27ccf5c164d 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/address/aztec_address.nr @@ -1,7 +1,7 @@ use crate::{ crate::address::{eth_address::EthAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS}, - contract_class::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, + contract_class_id::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, traits::{Empty, ToField, Serialize, Deserialize}, utils }; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/address/partial_address.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/address/partial_address.nr index 7e3f49ed8f6..a8dadd6b642 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/address/partial_address.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/address/partial_address.nr @@ -1,7 +1,7 @@ use crate::{ address::{eth_address::EthAddress, salted_initialization_hash::SaltedInitializationHash}, - constants::GENERATOR_INDEX__PARTIAL_ADDRESS, contract_class::ContractClassId, hash::pedersen_hash, - traits::ToField + constants::GENERATOR_INDEX__PARTIAL_ADDRESS, contract_class_id::ContractClassId, + hash::pedersen_hash, traits::ToField }; // Partial address diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/contract_class.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/contract_class_id.nr similarity index 100% rename from noir-projects/noir-protocol-circuits/src/crates/types/src/contract_class.nr rename to noir-projects/noir-protocol-circuits/src/crates/types/src/contract_class_id.nr diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr index 9e97e634e41..57c67f036d0 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr @@ -1,5 +1,5 @@ use crate::{ - address::EthAddress, contract_class::ContractClassId, + address::EthAddress, contract_class_id::ContractClassId, constants::{CONTRACT_DEPLOYMENT_DATA_LENGTH, GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA}, grumpkin_point::GrumpkinPoint, hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} }; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/hash.nr index b2804c6b6c1..76bb40ccbb9 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/hash.nr @@ -3,7 +3,7 @@ use crate::mocked::VerificationKey; use crate::abis::function_selector::FunctionSelector; use crate::abis::function_leaf_preimage::FunctionLeafPreimage; use crate::abis::contract_class_function_leaf_preimage::ContractClassFunctionLeafPreimage; -use crate::contract_class::ContractClassId; +use crate::contract_class_id::ContractClassId; use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage; use crate::abis::function_data::FunctionData; use crate::abis::side_effect::{SideEffect}; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/lib.nr index 6ed253e4810..1278f49b883 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/lib.nr @@ -9,7 +9,7 @@ mod contrakt; mod transaction; mod abis; mod constants; -mod contract_class; +mod contract_class_id; mod messaging; mod mocked; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr index 9da6995f294..7d62ee738f5 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/fixtures/contracts.nr @@ -1,7 +1,7 @@ use crate::abis::membership_witness::ContractLeafMembershipWitness; use crate::address::{AztecAddress, EthAddress, PublicKeysHash, SaltedInitializationHash, PartialAddress}; use crate::tests::fixtures; -use crate::contract_class::ContractClassId; +use crate::contract_class_id::ContractClassId; struct ContractData { address: AztecAddress, diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr index eb78404ee86..7eb785d088e 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr @@ -2,7 +2,7 @@ use crate::{ abis::{ call_context::CallContext, call_request::{CallerContext, CallRequest}, combined_constant_data::CombinedConstantData, - combined_accumulated_data::{CombinedAccumulatedDataBuilder, AccumulatedNonRevertibleDataBuilder, AccumulatedRevertibleDataBuilder}, + accumulated_data::{CombinedAccumulatedDataBuilder, AccumulatedNonRevertibleDataBuilder, AccumulatedRevertibleDataBuilder}, kernel_circuit_public_inputs::{ PrivateKernelInnerCircuitPublicInputs, PrivateKernelTailCircuitPublicInputs, PublicKernelCircuitPublicInputs, RollupKernelCircuitPublicInputs diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_request.nr index 25b1913cdee..ebbe212d5ea 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_request.nr @@ -61,7 +61,7 @@ impl Deserialize for TxRequest { mod tests { use crate::{ abis::{function_selector::FunctionSelector, function_data::FunctionData}, - address::{AztecAddress, EthAddress}, contract_class::ContractClassId, + address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId, contrakt::contract_deployment_data::ContractDeploymentData, grumpkin_point::GrumpkinPoint, transaction::{tx_request::TxRequest, tx_context::TxContext} }; diff --git a/yarn-project/foundation/src/abi/encoder.test.ts b/yarn-project/foundation/src/abi/encoder.test.ts index ff010d05f1d..fcbbeed6267 100644 --- a/yarn-project/foundation/src/abi/encoder.test.ts +++ b/yarn-project/foundation/src/abi/encoder.test.ts @@ -117,7 +117,7 @@ describe('abi/encoder', () => { name: 'contract_class', type: { kind: 'struct', - path: `types::contract_class::ContractClassId`, + path: `types::contract_class_id::ContractClassId`, fields: [ { name: 'inner',