From 342d30befc25d1ad973537788bfeaff7fadafb19 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 11:38:38 +0000 Subject: [PATCH 01/11] generate client ivc vks for all --- avm-transpiler/Cargo.lock | 1 - noir-projects/Earthfile | 3 +- ...circuits.json => client_ivc_circuits.json} | 4 +- noir-projects/gates_report.sh | 6 +-- noir-projects/ivc_integration_circuits.json | 8 ---- .../scripts/flamegraph.sh | 2 +- noir-projects/scripts/generate_vk_json.js | 47 +++++-------------- 7 files changed, 21 insertions(+), 50 deletions(-) rename noir-projects/{mega_honk_circuits.json => client_ivc_circuits.json} (58%) delete mode 100644 noir-projects/ivc_integration_circuits.json diff --git a/avm-transpiler/Cargo.lock b/avm-transpiler/Cargo.lock index bdac1771a70..4da74e41190 100644 --- a/avm-transpiler/Cargo.lock +++ b/avm-transpiler/Cargo.lock @@ -948,7 +948,6 @@ dependencies = [ "acvm", "iter-extended", "jsonrpc", - "regex", "serde", "serde_json", "thiserror", diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 0a876ac39f7..42cfb3d89ad 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -19,8 +19,7 @@ source: COPY package.json yarn.lock . RUN yarn - COPY mega_honk_circuits.json . - COPY ivc_integration_circuits.json . + COPY client_ivc_circuits.json . COPY --dir aztec-nr noir-contracts noir-protocol-circuits mock-protocol-circuits scripts . build-contracts: diff --git a/noir-projects/mega_honk_circuits.json b/noir-projects/client_ivc_circuits.json similarity index 58% rename from noir-projects/mega_honk_circuits.json rename to noir-projects/client_ivc_circuits.json index 1db696b11e6..f59ca78604e 100644 --- a/noir-projects/mega_honk_circuits.json +++ b/noir-projects/client_ivc_circuits.json @@ -2,5 +2,7 @@ "^private_kernel_init", "^private_kernel_inner", "^private_kernel_reset.*", - "^private_kernel_tail.*" + "^private_kernel_tail.*", + "app_creator", + "app_reader" ] \ No newline at end of file diff --git a/noir-projects/gates_report.sh b/noir-projects/gates_report.sh index eaeb52a0c13..d1b0d40aa05 100755 --- a/noir-projects/gates_report.sh +++ b/noir-projects/gates_report.sh @@ -5,7 +5,7 @@ set -eu # The script needs some slight updating as `nargo info` expects a complete JSON object, while this script expects a single object field # representing a list of circuit reports for a program. # The ACIR tests in barretenberg also expect every target bytecode to have the name `acir.gz` while this script expects the same name of the package -MEGA_HONK_CIRCUIT_PATTERNS=$(jq -r '.[]' mega_honk_circuits.json) +MEGA_HONK_CIRCUIT_PATTERNS=$(jq -r '.[]' client_ivc_circuits.json) cd noir-protocol-circuits PROTOCOL_CIRCUITS_DIR=$PWD @@ -31,13 +31,13 @@ for pathname in "$PROTOCOL_CIRCUITS_DIR/target"/*.json; do fi done - # If it's mega honk, we need to use the gates_mega_honk command + # If it's mega honk, we need to use the gates_mega_honk command if [ "$IS_MEGA_HONK_CIRCUIT" = "true" ]; then GATES_INFO=$($BB_BIN gates_mega_honk -h -b "$pathname") else GATES_INFO=$($BB_BIN gates -h -b "$pathname") fi - + MAIN_FUNCTION_INFO=$(echo $GATES_INFO | jq -r '.functions[0] | .name = "main"') echo "{\"package_name\": \"$ARTIFACT_NAME\", \"functions\": [$MAIN_FUNCTION_INFO]" >> gates_report.json diff --git a/noir-projects/ivc_integration_circuits.json b/noir-projects/ivc_integration_circuits.json deleted file mode 100644 index 01971872d1f..00000000000 --- a/noir-projects/ivc_integration_circuits.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - "mock_private_kernel_init", - "mock_private_kernel_inner", - "mock_private_kernel_reset.*", - "mock_private_kernel_tail.*", - "app_creator", - "app_reader" -] \ No newline at end of file diff --git a/noir-projects/noir-protocol-circuits/scripts/flamegraph.sh b/noir-projects/noir-protocol-circuits/scripts/flamegraph.sh index 4f0868e573a..b8307d845ee 100755 --- a/noir-projects/noir-protocol-circuits/scripts/flamegraph.sh +++ b/noir-projects/noir-protocol-circuits/scripts/flamegraph.sh @@ -123,7 +123,7 @@ fi DEST="$SCRIPT_DIR/../dest" mkdir -p $DEST -MEGA_HONK_CIRCUIT_PATTERNS=$(jq -r '.[]' "$SCRIPT_DIR/../../mega_honk_circuits.json") +MEGA_HONK_CIRCUIT_PATTERNS=$(jq -r '.[]' "$SCRIPT_DIR/../../client_ivc_circuits.json") # Process each CIRCUIT_NAME. for CIRCUIT_NAME in "${CIRCUIT_NAMES[@]}"; do diff --git a/noir-projects/scripts/generate_vk_json.js b/noir-projects/scripts/generate_vk_json.js index a2942e69cde..3bbe390ff9d 100644 --- a/noir-projects/scripts/generate_vk_json.js +++ b/noir-projects/scripts/generate_vk_json.js @@ -3,8 +3,7 @@ const fs = require("fs/promises"); const child_process = require("child_process"); const crypto = require("crypto"); -const megaHonkPatterns = require("../mega_honk_circuits.json"); -const ivcIntegrationPatterns = require("../ivc_integration_circuits.json"); +const clientIvcPatterns = require("../client_ivc_circuits.json"); const { readVKFromS3, writeVKToS3, @@ -33,19 +32,13 @@ async function getBytecodeHash(artifactPath) { return crypto.createHash("md5").update(bytecode).digest("hex"); } -async function getArtifactHash( - artifactPath, - isMegaHonk, - isIvcIntegration, - isRecursive -) { +async function getArtifactHash(artifactPath, isClientIvc, isRecursive) { const bytecodeHash = await getBytecodeHash(artifactPath); const barretenbergHash = await getBarretenbergHash(); return generateArtifactHash( barretenbergHash, bytecodeHash, - isMegaHonk, - isIvcIntegration, + isClientIvc, isRecursive ); } @@ -68,26 +61,19 @@ async function hasArtifactHashChanged(artifactHash, vkDataPath) { return true; } -function isMegaHonkCircuit(artifactName) { - return megaHonkPatterns.some((pattern) => - artifactName.match(new RegExp(pattern)) - ); -} -function isIvcIntegrationCircuit(artifactName) { - return ivcIntegrationPatterns.some((pattern) => +function isClientIvcCircuit(artifactName) { + return clientIvcPatterns.some((pattern) => artifactName.match(new RegExp(pattern)) ); } async function processArtifact(artifactPath, artifactName, outputFolder) { - const isMegaHonk = isMegaHonkCircuit(artifactName); - const isIvcIntegration = isIvcIntegrationCircuit(artifactName); + const isClientIvc = isClientIvcCircuit(artifactName); const isRecursive = true; const artifactHash = await getArtifactHash( artifactPath, - isMegaHonk, - isIvcIntegration, + isClientIvc, isRecursive ); @@ -106,8 +92,7 @@ async function processArtifact(artifactPath, artifactName, outputFolder) { outputFolder, artifactPath, artifactHash, - isMegaHonk, - isIvcIntegration, + isClientIvc, isRecursive ); await writeVKToS3(artifactName, artifactHash, JSON.stringify(vkData)); @@ -123,14 +108,11 @@ async function generateVKData( outputFolder, artifactPath, artifactHash, - isMegaHonk, - isIvcIntegration, + isClientIvc, isRecursive ) { - if (isMegaHonk) { - console.log("Generating new mega honk vk for", artifactName); - } else if (isIvcIntegration) { - console.log("Generating new IVC vk for", artifactName); + if (isClientIvc) { + console.log("Generating new client ivc vk for", artifactName); } else { console.log("Generating new vk for", artifactName); } @@ -142,8 +124,7 @@ async function generateVKData( const jsonVkPath = vkJsonFileNameForArtifactName(outputFolder, artifactName); function getVkCommand() { - if (isMegaHonk) return "write_vk_mega_honk"; - if (isIvcIntegration) return "write_vk_for_ivc"; + if (isClientIvc) return "write_vk_for_ivc"; return "write_vk_ultra_honk"; } @@ -154,9 +135,7 @@ async function generateVKData( console.log("WRITE VK CMD: ", writeVkCommand); const vkAsFieldsCommand = `${BB_BIN_PATH} ${ - isMegaHonk || isIvcIntegration - ? "vk_as_fields_mega_honk" - : "vk_as_fields_ultra_honk" + isClientIvc ? "vk_as_fields_mega_honk" : "vk_as_fields_ultra_honk" } -k "${binaryVkPath}" -o "${jsonVkPath}"`; await new Promise((resolve, reject) => { From f2d23c5568598787871e02e538074134f2dcb39d Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 13:43:19 +0000 Subject: [PATCH 02/11] added verify proof calls --- .../private-kernel-lib/src/private_kernel_init.nr | 5 +++++ .../private-kernel-lib/src/private_kernel_inner.nr | 10 +++++++++- .../private-kernel-lib/src/private_kernel_reset.nr | 9 ++++++++- .../private-kernel-lib/src/private_kernel_tail.nr | 8 +++++++- .../src/private_kernel_tail_to_public.nr | 8 +++++++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index aee9521cd15..de4d70861b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -9,6 +9,7 @@ use dep::types::{ private_circuit_public_inputs::PrivateCircuitPublicInputs, private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, }, + constants::PROOF_TYPE_OINK, transaction::tx_request::TxRequest, }; @@ -49,6 +50,10 @@ impl PrivateKernelInitCircuitPrivateInputs { } pub fn execute(self) -> PrivateKernelCircuitPublicInputs { + if !std::runtime::is_unconstrained() { + std::verify_proof_with_type(self.private_call.vk.key, [], [], 0, PROOF_TYPE_OINK); + } + // Generate output. let output = unsafe { self.generate_output() }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index e226b38865d..9adacb8ee58 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -13,7 +13,10 @@ use dep::types::{ private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + constants::{ + PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, + PROOF_TYPE_PG, + }, }; global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] = @@ -47,6 +50,11 @@ impl PrivateKernelInnerCircuitPrivateInputs { } pub fn execute(self) -> PrivateKernelCircuitPublicInputs { + if !std::runtime::is_unconstrained() { + std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + std::verify_proof_with_type(self.private_call.vk.key, [], [], 0, PROOF_TYPE_PG); + } + // Generate output. let output = unsafe { self.generate_output() }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 4f1ca592194..3b120bbae72 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -9,7 +9,10 @@ use dep::reset_kernel_lib::{ }; use dep::types::{ abis::private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + constants::{ + PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, + PROOF_TYPE_PG, + }, PrivateKernelCircuitPublicInputs, }; @@ -65,6 +68,10 @@ impl PrivateKernelCircuitPublicInputs { + if !std::runtime::is_unconstrained() { + std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + } + let previous_public_inputs = self.previous_kernel.public_inputs; let validation_request_processor = PrivateValidationRequestProcessor { validation_requests: previous_public_inputs.validation_requests, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index fab13095851..27649fe3434 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -7,7 +7,10 @@ use dep::types::{ kernel_circuit_public_inputs::KernelCircuitPublicInputs, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + constants::{ + PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, + PROOF_TYPE_PG, + }, PrivateKernelCircuitPublicInputs, }; @@ -33,6 +36,9 @@ impl PrivateKernelTailCircuitPrivateInputs { } pub fn execute(self) -> KernelCircuitPublicInputs { + if !std::runtime::is_unconstrained() { + std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + } // Generate output. let output = unsafe { self.generate_output() }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index cbcb984f479..924bbf658e9 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -8,7 +8,10 @@ use dep::types::{ kernel_circuit_public_inputs::PrivateToPublicKernelCircuitPublicInputs, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, + constants::{ + PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, + PROOF_TYPE_PG, + }, PrivateKernelCircuitPublicInputs, }; @@ -34,6 +37,9 @@ impl PrivateKernelTailToPublicCircuitPrivateInputs { } pub fn execute(self) -> PrivateToPublicKernelCircuitPublicInputs { + if !std::runtime::is_unconstrained() { + std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + } // Generate output. let output = unsafe { self.generate_output() }; From 381a6e075a9174bd6b634e79719ffdad40e5cbdd Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 13:44:22 +0000 Subject: [PATCH 03/11] added no auto verify --- yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts index 7f16b0292fd..a1da3048369 100644 --- a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts @@ -105,6 +105,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { path.join(directory, 'acir.msgpack'), path.join(directory, 'witnesses.msgpack'), this.log.info, + true, ); if (provingResult.status === BB_RESULT.FAILURE) { From c02b93732acb0cdb325ce4aec96c54873493a0d9 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 14:28:00 +0000 Subject: [PATCH 04/11] apps have also clientIVC vks --- aztec-nargo/compile_then_postprocess.sh | 2 +- noir-projects/noir-contracts/scripts/postprocess_contract.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aztec-nargo/compile_then_postprocess.sh b/aztec-nargo/compile_then_postprocess.sh index 03deed4d4cf..2ccca323078 100755 --- a/aztec-nargo/compile_then_postprocess.sh +++ b/aztec-nargo/compile_then_postprocess.sh @@ -41,7 +41,7 @@ for artifact in $artifacts_to_process; do echo "Generating verification key for function $fn_name" # BB outputs the verification key to stdout as raw bytes, however, we need to base64 encode it before storing it in the artifact - verification_key=$($BB write_vk_mega_honk -h -b ${fn_artifact_path} -o - | base64) + verification_key=$($BB write_vk_for_ivc -h -b ${fn_artifact_path} -o - | base64) rm $fn_artifact_path jq ".functions[$fn_index].verification_key = \"$verification_key\"" $artifact > $artifact.tmp mv $artifact.tmp $artifact diff --git a/noir-projects/noir-contracts/scripts/postprocess_contract.js b/noir-projects/noir-contracts/scripts/postprocess_contract.js index b423bf2a50f..012197d68c4 100644 --- a/noir-projects/noir-contracts/scripts/postprocess_contract.js +++ b/noir-projects/noir-contracts/scripts/postprocess_contract.js @@ -38,7 +38,7 @@ async function generateVkForFunction(functionArtifact, outputFolder) { ); try { - const writeVkCommand = `${BB_BIN_PATH} write_vk_mega_honk -h -b "${functionArtifactPath}" -o "${outputVkPath}" `; + const writeVkCommand = `${BB_BIN_PATH} write_vk_for_ivc -h -b "${functionArtifactPath}" -o "${outputVkPath}" `; console.log("WRITE VK CMD: ", writeVkCommand); From 03606e8b023592a022a05a23632af8981745a3be Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 16:18:52 +0000 Subject: [PATCH 05/11] fix vk caching --- noir-projects/scripts/verification_keys.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/scripts/verification_keys.js b/noir-projects/scripts/verification_keys.js index 90fd90cb991..0ec6d9258ec 100644 --- a/noir-projects/scripts/verification_keys.js +++ b/noir-projects/scripts/verification_keys.js @@ -67,11 +67,11 @@ function generateS3Client() { function generateArtifactHash( barretenbergHash, bytecodeHash, - isMegaHonk, + isClientIvc, isRecursive ) { return `${barretenbergHash}-${bytecodeHash}-${ - isMegaHonk ? "mega-honk" : "ultra-honk" + isClientIvc ? "client-ivc" : "ultra-honk" }-${isRecursive}`; } From 65049d26dc43a4aba54831eae7dec8ab056d9ab6 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 9 Dec 2024 18:43:17 +0000 Subject: [PATCH 06/11] fix --- noir-projects/client_ivc_circuits.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noir-projects/client_ivc_circuits.json b/noir-projects/client_ivc_circuits.json index f59ca78604e..98b0104f17e 100644 --- a/noir-projects/client_ivc_circuits.json +++ b/noir-projects/client_ivc_circuits.json @@ -1,8 +1,8 @@ [ - "^private_kernel_init", - "^private_kernel_inner", - "^private_kernel_reset.*", - "^private_kernel_tail.*", + "private_kernel_init", + "private_kernel_inner", + "private_kernel_reset.*", + "private_kernel_tail.*", "app_creator", "app_reader" ] \ No newline at end of file From c652679f73f5dacd492786b02436c48d6cdf6b64 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 9 Dec 2024 22:19:52 +0000 Subject: [PATCH 07/11] bump max table size constant to fix VK construction failure --- barretenberg/cpp/src/barretenberg/constants.hpp | 2 +- .../barretenberg/plonk_honk_shared/composer/composer_lib.hpp | 1 + .../polynomials/shared_shifted_virtual_zeroes_array.hpp | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/constants.hpp b/barretenberg/cpp/src/barretenberg/constants.hpp index 7ff2b6b002c..364600b2ef8 100644 --- a/barretenberg/cpp/src/barretenberg/constants.hpp +++ b/barretenberg/cpp/src/barretenberg/constants.hpp @@ -13,7 +13,7 @@ static constexpr uint32_t CONST_PG_LOG_N = 20; static constexpr uint32_t CONST_ECCVM_LOG_N = 15; -static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 70000; +static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 75000; static constexpr uint32_t MAX_DATABUS_SIZE = 10000; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 1216623ee32..5565d5197ee 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -23,6 +23,7 @@ void construct_lookup_table_polynomials(const RefArray tables_size + additional_offset); size_t offset = dyadic_circuit_size - tables_size - additional_offset; diff --git a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp index 191080edbe8..c9999fbad1b 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp @@ -85,7 +85,10 @@ template struct SharedShiftedVirtualZeroesArray { T& operator[](size_t index) { - ASSERT(index >= start_ && index < end_); + if (index < start_ || index >= end_) { + vinfo("index = ", index, ", start_ = ", start_, ", end_ = ", end_); + ASSERT(false); + } return data()[index - start_]; } // get() is more useful, but for completeness with the non-const operator[] From 95481fbd2120ab0834c6bbf6f42aefd7d72f90ca Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 10 Dec 2024 13:18:46 +0000 Subject: [PATCH 08/11] cleaner verification --- .../src/private_kernel_init.nr | 2 +- .../src/private_kernel_inner.nr | 9 +++------ .../src/private_kernel_reset.nr | 7 ++----- .../src/private_kernel_tail.nr | 7 ++----- .../src/private_kernel_tail_to_public.nr | 7 ++----- .../src/abis/previous_rollup_block_data.nr | 10 ++++++++-- .../src/abis/private_kernel/private_call_data.nr | 16 +++++++++++++++- .../crates/types/src/abis/private_kernel_data.nr | 11 +++++++++-- 8 files changed, 42 insertions(+), 27 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index de4d70861b2..b9122c52f52 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -51,7 +51,7 @@ impl PrivateKernelInitCircuitPrivateInputs { pub fn execute(self) -> PrivateKernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { - std::verify_proof_with_type(self.private_call.vk.key, [], [], 0, PROOF_TYPE_OINK); + self.private_call.verify(true); } // Generate output. diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index 9adacb8ee58..a2cded9d3a4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -13,10 +13,7 @@ use dep::types::{ private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{ - PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, - PROOF_TYPE_PG, - }, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, }; global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] = @@ -51,8 +48,8 @@ impl PrivateKernelInnerCircuitPrivateInputs { pub fn execute(self) -> PrivateKernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { - std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); - std::verify_proof_with_type(self.private_call.vk.key, [], [], 0, PROOF_TYPE_PG); + self.previous_kernel.verify(); + self.private_call.verify(false); } // Generate output. diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 3b120bbae72..09393be1f44 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -9,10 +9,7 @@ use dep::reset_kernel_lib::{ }; use dep::types::{ abis::private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, - constants::{ - PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, - PROOF_TYPE_PG, - }, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, PrivateKernelCircuitPublicInputs, }; @@ -69,7 +66,7 @@ impl PrivateKernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { - std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + self.previous_kernel.verify(); } let previous_public_inputs = self.previous_kernel.public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index 27649fe3434..3b61a4e8c53 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -7,10 +7,7 @@ use dep::types::{ kernel_circuit_public_inputs::KernelCircuitPublicInputs, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{ - PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, - PROOF_TYPE_PG, - }, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, PrivateKernelCircuitPublicInputs, }; @@ -37,7 +34,7 @@ impl PrivateKernelTailCircuitPrivateInputs { pub fn execute(self) -> KernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { - std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + self.previous_kernel.verify(); } // Generate output. let output = unsafe { self.generate_output() }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index 924bbf658e9..8a12ebb647d 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -8,10 +8,7 @@ use dep::types::{ kernel_circuit_public_inputs::PrivateToPublicKernelCircuitPublicInputs, private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs}, }, - constants::{ - PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX, - PROOF_TYPE_PG, - }, + constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX}, PrivateKernelCircuitPublicInputs, }; @@ -38,7 +35,7 @@ impl PrivateKernelTailToPublicCircuitPrivateInputs { pub fn execute(self) -> PrivateToPublicKernelCircuitPublicInputs { if !std::runtime::is_unconstrained() { - std::verify_proof_with_type(self.previous_kernel.vk.key, [], [], 0, PROOF_TYPE_PG); + self.previous_kernel.verify(); } // Generate output. let output = unsafe { self.generate_output() }; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index 6c2297ce367..dad1a5526c7 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -19,11 +19,17 @@ pub struct PreviousRollupBlockData { } impl Verifiable for PreviousRollupBlockData { - fn verify(self) { + fn verify_with_proof_type(self, proof_type: u32) { let inputs = BlockRootOrBlockMergePublicInputs::serialize( self.block_root_or_block_merge_public_inputs, ); - std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); + std::verify_proof_with_type( + self.vk.key, + self.proof.fields, + inputs, + self.vk.hash, + proof_type, + ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr index be9751aad92..82094d0a5eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr @@ -1,7 +1,9 @@ use crate::{ abis::private_circuit_public_inputs::PrivateCircuitPublicInputs, address::SaltedInitializationHash, - constants::{FUNCTION_TREE_HEIGHT, PROTOCOL_CONTRACT_TREE_HEIGHT}, + constants::{ + FUNCTION_TREE_HEIGHT, PROOF_TYPE_OINK, PROOF_TYPE_PG, PROTOCOL_CONTRACT_TREE_HEIGHT, + }, merkle_tree::membership::MembershipWitness, proof::verification_key::ClientIVCVerificationKey, public_keys::PublicKeys, @@ -22,6 +24,18 @@ pub struct PrivateCallData { pub acir_hash: Field, } +impl PrivateCallData { + fn verify(self, is_first: bool) { + let proof_type = if is_first { + PROOF_TYPE_OINK + } else { + PROOF_TYPE_PG + }; + // Client IVC public inputs are linked in the backend via the databus + std::verify_proof_with_type(self.vk.key, [], [], 0, proof_type); + } +} + pub struct PrivateCallDataWithoutPublicInputs { pub vk: ClientIVCVerificationKey, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index e272ede7eaa..d768c9e1837 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -1,8 +1,8 @@ use crate::{ abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, - constants::{PRIVATE_KERNEL_RESET_INDEX, VK_TREE_HEIGHT}, + constants::{PRIVATE_KERNEL_RESET_INDEX, PROOF_TYPE_PG, VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership, - proof::verification_key::ClientIVCVerificationKey, + proof::{traits::Verifiable, verification_key::ClientIVCVerificationKey}, utils::arrays::find_index_hint, }; @@ -38,6 +38,13 @@ impl PrivateKernelData { } } +impl Verifiable for PrivateKernelData { + fn verify(self) { + // Client IVC public inputs are linked in the backend via the databus + std::verify_proof_with_type(self.vk.key, [], [], 0, PROOF_TYPE_PG); + } +} + pub struct PrivateKernelDataWithoutPublicInputs { vk: ClientIVCVerificationKey, vk_index: u32, From 1f9f676965296b76cbaf4d3d7a5ed8ee10c9dcb8 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 10 Dec 2024 13:19:34 +0000 Subject: [PATCH 09/11] remove unused --- .../crates/private-kernel-lib/src/private_kernel_init.nr | 1 - 1 file changed, 1 deletion(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index b9122c52f52..94112c25ee2 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -9,7 +9,6 @@ use dep::types::{ private_circuit_public_inputs::PrivateCircuitPublicInputs, private_kernel::private_call_data::{PrivateCallData, PrivateCallDataWithoutPublicInputs}, }, - constants::PROOF_TYPE_OINK, transaction::tx_request::TxRequest, }; From 980dcd64eda5995efe2fce8143f32b41edbaa5f5 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 10 Dec 2024 13:21:12 +0000 Subject: [PATCH 10/11] fix extraneous change --- .../rollup-lib/src/abis/previous_rollup_block_data.nr | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index dad1a5526c7..6c2297ce367 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -19,17 +19,11 @@ pub struct PreviousRollupBlockData { } impl Verifiable for PreviousRollupBlockData { - fn verify_with_proof_type(self, proof_type: u32) { + fn verify(self) { let inputs = BlockRootOrBlockMergePublicInputs::serialize( self.block_root_or_block_merge_public_inputs, ); - std::verify_proof_with_type( - self.vk.key, - self.proof.fields, - inputs, - self.vk.hash, - proof_type, - ); + std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); } } From d29552d783f41d6657ac0afeaa33b27cf0f7476e Mon Sep 17 00:00:00 2001 From: sirasistant Date: Wed, 11 Dec 2024 10:37:51 +0000 Subject: [PATCH 11/11] small refactor to trigger ci --- .../crates/types/src/abis/private_kernel/private_call_data.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr index 82094d0a5eb..0d887f71f42 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr @@ -25,8 +25,8 @@ pub struct PrivateCallData { } impl PrivateCallData { - fn verify(self, is_first: bool) { - let proof_type = if is_first { + fn verify(self, is_first_app: bool) { + let proof_type = if is_first_app { PROOF_TYPE_OINK } else { PROOF_TYPE_PG