From b568649de607797820004667ffbe794eacce0388 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Fri, 8 Nov 2024 22:49:26 +0000 Subject: [PATCH 1/4] Remove public kernel inner. --- .../Nargo.template.toml | 1 - .../public-kernel-inner-simulated/Nargo.toml | 9 - .../public-kernel-inner-simulated/src/main.nr | 6 - .../public-kernel-lib/src/components/mod.nr | 1 - .../components/vm_circuit_output_composer.nr | 175 ------------------ .../crates/public-kernel-lib/src/lib.nr | 2 - .../src/public_kernel_inner.nr | 19 -- .../crates/types/src/abis/mod.nr | 2 - .../crates/types/src/abis/public_call_data.nr | 11 -- .../src/abis/public_kernel_inner_data.nr | 20 -- .../crates/types/src/tests/fixture_builder.nr | 10 - yarn-project/circuits.js/src/structs/index.ts | 3 - .../structs/kernel/public_call_data.test.ts | 10 - .../src/structs/kernel/public_call_data.ts | 38 ---- ...lic_kernel_inner_circuit_private_inputs.ts | 65 ------- .../kernel/public_kernel_inner_data.ts | 51 ----- .../circuits.js/src/tests/factories.ts | 30 --- .../src/artifacts.ts | 2 - .../noir-protocol-circuits-types/src/index.ts | 36 ---- .../src/scripts/generate_ts_from_abi.ts | 1 - .../src/type_conversion.ts | 36 ---- .../prover-client/src/prover-agent/rpc.ts | 3 - .../src/public/enqueued_call_simulator.ts | 18 +- .../simulator/src/public/public_kernel.ts | 26 --- .../public/public_kernel_circuit_simulator.ts | 8 - 25 files changed, 2 insertions(+), 581 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/Nargo.toml delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/src/main.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_inner.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_data.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr delete mode 100644 yarn-project/circuits.js/src/structs/kernel/public_call_data.test.ts delete mode 100644 yarn-project/circuits.js/src/structs/kernel/public_call_data.ts delete mode 100644 yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_circuit_private_inputs.ts delete mode 100644 yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts diff --git a/noir-projects/noir-protocol-circuits/Nargo.template.toml b/noir-projects/noir-protocol-circuits/Nargo.template.toml index 22ca431a62f..8f497e3b818 100644 --- a/noir-projects/noir-protocol-circuits/Nargo.template.toml +++ b/noir-projects/noir-protocol-circuits/Nargo.template.toml @@ -21,7 +21,6 @@ members = [ "crates/empty-nested", "crates/empty-nested-simulated", "crates/public-kernel-lib", - "crates/public-kernel-inner-simulated", "crates/public-kernel-merge-simulated", "crates/public-kernel-tail-simulated", "crates/reset-kernel-lib", diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/Nargo.toml b/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/Nargo.toml deleted file mode 100644 index f2b452faa2b..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "public_kernel_inner_simulated" -type = "bin" -authors = [""] -compiler_version = ">=0.18.0" - -[dependencies] -types = { path = "../types" } -public_kernel_lib = { path = "../public-kernel-lib" } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/src/main.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/src/main.nr deleted file mode 100644 index dd9e32e681d..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-inner-simulated/src/main.nr +++ /dev/null @@ -1,6 +0,0 @@ -use dep::public_kernel_lib::PublicKernelInnerCircuitPrivateInputs; -use dep::types::VMCircuitPublicInputs; - -unconstrained fn main(input: PublicKernelInnerCircuitPrivateInputs) -> pub VMCircuitPublicInputs { - input.execute() -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr index 285b74fd9f0..85870154be1 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr @@ -4,4 +4,3 @@ mod public_kernel_output_composer; mod public_kernel_output_validator; mod public_tail_output_composer; mod public_tail_output_validator; -mod vm_circuit_output_composer; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer.nr deleted file mode 100644 index f807831a546..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer.nr +++ /dev/null @@ -1,175 +0,0 @@ -mod propagate_accumulated_data; - -use crate::components::vm_circuit_output_composer::propagate_accumulated_data::propagate_accumulated_data; -use dep::types::{ - abis::{ - accumulated_data::{PublicAccumulatedDataArrayLengths, PublicAccumulatedDataBuilder}, - combined_constant_data::CombinedConstantData, - gas::Gas, - kernel_circuit_public_inputs::vm_circuit_public_inputs::VMCircuitPublicInputs, - public_call_request::PublicCallRequest, - public_circuit_public_inputs::PublicCircuitPublicInputs, - public_data_read::PublicDataRead, - public_inner_call_request::PublicInnerCallRequest, - validation_requests::{ - public_validation_requests_builder::PublicValidationRequestsBuilder, - PublicValidationRequestArrayLengths, - }, - }, - constants::MAX_ENQUEUED_CALLS_PER_TX, - traits::is_empty, - utils::arrays::array_to_bounded_vec, -}; - -// TODO(#7124): To be deprecated. -pub struct VMCircuitOutputComposer { - constants: CombinedConstantData, - call_request: PublicCallRequest, - public_call_stack: BoundedVec, - previous_validation_request_array_lengths: PublicValidationRequestArrayLengths, - validation_requests: PublicValidationRequestsBuilder, - previous_accumulated_data_array_lengths: PublicAccumulatedDataArrayLengths, - accumulated_data: PublicAccumulatedDataBuilder, - start_side_effect_counter: u32, - end_side_effect_counter: u32, - start_gas_left: Gas, - transaction_fee: Field, - reverted: bool, -} - -impl VMCircuitOutputComposer { - pub fn new_from_previous_kernel(previous_kernel: VMCircuitPublicInputs) -> Self { - let mut public_call_stack = array_to_bounded_vec(previous_kernel.public_call_stack); - let _ = public_call_stack.pop(); - let validation_requests = - PublicValidationRequestsBuilder::new(previous_kernel.validation_requests); - let accumulated_data = PublicAccumulatedDataBuilder::new(previous_kernel.accumulated_data); - VMCircuitOutputComposer { - constants: previous_kernel.constants, - call_request: previous_kernel.call_request, - public_call_stack, - previous_validation_request_array_lengths: previous_kernel - .previous_validation_request_array_lengths, - validation_requests, - previous_accumulated_data_array_lengths: previous_kernel - .previous_accumulated_data_array_lengths, - accumulated_data, - start_side_effect_counter: previous_kernel.start_side_effect_counter, - end_side_effect_counter: previous_kernel.end_side_effect_counter, - start_gas_left: previous_kernel.start_gas_left, - transaction_fee: previous_kernel.transaction_fee, - reverted: previous_kernel.reverted, - } - } - - pub fn propagate_from_public_call(&mut self, public_call: PublicCircuitPublicInputs) -> Self { - self.constants.global_variables = public_call.global_variables; - self.propagate_revert_flag(public_call); - self.propagate_validation_requests(public_call); - self.propagate_accumulated_data(public_call); - self.propagate_end_side_effect_counter(public_call); - // Other values should be the same through out the entire enqueued call. - *self - } - - pub fn finish(self) -> VMCircuitPublicInputs { - VMCircuitPublicInputs { - constants: self.constants, - call_request: self.call_request, - public_call_stack: self.public_call_stack.storage, - previous_validation_request_array_lengths: self - .previous_validation_request_array_lengths, - validation_requests: self.validation_requests.finish(), - previous_accumulated_data_array_lengths: self.previous_accumulated_data_array_lengths, - accumulated_data: self.accumulated_data.finish(), - start_side_effect_counter: self.start_side_effect_counter, - end_side_effect_counter: self.end_side_effect_counter, - start_gas_left: self.start_gas_left, - transaction_fee: self.transaction_fee, - reverted: self.reverted, - } - } - - fn propagate_revert_flag(&mut self, public_call: PublicCircuitPublicInputs) { - if !self.reverted { - self.reverted = public_call.revert_code != 0; - } - } - - fn propagate_validation_requests(&mut self, public_call: PublicCircuitPublicInputs) { - // Note that the public kernel cannot modify the max block number value - it simply forwards it to the rollup - let contract_address = public_call.call_context.contract_address; - - let note_hash_read_requests = public_call.note_hash_read_requests; - for i in 0..note_hash_read_requests.len() { - let request = note_hash_read_requests[i]; - if !is_empty(request) { - self.validation_requests.note_hash_read_requests.push(request); - } - } - - let nullifier_read_requests = public_call.nullifier_read_requests; - for i in 0..nullifier_read_requests.len() { - let request = nullifier_read_requests[i]; - if !is_empty(request) { - self.validation_requests.nullifier_read_requests.push(request.scope( - contract_address, - )); - } - } - - let nullifier_non_existent_read_requests = public_call.nullifier_non_existent_read_requests; - for i in 0..nullifier_non_existent_read_requests.len() { - let request = nullifier_non_existent_read_requests[i]; - if !is_empty(request) { - self.validation_requests.nullifier_non_existent_read_requests.push(request.scope( - contract_address, - )); - } - } - - let l1_to_l2_msg_read_requests = public_call.l1_to_l2_msg_read_requests; - for i in 0..l1_to_l2_msg_read_requests.len() { - let request = l1_to_l2_msg_read_requests[i]; - if !is_empty(request) { - self.validation_requests.l1_to_l2_msg_read_requests.push(request); - } - } - - let read_requests = public_call.contract_storage_reads; - for i in 0..read_requests.len() { - let read_request = read_requests[i]; - if !is_empty(read_request) { - self.validation_requests.public_data_reads.push( - PublicDataRead::from_contract_storage_read(contract_address, read_request), - ); - } - } - } - - fn propagate_accumulated_data(&mut self, public_call: PublicCircuitPublicInputs) { - // TODO: Should keep the data even when reverts. - // The data is required for verifying validation requests in the tail circuit, which will then discard the - // revertible data. - if self.reverted { - self.accumulated_data = PublicAccumulatedDataBuilder::empty(); - } else { - self.accumulated_data = - propagate_accumulated_data(&mut self.accumulated_data, public_call); - self.propagate_call_requests(public_call); - } - - self.accumulated_data.gas_used += public_call.start_gas_left.sub(public_call.end_gas_left); - } - - fn propagate_call_requests(&mut self, public_call: PublicCircuitPublicInputs) { - let call_requests = array_to_bounded_vec(public_call.public_call_requests); - self.public_call_stack.extend_from_bounded_vec(call_requests); - } - - fn propagate_end_side_effect_counter(&mut self, public_call: PublicCircuitPublicInputs) { - if public_call.end_side_effect_counter > self.end_side_effect_counter { - self.end_side_effect_counter = public_call.end_side_effect_counter; - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/lib.nr index 0f192aa4fe0..0fd94c3a1d4 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/lib.nr @@ -1,9 +1,7 @@ mod components; -mod public_kernel_inner; mod public_kernel_merge; mod public_kernel_phase; mod public_kernel_tail; -pub use public_kernel_inner::PublicKernelInnerCircuitPrivateInputs; pub use public_kernel_merge::PublicKernelMergeCircuitPrivateInputs; pub use public_kernel_tail::PublicKernelTailCircuitPrivateInputs; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_inner.nr deleted file mode 100644 index 8d5ceb2bbab..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_inner.nr +++ /dev/null @@ -1,19 +0,0 @@ -use crate::components::vm_circuit_output_composer::VMCircuitOutputComposer; -use dep::types::abis::{ - kernel_circuit_public_inputs::VMCircuitPublicInputs, public_call_data::PublicCallData, - public_kernel_inner_data::PublicKernelInnerData, -}; - -// TODO(#7124): To be deprecated. -pub struct PublicKernelInnerCircuitPrivateInputs { - previous_kernel: PublicKernelInnerData, - public_call: PublicCallData, -} - -impl PublicKernelInnerCircuitPrivateInputs { - fn execute(self) -> VMCircuitPublicInputs { - VMCircuitOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) - .propagate_from_public_call(self.public_call.public_inputs) - .finish() - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr index 4e48f564e92..7b3324e4c21 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr @@ -33,7 +33,6 @@ pub mod private_kernel; pub mod kernel_circuit_public_inputs; pub mod private_kernel_data; pub mod public_kernel_data; -pub mod public_kernel_inner_data; pub mod private_call_request; pub mod public_call_request; @@ -42,7 +41,6 @@ pub mod public_inner_call_request; pub mod call_context; pub mod enqueued_call_data; -pub mod public_call_data; pub mod public_circuit_public_inputs; pub mod private_circuit_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_data.nr deleted file mode 100644 index 1404e3ba1e9..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_data.nr +++ /dev/null @@ -1,11 +0,0 @@ -use crate::abis::public_circuit_public_inputs::PublicCircuitPublicInputs; - -// Mocked here as the only remaining non-recursive proof -pub struct Proof {} - -// TODO(#7124): To be deprecated. -pub struct PublicCallData { - public_inputs: PublicCircuitPublicInputs, - proof: Proof, - bytecode_hash: Field, -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr deleted file mode 100644 index b397965bf2c..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr +++ /dev/null @@ -1,20 +0,0 @@ -use crate::{ - abis::kernel_circuit_public_inputs::VMCircuitPublicInputs, - proof::{ - recursive_proof::NestedRecursiveProof, traits::Verifiable, - verification_key::HonkVerificationKey, - }, -}; - -pub struct PublicKernelInnerData { - public_inputs: VMCircuitPublicInputs, - proof: NestedRecursiveProof, - vk: HonkVerificationKey, -} - -impl Verifiable for PublicKernelInnerData { - fn verify(self) { - let inputs = VMCircuitPublicInputs::serialize(self.public_inputs); - std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index ba8b509e250..f6824eb726f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -9,7 +9,6 @@ use crate::{ combined_constant_data::CombinedConstantData, enqueued_call_data::{EnqueuedCallData, Proof}, function_data::FunctionData, - function_selector::FunctionSelector, gas::Gas, gas_settings::GasSettings, global_variables::GlobalVariables, @@ -26,7 +25,6 @@ use crate::{ private_circuit_public_inputs::PrivateCircuitPublicInputs, private_kernel::private_call_data::PrivateCallData, private_kernel_data::PrivateKernelData, - public_call_data::{Proof as PublicCallDataProof, PublicCallData}, public_call_request::PublicCallRequest, public_circuit_public_inputs::PublicCircuitPublicInputs, public_data_read::PublicDataRead, @@ -631,14 +629,6 @@ impl FixtureBuilder { } } - pub fn to_public_call_data(self) -> PublicCallData { - PublicCallData { - public_inputs: self.to_public_circuit_public_inputs(), - proof: PublicCallDataProof {}, - bytecode_hash: self.bytecode_hash, - } - } - pub fn to_public_validation_requests(self) -> PublicValidationRequests { PublicValidationRequests { for_rollup: self.to_rollup_validation_requests(), diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index 72a416afb67..39b77654dce 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -37,12 +37,9 @@ export * from './kernel/private_to_public_accumulated_data.js'; export * from './kernel/private_to_public_accumulated_data_builder.js'; export * from './kernel/private_to_public_kernel_circuit_public_inputs.js'; export * from './kernel/public_accumulated_data.js'; -export * from './kernel/public_call_data.js'; export * from './kernel/public_kernel_circuit_private_inputs.js'; export * from './kernel/public_kernel_circuit_public_inputs.js'; export * from './kernel/public_kernel_data.js'; -export * from './kernel/public_kernel_inner_data.js'; -export * from './kernel/public_kernel_inner_circuit_private_inputs.js'; export * from './kernel/public_kernel_tail_circuit_private_inputs.js'; export * from './kernel/tx_constant_data.js'; export * from './kernel/vm_circuit_public_inputs.js'; diff --git a/yarn-project/circuits.js/src/structs/kernel/public_call_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/public_call_data.test.ts deleted file mode 100644 index cafa167f31e..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/public_call_data.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { makePublicCallData } from '../../tests/factories.js'; -import { PublicCallData } from './public_call_data.js'; - -describe('PublicCallData', () => { - it('PublicCallData after serialization and deserialization is equal to the original', () => { - const original = makePublicCallData(123, true); - const serialized = PublicCallData.fromBuffer(original.toBuffer()); - expect(original).toEqual(serialized); - }); -}); diff --git a/yarn-project/circuits.js/src/structs/kernel/public_call_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_call_data.ts deleted file mode 100644 index bf8d7f9a2e1..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/public_call_data.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; - -import { Proof } from '../proof.js'; -import { PublicCircuitPublicInputs } from '../public_circuit_public_inputs.js'; - -/** - * Public calldata assembled from the kernel execution result and proof. - */ -export class PublicCallData { - constructor( - /** - * Public inputs of the public function. - */ - public publicInputs: PublicCircuitPublicInputs, - /** - * Proof of the call stack item execution. - */ - public readonly proof: Proof, - /** - * Hash of the L2 contract bytecode. - */ - public readonly bytecodeHash: Fr, - ) {} - - toBuffer() { - return serializeToBuffer(this.publicInputs, this.proof, this.bytecodeHash); - } - - static fromBuffer(buffer: BufferReader | Buffer) { - const reader = BufferReader.asReader(buffer); - return new PublicCallData( - reader.readObject(PublicCircuitPublicInputs), - reader.readObject(Proof), - reader.readObject(Fr), - ); - } -} diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_circuit_private_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_circuit_private_inputs.ts deleted file mode 100644 index 49698ec53de..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_circuit_private_inputs.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; - -import { PublicCallData } from './public_call_data.js'; -import { PublicKernelInnerData } from './public_kernel_inner_data.js'; - -/** - * Inputs to the public kernel circuit. - */ -export class PublicKernelInnerCircuitPrivateInputs { - constructor( - /** - * Kernels are recursive and this is the data from the previous kernel. - */ - public readonly previousKernel: PublicKernelInnerData, - /** - * Public calldata assembled from the execution result and proof. - */ - public readonly publicCall: PublicCallData, - ) {} - - /** - * Serializes the object to a buffer. - * @returns - Buffer representation of the object. - */ - toBuffer() { - return serializeToBuffer(this.previousKernel, this.publicCall); - } - - /** - * Serializes the object to a hex string. - * @returns - Hex string representation of the object. - */ - toString() { - return this.toBuffer().toString('hex'); - } - - /** - * Deserializes the object from a buffer. - * @param buffer - Buffer to deserialize. - * @returns - Deserialized object. - */ - static fromBuffer(buffer: BufferReader | Buffer) { - const reader = BufferReader.asReader(buffer); - const previousKernel = reader.readObject(PublicKernelInnerData); - const publicCall = reader.readObject(PublicCallData); - return new PublicKernelInnerCircuitPrivateInputs(previousKernel, publicCall); - } - - /** - * Deserializes the object from a hex string. - * @param str - Hex string to deserialize. - * @returns - Deserialized object. - */ - static fromString(str: string) { - return PublicKernelInnerCircuitPrivateInputs.fromBuffer(Buffer.from(str, 'hex')); - } - - /** - * Clones the object. - * @returns - Cloned object. - */ - clone() { - return PublicKernelInnerCircuitPrivateInputs.fromBuffer(this.toBuffer()); - } -} diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts deleted file mode 100644 index 5108818ae34..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; - -import { NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; -import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; -import { VerificationKeyData } from '../verification_key.js'; -import { VMCircuitPublicInputs } from './vm_circuit_public_inputs.js'; - -/** - * Data of the previous public kernel iteration in the chain of kernels. - */ -export class PublicKernelInnerData { - constructor( - /** - * Public inputs of the previous kernel. - */ - public publicInputs: VMCircuitPublicInputs, - /** - * Proof of the previous kernel. - */ - public proof: RecursiveProof, - /** - * Verification key of the previous kernel. - */ - public vk: VerificationKeyData, - ) {} - - static fromBuffer(buffer: Buffer | BufferReader): PublicKernelInnerData { - const reader = BufferReader.asReader(buffer); - return new this( - reader.readObject(VMCircuitPublicInputs), - RecursiveProof.fromBuffer(reader, NESTED_RECURSIVE_PROOF_LENGTH), - reader.readObject(VerificationKeyData), - ); - } - - static empty(): PublicKernelInnerData { - return new this( - VMCircuitPublicInputs.empty(), - makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFakeHonk(), - ); - } - - /** - * Serialize this as a buffer. - * @returns The buffer. - */ - toBuffer() { - return serializeToBuffer(this.publicInputs, this.proof, this.vk); - } -} diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 99851fe4554..dfb3ebcd89b 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -106,7 +106,6 @@ import { PrivateKernelTailCircuitPublicInputs, Proof, PublicAccumulatedData, - PublicCallData, PublicCallRequest, PublicCallStackItemCompressed, PublicCircuitPublicInputs, @@ -171,8 +170,6 @@ import { PublicDataWrite, PublicInnerCallRequest, PublicKernelCircuitPrivateInputs, - PublicKernelInnerCircuitPrivateInputs, - PublicKernelInnerData, PublicTubeData, PublicValidationRequestArrayLengths, PublicValidationRequests, @@ -769,33 +766,6 @@ function makePublicInnerCallRequest(seed = 1): PublicInnerCallRequest { return new PublicInnerCallRequest(makePublicCallStackItemCompressed(seed), seed + 0x60); } -/** - * Makes arbitrary public call data. - * @param seed - The seed to use for generating the public call data. - * @returns A public call data. - */ -export function makePublicCallData(seed = 1, full = false): PublicCallData { - const publicCallData = new PublicCallData( - makePublicCircuitPublicInputs(seed, undefined, full), - makeProof(), - fr(seed + 1), - ); - - return publicCallData; -} - -function makePublicKernelInnerData(seed = 1) { - return new PublicKernelInnerData( - makeVMCircuitPublicInputs(seed), - makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x100), - VerificationKeyData.makeFakeHonk(), - ); -} - -export function makePublicKernelInnerCircuitPrivateInputs(seed = 1) { - return new PublicKernelInnerCircuitPrivateInputs(makePublicKernelInnerData(seed), makePublicCallData(seed + 0x1000)); -} - function makeEnqueuedCallData(seed = 1) { return new EnqueuedCallData(makeVMCircuitPublicInputs(seed), makeProof()); } diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts.ts index 425ea18205c..2befc9ad5fe 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts.ts @@ -14,7 +14,6 @@ import PrivateKernelTailJson from '../artifacts/private_kernel_tail.json' assert import PrivateKernelTailSimulatedJson from '../artifacts/private_kernel_tail_simulated.json' assert { type: 'json' }; import PrivateKernelTailToPublicJson from '../artifacts/private_kernel_tail_to_public.json' assert { type: 'json' }; import PrivateKernelTailToPublicSimulatedJson from '../artifacts/private_kernel_tail_to_public_simulated.json' assert { type: 'json' }; -import PublicKernelInnerSimulatedJson from '../artifacts/public_kernel_inner_simulated.json' assert { type: 'json' }; import PublicKernelMergeSimulatedJson from '../artifacts/public_kernel_merge_simulated.json' assert { type: 'json' }; import PublicKernelTailSimulatedJson from '../artifacts/public_kernel_tail_simulated.json' assert { type: 'json' }; import PrivateBaseRollupJson from '../artifacts/rollup_base_private.json' assert { type: 'json' }; @@ -33,7 +32,6 @@ import { } from './private_kernel_reset_data.js'; // To be deprecated. -export const SimulatedPublicKernelInnerArtifact = PublicKernelInnerSimulatedJson as NoirCompiledCircuit; export const SimulatedPublicKernelMergeArtifact = PublicKernelMergeSimulatedJson as NoirCompiledCircuit; export const SimulatedPublicKernelTailArtifact = PublicKernelTailSimulatedJson as NoirCompiledCircuit; diff --git a/yarn-project/noir-protocol-circuits-types/src/index.ts b/yarn-project/noir-protocol-circuits-types/src/index.ts index bfda8a89930..c7744134bfd 100644 --- a/yarn-project/noir-protocol-circuits-types/src/index.ts +++ b/yarn-project/noir-protocol-circuits-types/src/index.ts @@ -21,12 +21,10 @@ import { type PublicBaseRollupInputs, type PublicKernelCircuitPrivateInputs, type PublicKernelCircuitPublicInputs, - type PublicKernelInnerCircuitPrivateInputs, type PublicKernelTailCircuitPrivateInputs, type RootParityInputs, type RootRollupInputs, type RootRollupPublicInputs, - type VMCircuitPublicInputs, } from '@aztec/circuits.js'; import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log'; @@ -40,7 +38,6 @@ import { ClientCircuitArtifacts, ServerCircuitArtifacts, SimulatedClientCircuitArtifacts, - SimulatedPublicKernelInnerArtifact, SimulatedPublicKernelMergeArtifact, SimulatedPublicKernelTailArtifact, SimulatedServerCircuitArtifacts, @@ -70,13 +67,11 @@ import { mapPublicBaseRollupInputsToNoir, mapPublicKernelCircuitPrivateInputsToNoir, mapPublicKernelCircuitPublicInputsFromNoir, - mapPublicKernelInnerCircuitPrivateInputsToNoir, mapPublicKernelTailCircuitPrivateInputsToNoir, mapRootParityInputsToNoir, mapRootRollupInputsToNoir, mapRootRollupPublicInputsFromNoir, mapTxRequestToNoir, - mapVMCircuitPublicInputsFromNoir, } from './type_conversion.js'; import { type ParityBaseReturnType, @@ -87,7 +82,6 @@ import { type PrivateKernelResetReturnType, type PrivateKernelTailReturnType, type PrivateKernelTailToPublicReturnType, - type PublicKernelInnerSimulatedReturnType, type PublicKernelMergeSimulatedReturnType, type PublicKernelTailSimulatedReturnType, type RollupBasePrivateReturnType, @@ -547,21 +541,6 @@ export function convertRootRollupInputsToWitnessMap(inputs: RootRollupInputs): W return initialWitnessMap; } -/** - * Converts the inputs of the public inner circuit into a witness map - * @param inputs - The public kernel inputs. - * @returns The witness map - */ -export function convertSimulatedPublicInnerInputsToWitnessMap( - inputs: PublicKernelInnerCircuitPrivateInputs, -): WitnessMap { - const mapped = mapPublicKernelInnerCircuitPrivateInputsToNoir(inputs); - const initialWitnessMap = abiEncode(SimulatedPublicKernelInnerArtifact.abi, { - input: mapped as any, - }); - return initialWitnessMap; -} - /** * Converts the inputs of the public merge circuit into a witness map * @param inputs - The public kernel inputs. @@ -781,21 +760,6 @@ export function convertRootParityOutputsFromWitnessMap(outputs: WitnessMap): Par return mapParityPublicInputsFromNoir(returnType); } -/** - * Converts the outputs of the public inner circuit from a witness map. - * @param outputs - The public kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertSimulatedPublicInnerOutputFromWitnessMap(outputs: WitnessMap): VMCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(SimulatedPublicKernelInnerArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PublicKernelInnerSimulatedReturnType; - - return mapVMCircuitPublicInputsFromNoir(returnType); -} - /** * Converts the outputs of the public merge circuit from a witness map. * @param outputs - The public kernel outputs as a witness map. diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts index 550e09f800c..ea26faf2102 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts @@ -15,7 +15,6 @@ const circuits = [ 'private_kernel_reset', 'private_kernel_tail', 'private_kernel_tail_to_public', - 'public_kernel_inner_simulated', 'public_kernel_merge_simulated', 'public_kernel_tail_simulated', 'rollup_base_private', diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index d67d6ade8f6..d0f18bc0edb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -103,7 +103,6 @@ import { PublicAccumulatedData, PublicAccumulatedDataArrayLengths, type PublicBaseRollupInputs, - type PublicCallData, PublicCallRequest, PublicCallStackItemCompressed, type PublicCircuitPublicInputs, @@ -118,8 +117,6 @@ import { type PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs, type PublicKernelData, - type PublicKernelInnerCircuitPrivateInputs, - type PublicKernelInnerData, type PublicKernelTailCircuitPrivateInputs, type PublicKeys, type PublicTubeData, @@ -240,7 +237,6 @@ import type { PublicAccumulatedDataArrayLengths as PublicAccumulatedDataArrayLengthsNoir, PublicAccumulatedData as PublicAccumulatedDataNoir, PublicBaseRollupInputs as PublicBaseRollupInputsNoir, - PublicCallData as PublicCallDataNoir, PublicCallRequest as PublicCallRequestNoir, PublicCallStackItemCompressed as PublicCallStackItemCompressedNoir, PublicCircuitPublicInputs as PublicCircuitPublicInputsNoir, @@ -254,8 +250,6 @@ import type { PublicInnerCallRequest as PublicInnerCallRequestNoir, PublicKernelCircuitPublicInputs as PublicKernelCircuitPublicInputsNoir, PublicKernelData as PublicKernelDataNoir, - PublicKernelInnerCircuitPrivateInputs as PublicKernelInnerCircuitPrivateInputsNoir, - PublicKernelInnerData as PublicKernelInnerDataNoir, PublicKernelMergeCircuitPrivateInputs as PublicKernelMergeCircuitPrivateInputsNoir, PublicKernelTailCircuitPrivateInputs as PublicKernelTailCircuitPrivateInputsNoir, PublicKeys as PublicKeysNoir, @@ -1760,14 +1754,6 @@ function mapPublicKernelDataToNoir(publicKernelData: PublicKernelData): PublicKe }; } -function mapPublicKernelInnerDataToNoir(publicKernelData: PublicKernelInnerData): PublicKernelInnerDataNoir { - return { - public_inputs: mapVMCircuitPublicInputsToNoir(publicKernelData.publicInputs), - proof: mapRecursiveProofToNoir(publicKernelData.proof), - vk: mapVerificationKeyToNoir(publicKernelData.vk.keyAsFields, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), - }; -} - export function mapVerificationKeyToNoir( key: VerificationKeyAsFields, length: N, @@ -1905,15 +1891,6 @@ export function mapPrivateKernelResetHintsToNoir< }; } -export function mapPublicKernelInnerCircuitPrivateInputsToNoir( - inputs: PublicKernelInnerCircuitPrivateInputs, -): PublicKernelInnerCircuitPrivateInputsNoir { - return { - previous_kernel: mapPublicKernelInnerDataToNoir(inputs.previousKernel), - public_call: mapPublicCallDataToNoir(inputs.publicCall), - }; -} - export function mapPublicKernelCircuitPrivateInputsToNoir( inputs: PublicKernelCircuitPrivateInputs, ): PublicKernelMergeCircuitPrivateInputsNoir { @@ -2152,19 +2129,6 @@ export function mapBlockRootOrBlockMergePublicInputsToNoir( }; } -/** - * Maps a public call data to noir. - * @param publicCall - The public call data. - * @returns The noir public call data. - */ -function mapPublicCallDataToNoir(publicCall: PublicCallData): PublicCallDataNoir { - return { - public_inputs: mapPublicCircuitPublicInputsToNoir(publicCall.publicInputs), - proof: {}, - bytecode_hash: mapFieldToNoir(publicCall.bytecodeHash), - }; -} - function mapVMCircuitPublicInputsToNoir(inputs: VMCircuitPublicInputs): VMCircuitPublicInputsNoir { return { constants: mapCombinedConstantDataToNoir(inputs.constants), diff --git a/yarn-project/prover-client/src/prover-agent/rpc.ts b/yarn-project/prover-client/src/prover-agent/rpc.ts index ff2a003db2a..46b10ddd99a 100644 --- a/yarn-project/prover-client/src/prover-agent/rpc.ts +++ b/yarn-project/prover-client/src/prover-agent/rpc.ts @@ -25,7 +25,6 @@ import { RootRollupInputs, RootRollupPublicInputs, TubeInputs, - VMCircuitPublicInputs, VerificationKeyData, } from '@aztec/circuits.js'; import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; @@ -51,7 +50,6 @@ export function createProvingJobSourceServer(queue: ProvingJobSource): JsonRpcSe Proof, ProvingError, PrivateKernelEmptyInputData, - VMCircuitPublicInputs, PublicKernelCircuitPublicInputs, RecursiveProof, RootParityInput, @@ -90,7 +88,6 @@ export function createProvingJobSourceClient( Proof, ProvingError, PrivateKernelEmptyInputData, - VMCircuitPublicInputs, PublicKernelCircuitPublicInputs, RecursiveProof, RootParityInput, diff --git a/yarn-project/simulator/src/public/enqueued_call_simulator.ts b/yarn-project/simulator/src/public/enqueued_call_simulator.ts index 43e8bbc4a6b..39ffa0e8fd1 100644 --- a/yarn-project/simulator/src/public/enqueued_call_simulator.ts +++ b/yarn-project/simulator/src/public/enqueued_call_simulator.ts @@ -35,7 +35,6 @@ import { NoteHash, Nullifier, PublicAccumulatedDataArrayLengths, - PublicCallData, type PublicCallRequest, PublicCircuitPublicInputs, PublicInnerCallRequest, @@ -44,7 +43,6 @@ import { RevertCode, TreeLeafReadRequest, type VMCircuitPublicInputs, - makeEmptyProof, } from '@aztec/circuits.js'; import { computeVarArgsHash } from '@aztec/circuits.js/hash'; import { padArrayEnd } from '@aztec/foundation/collection'; @@ -155,8 +153,8 @@ export class EnqueuedCallSimulator { avmCallResult, fnName, ); - const callData = await this.getPublicCallData(deprecatedFunctionCallResult); - avmProvingRequest = makeAvmProvingRequest(callData.publicInputs, deprecatedFunctionCallResult); + const publicInputs = await this.getPublicCircuitPublicInputs(deprecatedFunctionCallResult); + avmProvingRequest = makeAvmProvingRequest(publicInputs, deprecatedFunctionCallResult); } else { avmProvingRequest = emptyAvmProvingRequest(); } @@ -207,18 +205,6 @@ export class EnqueuedCallSimulator { return [...ko.end.nullifiers, ...ko.endNonRevertibleData.nullifiers].filter(n => !n.isEmpty()); } - /** - * Calculates the PublicCircuitOutput for this execution result along with its proof, - * and assembles a PublicCallData object from it. - * @param result - The execution result. - * @returns A corresponding PublicCallData object. - */ - private async getPublicCallData(result: PublicFunctionCallResult) { - const bytecodeHash = await this.getBytecodeHash(result); - const publicInputs = await this.getPublicCircuitPublicInputs(result); - return new PublicCallData(publicInputs, makeEmptyProof(), bytecodeHash); - } - private async getPublicCircuitPublicInputs(result: PublicFunctionCallResult) { const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE); this.historicalHeader.state.partial.publicDataTree.root = Fr.fromBuffer(publicDataTreeInfo.root); diff --git a/yarn-project/simulator/src/public/public_kernel.ts b/yarn-project/simulator/src/public/public_kernel.ts index 4a8c9198aa8..146c3441f23 100644 --- a/yarn-project/simulator/src/public/public_kernel.ts +++ b/yarn-project/simulator/src/public/public_kernel.ts @@ -2,18 +2,13 @@ import { type KernelCircuitPublicInputs, type PublicKernelCircuitPrivateInputs, type PublicKernelCircuitPublicInputs, - type PublicKernelInnerCircuitPrivateInputs, type PublicKernelTailCircuitPrivateInputs, - type VMCircuitPublicInputs, } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { elapsed } from '@aztec/foundation/timer'; import { - SimulatedPublicKernelInnerArtifact, SimulatedPublicKernelMergeArtifact, SimulatedPublicKernelTailArtifact, - convertSimulatedPublicInnerInputsToWitnessMap, - convertSimulatedPublicInnerOutputFromWitnessMap, convertSimulatedPublicMergeInputsToWitnessMap, convertSimulatedPublicMergeOutputFromWitnessMap, convertSimulatedPublicTailInputsToWitnessMap, @@ -31,27 +26,6 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu constructor(private simulator: SimulationProvider) {} - /** - * Simulates the public kernel setup circuit from its inputs. - * @param input - Inputs to the circuit. - * @returns The public inputs as outputs of the simulation. - */ - public async publicKernelCircuitInner(input: PublicKernelInnerCircuitPrivateInputs): Promise { - const inputWitness = convertSimulatedPublicInnerInputsToWitnessMap(input); - const [duration, witness] = await elapsed(() => - this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelInnerArtifact), - ); - const result = convertSimulatedPublicInnerOutputFromWitnessMap(witness); - this.log.debug(`Simulated public kernel inner circuit`, { - eventName: 'circuit-simulation', - circuitName: 'public-kernel-inner', - duration, - inputSize: input.toBuffer().length, - outputSize: result.toBuffer().length, - }); - return result; - } - /** * Simulates the public kernel app logic circuit from its inputs. * @param input - Inputs to the circuit. diff --git a/yarn-project/simulator/src/public/public_kernel_circuit_simulator.ts b/yarn-project/simulator/src/public/public_kernel_circuit_simulator.ts index e779d45bf79..36f26b36c4a 100644 --- a/yarn-project/simulator/src/public/public_kernel_circuit_simulator.ts +++ b/yarn-project/simulator/src/public/public_kernel_circuit_simulator.ts @@ -2,21 +2,13 @@ import { type KernelCircuitPublicInputs, type PublicKernelCircuitPrivateInputs, type PublicKernelCircuitPublicInputs, - type PublicKernelInnerCircuitPrivateInputs, type PublicKernelTailCircuitPrivateInputs, - type VMCircuitPublicInputs, } from '@aztec/circuits.js'; /** * Circuit simulator for the public kernel circuits. */ export interface PublicKernelCircuitSimulator { - /** - * Simulates the public kernel inner circuit from its inputs. - * @param inputs - Inputs to the circuit. - * @returns The public inputs as outputs of the simulation. - */ - publicKernelCircuitInner(inputs: PublicKernelInnerCircuitPrivateInputs): Promise; /** * Simulates the public kernel merge circuit from its inputs. * @param inputs - Inputs to the circuit. From 4f80449047582eb9fae71d4ab8ffa6159b088a78 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Sat, 9 Nov 2024 11:02:35 +0000 Subject: [PATCH 2/4] Remove output validators. --- .../enqueued_call_data_validator.nr | 35 -- .../public-kernel-lib/src/components/mod.nr | 3 - .../components/previous_kernel_validator.nr | 65 --- .../public_kernel_output_validator.nr | 413 ------------------ .../components/public_tail_output_composer.nr | 3 +- .../combine_data.nr | 21 +- .../generate_output_hints.nr | 107 +---- ...generate_overridable_public_data_writes.nr | 18 +- .../generate_public_data_leaves.nr | 14 +- .../public_tail_output_validator.nr | 253 ----------- .../validate_linked_public_data_writes.nr | 254 ----------- .../validate_public_data_leaf_memberships.nr | 36 -- .../validate_unique_leaf_slots.nr | 160 ------- .../src/public_kernel_merge.nr | 36 +- .../src/public_kernel_tail.nr | 20 +- 15 files changed, 38 insertions(+), 1400 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_kernel_output_validator.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_linked_public_data_writes.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_public_data_leaf_memberships.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_unique_leaf_slots.nr diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/enqueued_call_data_validator.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/enqueued_call_data_validator.nr index a760da90143..e09e427bfeb 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/enqueued_call_data_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/enqueued_call_data_validator.nr @@ -20,10 +20,6 @@ impl EnqueuedCallDataValidator { EnqueuedCallDataValidator { enqueued_call, phase } } - pub fn validate_proof(_self: Self) { - // TODO - } - pub fn validate(self) { self.validate_revert_flag() } @@ -31,19 +27,11 @@ impl EnqueuedCallDataValidator { pub fn validate_against_previous_kernel( self, previous_kernel: PublicKernelCircuitPublicInputs, - previous_validation_request_array_lengths: PublicValidationRequestArrayLengths, - previous_non_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, - previous_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, ) { self.validate_global_variables(previous_kernel); self.validate_against_call_request(previous_kernel); self.validate_start_gas(previous_kernel); self.validate_transaction_fee(previous_kernel); - self.validate_array_lengths( - previous_validation_request_array_lengths, - previous_non_revertible_data_array_lengths, - previous_revertible_data_array_lengths, - ); } fn validate_revert_flag(self) { @@ -138,27 +126,4 @@ impl EnqueuedCallDataValidator { ); } } - - fn validate_array_lengths( - self, - previous_validation_request_array_lengths: PublicValidationRequestArrayLengths, - previous_non_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, - previous_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, - ) { - assert_eq( - self.enqueued_call.data.previous_validation_request_array_lengths, - previous_validation_request_array_lengths, - "mismatch previous_validation_request_array_lengths", - ); - let prev_lengths = if self.phase == PublicKernelPhase.SETUP { - previous_non_revertible_data_array_lengths - } else { - previous_revertible_data_array_lengths - }; - assert_eq( - self.enqueued_call.data.previous_accumulated_data_array_lengths, - prev_lengths, - "mismatch previous_accumulated_data_array_lengths", - ); - } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr index 85870154be1..ffaa2d88a5c 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/mod.nr @@ -1,6 +1,3 @@ mod enqueued_call_data_validator; -mod previous_kernel_validator; mod public_kernel_output_composer; -mod public_kernel_output_validator; mod public_tail_output_composer; -mod public_tail_output_validator; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr deleted file mode 100644 index 5d6d9453d05..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr +++ /dev/null @@ -1,65 +0,0 @@ -use crate::public_kernel_phase::PublicKernelPhase; -use dep::types::abis::public_kernel_data::PublicKernelData; - -pub struct PreviousKernelValidator { - previous_kernel: PublicKernelData, -} - -impl PreviousKernelValidator { - pub fn new(previous_kernel: PublicKernelData) -> Self { - PreviousKernelValidator { previous_kernel } - } - - pub fn validate_proof(self, allowed_indices: [u32; N]) { - if !dep::std::runtime::is_unconstrained() { - // Recursively verify the tube proof or a previous public kernel proof - self.previous_kernel.verify(); - self.previous_kernel.validate_in_vk_tree(allowed_indices); - } - } - - pub fn validate_phase(self, phase: u8) { - let public_inputs = self.previous_kernel.public_inputs; - - let needs_setup = - !public_inputs.end_non_revertible.public_call_stack[0].contract_address.is_zero(); - if phase == PublicKernelPhase.SETUP { - assert_eq(needs_setup, true, "Cannot run unnecessary setup circuit"); - } - - let needs_app_logic = !public_inputs.end.public_call_stack[0].contract_address.is_zero(); - if phase == PublicKernelPhase.APP_LOGIC { - assert_eq(needs_setup, false, "Cannot run app logic circuit before setup circuit"); - assert_eq(needs_app_logic, true, "Cannot run unnecessary app logic circuit"); - } - - let needs_teardown = !public_inputs.public_teardown_call_request.contract_address.is_zero(); - if phase == PublicKernelPhase.TEARDOWN { - assert_eq(needs_setup, false, "Cannot run teardown circuit before setup circuit"); - assert_eq( - needs_app_logic, - false, - "Cannot run teardown circuit before app logic circuit", - ); - assert_eq(needs_teardown, true, "Cannot run unnecessary teardown circuit"); - } - - if phase == PublicKernelPhase.TAIL { - assert_eq( - needs_setup, - false, - "Revertible call stack must be empty when executing the tail circuit", - ); - assert_eq( - needs_app_logic, - false, - "Non-revertible call stack must be empty when executing the tail circuit", - ); - assert_eq( - needs_teardown, - false, - "Teardown call stack must be empty when executing the tail circuit", - ); - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_kernel_output_validator.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_kernel_output_validator.nr deleted file mode 100644 index d54de5d49e6..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_kernel_output_validator.nr +++ /dev/null @@ -1,413 +0,0 @@ -use crate::public_kernel_phase::PublicKernelPhase; -use dep::types::{ - abis::{ - accumulated_data::public_accumulated_data::{ - PublicAccumulatedData, PublicAccumulatedDataArrayLengths, - }, - kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, VMCircuitPublicInputs}, - validation_requests::public_validation_requests::PublicValidationRequestArrayLengths, - }, - traits::is_empty, - utils::arrays::{array_length, assert_array_appended, assert_array_prepended}, -}; - -pub struct PublicKernelOutputValidator { - output: PublicKernelCircuitPublicInputs, - previous_kernel: PublicKernelCircuitPublicInputs, - enqueued_call: VMCircuitPublicInputs, - phase: u8, - revertible: bool, - previous_validation_request_array_lengths: PublicValidationRequestArrayLengths, - previous_non_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, - previous_revertible_data_array_lengths: PublicAccumulatedDataArrayLengths, -} - -impl PublicKernelOutputValidator { - pub fn new( - output: PublicKernelCircuitPublicInputs, - previous_kernel: PublicKernelCircuitPublicInputs, - enqueued_call: VMCircuitPublicInputs, - phase: u8, - ) -> Self { - let revertible = phase != PublicKernelPhase.SETUP; - let previous_validation_request_array_lengths = - PublicValidationRequestArrayLengths::new(previous_kernel.validation_requests); - let previous_non_revertible_data_array_lengths = - PublicAccumulatedDataArrayLengths::new(previous_kernel.end_non_revertible); - let previous_revertible_data_array_lengths = - PublicAccumulatedDataArrayLengths::new(previous_kernel.end); - PublicKernelOutputValidator { - output, - previous_kernel, - enqueued_call, - phase, - revertible, - previous_validation_request_array_lengths, - previous_non_revertible_data_array_lengths, - previous_revertible_data_array_lengths, - } - } - - pub fn validate(self) { - self.validate_constants(); - self.validate_validation_requests(); - self.validate_accumulated_data(); - self.validate_end_side_effect_counter(); - self.validate_public_teardown_call_request(); - self.validate_fee_payer(); - self.validate_revert_code(); - } - - fn validate_constants(self) { - let prev = self.previous_kernel.constants; - let out = self.output.constants; - assert_eq(out.historical_header, prev.historical_header, "mismatch historical_header"); - assert_eq(out.tx_context, prev.tx_context, "mismatch tx_context"); - assert_eq(out.vk_tree_root, prev.vk_tree_root, "mismatch vk_tree_root"); - assert_eq( - out.protocol_contract_tree_root, - prev.protocol_contract_tree_root, - "mismatch protocol_contract_tree_root", - ); - assert_eq( - out.global_variables, - self.enqueued_call.constants.global_variables, - "mismatch global_variables", - ); - } - - fn validate_public_teardown_call_request(self) { - let out = self.output.public_teardown_call_request; - if self.phase == PublicKernelPhase.TEARDOWN { - assert(is_empty(out), "public_teardown_call_request must be empty after teardown"); - } else { - assert_eq( - out, - self.previous_kernel.public_teardown_call_request, - "mismatch public_teardown_call_request", - ); - } - } - - fn validate_fee_payer(self) { - assert_eq(self.output.fee_payer, self.previous_kernel.fee_payer, "mismatch fee payer"); - } - - fn validate_validation_requests(self) { - self.validate_validation_requests_from_previous_kernel(); - self.validate_validation_requests_from_enqueued_call(); - } - - fn validate_validation_requests_from_previous_kernel(self) { - let out = self.output.validation_requests; - let prev = self.previous_kernel.validation_requests; - let prev_lengths = self.previous_validation_request_array_lengths; - - assert_eq(out.for_rollup, prev.for_rollup); - - assert_array_prepended( - out.note_hash_read_requests, - prev.note_hash_read_requests, - prev_lengths.note_hash_read_requests, - ); - - assert_array_prepended( - out.nullifier_read_requests, - prev.nullifier_read_requests, - prev_lengths.nullifier_read_requests, - ); - - assert_array_prepended( - out.nullifier_non_existent_read_requests, - prev.nullifier_non_existent_read_requests, - prev_lengths.nullifier_non_existent_read_requests, - ); - - assert_array_prepended( - out.l1_to_l2_msg_read_requests, - prev.l1_to_l2_msg_read_requests, - prev_lengths.l1_to_l2_msg_read_requests, - ); - - assert_array_prepended( - out.public_data_reads, - prev.public_data_reads, - prev_lengths.public_data_reads, - ); - } - - fn validate_validation_requests_from_enqueued_call(self) { - let out = self.output.validation_requests; - let curr = self.enqueued_call.validation_requests; - let curr_lengths = PublicValidationRequestArrayLengths::new(curr); - let prev_lengths = self.previous_validation_request_array_lengths; - - // Note that the enqueued call cannot modify the max block number value - it simply forwards it to the rollup. - assert_array_appended( - out.note_hash_read_requests, - curr.note_hash_read_requests, - curr_lengths.note_hash_read_requests, - prev_lengths.note_hash_read_requests, - ); - - assert_array_appended( - out.nullifier_read_requests, - curr.nullifier_read_requests, - curr_lengths.nullifier_read_requests, - prev_lengths.nullifier_read_requests, - ); - - assert_array_appended( - out.nullifier_non_existent_read_requests, - curr.nullifier_non_existent_read_requests, - curr_lengths.nullifier_non_existent_read_requests, - prev_lengths.nullifier_non_existent_read_requests, - ); - - assert_array_appended( - out.l1_to_l2_msg_read_requests, - curr.l1_to_l2_msg_read_requests, - curr_lengths.l1_to_l2_msg_read_requests, - prev_lengths.l1_to_l2_msg_read_requests, - ); - - assert_array_appended( - out.public_data_reads, - curr.public_data_reads, - curr_lengths.public_data_reads, - prev_lengths.public_data_reads, - ); - } - - fn validate_accumulated_data(self) { - // TODO: Should keep the data even when reverts. - let revert_in_phase = (self.output.revert_code != 0) - & ((self.phase != PublicKernelPhase.TEARDOWN) | (self.output.revert_code != 1)); // Revert in APP_LOGIC - self.validate_accumulated_data_from_private(revert_in_phase); - self.validate_combined_accumulated_data(revert_in_phase); - self.validate_gas_used(); - } - - fn validate_accumulated_data_from_private(self, revert_in_phase: bool) { - let out = self.output.end_non_revertible; - let prev = self.previous_kernel.end_non_revertible; - assert_eq( - out.note_encrypted_logs_hashes, - prev.note_encrypted_logs_hashes, - "mismatch non-revertible note_encrypted_logs_hashes", - ); - assert_eq( - out.encrypted_logs_hashes, - prev.encrypted_logs_hashes, - "mismatch non-revertible encrypted_logs_hashes", - ); - - let out = self.output.end; - let prev = self.previous_kernel.end; - if revert_in_phase { - assert_eq( - array_length(out.note_encrypted_logs_hashes), - 0, - "revertible note_encrypted_logs_hashes must be cleared after revert", - ); - assert_eq( - array_length(out.encrypted_logs_hashes), - 0, - "revertible encrypted_logs_hashes must be cleared after revert", - ); - } else { - assert_eq( - out.note_encrypted_logs_hashes, - prev.note_encrypted_logs_hashes, - "mismatch revertible note_encrypted_logs_hashes", - ); - assert_eq( - out.encrypted_logs_hashes, - prev.encrypted_logs_hashes, - "mismatch revertible encrypted_logs_hashes", - ); - } - } - - fn validate_combined_accumulated_data(self, revert_in_phase: bool) { - // Prepended from previous kernel. - let out_non_revertible = self.output.end_non_revertible; - let out_revertible = self.output.end; - let prev_non_revertible = self.previous_kernel.end_non_revertible; - let prev_revertible = self.previous_kernel.end; - let mut prev_non_revertible_lengths = self.previous_non_revertible_data_array_lengths; - let mut prev_revertible_lengths = self.previous_revertible_data_array_lengths; - let empty_lengths = PublicAccumulatedDataArrayLengths::empty(); - - if self.phase == PublicKernelPhase.SETUP { - prev_non_revertible_lengths.public_call_stack -= 1; - } else if self.phase == PublicKernelPhase.APP_LOGIC { - prev_revertible_lengths.public_call_stack -= 1; - } - - self.validate_prepended_accumulated_data( - out_non_revertible, - prev_non_revertible, - prev_non_revertible_lengths, - ); - let prepended_revertible_lengths = if revert_in_phase { - empty_lengths - } else { - prev_revertible_lengths - }; - self.validate_prepended_accumulated_data( - out_revertible, - prev_revertible, - prepended_revertible_lengths, - ); - - // Appended from enqueued call. - let curr_data = self.enqueued_call.accumulated_data; - let curr_lengths = PublicAccumulatedDataArrayLengths::new(curr_data); - let appended_non_revertible_lengths = if self.revertible { - empty_lengths - } else { - curr_lengths - }; - let appended_revertible_lengths = if self.revertible & !revert_in_phase { - curr_lengths - } else { - empty_lengths - }; - self.validate_appended_accumulated_data( - out_non_revertible, - curr_data, - prev_non_revertible_lengths, - appended_non_revertible_lengths, - ); - self.validate_appended_accumulated_data( - out_revertible, - curr_data, - prev_revertible_lengths, - appended_revertible_lengths, - ); - } - - fn validate_prepended_accumulated_data( - _self: Self, - out: PublicAccumulatedData, - prev: PublicAccumulatedData, - lengths: PublicAccumulatedDataArrayLengths, - ) { - assert_array_prepended(out.note_hashes, prev.note_hashes, lengths.note_hashes); - assert_array_prepended(out.nullifiers, prev.nullifiers, lengths.nullifiers); - assert_array_prepended(out.l2_to_l1_msgs, prev.l2_to_l1_msgs, lengths.l2_to_l1_msgs); - assert_array_prepended( - out.unencrypted_logs_hashes, - prev.unencrypted_logs_hashes, - lengths.unencrypted_logs_hashes, - ); - assert_array_prepended( - out.public_data_update_requests, - prev.public_data_update_requests, - lengths.public_data_update_requests, - ); - assert_array_prepended( - out.public_call_stack, - prev.public_call_stack, - lengths.public_call_stack, - ); - } - - fn validate_appended_accumulated_data( - _self: Self, - out: PublicAccumulatedData, - curr: PublicAccumulatedData, - prev_lengths: PublicAccumulatedDataArrayLengths, - curr_lengths: PublicAccumulatedDataArrayLengths, - ) { - assert_array_appended( - out.note_hashes, - curr.note_hashes, - curr_lengths.note_hashes, - prev_lengths.note_hashes, - ); - assert_array_appended( - out.nullifiers, - curr.nullifiers, - curr_lengths.nullifiers, - prev_lengths.nullifiers, - ); - assert_array_appended( - out.l2_to_l1_msgs, - curr.l2_to_l1_msgs, - curr_lengths.l2_to_l1_msgs, - prev_lengths.l2_to_l1_msgs, - ); - assert_array_appended( - out.unencrypted_logs_hashes, - curr.unencrypted_logs_hashes, - curr_lengths.unencrypted_logs_hashes, - prev_lengths.unencrypted_logs_hashes, - ); - assert_array_appended( - out.public_data_update_requests, - curr.public_data_update_requests, - curr_lengths.public_data_update_requests, - prev_lengths.public_data_update_requests, - ); - } - - fn validate_gas_used(self) { - let out_non_revertible_gas_used = self.output.end_non_revertible.gas_used; - let out_revertible_gas_used = self.output.end.gas_used; - let curr_gas_used = self.enqueued_call.accumulated_data.gas_used; - let mut expected_non_revertible_gas_used = self.previous_kernel.end_non_revertible.gas_used; - let mut expected_revertible_gas_used = self.previous_kernel.end.gas_used; - if self.phase == PublicKernelPhase.SETUP { - expected_non_revertible_gas_used += curr_gas_used; - } else if self.phase == PublicKernelPhase.APP_LOGIC { - expected_revertible_gas_used += curr_gas_used; - } - assert_eq( - out_non_revertible_gas_used, - expected_non_revertible_gas_used, - "wrong non-revertible gas used", - ); - assert_eq( - out_revertible_gas_used, - expected_revertible_gas_used, - "wrong revertible gas used", - ); - } - - fn validate_end_side_effect_counter(self) { - assert_eq( - self.output.end_side_effect_counter, - self.enqueued_call.end_side_effect_counter, - "mismatch end_side_effect_counter", - ); - } - - fn validate_revert_code(self) { - if self.phase == PublicKernelPhase.SETUP { - // enqueued_call.reverted should be false. If not, EnqueuedCallDataValidator > validate_revert_flag will fail. - assert_eq(self.output.revert_code, 0, "expected revert code to be 0"); - } - - let prev = self.previous_kernel.revert_code; - let out = self.output.revert_code; - if !self.enqueued_call.reverted { - assert_eq(out, prev, "mismatch revert code"); - } else { - if self.phase == PublicKernelPhase.APP_LOGIC { - assert_eq(out, 1, "expected revert code to be 1"); - } - if self.phase == PublicKernelPhase.TEARDOWN { - // See https://docs.aztec.network/protocol-specs/gas-and-fees/kernel-tracking#handling-reverts - if prev == 0 { - // Case where there is a new error in teardown - assert_eq(out, 2, "expected revert code to be 2"); - } else { - // Case where there is an error in both app logic and teardown - assert_eq(out, 3, "expected revert code to be 3"); - }; - } - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer.nr index 70f8219bf52..788fd4eff55 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer.nr @@ -3,8 +3,7 @@ mod generate_output_hints; mod generate_overridable_public_data_writes; mod generate_public_data_leaves; -pub use generate_output_hints::{OutputHints, SiloedNoteHashHint}; -pub use generate_overridable_public_data_writes::LinkedIndexHint; +pub use generate_output_hints::OutputHints; use crate::components::public_tail_output_composer::{ combine_data::combine_data, generate_output_hints::generate_output_hints, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/combine_data.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/combine_data.nr index d4846909eeb..2e0c5f4fbc8 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/combine_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/combine_data.nr @@ -7,6 +7,8 @@ use dep::types::{ public_data_update_request::PublicDataUpdateRequest, public_data_write::PublicDataWrite, }, + constants::MAX_NOTE_HASHES_PER_TX, + hash::silo_note_hash, utils::arrays::{array_merge, dedupe_array, sort_by_counter_asc}, }; @@ -15,6 +17,23 @@ pub unconstrained fn combine_data( revertible: PublicAccumulatedData, output_hints: OutputHints, ) -> CombinedAccumulatedData { + // Note hashes. + let mut siloed_note_hashes = [0; MAX_NOTE_HASHES_PER_TX]; + let sorted_unsiloed_note_hashes = sort_by_counter_asc(array_merge( + non_revertible.note_hashes, + revertible.note_hashes, + )); + let tx_hash = non_revertible.nullifiers[0].value; + for i in 0..sorted_unsiloed_note_hashes.len() { + let note_hash = sorted_unsiloed_note_hashes[i]; + siloed_note_hashes[i] = if note_hash.counter() == 0 { + // If counter is zero, the note hash is either empty or is emitted from private and has been siloed in private_kernel_tail_to_public. + note_hash.value() + } else { + silo_note_hash(note_hash, tx_hash, i) + }; + } + let nullifiers = sort_by_counter_asc(array_merge( non_revertible.nullifiers, revertible.nullifiers, @@ -54,7 +73,7 @@ pub unconstrained fn combine_data( unencrypted_logs_hashes.fold(0, |a, b: ScopedLogHash| a + b.log_hash.length); CombinedAccumulatedData { - note_hashes: output_hints.siloed_note_hashes, + note_hashes: siloed_note_hashes, nullifiers, l2_to_l1_msgs, note_encrypted_logs_hashes, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_output_hints.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_output_hints.nr index e36f4ef41a8..c87831fc683 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_output_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_output_hints.nr @@ -1,7 +1,5 @@ use crate::components::public_tail_output_composer::{ - generate_overridable_public_data_writes::{ - generate_overridable_public_data_writes, LinkedIndexHint, - }, + generate_overridable_public_data_writes::generate_overridable_public_data_writes, generate_public_data_leaves::generate_public_data_leaves, }; use dep::types::{ @@ -9,124 +7,31 @@ use dep::types::{ kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, public_data_write::OverridablePublicDataWrite, }, - constants::{ - MAX_ENCRYPTED_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, - MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - MAX_UNENCRYPTED_LOGS_PER_TX, - }, + constants::MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, data::{OverridablePublicDataTreeLeaf, PublicDataLeafHint}, - hash::silo_note_hash, - traits::Empty, - utils::arrays::{ - array_merge, CombinedOrderHint, get_combined_order_hints_asc, sort_by_counter_asc, - SortedResult, - }, + utils::arrays::array_merge, }; -pub struct SiloedNoteHashHint { - siloed_note_hash: Field, - index: u32, -} - -impl Empty for SiloedNoteHashHint { - fn empty() -> Self { - SiloedNoteHashHint { siloed_note_hash: 0, index: 0 } - } -} - -impl Eq for SiloedNoteHashHint { - fn eq(self, other: Self) -> bool { - (self.siloed_note_hash == other.siloed_note_hash) & (self.index == other.index) - } -} - pub struct OutputHints { - siloed_note_hashes: [Field; MAX_NOTE_HASHES_PER_TX], - siloed_note_hash_hints: [SiloedNoteHashHint; MAX_NOTE_HASHES_PER_TX], - sorted_note_hash_hints: [CombinedOrderHint; MAX_NOTE_HASHES_PER_TX], - sorted_nullifier_hints: [CombinedOrderHint; MAX_NULLIFIERS_PER_TX], - sorted_l2_to_l1_msg_hints: [CombinedOrderHint; MAX_L2_TO_L1_MSGS_PER_TX], - sorted_note_encrypted_log_hash_hints: [CombinedOrderHint; MAX_NOTE_ENCRYPTED_LOGS_PER_TX], - sorted_encrypted_log_hash_hints: [CombinedOrderHint; MAX_ENCRYPTED_LOGS_PER_TX], - sorted_unencrypted_log_hash_hints: [CombinedOrderHint; MAX_UNENCRYPTED_LOGS_PER_TX], public_data_writes: [OverridablePublicDataWrite; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], public_data_leaves: [OverridablePublicDataTreeLeaf; NUM_PUBLIC_DATA_LEAVES], - unique_slot_index_hints: SortedResult, - public_data_linked_index_hints: [LinkedIndexHint; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } pub unconstrained fn generate_output_hints( previous_kernel: PublicKernelCircuitPublicInputs, public_data_leaf_hints: [PublicDataLeafHint; NUM_PUBLIC_DATA_LEAVES], ) -> OutputHints { - let non_revertible = previous_kernel.end_non_revertible; - let revertible = previous_kernel.end; - - // Note hashes. - let mut siloed_note_hashes = [0; MAX_NOTE_HASHES_PER_TX]; - let mut siloed_note_hash_hints = [SiloedNoteHashHint::empty(); MAX_NOTE_HASHES_PER_TX]; - let sorted_unsiloed_note_hashes = sort_by_counter_asc(array_merge( - non_revertible.note_hashes, - revertible.note_hashes, - )); - let tx_hash = non_revertible.nullifiers[0].value; - for i in 0..sorted_unsiloed_note_hashes.len() { - let note_hash = sorted_unsiloed_note_hashes[i]; - let siloed_note_hash = if note_hash.counter() == 0 { - // If counter is zero, the note hash is either empty or is emitted from private and has been siloed in private_kernel_tail_to_public. - note_hash.value() - } else { - silo_note_hash(note_hash, tx_hash, i) - }; - siloed_note_hashes[i] = siloed_note_hash; - if siloed_note_hash != 0 { - siloed_note_hash_hints[i] = SiloedNoteHashHint { siloed_note_hash, index: i }; - } - } - - // Public data. let combined_writes = array_merge( previous_kernel.end_non_revertible.public_data_update_requests, previous_kernel.end.public_data_update_requests, ); - let (public_data_leaves, unique_slot_index_hints) = generate_public_data_leaves( + let public_data_leaves = generate_public_data_leaves( previous_kernel.validation_requests.public_data_reads, combined_writes, public_data_leaf_hints, ); - let (public_data_writes, public_data_linked_index_hints) = + let public_data_writes = generate_overridable_public_data_writes(combined_writes, public_data_leaves); - OutputHints { - siloed_note_hashes, - siloed_note_hash_hints, - sorted_note_hash_hints: get_combined_order_hints_asc( - non_revertible.note_hashes, - revertible.note_hashes, - ), - sorted_nullifier_hints: get_combined_order_hints_asc( - non_revertible.nullifiers, - revertible.nullifiers, - ), - sorted_l2_to_l1_msg_hints: get_combined_order_hints_asc( - non_revertible.l2_to_l1_msgs, - revertible.l2_to_l1_msgs, - ), - sorted_note_encrypted_log_hash_hints: get_combined_order_hints_asc( - non_revertible.note_encrypted_logs_hashes, - revertible.note_encrypted_logs_hashes, - ), - sorted_encrypted_log_hash_hints: get_combined_order_hints_asc( - non_revertible.encrypted_logs_hashes, - revertible.encrypted_logs_hashes, - ), - sorted_unencrypted_log_hash_hints: get_combined_order_hints_asc( - non_revertible.unencrypted_logs_hashes, - revertible.unencrypted_logs_hashes, - ), - public_data_writes, - public_data_leaves, - unique_slot_index_hints, - public_data_linked_index_hints, - } + OutputHints { public_data_writes, public_data_leaves } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_overridable_public_data_writes.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_overridable_public_data_writes.nr index e18193b31be..b19c7b9f26e 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_overridable_public_data_writes.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_composer/generate_overridable_public_data_writes.nr @@ -4,27 +4,14 @@ use dep::types::{ public_data_write::OverridablePublicDataWrite, }, data::OverridablePublicDataTreeLeaf, - traits::Empty, utils::arrays::{array_length, find_index_hint}, }; -pub struct LinkedIndexHint { - is_first_write: bool, - prev_index: u32, -} - -impl Empty for LinkedIndexHint { - fn empty() -> Self { - LinkedIndexHint { is_first_write: false, prev_index: 0 } - } -} - pub unconstrained fn generate_overridable_public_data_writes( public_data_writes: [PublicDataUpdateRequest; NUM_WRITES], public_data_leaves: [OverridablePublicDataTreeLeaf; NUM_LEAVES], -) -> ([OverridablePublicDataWrite; NUM_WRITES], [LinkedIndexHint; NUM_WRITES]) { +) -> [OverridablePublicDataWrite; NUM_WRITES] { let mut overridable_public_data_writes = [OverridablePublicDataWrite::empty(); NUM_WRITES]; - let mut hints = [LinkedIndexHint::empty(); NUM_WRITES]; let writes_len = array_length(public_data_writes); for i in 0..writes_len { @@ -59,8 +46,7 @@ pub unconstrained fn generate_overridable_public_data_writes ([OverridablePublicDataTreeLeaf; NUM_HINTS], SortedResult) { +) -> [OverridablePublicDataTreeLeaf; NUM_HINTS] { // Combine reads and writes. The combined data has the slots and original indexes. // Original indexes for writes are modified to have an offset of NUM_READS, ensuring that writes are placed after reads. let mut combined_data: BoundedVec = BoundedVec::new(); @@ -82,7 +82,6 @@ pub unconstrained fn generate_public_data_leaves { - output: KernelCircuitPublicInputs, - previous_kernel: PublicKernelCircuitPublicInputs, - start_state: PartialStateReference, - hints: OutputHints, - public_data_leaf_hints: [PublicDataLeafHint; NUM_PUBLIC_DATA_LEAVES], -} - -impl PublicTailOutputValidator { - pub fn new( - output: KernelCircuitPublicInputs, - previous_kernel: PublicKernelCircuitPublicInputs, - start_state: PartialStateReference, - hints: OutputHints, - public_data_leaf_hints: [PublicDataLeafHint; NUM_PUBLIC_DATA_LEAVES], - ) -> Self { - PublicTailOutputValidator { - output, - previous_kernel, - start_state, - hints, - public_data_leaf_hints, - } - } - - pub fn validate(self) { - self.validate_aggregated_data(); - - // CombinedAccumulatedData - self.validate_combined_siloed_note_hashes(); - self.validate_combined_data(); - self.validate_deduped_public_data_writes(); - self.validate_gas(); - } - - fn validate_aggregated_data(self) { - assert_eq( - self.output.rollup_validation_requests, - self.previous_kernel.validation_requests.for_rollup, - "mismatch rollup_validation_requests", - ); - assert_eq(self.output.constants, self.previous_kernel.constants, "mismatch constants"); - assert_eq(self.output.start_state, self.start_state, "mismatch start_state"); - assert_eq( - self.output.revert_code, - self.previous_kernel.revert_code, - "mismatch revert_code", - ); - assert_eq(self.output.fee_payer, self.previous_kernel.fee_payer, "mismatch fee_payer"); - } - - fn validate_combined_siloed_note_hashes(self) { - let non_revertible = self.previous_kernel.end_non_revertible; - let revertible = self.previous_kernel.end; - let tx_hash = self.output.end.nullifiers[0]; - let output_note_hashes = self.output.end.note_hashes; - let siloed_note_hash_hints = self.hints.siloed_note_hash_hints; - for i in 0..output_note_hashes.len() { - let output_note_hash = output_note_hashes[i]; - assert_eq(output_note_hash, siloed_note_hash_hints[i].siloed_note_hash); - if output_note_hash != 0 { - assert_eq(i, siloed_note_hash_hints[i].index); - } - } - - assert_combined_sorted_transformed_value_array_asc( - non_revertible.note_hashes, - revertible.note_hashes, - siloed_note_hash_hints, - |prev: ScopedNoteHash, out: SiloedNoteHashHint| { - let siloed_value = if prev.counter() == 0 { - // If counter is zero, the note hash is either empty or is emitted from private and has been siloed in private_kernel_tail_to_public. - prev.value() - } else { - silo_note_hash(prev, tx_hash, out.index) - }; - out.siloed_note_hash == siloed_value - }, - self.hints.sorted_note_hash_hints, - ); - } - - fn validate_combined_data(self) { - let non_revertible = self.previous_kernel.end_non_revertible; - let revertible = self.previous_kernel.end; - - // nullifiers - assert_combined_sorted_transformed_value_array_asc( - non_revertible.nullifiers, - revertible.nullifiers, - self.output.end.nullifiers, - |prev: Nullifier, out: Field| out == prev.value, - self.hints.sorted_nullifier_hints, - ); - - // l2_to_l1_msgs - assert_combined_sorted_transformed_value_array_asc( - non_revertible.l2_to_l1_msgs, - revertible.l2_to_l1_msgs, - self.output.end.l2_to_l1_msgs, - |prev: ScopedL2ToL1Message, out: ScopedL2ToL1Message| out == prev, - self.hints.sorted_l2_to_l1_msg_hints, - ); - - // note_encrypted_logs_hashes - assert_combined_sorted_transformed_value_array_asc( - non_revertible.note_encrypted_logs_hashes, - revertible.note_encrypted_logs_hashes, - self.output.end.note_encrypted_logs_hashes, - |prev: LogHash, out: LogHash| out == prev, - self.hints.sorted_note_encrypted_log_hash_hints, - ); - - let note_encrypted_log_preimages_length = - self.output.end.note_encrypted_logs_hashes.fold(0, |a, b: LogHash| a + b.length); - assert_eq( - self.output.end.note_encrypted_log_preimages_length, - note_encrypted_log_preimages_length, - ); - - // encrypted_logs_hashes - assert_combined_sorted_transformed_value_array_asc( - non_revertible.encrypted_logs_hashes, - revertible.encrypted_logs_hashes, - self.output.end.encrypted_logs_hashes, - |prev: ScopedLogHash, out: ScopedLogHash| out == prev, - self.hints.sorted_encrypted_log_hash_hints, - ); - - let encrypted_log_preimages_length = self.output.end.encrypted_logs_hashes.fold( - 0, - |a, b: ScopedLogHash| a + b.log_hash.length, - ); - assert_eq(self.output.end.encrypted_log_preimages_length, encrypted_log_preimages_length); - - // unencrypted_logs_hashes - assert_combined_sorted_transformed_value_array_asc( - non_revertible.unencrypted_logs_hashes, - revertible.unencrypted_logs_hashes, - self.output.end.unencrypted_logs_hashes, - |prev: ScopedLogHash, out: ScopedLogHash| out == prev, - self.hints.sorted_unencrypted_log_hash_hints, - ); - - let unencrypted_log_preimages_length = self.output.end.unencrypted_logs_hashes.fold( - 0, - |a, b: ScopedLogHash| a + b.log_hash.length, - ); - assert_eq( - self.output.end.unencrypted_log_preimages_length, - unencrypted_log_preimages_length, - ); - } - - fn validate_deduped_public_data_writes(self) { - validate_public_data_leaf_memberships( - self.hints.public_data_leaves, - self.public_data_leaf_hints, - self.start_state.public_data_tree.root, - ); - - // Check that public_data_writes are simply the writes in the two accumulated data arrays combined, - // with override_counter added to each non-empty write as hint. - // override_counter is checked in validate_linked_public_data_writes. - assert_combined_transformed_array( - self.previous_kernel.end_non_revertible.public_data_update_requests, - self.previous_kernel.end.public_data_update_requests, - self.hints.public_data_writes, - |from: PublicDataUpdateRequest, to: OverridablePublicDataWrite| to.write == from, - ); - - // All non-zero slots in leaves must be unique, ensuring that writes with the same leaf slot are grouped into a single linked list. - validate_unique_leaf_slots( - self.hints.public_data_leaves, - self.hints.unique_slot_index_hints, - ); - - // Validate the override_counter of writes, ensuring that they in the correct list in the correct order. - validate_linked_public_data_writes( - self.hints.public_data_writes, - self.hints.public_data_leaves, - self.hints.public_data_linked_index_hints, - ); - - // Check that the output contains the last write in each linked list. - let original_array = self.hints.public_data_writes; - let deduped_array = self.output.end.public_data_writes; - - let mut num_added = 0; - for i in 0..original_array.len() { - let original = original_array[i]; - if original.override_counter() == 0 { - let update_request = original.inner(); - assert_eq( - deduped_array[num_added], - PublicDataWrite { - leaf_slot: update_request.leaf_slot, - value: update_request.new_value, - }, - "mismatch deduped item", - ); - num_added += 1; - } - } - let mut should_be_empty = false; - for i in 0..original_array.len() { - should_be_empty |= i == num_added; - if should_be_empty { - assert( - is_empty(deduped_array[i]), - "empty items must be padded to the deduped array", - ); - } - } - } - - fn validate_gas(self) { - let gas_used = - self.previous_kernel.end_non_revertible.gas_used + self.previous_kernel.end.gas_used; - assert_eq(self.output.end.gas_used, gas_used, "incorrect output gas_used"); - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_linked_public_data_writes.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_linked_public_data_writes.nr deleted file mode 100644 index 44bea48e398..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_linked_public_data_writes.nr +++ /dev/null @@ -1,254 +0,0 @@ -use crate::components::public_tail_output_composer::LinkedIndexHint; -use dep::types::{ - abis::public_data_write::OverridablePublicDataWrite, data::OverridablePublicDataTreeLeaf, -}; - -// Check that each non-empty write is correctly linked to either a leaf or another write. -// All the writes with the same leaf slot will form a single linked list. -// Note that public_data_leaves must be verified to contain unique slots before passing to this function. -pub fn validate_linked_public_data_writes( - public_data_writes: [OverridablePublicDataWrite; NUM_WRITES], - public_data_leaves: [OverridablePublicDataTreeLeaf; NUM_LEAVES], - hints: [LinkedIndexHint; NUM_WRITES], -) { - for i in 0..public_data_writes.len() { - let write = public_data_writes[i]; - let hint = hints[i]; - if write.counter() != 0 { - if hint.is_first_write { - // It's linked to a leaf in the tree. - let data_hint = public_data_leaves[hint.prev_index]; - assert_eq( - data_hint.leaf.slot, - write.inner().leaf_slot, - "hinted leaf has different slot", - ); - assert_eq( - data_hint.override_counter, - write.counter(), - "hinted leaf does not link to current write", - ); - } else { - // It's linked to another write for the same leaf slot. - let prev = public_data_writes[hint.prev_index]; - assert_eq( - prev.inner().leaf_slot, - write.inner().leaf_slot, - "hinted write has different slot", - ); - assert( - prev.counter() < write.counter(), - "previous write must have a smaller counter", - ); - assert_eq( - prev.override_counter, - write.counter(), - "hinted previous write does not link to current write", - ); - } - } - } -} - -mod tests { - use crate::components::{ - public_tail_output_composer::LinkedIndexHint, - public_tail_output_validator::validate_linked_public_data_writes::validate_linked_public_data_writes, - }; - use dep::types::{ - abis::{ - public_data_update_request::PublicDataUpdateRequest, - public_data_write::OverridablePublicDataWrite, - }, - data::{OverridablePublicDataTreeLeaf, PublicDataTreeLeaf}, - tests::utils::pad_end, - }; - - struct TestBuilder { - public_data_writes: [OverridablePublicDataWrite; 8], - public_data_leaves: [OverridablePublicDataTreeLeaf; 12], - hints: [LinkedIndexHint; 8], - } - - impl TestBuilder { - pub fn new_empty() -> Self { - let public_data_writes = pad_end([], OverridablePublicDataWrite::empty()); - let public_data_leaves = pad_end([], OverridablePublicDataTreeLeaf::empty()); - let hints = pad_end([], LinkedIndexHint::empty()); - TestBuilder { public_data_writes, public_data_leaves, hints } - } - - pub fn new() -> Self { - let public_data_writes = pad_end( - [ - OverridablePublicDataWrite { - write: PublicDataUpdateRequest { - leaf_slot: 33, - new_value: 300, - counter: 30, - }, - override_counter: 0, - }, - OverridablePublicDataWrite { - write: PublicDataUpdateRequest { - leaf_slot: 22, - new_value: 202, - counter: 40, - }, - override_counter: 50, - }, - OverridablePublicDataWrite { - write: PublicDataUpdateRequest { - leaf_slot: 11, - new_value: 100, - counter: 10, - }, - override_counter: 0, - }, - OverridablePublicDataWrite { - write: PublicDataUpdateRequest { - leaf_slot: 22, - new_value: 201, - counter: 20, - }, - override_counter: 40, - }, - OverridablePublicDataWrite { - write: PublicDataUpdateRequest { - leaf_slot: 22, - new_value: 203, - counter: 50, - }, - override_counter: 0, - }, - ], - OverridablePublicDataWrite::empty(), - ); - - let public_data_leaves = pad_end( - [ - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot: 0, value: 0 }, - override_counter: 0, - }, - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot: 22, value: 200 }, - override_counter: 20, - }, - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot: 44, value: 0 }, - override_counter: 0, - }, - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot: 11, value: 0 }, - override_counter: 10, - }, - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot: 33, value: 0 }, - override_counter: 30, - }, - ], - OverridablePublicDataTreeLeaf::empty(), - ); - - let hints = pad_end( - [ - LinkedIndexHint { is_first_write: true, prev_index: 4 }, - LinkedIndexHint { is_first_write: false, prev_index: 3 }, - LinkedIndexHint { is_first_write: true, prev_index: 3 }, - LinkedIndexHint { is_first_write: true, prev_index: 1 }, - LinkedIndexHint { is_first_write: false, prev_index: 1 }, - ], - LinkedIndexHint::empty(), - ); - - TestBuilder { public_data_writes, public_data_leaves, hints } - } - - pub fn execute(self) { - validate_linked_public_data_writes( - self.public_data_writes, - self.public_data_leaves, - self.hints, - ); - } - } - - #[test] - fn validate_linked_public_data_writes_empty_succeeds() { - let builder = TestBuilder::new_empty(); - builder.execute(); - } - - #[test] - fn validate_linked_public_data_writes_succeeds() { - let builder = TestBuilder::new(); - builder.execute(); - } - - #[test(should_fail_with = "hinted leaf has different slot")] - fn validate_linked_public_data_writes_link_prev_to_empty_leaf_fails() { - let mut builder = TestBuilder::new(); - - // Link the first write to an empty leaf. - builder.hints[0].prev_index = 7; - - builder.execute(); - } - - #[test(should_fail_with = "hinted leaf does not link to current write")] - fn validate_linked_public_data_writes_link_two_writes_to_same_leaf_fails() { - let mut builder = TestBuilder::new(); - - // Link the write to a leaf with the same slot. - builder.hints[1] = builder.hints[3]; - - builder.execute(); - } - - #[test(should_fail_with = "hinted write has different slot")] - fn validate_linked_public_data_writes_link_prev_to_empty_write_fails() { - let mut builder = TestBuilder::new(); - - // Link the write to an empty write. - builder.hints[1].prev_index = 7; - - builder.execute(); - } - - #[test(should_fail_with = "previous write must have a smaller counter")] - fn validate_linked_public_data_writes_not_sorted_by_counter_fails() { - let mut builder = TestBuilder::new(); - - // Change from leaf -> write[3] -> write[1] -> write[4] to leaf -> write[1] -> write[3] -> write[4] - let leaf_index = builder.hints[3].prev_index; - // Link the leaf to the 1st write. - builder.public_data_leaves[leaf_index].override_counter = - builder.public_data_writes[1].counter(); - // Link the 1st write to the leaf and the 3rd write. - builder.hints[1].is_first_write = true; - builder.hints[1].prev_index = leaf_index; - builder.public_data_writes[1].override_counter = builder.public_data_writes[3].counter(); - // Link the 3rd write to the 1st write and the 4th write. - builder.hints[3].is_first_write = false; - builder.hints[3].prev_index = 1; - builder.public_data_writes[3].override_counter = builder.public_data_writes[4].counter(); - // Link the 4th write to the 3rd write. - builder.hints[4].prev_index = 3; - - builder.execute(); - } - - #[test(should_fail_with = "hinted previous write does not link to current write")] - fn validate_linked_public_data_writes_link_two_writes_to_same_prev_write_fails() { - let mut builder = TestBuilder::new(); - - // Link a write to the previous write of its previous write. - let prev_write_index = builder.hints[4].prev_index; - builder.hints[4].prev_index = 3; - // Clear the counter and link of its previous write. - builder.public_data_writes[prev_write_index].override_counter = 0; - - builder.execute(); - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_public_data_leaf_memberships.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_public_data_leaf_memberships.nr deleted file mode 100644 index c5c184ff8c2..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_public_data_leaf_memberships.nr +++ /dev/null @@ -1,36 +0,0 @@ -use dep::types::{ - data::{OverridablePublicDataTreeLeaf, PublicDataLeafHint}, - merkle_tree::conditionally_assert_check_membership, -}; - -// Perform membership check for all non-zero leaf slots, ensuring that the values being read are correct and the public data tree is updated with the correct low leaves. -// TODO: Update public data tree in the tail circuit. Otherwise, change this to just check the leaves for public data reads. -pub fn validate_public_data_leaf_memberships( - leaves: [OverridablePublicDataTreeLeaf; N], - leaf_hints: [PublicDataLeafHint; N], - tree_root: Field, -) { - for i in 0..leaves.len() { - let leaf = leaves[i].leaf; - let hint = leaf_hints[i]; - if leaf.slot != 0 { - let exists_in_tree = leaf.slot == hint.preimage.slot; - if exists_in_tree { - assert( - leaf.value == hint.preimage.value, - "Hinted public data value does not match the value in leaf preimage", - ); - } else { - assert(leaf.value == 0, "Value must be 0 for non-existent public data"); - } - - conditionally_assert_check_membership( - leaf.slot, - exists_in_tree, - hint.preimage, - hint.membership_witness, - tree_root, - ); - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_unique_leaf_slots.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_unique_leaf_slots.nr deleted file mode 100644 index e0c3ec42171..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/public_tail_output_validator/validate_unique_leaf_slots.nr +++ /dev/null @@ -1,160 +0,0 @@ -use dep::types::{data::OverridablePublicDataTreeLeaf, utils::arrays::SortedResult}; - -// Validate that every non-zero slot in leaves is unique. -pub fn validate_unique_leaf_slots( - leaves: [OverridablePublicDataTreeLeaf; N], - unique_slot_index_hints: SortedResult, -) { - let sorted_leaf_slots = unique_slot_index_hints.sorted_array; - let sorted_leaf_slot_indexes = unique_slot_index_hints.sorted_index_hints; - let original_leaf_indexes = unique_slot_index_hints.original_index_hints; - let mut prev_slot = 0; - for i in 0..N { - let leaf = leaves[i].leaf; - let sorted_index = if leaf.slot != 0 { - sorted_leaf_slot_indexes[i] - } else { - i // This ensures that sorted_leaf_slots is padded with the same amount of zero slots as leaves. - }; - let hinted_leaf_slot = sorted_leaf_slots[sorted_index]; - assert_eq(hinted_leaf_slot, leaf.slot, "mismatch hinted slot"); - assert_eq(original_leaf_indexes[sorted_index], i, "sorted value does not link to leaf"); // This ensures that each sorted_leaf_slot can only be refered to once. - let curr_leaf_alot = sorted_leaf_slots[i]; - if leaf.slot != 0 { - assert(prev_slot.lt(curr_leaf_alot), "hinted slots are not sorted"); // This ensures that all non-zero slots are unique. - } - prev_slot = curr_leaf_alot; - } -} - -mod tests { - use crate::components::public_tail_output_validator::validate_unique_leaf_slots::validate_unique_leaf_slots; - use dep::types::{ - data::{OverridablePublicDataTreeLeaf, PublicDataTreeLeaf}, - tests::utils::pad_end, - utils::arrays::SortedResult, - }; - - global NUM_TEST_LEAVES = 10; - - struct TestBuilder { - leaves: [OverridablePublicDataTreeLeaf; NUM_TEST_LEAVES], - sorted_array: [Field; NUM_TEST_LEAVES], - sorted_index_hints: [u32; NUM_TEST_LEAVES], - original_index_hints: [u32; NUM_TEST_LEAVES], - } - - impl TestBuilder { - pub fn new() -> Self { - let leaves = pad_end([], OverridablePublicDataTreeLeaf::empty()); - let sorted_array = pad_end([], 0); - let sorted_index_hints = pad_end([], 0); - let mut original_index_hints = pad_end([], 0); - for i in 0..original_index_hints.len() { - original_index_hints[i] = i; - } - TestBuilder { leaves, sorted_array, sorted_index_hints, original_index_hints } - } - - pub fn update_leaves(&mut self, slots: [Field; N]) { - let leaves = slots.map(|slot: Field| { - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf { slot, value: 1 }, - override_counter: 0, - } - }); - self.leaves = pad_end(leaves, OverridablePublicDataTreeLeaf::empty()); - } - - pub fn update_sorted_array(&mut self, sorted_values: [Field; N]) { - self.sorted_array = pad_end(sorted_values, 0); - } - - pub fn update_sorted_index_hints(&mut self, sorted_indexes: [u32; N]) { - self.sorted_index_hints = pad_end(sorted_indexes, 0); - } - - pub fn update_original_index_hints(&mut self, original_indexes: [u32; N]) { - let mut original_index_hints = pad_end(original_indexes, 0); - for i in original_indexes.len()..original_index_hints.len() { - original_index_hints[i] = i; - } - self.original_index_hints = original_index_hints; - } - - pub fn execute(self) { - let hints = SortedResult { - sorted_array: self.sorted_array, - sorted_index_hints: self.sorted_index_hints, - original_index_hints: self.original_index_hints, - }; - validate_unique_leaf_slots(self.leaves, hints); - } - } - - #[test] - fn validate_unique_leaf_slots_empty_succeeds() { - let builder = TestBuilder::new(); - builder.execute() - } - - #[test] - fn validate_unique_leaf_slots_succeeds() { - let mut builder = TestBuilder::new(); - - builder.update_leaves([22, 44, 33, 11]); - builder.update_sorted_array([11, 22, 33, 44]); - builder.update_sorted_index_hints([1, 3, 2, 0]); - builder.update_original_index_hints([3, 0, 2, 1]); - - builder.execute() - } - - #[test(should_fail_with = "sorted value does not link to leaf")] - fn validate_unique_leaf_slots_duplicates_remove_hint_fails() { - let mut builder = TestBuilder::new(); - - builder.update_leaves([22, 11, 11]); - builder.update_sorted_array([11, 22]); - builder.update_sorted_index_hints([1, 0, 0]); - builder.update_original_index_hints([1, 0]); - - builder.execute() - } - - #[test(should_fail_with = "hinted slots are not sorted")] - fn validate_unique_leaf_slots_duplicates_extra_hint_fails() { - let mut builder = TestBuilder::new(); - - builder.update_leaves([22, 11, 11]); - builder.update_sorted_array([11, 11, 22]); - builder.update_sorted_index_hints([2, 0, 1]); - builder.update_original_index_hints([1, 2, 0]); - - builder.execute() - } - - #[test(should_fail_with = "hinted slots are not sorted")] - fn validate_unique_leaf_slots_duplicates_extra_hint_in_padded_first_zero_fails() { - let mut builder = TestBuilder::new(); - - builder.update_leaves([22, 11, 11]); - builder.update_sorted_array([0, 11, 22, 0, 11]); // The first zero slot triggers the assert. - builder.update_sorted_index_hints([2, 1, 4]); - builder.update_original_index_hints([3, 1, 0, 4, 2]); - - builder.execute() - } - - #[test(should_fail_with = "mismatch hinted slot")] - fn validate_unique_leaf_slots_duplicates_extra_hint_in_padded_first_non_zero_fails() { - let mut builder = TestBuilder::new(); - - builder.update_leaves([22, 11, 11]); - builder.update_sorted_array([1, 11, 22, 0, 11]); // Change the first slot to be non-zero. - builder.update_sorted_index_hints([2, 1, 4]); - builder.update_original_index_hints([3, 1, 0, 3, 2]); - - builder.execute() - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr index 094e33dc483..34bf781b17a 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr @@ -1,9 +1,7 @@ use crate::{ components::{ enqueued_call_data_validator::EnqueuedCallDataValidator, - previous_kernel_validator::PreviousKernelValidator, public_kernel_output_composer::PublicKernelOutputComposer, - public_kernel_output_validator::PublicKernelOutputValidator, }, public_kernel_phase::PublicKernelPhase, }; @@ -13,22 +11,12 @@ use dep::types::abis::{ public_kernel_data::PublicKernelData, }; -global ALLOWED_PREVIOUS_CIRCUITS = []; - pub struct PublicKernelMergeCircuitPrivateInputs { previous_kernel: PublicKernelData, enqueued_call: EnqueuedCallData, } impl PublicKernelMergeCircuitPrivateInputs { - unconstrained fn generate_output(self, phase: u8) -> PublicKernelCircuitPublicInputs { - // noir-fmt:ignore - PublicKernelOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) - .remove_top_call_request(phase) - .propagate_from_enqueued_call(self.enqueued_call.data, phase) - .finish() - } - fn get_phase(self) -> u8 { let public_inputs = self.previous_kernel.public_inputs; let needs_setup = @@ -46,36 +34,22 @@ impl PublicKernelMergeCircuitPrivateInputs { fn execute(self) -> PublicKernelCircuitPublicInputs { let phase = self.get_phase(); - let output = unsafe { self.generate_output(phase) }; - - let output_validator = PublicKernelOutputValidator::new( - output, - self.previous_kernel.public_inputs, - self.enqueued_call.data, - phase, - ); - - // let previous_kernel_validator = PreviousKernelValidator::new(self.previous_kernel); - // previous_kernel_validator.validate_proof(ALLOWED_PREVIOUS_CIRCUITS); let enqueued_call_data_validator = EnqueuedCallDataValidator::new(self.enqueued_call, phase); - // enqueued_call_data_validator.validate_proof(); enqueued_call_data_validator.validate_against_previous_kernel( self.previous_kernel.public_inputs, - output_validator.previous_validation_request_array_lengths, - output_validator.previous_non_revertible_data_array_lengths, - output_validator.previous_revertible_data_array_lengths, ); - output_validator.validate(); - - output + PublicKernelOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) + .remove_top_call_request(phase) + .propagate_from_enqueued_call(self.enqueued_call.data, phase) + .finish() } } mod tests { use crate::{ - public_kernel_merge::{ALLOWED_PREVIOUS_CIRCUITS, PublicKernelMergeCircuitPrivateInputs}, + public_kernel_merge::PublicKernelMergeCircuitPrivateInputs, public_kernel_phase::PublicKernelPhase, }; use dep::types::{ diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 2fafa38eb6e..3e413125fe1 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -1,9 +1,5 @@ use crate::{ - components::{ - previous_kernel_validator::PreviousKernelValidator, - public_tail_output_composer::{OutputHints, PublicTailOutputComposer}, - public_tail_output_validator::PublicTailOutputValidator, - }, + components::public_tail_output_composer::{OutputHints, PublicTailOutputComposer}, public_kernel_phase::PublicKernelPhase, }; use dep::reset_kernel_lib::{ @@ -29,8 +25,6 @@ use dep::types::{ partial_state_reference::PartialStateReference, }; -global ALLOWED_PREVIOUS_CIRCUITS = []; - pub struct PublicKernelTailCircuitPrivateInputs { previous_kernel: PublicKernelData, note_hash_read_request_hints: [TreeLeafReadRequestHint; MAX_NOTE_HASH_READ_REQUESTS_PER_TX], @@ -62,9 +56,6 @@ impl PublicKernelTailCircuitPrivateInputs { } pub fn execute(self) -> KernelCircuitPublicInputs { - let previous_kernel_validator = PreviousKernelValidator::new(self.previous_kernel); - previous_kernel_validator.validate_phase(PublicKernelPhase.TAIL); - // previous_kernel_validator.validate_proof(ALLOWED_PREVIOUS_CIRCUITS); let (output, output_hints, public_data_read_request_hints) = unsafe { self.generate_output_and_hints() }; @@ -81,15 +72,6 @@ impl PublicKernelTailCircuitPrivateInputs { ) .validate(); - PublicTailOutputValidator::new( - output, - self.previous_kernel.public_inputs, - self.start_state, - output_hints, - self.public_data_hints, - ) - .validate(); - output } } From e5620ffd943a7e44af2e98431b9b7f2d02af955e Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Sat, 9 Nov 2024 11:19:06 +0000 Subject: [PATCH 3/4] Remove hack of array lengths in ts. --- .../src/public/enqueued_call_simulator.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/yarn-project/simulator/src/public/enqueued_call_simulator.ts b/yarn-project/simulator/src/public/enqueued_call_simulator.ts index 39ffa0e8fd1..e49fbd1ca00 100644 --- a/yarn-project/simulator/src/public/enqueued_call_simulator.ts +++ b/yarn-project/simulator/src/public/enqueued_call_simulator.ts @@ -4,7 +4,7 @@ import { NestedProcessReturnValues, ProvingRequestType, type PublicExecutionRequest, - PublicKernelPhase, + type PublicKernelPhase, type SimulationError, UnencryptedFunctionL2Logs, } from '@aztec/circuit-types'; @@ -34,7 +34,6 @@ import { MAX_UNENCRYPTED_LOGS_PER_CALL, NoteHash, Nullifier, - PublicAccumulatedDataArrayLengths, type PublicCallRequest, PublicCircuitPublicInputs, PublicInnerCallRequest, @@ -174,18 +173,6 @@ export class EnqueuedCallSimulator { transactionFee, avmCallResult, ); - // FIXME(dbanks12): For now, override this because there is a disconnect with how the TS/simulator - // tracks "previous lengths" versus the kernel. The kernel uses "non revertible lengths" in SETUP - // and "revertible lengths" otherwise. TS also uses "non revertible lengths" in SETUP, but then - // uses _total_/combined lengths otherwise. - const prevAccumulatedData = - phase === PublicKernelPhase.SETUP - ? previousPublicKernelOutput.endNonRevertibleData - : previousPublicKernelOutput.end; - const previousAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.new(prevAccumulatedData); - vmCircuitPublicInputs.previousAccumulatedDataArrayLengths = previousAccumulatedDataArrayLengths; - // END TEMPORARY - /////////////////////////////////////////////////////////////////////////// const gasUsed = allocatedGas.sub(Gas.from(result.endGasLeft)); From 0ddf058f76f158c62f4169e70f83d222370857b3 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Sat, 9 Nov 2024 12:43:47 +0000 Subject: [PATCH 4/4] Remove PublicCircuitPublicInputs from protocol circuit. --- .../propagate_accumulated_data.nr | 102 -------- .../vm_circuit_public_inputs.nr | 2 +- .../crates/types/src/abis/mod.nr | 1 - .../src/abis/public_circuit_public_inputs.nr | 237 ------------------ .../crates/types/src/abis/public_data_read.nr | 16 -- .../src/abis/public_data_update_request.nr | 23 +- .../src/abis/public_inner_call_request.nr | 2 +- .../crates/types/src/contrakt/mod.nr | 2 - .../crates/types/src/contrakt/storage_read.nr | 51 ---- .../src/contrakt/storage_update_request.nr | 52 ---- .../crates/types/src/lib.nr | 2 - .../crates/types/src/tests/fixture_builder.nr | 84 +------ .../src/type_conversion.ts | 69 ----- 13 files changed, 4 insertions(+), 639 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer/propagate_accumulated_data.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/contrakt/mod.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer/propagate_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer/propagate_accumulated_data.nr deleted file mode 100644 index 6010ea888b4..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/vm_circuit_output_composer/propagate_accumulated_data.nr +++ /dev/null @@ -1,102 +0,0 @@ -use dep::types::{ - abis::{ - accumulated_data::PublicAccumulatedDataBuilder, nullifier::Nullifier, - public_circuit_public_inputs::PublicCircuitPublicInputs, - public_data_update_request::PublicDataUpdateRequest, - }, - hash::compute_siloed_nullifier, -}; - -pub fn propagate_accumulated_data( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) -> PublicAccumulatedDataBuilder { - propagate_note_hashes(data, public_call); - propagate_nullifiers(data, public_call); - propagate_l2_to_l1_messages(data, public_call); - propagate_unencrypted_logs(data, public_call); - propagate_public_data_writes(data, public_call); - *data -} - -fn propagate_note_hashes( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) { - let contract_address = public_call.call_context.contract_address; - let note_hashes = public_call.note_hashes; - for i in 0..note_hashes.len() { - let note_hash = note_hashes[i]; - if note_hash.counter != 0 { - data.note_hashes.push(note_hash.scope(contract_address)); - } - } -} - -fn propagate_nullifiers( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) { - let contract_address = public_call.call_context.contract_address; - let nullifiers = public_call.nullifiers; - for i in 0..nullifiers.len() { - let nullifier = nullifiers[i]; - if nullifier.counter != 0 { - let siloed_value = compute_siloed_nullifier(contract_address, nullifier.value); - data.nullifiers.push( - Nullifier { - value: siloed_value, - counter: nullifier.counter, - note_hash: nullifier.note_hash, - }, - ); - } - } -} - -fn propagate_l2_to_l1_messages( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) { - let contract_address = public_call.call_context.contract_address; - let msgs = public_call.l2_to_l1_msgs; - for i in 0..msgs.len() { - let msg = msgs[i]; - if msg.counter != 0 { - data.l2_to_l1_msgs.push(msg.scope(contract_address)); - } - } -} - -fn propagate_unencrypted_logs( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) { - let contract_address = public_call.call_context.contract_address; - let logs = public_call.unencrypted_logs_hashes; - for i in 0..logs.len() { - let log = logs[i]; - if log.counter != 0 { - data.unencrypted_logs_hashes.push(log.scope(contract_address)); - } - } -} - -fn propagate_public_data_writes( - data: &mut PublicAccumulatedDataBuilder, - public_call: PublicCircuitPublicInputs, -) { - let contract_address = public_call.call_context.contract_address; - let writes = public_call.contract_storage_update_requests; - for i in 0..writes.len() { - let write = writes[i]; - if write.counter != 0 { - data.public_data_update_requests.push( - PublicDataUpdateRequest::from_contract_storage_update_request( - contract_address, - write, - ), - ); - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/vm_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/vm_circuit_public_inputs.nr index 402b1867733..ca283b49fdf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/vm_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/vm_circuit_public_inputs.nr @@ -12,11 +12,11 @@ use crate::{ utils::reader::Reader, }; +// TODO(#9594): To be deprecated. pub struct VMCircuitPublicInputs { constants: CombinedConstantData, call_request: PublicCallRequest, - // TODO(#7124): To be deprecated. public_call_stack: [PublicInnerCallRequest; MAX_ENQUEUED_CALLS_PER_TX], previous_validation_request_array_lengths: PublicValidationRequestArrayLengths, // Lengths of the validation requests before the enqueued call. diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr index 7b3324e4c21..e29706c42ed 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/mod.nr @@ -42,7 +42,6 @@ pub mod call_context; pub mod enqueued_call_data; -pub mod public_circuit_public_inputs; pub mod private_circuit_public_inputs; pub mod gas_fees; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr deleted file mode 100644 index 746d9097790..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ /dev/null @@ -1,237 +0,0 @@ -use crate::{ - abis::{ - call_context::CallContext, gas::Gas, global_variables::GlobalVariables, log_hash::LogHash, - note_hash::NoteHash, nullifier::Nullifier, - public_inner_call_request::PublicInnerCallRequest, read_request::ReadRequest, - tree_leaf_read_request::TreeLeafReadRequest, - }, - address::AztecAddress, - constants::{ - MAX_ENQUEUED_CALLS_PER_CALL, MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, - MAX_L2_TO_L1_MSGS_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_CALL, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_NULLIFIERS_PER_CALL, MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, MAX_UNENCRYPTED_LOGS_PER_CALL, - PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, - }, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - header::Header, - messaging::l2_to_l1_message::L2ToL1Message, - traits::{Deserialize, Empty, Serialize}, - utils::reader::Reader, -}; - -// Public inputs to public app circuit. -pub struct PublicCircuitPublicInputs { - call_context: CallContext, - - args_hash: Field, - returns_hash: Field, - - note_hash_read_requests: [TreeLeafReadRequest; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], - nullifier_read_requests: [ReadRequest; MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ReadRequest; MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - l1_to_l2_msg_read_requests: [TreeLeafReadRequest; MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead; MAX_PUBLIC_DATA_READS_PER_CALL], - - // todo: add sideeffect ranges for the input to these hashes - public_call_requests: [PublicInnerCallRequest; MAX_ENQUEUED_CALLS_PER_CALL], - note_hashes: [NoteHash; MAX_NOTE_HASHES_PER_CALL], - nullifiers: [Nullifier; MAX_NULLIFIERS_PER_CALL], - l2_to_l1_msgs: [L2ToL1Message; MAX_L2_TO_L1_MSGS_PER_CALL], - - start_side_effect_counter: u32, - end_side_effect_counter: u32, - - unencrypted_logs_hashes: [LogHash; MAX_UNENCRYPTED_LOGS_PER_CALL], - - // Header of a block whose state is used during public execution. Set by sequencer to be a header of a block - // previous to the one in which the tx is included. - historical_header: Header, - - // Global variables injected into this circuit - global_variables: GlobalVariables, - - prover_address: AztecAddress, - - revert_code: u8, - - start_gas_left: Gas, - end_gas_left: Gas, - transaction_fee: Field, -} - -impl Eq for PublicCircuitPublicInputs { - fn eq(self, other: Self) -> bool { - self.serialize() == other.serialize() - } -} - -impl Serialize for PublicCircuitPublicInputs { - fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.call_context.serialize()); - fields.push(self.args_hash); - fields.push(self.returns_hash); - for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_CALL { - fields.extend_from_array(self.note_hash_read_requests[i].serialize()); - } - for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { - fields.extend_from_array(self.nullifier_read_requests[i].serialize()); - } - for i in 0..MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL { - fields.extend_from_array(self.nullifier_non_existent_read_requests[i].serialize()); - } - for i in 0..MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL { - fields.extend_from_array(self.l1_to_l2_msg_read_requests[i].serialize()); - } - for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { - fields.extend_from_array(self.contract_storage_update_requests[i].serialize()); - } - for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { - fields.extend_from_array(self.contract_storage_reads[i].serialize()); - } - for i in 0..MAX_ENQUEUED_CALLS_PER_CALL { - fields.extend_from_array(self.public_call_requests[i].serialize()); - } - for i in 0..MAX_NOTE_HASHES_PER_CALL { - fields.extend_from_array(self.note_hashes[i].serialize()); - } - for i in 0..MAX_NULLIFIERS_PER_CALL { - fields.extend_from_array(self.nullifiers[i].serialize()); - } - for i in 0..MAX_L2_TO_L1_MSGS_PER_CALL { - fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); - } - - fields.push(self.start_side_effect_counter as Field); - fields.push(self.end_side_effect_counter as Field); - - for i in 0..MAX_UNENCRYPTED_LOGS_PER_CALL { - fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); - } - fields.extend_from_array(self.historical_header.serialize()); - fields.extend_from_array(self.global_variables.serialize()); - fields.push(self.prover_address.to_field()); - fields.push(self.revert_code as Field); - fields.extend_from_array(self.start_gas_left.serialize()); - fields.extend_from_array(self.end_gas_left.serialize()); - fields.push(self.transaction_fee); - fields.storage() - } -} - -impl Deserialize for PublicCircuitPublicInputs { - fn deserialize(serialized: [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> Self { - // TODO(#4390): This should accept a reader ^ to avoid copying data. - let mut reader = Reader::new(serialized); - let inputs = PublicCircuitPublicInputs { - call_context: reader.read_struct(CallContext::deserialize), - args_hash: reader.read(), - returns_hash: reader.read(), - note_hash_read_requests: reader.read_struct_array( - TreeLeafReadRequest::deserialize, - [TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], - ), - nullifier_read_requests: reader.read_struct_array( - ReadRequest::deserialize, - [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - ), - nullifier_non_existent_read_requests: reader.read_struct_array( - ReadRequest::deserialize, - [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - ), - l1_to_l2_msg_read_requests: reader.read_struct_array( - TreeLeafReadRequest::deserialize, - [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL], - ), - contract_storage_update_requests: reader.read_struct_array( - StorageUpdateRequest::deserialize, - [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - ), - contract_storage_reads: reader.read_struct_array( - StorageRead::deserialize, - [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], - ), - public_call_requests: reader.read_struct_array( - PublicInnerCallRequest::deserialize, - [PublicInnerCallRequest::empty(); MAX_ENQUEUED_CALLS_PER_CALL], - ), - note_hashes: reader.read_struct_array( - NoteHash::deserialize, - [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL], - ), - nullifiers: reader.read_struct_array( - Nullifier::deserialize, - [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL], - ), - l2_to_l1_msgs: reader.read_struct_array( - L2ToL1Message::deserialize, - [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL], - ), - start_side_effect_counter: reader.read() as u32, - end_side_effect_counter: reader.read() as u32, - unencrypted_logs_hashes: reader.read_struct_array( - LogHash::deserialize, - [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL], - ), - historical_header: reader.read_struct(Header::deserialize), - global_variables: reader.read_struct(GlobalVariables::deserialize), - prover_address: reader.read_struct(AztecAddress::deserialize), - revert_code: reader.read() as u8, - start_gas_left: reader.read_struct(Gas::deserialize), - end_gas_left: reader.read_struct(Gas::deserialize), - transaction_fee: reader.read(), - }; - - reader.finish(); - inputs - } -} - -impl Empty for PublicCircuitPublicInputs { - fn empty() -> Self { - PublicCircuitPublicInputs { - call_context: CallContext::empty(), - args_hash: 0, - returns_hash: 0, - note_hash_read_requests: [ - TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL - ], - nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ - ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL - ], - l1_to_l2_msg_read_requests: [ - TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL - ], - contract_storage_update_requests: [ - StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL - ], - contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], - public_call_requests: [PublicInnerCallRequest::empty(); MAX_ENQUEUED_CALLS_PER_CALL], - note_hashes: [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL], - nullifiers: [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL], - l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL], - start_side_effect_counter: 0 as u32, - end_side_effect_counter: 0 as u32, - unencrypted_logs_hashes: [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL], - historical_header: Header::empty(), - global_variables: GlobalVariables::empty(), - prover_address: AztecAddress::zero(), - revert_code: 0 as u8, - start_gas_left: Gas::empty(), - end_gas_left: Gas::empty(), - transaction_fee: 0, - } - } -} - -#[test] -fn serialization_of_empty() { - let pcpi = PublicCircuitPublicInputs::empty(); - let serialized = pcpi.serialize(); - let deserialized = PublicCircuitPublicInputs::deserialize(serialized); - assert(pcpi.eq(deserialized)); -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index 89427f042c2..15ae34c512e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,9 +1,6 @@ use crate::{ abis::side_effect::Ordered, - address::AztecAddress, constants::PUBLIC_DATA_READ_LENGTH, - contrakt::storage_read::StorageRead, - data::hash::{compute_public_data_tree_index, compute_public_data_tree_value}, traits::{Deserialize, Empty, Serialize}, }; @@ -13,19 +10,6 @@ pub struct PublicDataRead { counter: u32, } -impl PublicDataRead { - pub fn from_contract_storage_read( - contract_address: AztecAddress, - read_request: StorageRead, - ) -> PublicDataRead { - PublicDataRead { - leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), - value: compute_public_data_tree_value(read_request.current_value), - counter: read_request.counter, - } - } -} - impl Eq for PublicDataRead { fn eq(self, other: PublicDataRead) -> bool { (other.leaf_slot == self.leaf_slot) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index 6b55882403a..988e795f267 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,12 +1,7 @@ use crate::{ abis::side_effect::Ordered, - address::AztecAddress, constants::PUBLIC_DATA_UPDATE_REQUEST_LENGTH, - contrakt::storage_update_request::StorageUpdateRequest, - data::{ - hash::{compute_public_data_tree_index, compute_public_data_tree_value}, - public_data_tree_leaf::PublicDataTreeLeaf, - }, + data::public_data_tree_leaf::PublicDataTreeLeaf, traits::{Deserialize, Empty, Serialize}, }; @@ -17,22 +12,6 @@ pub struct PublicDataUpdateRequest { counter: u32, } -impl PublicDataUpdateRequest { - pub fn from_contract_storage_update_request( - contract_address: AztecAddress, - update_request: StorageUpdateRequest, - ) -> PublicDataUpdateRequest { - PublicDataUpdateRequest { - leaf_slot: compute_public_data_tree_index( - contract_address, - update_request.storage_slot, - ), - new_value: compute_public_data_tree_value(update_request.new_value), - counter: update_request.counter, - } - } -} - impl Ordered for PublicDataUpdateRequest { fn counter(self) -> u32 { self.counter diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_inner_call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_inner_call_request.nr index ddd5731fd95..801df9e64f1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_inner_call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_inner_call_request.nr @@ -5,7 +5,7 @@ use crate::{ utils::reader::Reader, }; -// TODO(#7124): To be deprecated. +// TODO(#9594): To be deprecated. pub struct PublicInnerCallRequest { item: PublicCallStackItemCompressed, counter: u32, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/mod.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/mod.nr deleted file mode 100644 index 1a84b4f0a76..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/mod.nr +++ /dev/null @@ -1,2 +0,0 @@ -mod storage_read; -mod storage_update_request; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr deleted file mode 100644 index c72347be04f..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ /dev/null @@ -1,51 +0,0 @@ -use crate::{constants::CONTRACT_STORAGE_READ_LENGTH, traits::{Deserialize, Empty, Serialize}}; - -pub struct StorageRead { - storage_slot: Field, - current_value: Field, - counter: u32, -} - -impl Eq for StorageRead { - fn eq(self, other: Self) -> bool { - (self.storage_slot == other.storage_slot) - & (self.current_value == other.current_value) - & (self.current_value == other.current_value) - } -} - -impl Empty for StorageRead { - fn empty() -> Self { - Self { storage_slot: 0, current_value: 0, counter: 0 } - } -} - -impl Serialize for StorageRead { - fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] { - [self.storage_slot, self.current_value, self.counter as Field] - } -} - -impl Deserialize for StorageRead { - fn deserialize(serialized: [Field; CONTRACT_STORAGE_READ_LENGTH]) -> Self { - Self { - storage_slot: serialized[0], - current_value: serialized[1], - counter: serialized[2] as u32, - } - } -} - -impl StorageRead { - pub fn is_empty(self) -> bool { - (self.storage_slot == 0) & (self.current_value == 0) & (self.counter == 0) - } -} - -#[test] -fn serialization_of_empty() { - let item = StorageRead::empty(); - let serialized = item.serialize(); - let deserialized = StorageRead::deserialize(serialized); - assert(item.eq(deserialized)); -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr deleted file mode 100644 index d9a8071a605..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ /dev/null @@ -1,52 +0,0 @@ -use crate::{ - constants::CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, - traits::{Deserialize, Empty, Serialize}, -}; - -pub struct StorageUpdateRequest { - storage_slot: Field, - new_value: Field, - counter: u32, -} - -impl Eq for StorageUpdateRequest { - fn eq(self, request: Self) -> bool { - (request.storage_slot == self.storage_slot) & (request.new_value == self.new_value) - } -} - -impl Empty for StorageUpdateRequest { - fn empty() -> Self { - StorageUpdateRequest { storage_slot: 0, new_value: 0, counter: 0 } - } -} - -impl Serialize for StorageUpdateRequest { - fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] { - [self.storage_slot, self.new_value, self.counter as Field] - } -} - -impl Deserialize for StorageUpdateRequest { - fn deserialize(serialized: [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH]) -> Self { - StorageUpdateRequest { - storage_slot: serialized[0], - new_value: serialized[1], - counter: serialized[2] as u32, - } - } -} - -impl StorageUpdateRequest { - pub fn is_empty(self) -> bool { - self.storage_slot == 0 - } -} - -#[test] -fn serialization_of_empty() { - let item = StorageUpdateRequest::empty(); - let serialized = item.serialize(); - let deserialized = StorageUpdateRequest::deserialize(serialized); - assert(item.eq(deserialized)); -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr index 5bc9d7273a2..90bbb47c139 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr @@ -4,8 +4,6 @@ pub mod debug_log; pub mod public_keys; mod point; mod scalar; -// This is intentionally spelled like this since contract is a reserved keyword, so it cannot be used as an ident. -mod contrakt; mod transaction; mod abis; pub mod constants; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index f6824eb726f..e75ebd6e413 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -26,7 +26,6 @@ use crate::{ private_kernel::private_call_data::PrivateCallData, private_kernel_data::PrivateKernelData, public_call_request::PublicCallRequest, - public_circuit_public_inputs::PublicCircuitPublicInputs, public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, public_data_write::PublicDataWrite, @@ -50,13 +49,11 @@ use crate::{ MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, - MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, PRIVATE_CALL_REQUEST_LENGTH, PROTOCOL_CONTRACT_TREE_HEIGHT, PUBLIC_CALL_REQUEST_LENGTH, VK_TREE_HEIGHT, }, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, hash::{ compute_l2_to_l1_hash, compute_siloed_nullifier, compute_tx_logs_hash, mask_encrypted_log_hash, silo_note_hash, silo_unencrypted_log_hash, @@ -129,7 +126,6 @@ pub struct FixtureBuilder { unencrypted_log_preimages_length: Field, public_data_writes: BoundedVec, public_data_update_requests: BoundedVec, - contract_storage_update_requests: BoundedVec, private_call_requests: BoundedVec, public_call_requests: BoundedVec, MAX_ENQUEUED_CALLS_PER_TX>, public_inner_call_requests: BoundedVec, @@ -145,7 +141,6 @@ pub struct FixtureBuilder { l1_to_l2_msg_read_requests: BoundedVec, scoped_key_validation_requests_and_generators: BoundedVec, public_data_reads: BoundedVec, - contract_storage_reads: BoundedVec, validation_requests_split_counter: Option, // Function. @@ -586,49 +581,6 @@ impl FixtureBuilder { } } - pub fn to_public_circuit_public_inputs(self) -> PublicCircuitPublicInputs { - PublicCircuitPublicInputs { - call_context: self.build_call_context(), - args_hash: self.args_hash, - returns_hash: self.returns_hash, - note_hash_read_requests: subarray(self.note_hash_tree_leaf_read_requests.storage), - nullifier_read_requests: subarray(self.nullifier_read_requests.storage.map( - |r: ScopedReadRequest| r.read_request, - )), - nullifier_non_existent_read_requests: subarray(self - .nullifier_non_existent_read_requests - .storage - .map(|r: ScopedReadRequest| r.read_request)), - l1_to_l2_msg_read_requests: subarray(self.l1_to_l2_msg_read_requests.storage), - contract_storage_update_requests: subarray( - self.contract_storage_update_requests.storage, - ), - contract_storage_reads: self.contract_storage_reads.storage, - public_call_requests: subarray(self.public_inner_call_requests.storage), - note_hashes: subarray( - self.note_hashes.storage.map(|n: ScopedNoteHash| n.note_hash), - ), - nullifiers: subarray( - self.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier), - ), - l2_to_l1_msgs: subarray(self.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| { - m.message - })), - start_side_effect_counter: self.counter_start, - end_side_effect_counter: self.counter, - unencrypted_logs_hashes: subarray(self.unencrypted_logs_hashes.storage.map( - |l: ScopedLogHash| l.log_hash, - )), - historical_header: self.historical_header, - global_variables: self.global_variables, - prover_address: self.prover_address, - revert_code: self.revert_code, - start_gas_left: self.start_gas_left, - end_gas_left: self.end_gas_left, - transaction_fee: self.transaction_fee, - } - } - pub fn to_public_validation_requests(self) -> PublicValidationRequests { PublicValidationRequests { for_rollup: self.to_rollup_validation_requests(), @@ -865,38 +817,6 @@ impl FixtureBuilder { } } - pub fn add_contract_storage_read_request(&mut self, storage_slot: Field, value: Field) { - self.contract_storage_reads.push( - StorageRead { storage_slot, current_value: value, counter: self.next_counter() }, - ); - } - - pub fn append_contract_storage_read_requests(&mut self, num: u32) { - let index_offset = self.contract_storage_reads.len(); - for i in 0..self.contract_storage_reads.max_len() { - if i < num { - let (storage_slot, value) = self.mock_contract_storage_read(index_offset + i); - self.add_contract_storage_read_request(storage_slot, value); - } - } - } - - pub fn add_contract_storage_update_request(&mut self, storage_slot: Field, value: Field) { - let update_request = - StorageUpdateRequest { storage_slot, new_value: value, counter: self.next_counter() }; - self.contract_storage_update_requests.push(update_request); - } - - pub fn append_contract_storage_update_requests(&mut self, num: u32) { - let index_offset = self.contract_storage_update_requests.len(); - for i in 0..self.contract_storage_update_requests.max_len() { - if i < num { - let (storage_slot, value) = self.mock_contract_storage_write(index_offset + i); - self.add_contract_storage_update_request(storage_slot, value); - } - } - } - pub fn add_public_data_update_request(&mut self, leaf_slot: Field, value: Field) { let update_request = PublicDataUpdateRequest { leaf_slot, new_value: value, counter: self.next_counter() }; @@ -1350,7 +1270,6 @@ impl Empty for FixtureBuilder { unencrypted_log_preimages_length: 0, public_data_writes: BoundedVec::new(), public_data_update_requests: BoundedVec::new(), - contract_storage_update_requests: BoundedVec::new(), private_call_requests: BoundedVec::new(), public_call_requests: BoundedVec::new(), public_inner_call_requests: BoundedVec::new(), @@ -1362,7 +1281,6 @@ impl Empty for FixtureBuilder { l1_to_l2_msg_read_requests: BoundedVec::new(), scoped_key_validation_requests_and_generators: BoundedVec::new(), public_data_reads: BoundedVec::new(), - contract_storage_reads: BoundedVec::new(), validation_requests_split_counter: Option::none(), function_data: FunctionData::empty(), args_hash: 0, diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index d0f18bc0edb..e3ba45bb436 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -18,8 +18,6 @@ import { CombinedConstantData, ConstantRollupData, ContentCommitment, - type ContractStorageRead, - type ContractStorageUpdateRequest, CountedPublicCallRequest, type EmptyBlockRootRollupInputs, type EmptyNestedData, @@ -105,7 +103,6 @@ import { type PublicBaseRollupInputs, PublicCallRequest, PublicCallStackItemCompressed, - type PublicCircuitPublicInputs, type PublicDataHint, type PublicDataLeafHint, PublicDataRead, @@ -239,7 +236,6 @@ import type { PublicBaseRollupInputs as PublicBaseRollupInputsNoir, PublicCallRequest as PublicCallRequestNoir, PublicCallStackItemCompressed as PublicCallStackItemCompressedNoir, - PublicCircuitPublicInputs as PublicCircuitPublicInputsNoir, PublicDataHint as PublicDataHintNoir, PublicDataLeafHint as PublicDataLeafHintNoir, PublicDataRead as PublicDataReadNoir, @@ -272,8 +268,6 @@ import type { ScopedReadRequest as ScopedReadRequestNoir, StateDiffHints as StateDiffHintsNoir, StateReference as StateReferenceNoir, - StorageRead as StorageReadNoir, - StorageUpdateRequest as StorageUpdateRequestNoir, TransientDataIndexHint as TransientDataIndexHintNoir, TreeLeafReadRequestHint as TreeLeafReadRequestHintNoir, TreeLeafReadRequest as TreeLeafReadRequestNoir, @@ -1937,20 +1931,6 @@ export function mapPublicKernelCircuitPublicInputsFromNoir( ); } -/** - * Maps a private kernel inputs final to noir. - * @param storageUpdateRequest - The storage update request. - * @returns The noir storage update request. - */ -export function mapStorageUpdateRequestToNoir( - storageUpdateRequest: ContractStorageUpdateRequest, -): StorageUpdateRequestNoir { - return { - storage_slot: mapFieldToNoir(storageUpdateRequest.storageSlot), - new_value: mapFieldToNoir(storageUpdateRequest.newValue), - counter: mapNumberToNoir(storageUpdateRequest.counter), - }; -} /** * Maps global variables to the noir type. * @param globalVariables - The global variables. @@ -1969,18 +1949,6 @@ export function mapGlobalVariablesToNoir(globalVariables: GlobalVariables): Glob }; } -/** - * Maps a storage read to noir. - * @param storageRead - The storage read. - * @returns The noir storage read. - */ -export function mapStorageReadToNoir(storageRead: ContractStorageRead): StorageReadNoir { - return { - storage_slot: mapFieldToNoir(storageRead.storageSlot), - current_value: mapFieldToNoir(storageRead.currentValue), - counter: mapNumberToNoir(storageRead.counter), - }; -} /** * Maps global variables from the noir type. * @param globalVariables - The noir global variables. @@ -2035,43 +2003,6 @@ export function mapConstantRollupDataToNoir(constantRollupData: ConstantRollupDa }; } -/** - * Maps a public circuit public inputs to noir. - * @param publicInputs - The public circuit public inputs. - * @returns The noir public circuit public inputs. - */ -export function mapPublicCircuitPublicInputsToNoir( - publicInputs: PublicCircuitPublicInputs, -): PublicCircuitPublicInputsNoir { - return { - call_context: mapCallContextToNoir(publicInputs.callContext), - args_hash: mapFieldToNoir(publicInputs.argsHash), - returns_hash: mapFieldToNoir(publicInputs.returnsHash), - note_hash_read_requests: mapTuple(publicInputs.noteHashReadRequests, mapTreeLeafReadRequestToNoir), - nullifier_read_requests: mapTuple(publicInputs.nullifierReadRequests, mapReadRequestToNoir), - nullifier_non_existent_read_requests: mapTuple(publicInputs.nullifierNonExistentReadRequests, mapReadRequestToNoir), - l1_to_l2_msg_read_requests: mapTuple(publicInputs.l1ToL2MsgReadRequests, mapTreeLeafReadRequestToNoir), - contract_storage_update_requests: mapTuple( - publicInputs.contractStorageUpdateRequests, - mapStorageUpdateRequestToNoir, - ), - contract_storage_reads: mapTuple(publicInputs.contractStorageReads, mapStorageReadToNoir), - public_call_requests: mapTuple(publicInputs.publicCallRequests, mapPublicInnerCallRequestToNoir), - note_hashes: mapTuple(publicInputs.noteHashes, mapNoteHashToNoir), - nullifiers: mapTuple(publicInputs.nullifiers, mapNullifierToNoir), - l2_to_l1_msgs: mapTuple(publicInputs.l2ToL1Msgs, mapL2ToL1MessageToNoir), - start_side_effect_counter: mapFieldToNoir(publicInputs.startSideEffectCounter), - end_side_effect_counter: mapFieldToNoir(publicInputs.endSideEffectCounter), - unencrypted_logs_hashes: mapTuple(publicInputs.unencryptedLogsHashes, mapLogHashToNoir), - historical_header: mapHeaderToNoir(publicInputs.historicalHeader), - global_variables: mapGlobalVariablesToNoir(publicInputs.globalVariables), - prover_address: mapAztecAddressToNoir(publicInputs.proverAddress), - revert_code: mapRevertCodeToNoir(publicInputs.revertCode), - start_gas_left: mapGasToNoir(publicInputs.startGasLeft), - end_gas_left: mapGasToNoir(publicInputs.endGasLeft), - transaction_fee: mapFieldToNoir(publicInputs.transactionFee), - }; -} /** * Maps a constant rollup data from noir to the circuits.js type. * @param constantRollupData - The noir constant rollup data.