From ee92e4d87e6f605db894cbbacb35ef4ed2ac7bce Mon Sep 17 00:00:00 2001 From: Zara Date: Thu, 19 Nov 2026 21:41:10 +0000 Subject: [PATCH 01/19] refactor(circuits)!: aggregate C6 proofs over Chonk A decryption's T + 1 C6 proofs now run in one Chonk stack instead of a sequential c6_fold chain. c6_chonk_app verifies every C6 proof, checks they share the first leaf's domain and places their sk, esm, ct and d commitments by slot; c6_chonk_tube verifies the stack as a rollup proof and c6_chonk_root closes its IPA claim. A root rollup closes exactly two claims, so the root takes the tube twice under the tube key. decryption_aggregator verifies c6_chonk_root and binds the anchored C6 tree hash to hash(root key, key-list hash). The C6 tree is now hash(c6_chonk_root, c6 chain); its anchor keeps the retired c6_fold artifact path. CircuitName gains six C6 Chonk variants; C6Fold and C6FoldKernel stay as retired variants so stored encodings keep their indices. Split from #2398. --- circuits/README.md | 4 +- circuits/bin/chonk/Nargo.toml | 4 + .../c6_fold => chonk/c6_chonk_app}/Nargo.toml | 2 +- circuits/bin/chonk/c6_chonk_app/src/main.nr | 55 ++ .../chonk/c6_chonk_hiding_kernel/Nargo.toml | 8 + .../chonk/c6_chonk_hiding_kernel/src/main.nr | 23 + .../bin/chonk/c6_chonk_init_kernel/Nargo.toml | 8 + .../chonk/c6_chonk_init_kernel/src/main.nr | 22 + .../bin/chonk/c6_chonk_tail_kernel/Nargo.toml | 8 + .../chonk/c6_chonk_tail_kernel/src/main.nr | 22 + .../Nargo.toml | 2 +- .../c6_chonk_root/src/main.nr | 42 + .../c6_chonk_tube/Nargo.toml | 8 + .../c6_chonk_tube/src/main.nr | 42 + .../recursive_aggregation/c6_fold/src/main.nr | 98 --- .../c6_fold_kernel/src/main.nr | 75 -- .../decryption_aggregator/src/main.nr | 62 +- circuits/lib/src/math/c6_chonk_rows.nr | 99 +++ circuits/lib/src/math/chonk.nr | 14 +- circuits/lib/src/math/mod.nr | 1 + .../src/interfold_event/compute_request/zk.rs | 4 +- .../effects/prove_plaintext.rs | 6 +- crates/zk/build/src/artifacts.rs | 2 +- crates/zk/build/src/tests.rs | 21 +- crates/zk/build/src/vk_tree.rs | 16 +- crates/zk/config/src/circuit.rs | 44 +- crates/zk/config/tests/circuit_identity.rs | 35 +- crates/zk/prover/required-artifacts.json | 24 +- .../circuits/aggregation/c6_accumulator.rs | 305 ------- .../src/circuits/aggregation/c6_chonk.rs | 252 ++++++ .../src/circuits/aggregation/helpers.rs | 40 +- .../zk/prover/src/circuits/aggregation/mod.rs | 2 +- .../src/circuits/aggregation/node_dkg_fold.rs | 55 +- crates/zk/prover/src/lib.rs | 2 +- crates/zk/prover/src/test_utils.rs | 1 + crates/zk/prover/tests/common/helpers.rs | 35 +- .../tests/fold_accumulators_e2e_tests.rs | 833 ++++++++---------- docs/architecture/circuit-artifacts.md | 19 +- docs/architecture/proof-statements.md | 53 +- docs/architecture/threshold-decryption.md | 2 +- docs/pages/build/noir-circuits.mdx | 17 +- docs/pages/internals/dkg.mdx | 16 +- docs/pages/learn/cryptography.mdx | 4 +- scripts/circuits/lint.sh | 4 +- 44 files changed, 1249 insertions(+), 1142 deletions(-) rename circuits/bin/{recursive_aggregation/c6_fold => chonk/c6_chonk_app}/Nargo.toml (92%) create mode 100644 circuits/bin/chonk/c6_chonk_app/src/main.nr create mode 100644 circuits/bin/chonk/c6_chonk_hiding_kernel/Nargo.toml create mode 100644 circuits/bin/chonk/c6_chonk_hiding_kernel/src/main.nr create mode 100644 circuits/bin/chonk/c6_chonk_init_kernel/Nargo.toml create mode 100644 circuits/bin/chonk/c6_chonk_init_kernel/src/main.nr create mode 100644 circuits/bin/chonk/c6_chonk_tail_kernel/Nargo.toml create mode 100644 circuits/bin/chonk/c6_chonk_tail_kernel/src/main.nr rename circuits/bin/recursive_aggregation/{c6_fold_kernel => c6_chonk_root}/Nargo.toml (91%) create mode 100644 circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr create mode 100644 circuits/bin/recursive_aggregation/c6_chonk_tube/Nargo.toml create mode 100644 circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr delete mode 100644 circuits/bin/recursive_aggregation/c6_fold/src/main.nr delete mode 100644 circuits/bin/recursive_aggregation/c6_fold_kernel/src/main.nr create mode 100644 circuits/lib/src/math/c6_chonk_rows.nr delete mode 100644 crates/zk/prover/src/circuits/aggregation/c6_accumulator.rs create mode 100644 crates/zk/prover/src/circuits/aggregation/c6_chonk.rs diff --git a/circuits/README.md b/circuits/README.md index 26ebc41710..e0eb27ce03 100644 --- a/circuits/README.md +++ b/circuits/README.md @@ -86,8 +86,8 @@ C2a and C2b proofs and hashes each one's chunk key tree into its key hash. | `node_fold` | `NodeFold` | Folds C0, C1, `c2ab_fold`, `c3ab_fold`, and `c4ab_fold` for one node. | | `nodes_fold`, `nodes_fold_kernel` | `NodesFold`, `NodesFoldKernel` | Folds the H `node_fold` proofs in sequence. | | `dkg_aggregator` | `DkgAggregator` | Verifies `nodes_fold` and C5. Its EVM proof goes to `publishCommittee`. | -| `c6_fold`, `c6_fold_kernel` | `C6Fold`, `C6FoldKernel` | Folds the T + 1 C6 proofs of one ciphertext. | -| `decryption_aggregator` | `DecryptionAggregator` | Verifies `c6_fold` and C7. Its EVM proof goes to `publishPlaintextOutput`. | +| `c6_chonk_*` | `C6Chonk*` | Verifies the T + 1 C6 proofs of one ciphertext in one Chonk stack and closes it. | +| `decryption_aggregator` | `DecryptionAggregator` | Verifies `c6_chonk_root` and C7. Its EVM proof goes to `publishPlaintextOutput`. | For recursive trust and public-input bindings, see [proof statements](../docs/architecture/proof-statements.md#recursive-trust-and-exported-values). diff --git a/circuits/bin/chonk/Nargo.toml b/circuits/bin/chonk/Nargo.toml index 5ac7081031..ea76a18938 100644 --- a/circuits/bin/chonk/Nargo.toml +++ b/circuits/bin/chonk/Nargo.toml @@ -4,4 +4,8 @@ members = [ "c3_chonk_init_kernel", "c3_chonk_tail_kernel", "c3_chonk_hiding_kernel", + "c6_chonk_app", + "c6_chonk_init_kernel", + "c6_chonk_tail_kernel", + "c6_chonk_hiding_kernel", ] diff --git a/circuits/bin/recursive_aggregation/c6_fold/Nargo.toml b/circuits/bin/chonk/c6_chonk_app/Nargo.toml similarity index 92% rename from circuits/bin/recursive_aggregation/c6_fold/Nargo.toml rename to circuits/bin/chonk/c6_chonk_app/Nargo.toml index f0ffd7e5e5..8a8190d6dc 100644 --- a/circuits/bin/recursive_aggregation/c6_fold/Nargo.toml +++ b/circuits/bin/chonk/c6_chonk_app/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "c6_fold" +name = "c6_chonk_app" type = "bin" authors = ["Gnosis Guild / Interfold"] diff --git a/circuits/bin/chonk/c6_chonk_app/src/main.nr b/circuits/bin/chonk/c6_chonk_app/src/main.nr new file mode 100644 index 0000000000..946ae5d2e9 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_app/src/main.nr @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Chonk app for C6: verifies a decryption's `T + 1` C6 proofs, checks they share one domain and +//! writes their sk, esm, ct and d commitments by slot, then the C6 leaf key hash +//! (`lib::math::chonk`). Every slot is filled: the stack holds the whole column. + +use bb_proof_verification::{UltraHonkVerificationKey, UltraHonkZKProof, verify_honk_proof}; +use lib::configs::default::T; +use lib::math::c6_chonk_rows::{assert_c6_domain, C6_PUBLIC_LEN, place_c6_leaves}; +use lib::math::chonk::{C3_CHONK_LEAVES, C6_CHONK_DATA_LEN, C6_CHONK_LEAVES}; + +fn main( + leaf_vk: UltraHonkVerificationKey, + leaf_key_hash: Field, + proofs: [UltraHonkZKProof; C6_CHONK_LEAVES], + c6_public_inputs: [[Field; C6_PUBLIC_LEN]; C6_CHONK_LEAVES], + slot_indices: [u32; C6_CHONK_LEAVES], +) -> return_data [Field; C6_CHONK_DATA_LEN + 1] { + // One stack holds the whole column; bb's ECCVM bound was measured at 24 UltraHonk proofs per + // stack (`C3_CHONK_LEAVES`), so a larger committee needs a second stack. + std::static_assert( + C6_CHONK_LEAVES <= C3_CHONK_LEAVES, + "T + 1 C6 proofs must fit one Chonk stack", + ); + for k in 0..C6_CHONK_LEAVES { + verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k], leaf_key_hash); + } + let domain_hi = c6_public_inputs[0][3]; + let domain_lo = c6_public_inputs[0][4]; + assert_c6_domain(c6_public_inputs, domain_hi, domain_lo); + // `T + 1` leaves in distinct slots fill every slot. + let (sk, esm, ct, d) = place_c6_leaves( + [0; T + 1], + [0; T + 1], + [0; T + 1], + [0; T + 1], + c6_public_inputs, + slot_indices, + ); + let mut out = [0; C6_CHONK_DATA_LEN + 1]; + out[0] = domain_hi; + out[1] = domain_lo; + for i in 0..(T + 1) { + out[2 + i] = sk[i]; + out[2 + (T + 1) + i] = esm[i]; + out[2 + 2 * (T + 1) + i] = ct[i]; + out[2 + 3 * (T + 1) + i] = d[i]; + } + out[C6_CHONK_DATA_LEN] = leaf_key_hash; + out +} diff --git a/circuits/bin/chonk/c6_chonk_hiding_kernel/Nargo.toml b/circuits/bin/chonk/c6_chonk_hiding_kernel/Nargo.toml new file mode 100644 index 0000000000..3d1fab83a8 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_hiding_kernel/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c6_chonk_hiding_kernel" +type = "bin" +authors = ["Gnosis Guild / Interfold"] + +[dependencies] +lib = { path = "../../../lib" } +bb_proof_verification = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v6.0.0", directory = "barretenberg/noir/bb_proof_verification" } diff --git a/circuits/bin/chonk/c6_chonk_hiding_kernel/src/main.nr b/circuits/bin/chonk/c6_chonk_hiding_kernel/src/main.nr new file mode 100644 index 0000000000..18c23af325 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_hiding_kernel/src/main.nr @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Chonk hiding kernel for C6: verifies the tail kernel, appends its key hash and makes the data +//! and the four key hashes the stack's public outputs. + +use lib::math::chonk::{C6_CHONK_DATA_LEN, KernelVerificationKey, PROOF_TYPE_HN_FINAL}; + +fn main( + prev_outputs: call_data(0) [Field; C6_CHONK_DATA_LEN + 3], + kernel_vk: KernelVerificationKey, +) -> pub [Field; C6_CHONK_DATA_LEN + 4] { + std::verify_proof_with_type(kernel_vk.key, [], [], kernel_vk.hash, PROOF_TYPE_HN_FINAL); + let mut out = [0; C6_CHONK_DATA_LEN + 4]; + for i in 0..C6_CHONK_DATA_LEN + 3 { + out[i] = prev_outputs[i]; + } + out[C6_CHONK_DATA_LEN + 3] = kernel_vk.hash; + out +} diff --git a/circuits/bin/chonk/c6_chonk_init_kernel/Nargo.toml b/circuits/bin/chonk/c6_chonk_init_kernel/Nargo.toml new file mode 100644 index 0000000000..6586c30a2b --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_init_kernel/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c6_chonk_init_kernel" +type = "bin" +authors = ["Gnosis Guild / Interfold"] + +[dependencies] +lib = { path = "../../../lib" } +bb_proof_verification = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v6.0.0", directory = "barretenberg/noir/bb_proof_verification" } diff --git a/circuits/bin/chonk/c6_chonk_init_kernel/src/main.nr b/circuits/bin/chonk/c6_chonk_init_kernel/src/main.nr new file mode 100644 index 0000000000..15874c4113 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_init_kernel/src/main.nr @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Chonk init kernel for C6: verifies the app and appends the app key hash. + +use lib::math::chonk::{AppVerificationKey, C6_CHONK_DATA_LEN, PROOF_TYPE_OINK}; + +fn main( + app_outputs: call_data(1) [Field; C6_CHONK_DATA_LEN + 1], + app_vk: AppVerificationKey, +) -> return_data [Field; C6_CHONK_DATA_LEN + 2] { + std::verify_proof_with_type(app_vk.key, [], [], app_vk.hash, PROOF_TYPE_OINK); + let mut out = [0; C6_CHONK_DATA_LEN + 2]; + for i in 0..C6_CHONK_DATA_LEN + 1 { + out[i] = app_outputs[i]; + } + out[C6_CHONK_DATA_LEN + 1] = app_vk.hash; + out +} diff --git a/circuits/bin/chonk/c6_chonk_tail_kernel/Nargo.toml b/circuits/bin/chonk/c6_chonk_tail_kernel/Nargo.toml new file mode 100644 index 0000000000..66c970f1e3 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_tail_kernel/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c6_chonk_tail_kernel" +type = "bin" +authors = ["Gnosis Guild / Interfold"] + +[dependencies] +lib = { path = "../../../lib" } +bb_proof_verification = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v6.0.0", directory = "barretenberg/noir/bb_proof_verification" } diff --git a/circuits/bin/chonk/c6_chonk_tail_kernel/src/main.nr b/circuits/bin/chonk/c6_chonk_tail_kernel/src/main.nr new file mode 100644 index 0000000000..5e9e7a7497 --- /dev/null +++ b/circuits/bin/chonk/c6_chonk_tail_kernel/src/main.nr @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Chonk tail kernel for C6: verifies the init kernel and appends its key hash. + +use lib::math::chonk::{C6_CHONK_DATA_LEN, KernelVerificationKey, PROOF_TYPE_HN}; + +fn main( + prev_outputs: call_data(0) [Field; C6_CHONK_DATA_LEN + 2], + kernel_vk: KernelVerificationKey, +) -> return_data [Field; C6_CHONK_DATA_LEN + 3] { + std::verify_proof_with_type(kernel_vk.key, [], [], kernel_vk.hash, PROOF_TYPE_HN); + let mut out = [0; C6_CHONK_DATA_LEN + 3]; + for i in 0..C6_CHONK_DATA_LEN + 2 { + out[i] = prev_outputs[i]; + } + out[C6_CHONK_DATA_LEN + 2] = kernel_vk.hash; + out +} diff --git a/circuits/bin/recursive_aggregation/c6_fold_kernel/Nargo.toml b/circuits/bin/recursive_aggregation/c6_chonk_root/Nargo.toml similarity index 91% rename from circuits/bin/recursive_aggregation/c6_fold_kernel/Nargo.toml rename to circuits/bin/recursive_aggregation/c6_chonk_root/Nargo.toml index 58ea82ab85..7114c5e9c3 100644 --- a/circuits/bin/recursive_aggregation/c6_fold_kernel/Nargo.toml +++ b/circuits/bin/recursive_aggregation/c6_chonk_root/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "c6_fold_kernel" +name = "c6_chonk_root" type = "bin" authors = ["Gnosis Guild / Interfold"] diff --git a/circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr b/circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr new file mode 100644 index 0000000000..bf9a2df573 --- /dev/null +++ b/circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Closes the C6 Chonk tube's IPA claim as a root rollup and re-exposes its data behind one hash of +//! its seven key hashes (tube, tube, Chonk, C6 leaf, app, init, tail). The decryption aggregator +//! verifies this proof and binds that hash, with this circuit's key, to the anchored C6 tree. + +use bb_proof_verification::{ + RollupHonkProof, RollupHonkVerificationKey, verify_root_rolluphonk_proof, +}; +use lib::math::chonk::{C3_CHONK_KEYS, C3_CHONK_OWN_KEY, C6_CHONK_DATA_LEN}; +use lib::math::commitments::compute_vk_hash; + +pub global C6_TUBE_PUBLIC_LEN: u32 = C3_CHONK_KEYS + C6_CHONK_DATA_LEN; + +/// A root rollup closes exactly two IPA claims and a C6 column has one tube, so the prover passes +/// the tube twice. Both inputs verify under the tube's own key; only the first gives the statement, +/// and the root's final IPA check fails unless both accumulated claims are valid. +fn main( + tube_vk: RollupHonkVerificationKey, + tube_proofs: [RollupHonkProof; 2], + tube_publics: [[Field; C6_TUBE_PUBLIC_LEN]; 2], +) -> pub (Field, [Field; C6_CHONK_DATA_LEN]) { + let tube_key = tube_publics[0][C3_CHONK_OWN_KEY]; + assert(tube_publics[1][C3_CHONK_OWN_KEY] == tube_key, "both inputs must be tube proofs"); + for k in 0..2 { + verify_root_rolluphonk_proof(tube_vk, tube_proofs[k], tube_publics[k], tube_key); + } + // The tube's own key opens its public inputs, so the key list hash covers it. + let mut keys = [0; C3_CHONK_KEYS]; + for k in 0..C3_CHONK_KEYS { + keys[k] = tube_publics[0][k]; + } + let mut data = [0; C6_CHONK_DATA_LEN]; + for i in 0..C6_CHONK_DATA_LEN { + data[i] = tube_publics[0][C3_CHONK_KEYS + i]; + } + (compute_vk_hash(keys.as_vector()), data) +} diff --git a/circuits/bin/recursive_aggregation/c6_chonk_tube/Nargo.toml b/circuits/bin/recursive_aggregation/c6_chonk_tube/Nargo.toml new file mode 100644 index 0000000000..d200b3a16c --- /dev/null +++ b/circuits/bin/recursive_aggregation/c6_chonk_tube/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c6_chonk_tube" +type = "bin" +authors = ["Gnosis Guild / Interfold"] + +[dependencies] +lib = { path = "../../../lib" } +bb_proof_verification = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v6.0.0", directory = "barretenberg/noir/bb_proof_verification" } diff --git a/circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr b/circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr new file mode 100644 index 0000000000..60b50ddff6 --- /dev/null +++ b/circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Verifies the C6 Chonk stack's proof and exposes its data behind the Chonk key list +//! (`lib::math::chonk`): own key, tube key (the same), Chonk key, then the C6 leaf, app, init and +//! tail key hashes the stack's kernels appended. Proven as a rollup proof carrying an IPA claim. + +use lib::math::chonk::{ + C3_CHONK_KEYS, C6_CHONK_DATA_LEN, CHONK_PROOF_LENGTH, CHONK_VK_LENGTH, PROOF_TYPE_CHONK, +}; + +fn main( + chonk_vk: [Field; CHONK_VK_LENGTH], + chonk_key_hash: Field, + proof: [Field; CHONK_PROOF_LENGTH], + stack_outputs: [Field; C6_CHONK_DATA_LEN + 4], + own_key_hash: pub Field, +) -> pub ([Field; C3_CHONK_KEYS - 1], [Field; C6_CHONK_DATA_LEN]) { + std::verify_proof_with_type( + chonk_vk, + proof, + stack_outputs, + chonk_key_hash, + PROOF_TYPE_CHONK, + ); + + // The stack appended the leaf, app, init and tail key hashes after its data. + let mut keys = [0; C3_CHONK_KEYS - 1]; + keys[0] = own_key_hash; + keys[1] = chonk_key_hash; + for k in 0..4 { + keys[2 + k] = stack_outputs[C6_CHONK_DATA_LEN + k]; + } + let mut data = [0; C6_CHONK_DATA_LEN]; + for i in 0..C6_CHONK_DATA_LEN { + data[i] = stack_outputs[i]; + } + (keys, data) +} diff --git a/circuits/bin/recursive_aggregation/c6_fold/src/main.nr b/circuits/bin/recursive_aggregation/c6_fold/src/main.nr deleted file mode 100644 index eba71823c5..0000000000 --- a/circuits/bin/recursive_aggregation/c6_fold/src/main.nr +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-only -// -// This file is provided WITHOUT ANY WARRANTY; -// without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. - -//! Sequential C6 fold: one inner ZK `ThresholdShareDecryption` proof per step, chained with the -//! previous accumulator: the `c6_fold_kernel` proof of the chain's first leaf on the first step, a -//! `c6_fold` non-ZK proof after that (see `crates/zk/prover` and `c6_fold_kernel`). - -use bb_proof_verification::{ - UltraHonkProof, UltraHonkVerificationKey, UltraHonkZKProof, verify_honk_proof, - verify_honk_proof_non_zk, -}; -use lib::configs::default::T; -use lib::math::recursive_vk::predecessor_key_hash; - -/// One C6 public row: `expected_sk`, `expected_e_sm`, `ct_commitment`, -/// `domain_hi`, `domain_lo`, `d_commitment` (see C6 leaf). -pub global C6_PUBLIC_LEN: u32 = 6; - -/// Five public parameters, the common domain limbs, and four columns of -/// `T + 1` party slots each. -pub global C6_FOLD_PUBLIC_LEN: u32 = 7 + (4 * (T + 1)); - -pub global C6_FOLD_PREFIX_LEN: u32 = C6_FOLD_PUBLIC_LEN - (4 * (T + 1)); - -fn main( - inner_vk: UltraHonkVerificationKey, - inner_proof: UltraHonkZKProof, - c6_public_inputs: [Field; C6_PUBLIC_LEN], - acc_vk: UltraHonkVerificationKey, - acc_proof: UltraHonkProof, - acc_public_inputs: [Field; C6_FOLD_PUBLIC_LEN], - inner_key_hash: pub Field, - fold_key_hash: pub Field, - kernel_key_hash: pub Field, - is_first_step: pub bool, - slot_index: pub u32, -) -> pub (Field, Field, [Field; T + 1], [Field; T + 1], [Field; T + 1], [Field; T + 1]) { - assert(slot_index < T + 1); - - verify_honk_proof(inner_vk, inner_proof, c6_public_inputs, inner_key_hash); - - let acc_key_hash = predecessor_key_hash( - inner_key_hash, - fold_key_hash, - kernel_key_hash, - is_first_step, - [acc_public_inputs[0], acc_public_inputs[1], acc_public_inputs[2]], - ); - verify_honk_proof_non_zk(acc_vk, acc_proof, acc_public_inputs, acc_key_hash); - - let sk_new = c6_public_inputs[0]; - let esm_new = c6_public_inputs[1]; - let ct_new = c6_public_inputs[2]; - let domain_hi = c6_public_inputs[3]; - let domain_lo = c6_public_inputs[4]; - let d_new = c6_public_inputs[5]; - - // The kernel records its leaf's domain too, so every step checks it. - assert(acc_public_inputs[5] == domain_hi); - assert(acc_public_inputs[6] == domain_lo); - - let mut out_sk: [Field; T + 1] = [0; T + 1]; - let mut out_esm: [Field; T + 1] = [0; T + 1]; - let mut out_ct: [Field; T + 1] = [0; T + 1]; - let mut out_d: [Field; T + 1] = [0; T + 1]; - - // The predecessor's rows carry forward, whether it is the kernel (which holds the chain's first - // leaf, so `is_first_step` only selects its key) or an earlier fold. The new leaf must land in - // an empty slot. - for i in 0..(T + 1) { - let idx = i as u32; - let prior_sk = acc_public_inputs[C6_FOLD_PREFIX_LEN + i]; - let prior_esm = acc_public_inputs[C6_FOLD_PREFIX_LEN + (T + 1) + i]; - let prior_ct = acc_public_inputs[C6_FOLD_PREFIX_LEN + (2 * (T + 1)) + i]; - let prior_d = acc_public_inputs[C6_FOLD_PREFIX_LEN + (3 * (T + 1)) + i]; - - if idx == slot_index { - assert(prior_sk == 0); - assert(prior_esm == 0); - assert(prior_ct == 0); - assert(prior_d == 0); - out_sk[i] = sk_new; - out_esm[i] = esm_new; - out_ct[i] = ct_new; - out_d[i] = d_new; - } else { - out_sk[i] = prior_sk; - out_esm[i] = prior_esm; - out_ct[i] = prior_ct; - out_d[i] = prior_d; - } - } - - (domain_hi, domain_lo, out_sk, out_esm, out_ct, out_d) -} diff --git a/circuits/bin/recursive_aggregation/c6_fold_kernel/src/main.nr b/circuits/bin/recursive_aggregation/c6_fold_kernel/src/main.nr deleted file mode 100644 index a70dc10ba1..0000000000 --- a/circuits/bin/recursive_aggregation/c6_fold_kernel/src/main.nr +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-only -// -// This file is provided WITHOUT ANY WARRANTY; -// without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. - -//! Same IO as [`c6_fold`](../c6_fold/src/main.nr) but **only** verifies the inner `ThresholdShareDecryption` proof. It -//! proves the chain's first leaf on its own: its proof carries that leaf's row and is the -//! accumulator the first `c6_fold` step verifies (with `is_first_step`, under this circuit's key). - -use bb_proof_verification::{ - UltraHonkProof, UltraHonkVerificationKey, UltraHonkZKProof, verify_honk_proof, -}; -use lib::configs::default::T; - -/// One C6 public row: `expected_sk`, `expected_e_sm`, `ct_commitment`, -/// `domain_hi`, `domain_lo`, `d_commitment` (see C6 leaf). -pub global C6_PUBLIC_LEN: u32 = 6; - -/// Same shape as `c6_fold`: five public parameters, the common domain limbs, and -/// 4 columns of `T + 1` party slots each. -pub global C6_FOLD_PUBLIC_LEN: u32 = 7 + (4 * (T + 1)); - -fn main( - inner_vk: UltraHonkVerificationKey, - inner_proof: UltraHonkZKProof, - c6_public_inputs: [Field; C6_PUBLIC_LEN], - acc_vk: UltraHonkVerificationKey, - acc_proof: UltraHonkProof, - acc_public_inputs: [Field; C6_FOLD_PUBLIC_LEN], - inner_key_hash: pub Field, - fold_key_hash: pub Field, - kernel_key_hash: pub Field, - is_first_step: pub bool, - slot_index: pub u32, -) -> pub (Field, Field, [Field; T + 1], [Field; T + 1], [Field; T + 1], [Field; T + 1]) { - assert(slot_index < T + 1); - - verify_honk_proof(inner_vk, inner_proof, c6_public_inputs, inner_key_hash); - - // Signature parity with `c6_fold`: the kernel takes the same inputs and ignores the - // accumulator, so both share one witness layout. - let _ = (acc_vk, acc_proof, fold_key_hash, kernel_key_hash, acc_public_inputs); - - assert(is_first_step); - - let sk_new = c6_public_inputs[0]; - let esm_new = c6_public_inputs[1]; - let ct_new = c6_public_inputs[2]; - let domain_hi = c6_public_inputs[3]; - let domain_lo = c6_public_inputs[4]; - let d_new = c6_public_inputs[5]; - - let mut out_sk: [Field; T + 1] = [0; T + 1]; - let mut out_esm: [Field; T + 1] = [0; T + 1]; - let mut out_ct: [Field; T + 1] = [0; T + 1]; - let mut out_d: [Field; T + 1] = [0; T + 1]; - - for i in 0..(T + 1) { - let idx = i as u32; - if idx == slot_index { - out_sk[i] = sk_new; - out_esm[i] = esm_new; - out_ct[i] = ct_new; - out_d[i] = d_new; - } else { - out_sk[i] = 0; - out_esm[i] = 0; - out_ct[i] = 0; - out_d[i] = 0; - } - } - - (domain_hi, domain_lo, out_sk, out_esm, out_ct, out_d) -} diff --git a/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr b/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr index 7a4f71271f..339b32f8ed 100644 --- a/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr +++ b/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr @@ -4,7 +4,7 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Decryption aggregator: non-ZK `c6_fold` (folded C6 column) + non-ZK `decrypted_shares_aggregation` +//! Decryption aggregator: non-ZK `c6_chonk_root` (the C6 column) + non-ZK `decrypted_shares_aggregation` //! (C7, both `noir-recursive-no-zk`). The final `bb prove -t evm` proof of this circuit is what the //! contract verifies on-chain. //! `committee_hash_hi` / `committee_hash_lo` bind the proof to the full on-chain committee ordering. @@ -18,23 +18,19 @@ use bb_proof_verification::{UltraHonkProof, UltraHonkVerificationKey, verify_hon use lib::configs::default::MAX_MSG_NON_ZERO_COEFFS; use lib::configs::default::N_PARTIES; use lib::configs::default::T; +use lib::math::chonk::C6_CHONK_DATA_LEN; use lib::math::commitments::compute_vk_hash; use lib::math::committee_hash::committee_hash_limbs; -use lib::math::recursive_vk::sequential_fold_vk_hash; -/// Must match `c6_fold::C6_FOLD_PUBLIC_LEN`: pub params, common domain limbs, -/// and flattened `(out_sk, out_esm, out_ct, out_d)`. -pub global C6_FOLD_PUBLIC_LEN: u32 = 7 + (4 * (T + 1)); - -pub global C6_FOLD_PREFIX_LEN: u32 = C6_FOLD_PUBLIC_LEN - (4 * (T + 1)); - -/// Column offsets inside the `c6_fold` flattened tail (after `C6_FOLD_PREFIX_LEN`): -/// `(out_sk, out_esm, out_ct, out_d)`, each `C6_FOLD_COL_WIDTH = T + 1` long. -pub global C6_FOLD_COL_WIDTH: u32 = T + 1; -pub global C6_FOLD_SK_COL_OFFSET: u32 = 0; -pub global C6_FOLD_ESM_COL_OFFSET: u32 = C6_FOLD_COL_WIDTH; -pub global C6_FOLD_CT_COL_OFFSET: u32 = 2 * C6_FOLD_COL_WIDTH; -pub global C6_FOLD_D_COL_OFFSET: u32 = 3 * C6_FOLD_COL_WIDTH; +/// `c6_chonk_root` public layout: its chain key hash, the two domain limbs, then the +/// `(sk, esm, ct, d)` columns, each `T + 1` long. +pub global C6_ROOT_PUBLIC_LEN: u32 = 1 + C6_CHONK_DATA_LEN; +pub global C6_ROOT_DOMAIN_HI: u32 = 1; +pub global C6_ROOT_DOMAIN_LO: u32 = 2; +pub global C6_ROOT_SK_OFFSET: u32 = 3; +pub global C6_ROOT_ESM_OFFSET: u32 = 3 + (T + 1); +pub global C6_ROOT_CT_OFFSET: u32 = 3 + 2 * (T + 1); +pub global C6_ROOT_D_OFFSET: u32 = 3 + 3 * (T + 1); /// `c7_public` layout: `[expected_d_commitments | party_ids | message]`. pub global C7_D_COMMITMENT_OFFSET: u32 = 0; @@ -66,10 +62,10 @@ fn assert_strictly_increasing(prev: u32, curr: u32) { } fn main( - c6_fold_vk: UltraHonkVerificationKey, - c6_fold_proof: UltraHonkProof, - c6_fold_public: [Field; C6_FOLD_PUBLIC_LEN], - c6_fold_vk_hash: Field, + c6_root_vk: UltraHonkVerificationKey, + c6_root_proof: UltraHonkProof, + c6_root_public: [Field; C6_ROOT_PUBLIC_LEN], + c6_root_vk_hash: Field, c7_vk: UltraHonkVerificationKey, c7_proof: UltraHonkProof, c7_public: [Field; C7_PUBLIC_LEN], @@ -86,35 +82,27 @@ fn main( assert(expected_hi == committee_hash_hi); assert(expected_lo == committee_hash_lo); - verify_honk_proof_non_zk(c6_fold_vk, c6_fold_proof, c6_fold_public, c6_fold_vk_hash); + verify_honk_proof_non_zk(c6_root_vk, c6_root_proof, c6_root_public, c6_root_vk_hash); verify_honk_proof_non_zk(c7_vk, c7_proof, c7_public, c7_key_hash); - assert(c6_fold_public[1] == c6_fold_vk_hash); - assert( - c6_fold_key_hash - == sequential_fold_vk_hash(c6_fold_vk_hash, c6_fold_public[2], c6_fold_public[0]), - ); + // The C6 tree is the root key and the hash of the stack's key list. + assert(c6_fold_key_hash == compute_vk_hash([c6_root_vk_hash, c6_root_public[0]].as_vector())); - // The C6 fold only accepts secret-bearing leaf proofs carrying one common + // The C6 stack only accepts secret-bearing leaf proofs carrying one common // domain. Expose that domain in the final EVM proof for on-chain checking. - assert(c6_fold_public[5] == domain_hi); - assert(c6_fold_public[6] == domain_lo); + assert(c6_root_public[C6_ROOT_DOMAIN_HI] == domain_hi); + assert(c6_root_public[C6_ROOT_DOMAIN_LO] == domain_lo); // Every C6 leaf commits to the same decoded BFV ciphertext. Expose that // canonical commitment as a final public input for the EVM wrapper. for i in 0..(T + 1) { - assert( - c6_fold_public[C6_FOLD_PREFIX_LEN + C6_FOLD_CT_COL_OFFSET + i] == ciphertext_commitment, - ); + assert(c6_root_public[C6_ROOT_CT_OFFSET + i] == ciphertext_commitment); } // Cross-circuit C6 to C7: each folded `d_commitment` column entry must match `c7_public[i]` // (leading `T + 1` words of `c7_public`). for i in 0..(T + 1) { - assert( - c6_fold_public[C6_FOLD_PREFIX_LEN + C6_FOLD_D_COL_OFFSET + i] - == c7_public[C7_D_COMMITMENT_OFFSET + i], - ); + assert(c6_root_public[C6_ROOT_D_OFFSET + i] == c7_public[C7_D_COMMITMENT_OFFSET + i]); } let vk_hashes = [c6_fold_key_hash, c7_key_hash].as_vector(); @@ -126,8 +114,8 @@ fn main( let mut prev_party_id: u32 = 0; for i in 0..(T + 1) { party_ids[i] = c7_public[C7_PARTY_ID_OFFSET + i]; - expected_sk[i] = c6_fold_public[C6_FOLD_PREFIX_LEN + C6_FOLD_SK_COL_OFFSET + i]; - expected_esm[i] = c6_fold_public[C6_FOLD_PREFIX_LEN + C6_FOLD_ESM_COL_OFFSET + i]; + expected_sk[i] = c6_root_public[C6_ROOT_SK_OFFSET + i]; + expected_esm[i] = c6_root_public[C6_ROOT_ESM_OFFSET + i]; // `committee_members` and `topNodes` are 0-indexed; a future per-party // signer/identity check must index them with `committee_members[party_ids[i] - 1]`, diff --git a/circuits/lib/src/math/c6_chonk_rows.nr b/circuits/lib/src/math/c6_chonk_rows.nr new file mode 100644 index 0000000000..7f0f80a9ad --- /dev/null +++ b/circuits/lib/src/math/c6_chonk_rows.nr @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! Row placement for the C6 Chonk app (`c6_chonk_app`). Its leaves fill every slot, so there is no +//! empty place; the decryption aggregator requires the ciphertext commitment in each slot. + +/// Fields of a C6 public transcript: sk, esm and ct commitments, the domain limbs, then d. +pub global C6_PUBLIC_LEN: u32 = 6; + +/// Writes each leaf's sk, esm, ct and d commitments into its slot, which must be empty and in +/// range. +pub fn place_c6_leaves( + sk: [Field; SLOTS], + esm: [Field; SLOTS], + ct: [Field; SLOTS], + d: [Field; SLOTS], + leaves: [[Field; C6_PUBLIC_LEN]; K], + slot_indices: [u32; K], +) -> ([Field; SLOTS], [Field; SLOTS], [Field; SLOTS], [Field; SLOTS]) { + let mut sk = sk; + let mut esm = esm; + let mut ct = ct; + let mut d = d; + for k in 0..K { + let slot = slot_indices[k]; + assert(slot < SLOTS, "slot index out of range"); + for i in 0..SLOTS { + if slot == i { + assert(sk[i] == 0, "slot already filled"); + assert(esm[i] == 0, "slot already filled"); + assert(ct[i] == 0, "slot already filled"); + assert(d[i] == 0, "slot already filled"); + sk[i] = leaves[k][0]; + esm[i] = leaves[k][1]; + ct[i] = leaves[k][2]; + d[i] = leaves[k][5]; + } + } + } + (sk, esm, ct, d) +} + +/// Every leaf must carry the chain's domain limbs. +pub fn assert_c6_domain( + leaves: [[Field; C6_PUBLIC_LEN]; K], + domain_hi: Field, + domain_lo: Field, +) { + for k in 0..K { + assert(leaves[k][3] == domain_hi, "C6 leaf domain differs"); + assert(leaves[k][4] == domain_lo, "C6 leaf domain differs"); + } +} + +#[test] +fn c6_leaves_land_in_their_slots() { + let (sk, esm, ct, d) = place_c6_leaves::<3, 3>( + [0; 3], + [0; 3], + [0; 3], + [0; 3], + [[1, 2, 3, 9, 9, 4], [5, 6, 7, 9, 9, 8], [11, 12, 13, 9, 9, 14]], + [2, 0, 1], + ); + assert(sk == [5, 11, 1]); + assert(esm == [6, 12, 2]); + assert(ct == [7, 13, 3]); + assert(d == [8, 14, 4]); +} + +#[test(should_fail_with = "slot already filled")] +fn a_c6_leaf_cannot_overwrite_a_filled_slot() { + let _ = place_c6_leaves::<2, 1>([0, 1], [0; 2], [0; 2], [0; 2], [[1, 2, 3, 0, 0, 4]], [1]); +} + +#[test(should_fail_with = "slot already filled")] +fn two_c6_leaves_cannot_share_a_slot() { + let _ = place_c6_leaves::<2, 2>( + [0; 2], + [0; 2], + [0; 2], + [0; 2], + [[1, 2, 3, 0, 0, 4], [5, 6, 7, 0, 0, 8]], + [1, 1], + ); +} + +#[test(should_fail_with = "slot index out of range")] +fn a_c6_slot_past_the_last_is_rejected() { + let _ = place_c6_leaves::<2, 1>([0; 2], [0; 2], [0; 2], [0; 2], [[1, 2, 3, 0, 0, 4]], [2]); +} + +#[test(should_fail_with = "C6 leaf domain differs")] +fn a_c6_leaf_from_another_domain_is_rejected() { + assert_c6_domain([[1, 2, 3, 7, 8, 4], [1, 2, 3, 7, 9, 4]], 7, 8); +} diff --git a/circuits/lib/src/math/chonk.nr b/circuits/lib/src/math/chonk.nr index 859fe15eea..f44bd63ac6 100644 --- a/circuits/lib/src/math/chonk.nr +++ b/circuits/lib/src/math/chonk.nr @@ -4,7 +4,7 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Chonk (Barretenberg client IVC) types and the C3 Chonk accumulator. +//! Chonk (Barretenberg client IVC) types, the C3 Chonk accumulator and the C6 Chonk stack. //! //! **C3 over Chonk.** A Chonk stack is an app and three kernels. The app (`c3_chonk_app`) verifies //! a batch of C3 proofs and writes their rows; each kernel verifies the circuit before it and @@ -19,6 +19,12 @@ //! //! **Rollups.** The tube and `c3_chonk_accumulate` are rollup proofs: each carries an IPA claim, //! the accumulate step merges two into one, and `c3ab_fold` closes both chains' claims once. +//! +//! **C6 over Chonk.** A decryption's `T + 1` C6 proofs fit one stack (`c6_chonk_app`, with its own +//! init, tail and hiding kernels), so there is nothing to accumulate: `c6_chonk_tube` verifies the +//! stack and `c6_chonk_root` closes the tube's IPA claim for `decryption_aggregator`. + +use crate::configs::default::T; /// Mega verification keys, as a kernel verifies the circuit before it. bb 6 derives app keys /// (`MegaAppFlavor`) and kernel keys (`MegaKernelFlavor`) separately; both are 151 fields. @@ -61,6 +67,12 @@ pub global C3_CHONK_KEYS: u32 = 7; pub global C3_CHONK_OWN_KEY: u32 = 0; pub global C3_CHONK_TUBE_KEY: u32 = 1; +/// C6 proofs one `c6_chonk_app` verifies: a decryption's whole column, one per slot. One stack +/// holds it while `T + 1` stays within `C3_CHONK_LEAVES`, the ECCVM bound. +pub global C6_CHONK_LEAVES: u32 = T + 1; +/// Data a C6 Chonk stack carries: the two domain limbs, then the sk, esm, ct and d columns. +pub global C6_CHONK_DATA_LEN: u32 = 2 + 4 * (T + 1); + /// Merges two disjoint row sets. A slot may be filled on at most one side. pub fn merge_rows(left: [Field; ROWS], right: [Field; ROWS]) -> [Field; ROWS] { let mut merged = [0; ROWS]; diff --git a/circuits/lib/src/math/mod.nr b/circuits/lib/src/math/mod.nr index fe174f35ba..2235acef07 100644 --- a/circuits/lib/src/math/mod.nr +++ b/circuits/lib/src/math/mod.nr @@ -12,5 +12,6 @@ pub mod commitments; pub mod recursive_vk; pub mod c3_chonk_rows; pub mod nodes_fold; +pub mod c6_chonk_rows; pub mod chonk; pub mod committee_hash; diff --git a/crates/events/src/interfold_event/compute_request/zk.rs b/crates/events/src/interfold_event/compute_request/zk.rs index 3ec6f43187..36abf525f6 100644 --- a/crates/events/src/interfold_event/compute_request/zk.rs +++ b/crates/events/src/interfold_event/compute_request/zk.rs @@ -45,7 +45,7 @@ pub enum ZkRequest { NodesFoldStep(NodesFoldStepRequest), /// Cross-node DKG aggregator (NodesFold + C5 + DkgAggregator). DkgAggregation(DkgAggregationRequest), - /// Phase-7 decryption aggregator (C6Fold + C7 + DecryptionAggregator). + /// Phase-7 decryption aggregator (C6 Chonk root + C7 + DecryptionAggregator). DecryptionAggregation(DecryptionAggregationRequest), /// Re-verify a C3a/C3b proof that an accusation forwards. It is accusation work, so it still /// runs after the E3 fails, until the request completes. Its response is @@ -114,7 +114,7 @@ pub struct DkgAggregationRequest { pub committee_size: CiphernodesCommitteeSize, } -/// Decryption aggregation: sequential C6 fold + DecryptionAggregator per job. +/// Decryption aggregation: C6 Chonk root + DecryptionAggregator per job. #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct DecryptionAggregationRequest { pub c6_total_slots: usize, diff --git a/crates/orchestration/aggregator/src/plaintext_aggregation/effects/prove_plaintext.rs b/crates/orchestration/aggregator/src/plaintext_aggregation/effects/prove_plaintext.rs index 1b951f7ec8..c3f8d0b30d 100644 --- a/crates/orchestration/aggregator/src/plaintext_aggregation/effects/prove_plaintext.rs +++ b/crates/orchestration/aggregator/src/plaintext_aggregation/effects/prove_plaintext.rs @@ -33,7 +33,7 @@ impl ThresholdPlaintextAggregator { Ok(()) } - /// Handle AggregationProofSigned: store C7 proofs and wait for C6 fold before publishing. + /// Handle AggregationProofSigned: store C7 proofs and wait for the C6 aggregation before publishing. pub fn handle_aggregation_proof_signed( &mut self, msg: TypedEvent, @@ -236,9 +236,9 @@ impl ThresholdPlaintextAggregator { .get() .ok_or(anyhow!("Could not get state"))? .try_into()?; - // C6Fold witness width is `T + 1` (same `T` as `threshold_m`). C7 is only proven for the + // The C6 column is `T + 1` wide (same `T` as `threshold_m`). C7 is only proven for the // first `T + 1` parties after sorting by party id (`handle_decrypted_shares_aggregation_proof` - // truncates); fold slot indices must stay in `0..T+1` and use that same party subset. + // truncates); C6 slot indices must stay in `0..T+1` and use that same party subset. let c6_total_slots = state.threshold_m as usize + 1; if honest_c6.len() < c6_total_slots { warn!( diff --git a/crates/zk/build/src/artifacts.rs b/crates/zk/build/src/artifacts.rs index 322994ab30..3f96a797e8 100644 --- a/crates/zk/build/src/artifacts.rs +++ b/crates/zk/build/src/artifacts.rs @@ -1061,7 +1061,7 @@ mod tests { before, "wildcard sync dry-run wrote files" ); - dry.circuits = vec!["c6_fold".into()]; + dry.circuits = vec!["decryption_aggregator".into()]; assert!(build(root, &dry).is_err()); assert_eq!(crate::tests::snapshot(root), before); let manifest = circuit.path.join("Nargo.toml"); diff --git a/crates/zk/build/src/tests.rs b/crates/zk/build/src/tests.rs index 3271b4062c..e6fbdeaa01 100644 --- a/crates/zk/build/src/tests.rs +++ b/crates/zk/build/src/tests.rs @@ -397,7 +397,7 @@ fn synchronized_sources_and_targets_are_isolated_and_missing_descendants_never_f } full.circuits = vec!["e_sm_share_computation".into()]; assert!(artifacts::discover(&repo, &full).is_err()); - full.circuits = vec!["c6_fold".into()]; + full.circuits = vec!["decryption_aggregator".into()]; assert!(artifacts::discover(&repo, &full).is_err()); let mut ss = request(); ss.circuits = vec!["pk".into()]; @@ -1466,8 +1466,8 @@ const VK_PATHS: &[(&str, &str, &str)] = &[ ("default", "recursive_aggregation", "nodes_fold"), ("default", "recursive_aggregation", "nodes_fold_kernel"), ("default", "recursive_aggregation", "node_fold"), - ("default", "recursive_aggregation", "c6_fold"), - ("default", "recursive_aggregation", "c6_fold_kernel"), + ("default", "recursive_aggregation", "c6_chonk_root"), + ("default", "recursive_aggregation", "c6_chonk_tube"), ("recursive", "threshold", "share_decryption"), ("default", "dkg", "sk_share_computation_chain"), ("default", "dkg", "sk_share_computation_chain_last"), @@ -1477,6 +1477,10 @@ const VK_PATHS: &[(&str, &str, &str)] = &[ ("default", "chonk", "c3_chonk_app"), ("default", "chonk", "c3_chonk_init_kernel"), ("default", "chonk", "c3_chonk_tail_kernel"), + ("default", "chonk", "c6_chonk_hiding_kernel"), + ("default", "chonk", "c6_chonk_app"), + ("default", "chonk", "c6_chonk_init_kernel"), + ("default", "chonk", "c6_chonk_tail_kernel"), ]; pub(crate) fn seed_anchor_keys(pair: &Path) { for i in 0..VK_PATHS.len() { @@ -1528,13 +1532,18 @@ fn anchors_bind_all_descendants_in_circuit_order_and_reject_noncanonical_keys() ), ( "c6_fold", - field_bytes(compute_vk_hash(vec![keys[14], keys[15], keys[16]])), + field_bytes(compute_vk_hash(vec![ + keys[14], + compute_vk_hash(vec![ + keys[15], keys[15], keys[25], keys[16], keys[26], keys[27], keys[28], + ]), + ])), ), ]; assert_eq!(vk_tree::hashes(root).unwrap(), expected); for (i, key) in keys.iter().enumerate() { - // Keys 14..=16 are the C6 chain; every other key is under the node fold. - let c6 = usize::from((14..=16).contains(&i)); + // Keys 14..=16 and 25.. are the C6 chain; every other key is under the node fold. + let c6 = usize::from((14..=16).contains(&i) || i >= 25); write(root, &key_path(i), field_bytes(Fr::from(99_u64))); let changed = vk_tree::hashes(root).unwrap(); assert_ne!(changed[c6].1, expected[c6].1, "{}", key_path(i)); diff --git a/crates/zk/build/src/vk_tree.rs b/crates/zk/build/src/vk_tree.rs index 53aa2c8805..55b821d843 100644 --- a/crates/zk/build/src/vk_tree.rs +++ b/crates/zk/build/src/vk_tree.rs @@ -79,10 +79,20 @@ pub fn hashes(root: &Path) -> Result<[(&'static str, [u8; 32]); 2]> { fold("node_fold")?, node, ]); + // The decryption aggregator binds the root key next to the hash of the C6 stack's key list, in + // the order the tube exposes it (its own key twice, then Chonk, C6, app, init and tail). + let c6_tube = fold("c6_chonk_tube")?; let c6 = compute_vk_hash(vec![ - fold("c6_fold")?, - fold("c6_fold_kernel")?, - load(root, "recursive", "threshold", "share_decryption")?, + fold("c6_chonk_root")?, + compute_vk_hash(vec![ + c6_tube, + c6_tube, + chonk("c6_chonk_hiding_kernel")?, + load(root, "recursive", "threshold", "share_decryption")?, + chonk("c6_chonk_app")?, + chonk("c6_chonk_init_kernel")?, + chonk("c6_chonk_tail_kernel")?, + ]), ]); let encode = |value: Fr| { let repr = value.into_bigint().to_bytes_be(); diff --git a/crates/zk/config/src/circuit.rs b/crates/zk/config/src/circuit.rs index d7c9aaf763..1327e45143 100644 --- a/crates/zk/config/src/circuit.rs +++ b/crates/zk/config/src/circuit.rs @@ -77,10 +77,10 @@ pub enum CircuitName { C3Fold, /// Retired `c3_fold` kernel. Kept so stored encodings keep their indices. C3FoldKernel, - /// Sequential C6 fold: inner ZK + prior `c6_fold` non-ZK proof (phase-7 aggregator). + /// Retired sequential C6 fold; C6 runs over Chonk, and the C6 tree anchor keeps this name's + /// artifact path. Kept so stored encodings keep their indices. C6Fold, - /// First step of a [`CircuitName::C6Fold`] chain: proves the first leaf and starts the accumulator - /// (same ABI; it verifies no accumulator). + /// Retired `c6_fold` kernel. Kept so stored encodings keep their indices. C6FoldKernel, /// Ad-hoc recursive aggregation: C2a + C2b. C2abFold, @@ -97,7 +97,7 @@ pub enum CircuitName { NodesFoldKernel, /// DKG aggregator (folded `node_fold` via `nodes_fold` + C5). DkgAggregator, - /// Phase-7 decryption aggregator (folded C6 via `c6_fold` + C7). + /// Phase-7 decryption aggregator (the C6 Chonk root + C7). DecryptionAggregator, /// Chunked C2a: a chunk other than the last (non-ZK, verified by the final C2 circuit). SkShareComputationChain, @@ -119,6 +119,18 @@ pub enum CircuitName { C3ChonkTube, /// Rollup proof merging a C3 Chonk accumulator or tube with a tube. C3ChonkAccumulate, + /// C6 Chonk stack app: verifies a decryption's `T + 1` C6 proofs and writes their columns. + C6ChonkApp, + /// C6 Chonk stack kernel that verifies the app. + C6ChonkInitKernel, + /// C6 Chonk stack kernel that verifies the init kernel. + C6ChonkTailKernel, + /// C6 Chonk stack kernel that verifies the tail kernel and ends the stack. + C6ChonkHidingKernel, + /// Rollup proof of the C6 Chonk stack's Chonk proof. + C6ChonkTube, + /// Closes the C6 tube's IPA claim; the decryption aggregator verifies it. + C6ChonkRoot, } impl CircuitName { @@ -257,6 +269,12 @@ impl CircuitName { CircuitName::C3ChonkHidingKernel => "c3_chonk_hiding_kernel", CircuitName::C3ChonkTube => "c3_chonk_tube", CircuitName::C3ChonkAccumulate => "c3_chonk_accumulate", + CircuitName::C6ChonkApp => "c6_chonk_app", + CircuitName::C6ChonkInitKernel => "c6_chonk_init_kernel", + CircuitName::C6ChonkTailKernel => "c6_chonk_tail_kernel", + CircuitName::C6ChonkHidingKernel => "c6_chonk_hiding_kernel", + CircuitName::C6ChonkTube => "c6_chonk_tube", + CircuitName::C6ChonkRoot => "c6_chonk_root", } } @@ -278,7 +296,11 @@ impl CircuitName { CircuitName::C3ChonkApp | CircuitName::C3ChonkInitKernel | CircuitName::C3ChonkTailKernel - | CircuitName::C3ChonkHidingKernel => "chonk", + | CircuitName::C3ChonkHidingKernel + | CircuitName::C6ChonkApp + | CircuitName::C6ChonkInitKernel + | CircuitName::C6ChonkTailKernel + | CircuitName::C6ChonkHidingKernel => "chonk", CircuitName::C3Fold | CircuitName::C3FoldKernel | CircuitName::C6Fold @@ -292,7 +314,9 @@ impl CircuitName { | CircuitName::DkgAggregator | CircuitName::DecryptionAggregator | CircuitName::C3ChonkTube - | CircuitName::C3ChonkAccumulate => "recursive_aggregation", + | CircuitName::C3ChonkAccumulate + | CircuitName::C6ChonkTube + | CircuitName::C6ChonkRoot => "recursive_aggregation", } } @@ -346,7 +370,13 @@ impl CircuitName { | CircuitName::C3ChonkTailKernel | CircuitName::C3ChonkHidingKernel | CircuitName::C3ChonkTube - | CircuitName::C3ChonkAccumulate => CircuitOutputLayout::None, + | CircuitName::C3ChonkAccumulate + | CircuitName::C6ChonkApp + | CircuitName::C6ChonkInitKernel + | CircuitName::C6ChonkTailKernel + | CircuitName::C6ChonkHidingKernel + | CircuitName::C6ChonkTube + | CircuitName::C6ChonkRoot => CircuitOutputLayout::None, } } diff --git a/crates/zk/config/tests/circuit_identity.rs b/crates/zk/config/tests/circuit_identity.rs index 219586e638..46feac75dc 100644 --- a/crates/zk/config/tests/circuit_identity.rs +++ b/crates/zk/config/tests/circuit_identity.rs @@ -34,8 +34,8 @@ fn secure_minimum_is_decryption_only_and_does_not_fall_back_to_ss() { #[test] fn baseline_enum_bytes_names_paths_and_layout_selection_are_unchanged() { // Frozen from the e3-events definitions at 26023af50, including the shared C4/C6 basename. - // The four share-computation chunk circuits, then the C3 Chonk circuits, are new rows appended - // after the existing variants. + // The four share-computation chunk circuits, then the C3 and C6 Chonk circuits, are new rows + // appended after the existing variants. for (index, (name, path, inputs, outputs)) in [ ("PkBfv", "dkg/pk", 0, Some(1)), ("PkGeneration", "threshold/pk_generation", 0, Some(3)), @@ -148,6 +148,37 @@ fn baseline_enum_bytes_names_paths_and_layout_selection_are_unchanged() { 0, Some(0), ), + ("C6ChonkApp", "chonk/c6_chonk_app", 0, Some(0)), + ( + "C6ChonkInitKernel", + "chonk/c6_chonk_init_kernel", + 0, + Some(0), + ), + ( + "C6ChonkTailKernel", + "chonk/c6_chonk_tail_kernel", + 0, + Some(0), + ), + ( + "C6ChonkHidingKernel", + "chonk/c6_chonk_hiding_kernel", + 0, + Some(0), + ), + ( + "C6ChonkTube", + "recursive_aggregation/c6_chonk_tube", + 0, + Some(0), + ), + ( + "C6ChonkRoot", + "recursive_aggregation/c6_chonk_root", + 0, + Some(0), + ), ] .into_iter() .enumerate() diff --git a/crates/zk/prover/required-artifacts.json b/crates/zk/prover/required-artifacts.json index ceea65b9d0..506dcf3c53 100644 --- a/crates/zk/prover/required-artifacts.json +++ b/crates/zk/prover/required-artifacts.json @@ -53,6 +53,18 @@ "default/chonk/c3_chonk_tail_kernel/c3_chonk_tail_kernel.json", "default/chonk/c3_chonk_tail_kernel/c3_chonk_tail_kernel.vk", "default/chonk/c3_chonk_tail_kernel/c3_chonk_tail_kernel.vk_hash", + "default/chonk/c6_chonk_app/c6_chonk_app.json", + "default/chonk/c6_chonk_app/c6_chonk_app.vk", + "default/chonk/c6_chonk_app/c6_chonk_app.vk_hash", + "default/chonk/c6_chonk_hiding_kernel/c6_chonk_hiding_kernel.json", + "default/chonk/c6_chonk_hiding_kernel/c6_chonk_hiding_kernel.vk", + "default/chonk/c6_chonk_hiding_kernel/c6_chonk_hiding_kernel.vk_hash", + "default/chonk/c6_chonk_init_kernel/c6_chonk_init_kernel.json", + "default/chonk/c6_chonk_init_kernel/c6_chonk_init_kernel.vk", + "default/chonk/c6_chonk_init_kernel/c6_chonk_init_kernel.vk_hash", + "default/chonk/c6_chonk_tail_kernel/c6_chonk_tail_kernel.json", + "default/chonk/c6_chonk_tail_kernel/c6_chonk_tail_kernel.vk", + "default/chonk/c6_chonk_tail_kernel/c6_chonk_tail_kernel.vk_hash", "default/recursive_aggregation/c2ab_fold/c2ab_fold.json", "default/recursive_aggregation/c2ab_fold/c2ab_fold.vk", "default/recursive_aggregation/c2ab_fold/c2ab_fold.vk_hash", @@ -68,12 +80,12 @@ "default/recursive_aggregation/c4ab_fold/c4ab_fold.json", "default/recursive_aggregation/c4ab_fold/c4ab_fold.vk", "default/recursive_aggregation/c4ab_fold/c4ab_fold.vk_hash", - "default/recursive_aggregation/c6_fold/c6_fold.json", - "default/recursive_aggregation/c6_fold/c6_fold.vk", - "default/recursive_aggregation/c6_fold/c6_fold.vk_hash", - "default/recursive_aggregation/c6_fold_kernel/c6_fold_kernel.json", - "default/recursive_aggregation/c6_fold_kernel/c6_fold_kernel.vk", - "default/recursive_aggregation/c6_fold_kernel/c6_fold_kernel.vk_hash", + "default/recursive_aggregation/c6_chonk_root/c6_chonk_root.json", + "default/recursive_aggregation/c6_chonk_root/c6_chonk_root.vk", + "default/recursive_aggregation/c6_chonk_root/c6_chonk_root.vk_hash", + "default/recursive_aggregation/c6_chonk_tube/c6_chonk_tube.json", + "default/recursive_aggregation/c6_chonk_tube/c6_chonk_tube.vk", + "default/recursive_aggregation/c6_chonk_tube/c6_chonk_tube.vk_hash", "default/recursive_aggregation/decryption_aggregator/decryption_aggregator.json", "default/recursive_aggregation/decryption_aggregator/decryption_aggregator.vk", "default/recursive_aggregation/decryption_aggregator/decryption_aggregator.vk_hash", diff --git a/crates/zk/prover/src/circuits/aggregation/c6_accumulator.rs b/crates/zk/prover/src/circuits/aggregation/c6_accumulator.rs deleted file mode 100644 index bb6eb7c239..0000000000 --- a/crates/zk/prover/src/circuits/aggregation/c6_accumulator.rs +++ /dev/null @@ -1,305 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-only -// -// This file is provided WITHOUT ANY WARRANTY; -// without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. - -//! Sequential C6 fold. The first inner `ThresholdShareDecryption` proof goes into -//! [`CircuitName::C6FoldKernel`], whose proof carries that leaf's row and starts the chain (see -//! `circuits/bin/recursive_aggregation/c6_fold_kernel`). Each later step verifies one more inner -//! proof and the accumulator: the kernel proof on the first step, a `c6_fold` proof after that. - -use crate::circuits::aggregation::helpers::{ - extract_single_field, field_keys, parse_acc_public_field_strings, sequential_fold, - zero_field_hex_strings, ACC_NONZK_PROOF_FIELDS, -}; -use crate::circuits::utils::{bytes_to_field_strings, inputs_json_to_input_map}; -use crate::circuits::vk; -use crate::error::ZkError; -use crate::prover::ZkProver; -use crate::witness::{CompiledCircuit, WitnessGenerator}; -use e3_events::Proof; -use e3_zk_config::{CircuitName, CircuitVariant}; -use serde::Serialize; - -/// `total_slots` = `T + 1` (one slot per party index in the C6 leaf layout). -fn c6_fold_public_input_field_count(total_slots: usize) -> usize { - 7 + 4 * total_slots -} - -/// Public-signal layout of `c6_fold`: five fold parameters, two common domain -/// limbs, then four columns of slots. -const C6_FOLD_PREFIX_LEN: usize = 7; -const C6_FOLD_SLOT_WIDTH: usize = 4; - -struct C6FoldVks { - inner_vk: vk::VkArtifacts, - fold_vk: vk::VkArtifacts, - kernel_vk: vk::VkArtifacts, -} - -impl C6FoldVks { - fn load(prover: &ZkProver, artifacts_dir: &str) -> Result { - Ok(Self { - inner_vk: vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Recursive, artifacts_dir), - CircuitName::ThresholdShareDecryption, - )?, - fold_vk: vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), - CircuitName::C6Fold, - )?, - kernel_vk: vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), - CircuitName::C6FoldKernel, - )?, - }) - } -} - -/// Proves [`CircuitName::C6FoldKernel`] over the chain's first leaf, at that leaf's slot. The proof -/// carries the leaf's row and is the accumulator the first fold step verifies. -fn generate_c6_fold_kernel_proof( - prover: &ZkProver, - inner: &Proof, - slot_index: u32, - total_slots: usize, - artifacts_dir: &str, - job_id: &str, -) -> Result { - let inner_vk = vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Recursive, artifacts_dir), - CircuitName::ThresholdShareDecryption, - )?; - let kernel_vk = vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), - CircuitName::C6FoldKernel, - )?; - let fold_vk = vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), - CircuitName::C6Fold, - )?; - let c6_public_inputs = threshold_share_decryption_inner_public_inputs(inner)?; - let expected_acc_pub = c6_fold_public_input_field_count(total_slots); - let acc_pi = zero_field_hex_strings(expected_acc_pub)?; - let acc_pf = zero_field_hex_strings(ACC_NONZK_PROOF_FIELDS)?; - - let full_input = C6FoldStepInput { - inner_vk: inner_vk.verification_key, - inner_proof: bytes_to_field_strings(&inner.data)?, - c6_public_inputs, - acc_vk: kernel_vk.verification_key, - acc_proof: acc_pf, - acc_public_inputs: acc_pi, - inner_key_hash: inner_vk.key_hash, - fold_key_hash: fold_vk.key_hash, - kernel_key_hash: kernel_vk.key_hash, - is_first_step: true, - slot_index, - }; - - let circuit_path = prover - .circuits_dir(CircuitVariant::Default, artifacts_dir) - .join(CircuitName::C6FoldKernel.dir_path()) - .join(format!("{}.json", CircuitName::C6FoldKernel.as_str())); - let compiled = CompiledCircuit::from_file(&circuit_path)?; - - let json = serde_json::to_value(&full_input) - .map_err(|e| ZkError::SerializationError(e.to_string()))?; - let input_map = inputs_json_to_input_map(&json)?; - let witness_gen = WitnessGenerator::new(); - let witness = witness_gen.generate_witness(&compiled, input_map)?; - - let proof = prover.generate_recursive_aggregation_bin_proof( - CircuitName::C6FoldKernel, - &witness, - job_id, - artifacts_dir, - )?; - let _ = prover.cleanup(job_id); - Ok(proof) -} - -fn threshold_share_decryption_inner_public_inputs(proof: &Proof) -> Result<[String; 6], ZkError> { - if proof.circuit != CircuitName::ThresholdShareDecryption { - return Err(ZkError::InvalidInput(format!( - "expected ThresholdShareDecryption inner proof, got {}", - proof.circuit - ))); - } - let ctx = "C6 inner ThresholdShareDecryption proof"; - Ok([ - extract_single_field(proof, "input", field_keys::EXPECTED_SK_COMMITMENT, ctx)?, - extract_single_field(proof, "input", field_keys::EXPECTED_E_SM_COMMITMENT, ctx)?, - extract_single_field(proof, "input", field_keys::CT_COMMITMENT, ctx)?, - extract_single_field(proof, "input", field_keys::DOMAIN_HI, ctx)?, - extract_single_field(proof, "input", field_keys::DOMAIN_LO, ctx)?, - extract_single_field(proof, "output", field_keys::D_COMMITMENT, ctx)?, - ]) -} - -#[derive(Serialize)] -struct C6FoldStepInput { - inner_vk: Vec, - inner_proof: Vec, - c6_public_inputs: [String; 6], - acc_vk: Vec, - acc_proof: Vec, - acc_public_inputs: Vec, - inner_key_hash: String, - fold_key_hash: String, - kernel_key_hash: String, - is_first_step: bool, - slot_index: u32, -} - -#[allow(clippy::too_many_arguments)] -fn generate_c6_fold_step_with_vks( - prover: &ZkProver, - inner: &Proof, - prior_fold: Option<&Proof>, - slot_index: u32, - total_slots: usize, - e3_id: &str, - artifacts_dir: &str, - vks: &C6FoldVks, -) -> Result { - // The first leaf goes into the kernel on its own. The kernel proof already carries that leaf's - // row, so it is the accumulator the next step verifies; folding the same leaf again on top of - // it would only repeat that verification. - let Some(prior) = prior_fold else { - let kernel_job_id = format!("{e3_id}-c6fold-kernel"); - return generate_c6_fold_kernel_proof( - prover, - inner, - slot_index, - total_slots, - artifacts_dir, - &kernel_job_id, - ); - }; - // A kernel predecessor marks the first fold step, which the circuit verifies with the kernel key. - let is_first_step = prior.circuit == CircuitName::C6FoldKernel; - - let c6_public_inputs = threshold_share_decryption_inner_public_inputs(inner)?; - let expected_acc_pub = c6_fold_public_input_field_count(total_slots); - - let acc_pi = parse_acc_public_field_strings( - prior, - if is_first_step { - CircuitName::C6FoldKernel - } else { - CircuitName::C6Fold - }, - C6_FOLD_PREFIX_LEN, - C6_FOLD_SLOT_WIDTH, - )?; - let prior_slots = (acc_pi.len() - C6_FOLD_PREFIX_LEN) / C6_FOLD_SLOT_WIDTH; - if prior_slots != total_slots || acc_pi.len() != expected_acc_pub { - return Err(ZkError::InvalidInput(format!( - "prior {} has {} public fields ({} slots); expected {} for total_slots={}", - prior.circuit, - acc_pi.len(), - prior_slots, - expected_acc_pub, - total_slots - ))); - } - let acc_vk_fields = if is_first_step { - vks.kernel_vk.verification_key.clone() - } else { - vks.fold_vk.verification_key.clone() - }; - let acc_proof = bytes_to_field_strings(&prior.data)?; - let acc_public_inputs = acc_pi; - - let full_input = C6FoldStepInput { - inner_vk: vks.inner_vk.verification_key.clone(), - inner_proof: bytes_to_field_strings(&inner.data)?, - c6_public_inputs, - acc_vk: acc_vk_fields, - acc_proof, - acc_public_inputs, - inner_key_hash: vks.inner_vk.key_hash.clone(), - fold_key_hash: vks.fold_vk.key_hash.clone(), - kernel_key_hash: vks.kernel_vk.key_hash.clone(), - is_first_step, - slot_index, - }; - - let circuit_path = prover - .circuits_dir(CircuitVariant::Default, artifacts_dir) - .join(CircuitName::C6Fold.dir_path()) - .join(format!("{}.json", CircuitName::C6Fold.as_str())); - let compiled = CompiledCircuit::from_file(&circuit_path)?; - - let json = serde_json::to_value(&full_input) - .map_err(|e| ZkError::SerializationError(e.to_string()))?; - let input_map = inputs_json_to_input_map(&json)?; - - let witness_gen = WitnessGenerator::new(); - let witness = witness_gen.generate_witness(&compiled, input_map)?; - - prover.generate_recursive_aggregation_bin_proof( - CircuitName::C6Fold, - &witness, - e3_id, - artifacts_dir, - ) -} - -/// Folds `inner_proofs` in order, one inner C6 proof per step — the integration surface for -/// ciphernodes (batch in, single `C6Fold` proof out). -/// -/// `slot_indices[i]` is the party slot index for `inner_proofs[i]`. -/// `total_slots` must equal `T + 1` and determines the accumulator width. -pub fn generate_sequential_c6_fold( - prover: &ZkProver, - inner_proofs: &[Proof], - slot_indices: &[u32], - total_slots: usize, - e3_id: &str, - artifacts_dir: &str, -) -> Result { - // Defense in depth: every C6 slot must be filled exactly once and indices must be in range. - // Without this a partial fold or duplicate slot could reach the decryption aggregator. - if inner_proofs.len() != total_slots { - return Err(ZkError::InvalidInput(format!( - "generate_sequential_c6_fold: expected {total_slots} inner proofs, got {}", - inner_proofs.len() - ))); - } - let mut seen = vec![false; total_slots]; - for &s in slot_indices { - let idx = s as usize; - if idx >= total_slots { - return Err(ZkError::InvalidInput(format!( - "generate_sequential_c6_fold: slot index {s} out of range (total_slots={total_slots})" - ))); - } - if seen[idx] { - return Err(ZkError::InvalidInput(format!( - "generate_sequential_c6_fold: duplicate slot index {s}" - ))); - } - seen[idx] = true; - } - let vks = C6FoldVks::load(prover, artifacts_dir)?; - sequential_fold( - "generate_sequential_c6_fold", - inner_proofs, - slot_indices, - |inner, prior, slot| { - generate_c6_fold_step_with_vks( - prover, - inner, - prior, - slot, - total_slots, - e3_id, - artifacts_dir, - &vks, - ) - }, - ) -} diff --git a/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs b/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs new file mode 100644 index 0000000000..9f979adf1b --- /dev/null +++ b/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs @@ -0,0 +1,252 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +//! C6 over Chonk (see `circuits/lib/src/math/chonk.nr`). A decryption's `T + 1` inner +//! `ThresholdShareDecryption` proofs go into one Chonk stack whose app verifies them all, a +//! [`CircuitName::C6ChonkTube`] rollup proof verifies the stack's Chonk proof, and +//! [`CircuitName::C6ChonkRoot`] closes the tube's IPA claim. The decryption aggregator verifies +//! the root proof. + +use crate::circuits::aggregation::chonk_stack::{load_compiled, witness, ChonkStack}; +use crate::circuits::aggregation::helpers::{extract_single_field, field_keys}; +use crate::circuits::utils::bytes_to_field_strings; +use crate::circuits::vk::{self, VkArtifacts}; +use crate::error::ZkError; +use crate::prover::ZkProver; +use e3_events::Proof; +use e3_zk_config::{CircuitName, CircuitVariant}; +use serde::Serialize; + +/// `c6_chonk_root` public layout: the key list hash, the two domain limbs, then the sk, esm, ct and +/// d columns of `T + 1` slots each. +pub(crate) const C6_ROOT_DOMAIN_HI: usize = 1; +pub(crate) const C6_ROOT_COLUMNS_START: usize = 3; + +fn threshold_share_decryption_inner_public_inputs(proof: &Proof) -> Result<[String; 6], ZkError> { + if proof.circuit != CircuitName::ThresholdShareDecryption { + return Err(ZkError::InvalidInput(format!( + "expected ThresholdShareDecryption inner proof, got {}", + proof.circuit + ))); + } + let ctx = "C6 inner ThresholdShareDecryption proof"; + Ok([ + extract_single_field(proof, "input", field_keys::EXPECTED_SK_COMMITMENT, ctx)?, + extract_single_field(proof, "input", field_keys::EXPECTED_E_SM_COMMITMENT, ctx)?, + extract_single_field(proof, "input", field_keys::CT_COMMITMENT, ctx)?, + extract_single_field(proof, "input", field_keys::DOMAIN_HI, ctx)?, + extract_single_field(proof, "input", field_keys::DOMAIN_LO, ctx)?, + extract_single_field(proof, "output", field_keys::D_COMMITMENT, ctx)?, + ]) +} + +/// The C6 Chonk circuits, loaded once and reused for every ciphertext. +pub(crate) struct C6ChonkCircuits { + leaf: VkArtifacts, + stack: ChonkStack, + tube: VkArtifacts, + pub(crate) root: VkArtifacts, +} + +impl C6ChonkCircuits { + pub(crate) fn load(prover: &ZkProver, artifacts_dir: &str) -> Result { + let default = prover.circuits_dir(CircuitVariant::Default, artifacts_dir); + Ok(Self { + leaf: vk::load_vk_artifacts( + &prover.circuits_dir(CircuitVariant::Recursive, artifacts_dir), + CircuitName::ThresholdShareDecryption, + )?, + stack: ChonkStack::load( + prover, + artifacts_dir, + [ + CircuitName::C6ChonkApp, + CircuitName::C6ChonkInitKernel, + CircuitName::C6ChonkTailKernel, + CircuitName::C6ChonkHidingKernel, + ], + )?, + tube: vk::load_vk_artifacts(&default, CircuitName::C6ChonkTube)?, + root: vk::load_vk_artifacts(&default, CircuitName::C6ChonkRoot)?, + }) + } +} + +#[derive(Serialize)] +struct AppInput { + leaf_vk: Vec, + leaf_key_hash: String, + proofs: Vec>, + c6_public_inputs: Vec<[String; 6]>, + slot_indices: Vec, +} + +#[derive(Serialize)] +struct TubeInput { + chonk_vk: Vec, + chonk_key_hash: String, + proof: Vec, + stack_outputs: Vec, + own_key_hash: String, +} + +/// The root closes exactly two IPA claims, so it takes the one tube twice. +#[derive(Serialize)] +struct RootInput { + tube_vk: Vec, + tube_proofs: [Vec; 2], + tube_publics: [Vec; 2], +} + +/// Proves one decryption's C6 column: the stack over all `total_slots` (`T + 1`) inner proofs, its +/// tube and the root. Returns the [`CircuitName::C6ChonkRoot`] proof. +/// +/// `slot_indices[i]` is the party slot index for `inner_proofs[i]`; every slot appears once. +pub(crate) fn generate_c6_chonk( + prover: &ZkProver, + circuits: &C6ChonkCircuits, + inner_proofs: &[Proof], + slot_indices: &[u32], + total_slots: usize, + job_id: &str, + artifacts_dir: &str, +) -> Result { + // Defense in depth: the app requires every slot exactly once. + let leaves = circuits.stack.app_leaves()?; + if inner_proofs.len() != total_slots + || slot_indices.len() != total_slots + || total_slots != leaves + { + return Err(ZkError::InvalidInput(format!( + "generate_c6_chonk: {} proofs and {} slots for {total_slots} slots; the app takes {leaves}", + inner_proofs.len(), + slot_indices.len() + ))); + } + let mut seen = vec![false; total_slots]; + for &s in slot_indices { + let idx = s as usize; + if idx >= total_slots || seen[idx] { + return Err(ZkError::InvalidInput(format!( + "generate_c6_chonk: slot index {s} out of range or repeated (total_slots={total_slots})" + ))); + } + seen[idx] = true; + } + + let zero = format!("0x{}", "0".repeat(64)); + let mut columns = vec![zero; 4 * total_slots]; + let mut proofs = Vec::with_capacity(total_slots); + let mut c6_public_inputs = Vec::with_capacity(total_slots); + for (proof, &slot) in inner_proofs.iter().zip(slot_indices) { + let public = threshold_share_decryption_inner_public_inputs(proof)?; + for (column, field) in [0, 1, 2, 5].into_iter().enumerate() { + columns[column * total_slots + slot as usize] = public[field].clone(); + } + proofs.push(bytes_to_field_strings(&proof.data)?); + c6_public_inputs.push(public); + } + // The app's data: the first leaf's domain limbs, the four columns, then the leaf key hash. + let mut outputs = vec![ + c6_public_inputs[0][3].clone(), + c6_public_inputs[0][4].clone(), + ]; + outputs.extend(columns); + outputs.push(circuits.leaf.key_hash.clone()); + let (stack_outputs, chonk_proof) = circuits.stack.prove( + prover, + &AppInput { + leaf_vk: circuits.leaf.verification_key.clone(), + leaf_key_hash: circuits.leaf.key_hash.clone(), + proofs, + c6_public_inputs, + slot_indices: slot_indices.to_vec(), + }, + outputs, + job_id, + )?; + + let tube_witness = witness( + &load_compiled(prover, CircuitName::C6ChonkTube, artifacts_dir)?, + &TubeInput { + chonk_vk: circuits.stack.chonk_key().verification_key.clone(), + chonk_key_hash: circuits.stack.chonk_key().key_hash.clone(), + proof: chonk_proof, + stack_outputs, + own_key_hash: circuits.tube.key_hash.clone(), + }, + )?; + let tube = prover.generate_rollup_proof( + CircuitName::C6ChonkTube, + &tube_witness, + job_id, + artifacts_dir, + )?; + + let tube_proof = bytes_to_field_strings(&tube.data)?; + let tube_public = bytes_to_field_strings(&tube.public_signals)?; + let root_witness = witness( + &load_compiled(prover, CircuitName::C6ChonkRoot, artifacts_dir)?, + &RootInput { + tube_vk: circuits.tube.verification_key.clone(), + tube_proofs: [tube_proof.clone(), tube_proof], + tube_publics: [tube_public.clone(), tube_public], + }, + )?; + let root = prover.generate_recursive_aggregation_bin_proof( + CircuitName::C6ChonkRoot, + &root_witness, + job_id, + artifacts_dir, + )?; + let _ = prover.cleanup(job_id); + Ok(root) +} + +/// [`generate_c6_chonk`] that loads the circuits itself — for callers proving one column. +pub fn generate_c6_chonk_root( + prover: &ZkProver, + inner_proofs: &[Proof], + slot_indices: &[u32], + total_slots: usize, + job_id: &str, + artifacts_dir: &str, +) -> Result { + let circuits = C6ChonkCircuits::load(prover, artifacts_dir)?; + generate_c6_chonk( + prover, + &circuits, + inner_proofs, + slot_indices, + total_slots, + job_id, + artifacts_dir, + ) +} + +/// [`generate_c6_chonk_root`] with stack stage `stage` (0 app, 1 init kernel, 2 tail kernel) +/// claimed under stage `from`'s key. Negative tests only: the root must fail to prove or verify. +pub fn generate_c6_chonk_root_with_substituted_key( + prover: &ZkProver, + inner_proofs: &[Proof], + slot_indices: &[u32], + total_slots: usize, + (stage, from): (usize, usize), + job_id: &str, + artifacts_dir: &str, +) -> Result { + let mut circuits = C6ChonkCircuits::load(prover, artifacts_dir)?; + circuits.stack.substitute_key(stage, from); + generate_c6_chonk( + prover, + &circuits, + inner_proofs, + slot_indices, + total_slots, + job_id, + artifacts_dir, + ) +} diff --git a/crates/zk/prover/src/circuits/aggregation/helpers.rs b/crates/zk/prover/src/circuits/aggregation/helpers.rs index ae2f6cc210..02e48dccc2 100644 --- a/crates/zk/prover/src/circuits/aggregation/helpers.rs +++ b/crates/zk/prover/src/circuits/aggregation/helpers.rs @@ -4,8 +4,8 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Shared helpers for the sequential `c6_fold` / `nodes_fold` accumulators and -//! the single-shot `node_dkg_fold` builder. +//! Shared helpers for the sequential `nodes_fold` accumulator and the single-shot `node_dkg_fold` +//! builder. use crate::circuits::utils::bytes_to_field_strings; use crate::error::ZkError; @@ -83,38 +83,10 @@ pub fn extract_single_field( Ok(fields.into_iter().next().expect("len == 1 verified above")) } -/// Parse and validate fold-accumulator public-signal field strings against -/// `(prefix_len, slot_width)`. Returns the flattened field-string vector. -/// -/// Use this when the accumulator has a per-slot tail of fixed `slot_width` (e.g. `c6_fold`). For accumulators whose tail layout is determined at runtime by the inner proof -/// shape (e.g. `nodes_fold`, where each slot stores a whole `node_fold` statement), use -/// [`parse_acc_public_field_strings_flat`] and perform the per-slot length check at the call site. -pub fn parse_acc_public_field_strings( - proof: &Proof, - expected_circuit: CircuitName, - prefix_len: usize, - slot_width: usize, -) -> Result, ZkError> { - if proof.circuit != expected_circuit { - return Err(ZkError::InvalidInput(format!( - "expected {expected_circuit} proof, got {}", - proof.circuit - ))); - } - let v = bytes_to_field_strings(proof.public_signals.as_ref())?; - if v.len() < prefix_len || !(v.len() - prefix_len).is_multiple_of(slot_width) { - return Err(ZkError::InvalidInput(format!( - "unexpected {expected_circuit} public signal field count: {} (prefix={prefix_len}, slot_width={slot_width})", - v.len() - ))); - } - Ok(v) -} - -/// Same as [`parse_acc_public_field_strings`] but only validates the prefix length -/// (no slot-width modulo check). Intended for accumulators whose per-slot width is determined -/// at runtime from the inner proof shape; the caller is responsible for verifying the total -/// length against the expected `prefix_len + slots * `. +/// Parses an accumulator proof's public signals as field strings, checking its circuit and that +/// they hold at least the prefix. The per-slot width (`nodes_fold` stores a whole `node_fold` +/// statement per slot) is known only at runtime, so the caller checks the total length against +/// `prefix_len + slots * `. pub fn parse_acc_public_field_strings_flat( proof: &Proof, expected_circuit: CircuitName, diff --git a/crates/zk/prover/src/circuits/aggregation/mod.rs b/crates/zk/prover/src/circuits/aggregation/mod.rs index 5c8f750301..bd5573b7c2 100644 --- a/crates/zk/prover/src/circuits/aggregation/mod.rs +++ b/crates/zk/prover/src/circuits/aggregation/mod.rs @@ -8,7 +8,7 @@ pub mod c2_chain; pub mod c3_chonk; -pub mod c6_accumulator; +pub mod c6_chonk; pub mod chain_keys; pub mod chonk_stack; pub mod helpers; diff --git a/crates/zk/prover/src/circuits/aggregation/node_dkg_fold.rs b/crates/zk/prover/src/circuits/aggregation/node_dkg_fold.rs index 5d710316d3..668db1531d 100644 --- a/crates/zk/prover/src/circuits/aggregation/node_dkg_fold.rs +++ b/crates/zk/prover/src/circuits/aggregation/node_dkg_fold.rs @@ -8,7 +8,9 @@ //! proofs ([`CircuitName::NodeFold`], [`CircuitName::DkgAggregator`], [`CircuitName::DecryptionAggregator`]). use crate::circuits::aggregation::c3_chonk::generate_c3_chonk_chain; -use crate::circuits::aggregation::c6_accumulator::generate_sequential_c6_fold; +use crate::circuits::aggregation::c6_chonk::{ + generate_c6_chonk, C6ChonkCircuits, C6_ROOT_COLUMNS_START, C6_ROOT_DOMAIN_HI, +}; use crate::circuits::aggregation::helpers::{address_to_field_hex, u64_to_field_hex}; use crate::circuits::aggregation::nodes_fold_accumulator::generate_sequential_nodes_fold; use crate::circuits::utils::{bytes_to_field_strings, inputs_json_to_input_map}; @@ -545,10 +547,10 @@ pub struct DecryptionAggregationJob<'a> { #[derive(Serialize)] struct DecryptionAggregatorWitness { - c6_fold_vk: Vec, - c6_fold_vk_hash: String, - c6_fold_proof: Vec, - c6_fold_public: Vec, + c6_root_vk: Vec, + c6_root_vk_hash: String, + c6_root_proof: Vec, + c6_root_public: Vec, c7_vk: Vec, c7_proof: Vec, c7_public: Vec, @@ -562,7 +564,7 @@ struct DecryptionAggregatorWitness { ciphertext_commitment: String, } -/// Prove [`CircuitName::DecryptionAggregator`] for each job (C6 fold + C7), with +/// Prove [`CircuitName::DecryptionAggregator`] for each job (C6 Chonk root + C7), with /// [`CircuitVariant::Evm`] for on-chain verification. pub fn prove_decryption_aggregation_jobs( prover: &ZkProver, @@ -573,10 +575,7 @@ pub fn prove_decryption_aggregation_jobs( artifacts_dir: &str, ) -> Result, ZkError> { // VKs and the compiled circuit are job-independent: load once, reuse per ciphertext. - let c6_fold_vk = vk::load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), - CircuitName::C6Fold, - )?; + let c6_circuits = C6ChonkCircuits::load(prover, artifacts_dir)?; let c7_vk = vk::load_vk_artifacts( &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), CircuitName::DecryptedSharesAggregation, @@ -604,38 +603,42 @@ pub fn prove_decryption_aggregation_jobs( let mut out = Vec::with_capacity(jobs.len()); for (i, job) in jobs.iter().enumerate() { - let c6_fold = generate_sequential_c6_fold( + let c6_root = generate_c6_chonk( prover, + &c6_circuits, job.c6_inner_proofs, job.c6_slot_indices, c6_total_slots, - &format!("{e3_id}-c6fold-{i}"), + &format!("{e3_id}-c6chonk-{i}"), artifacts_dir, )?; - let c6_fold_public = proof_public_field_strings(&c6_fold)?; - let domain_hi = c6_fold_public.get(5).cloned().ok_or_else(|| { - ZkError::InvalidInput("C6 fold proof is missing domain_hi at public input 5".into()) - })?; - let domain_lo = c6_fold_public.get(6).cloned().ok_or_else(|| { - ZkError::InvalidInput("C6 fold proof is missing domain_lo at public input 6".into()) - })?; - let ciphertext_commitment = c6_fold_public - .get(7 + (2 * c6_total_slots)) + let c6_root_public = proof_public_field_strings(&c6_root)?; + let domain_hi = c6_root_public + .get(C6_ROOT_DOMAIN_HI) + .cloned() + .ok_or_else(|| ZkError::InvalidInput("C6 root proof is missing domain_hi".into()))?; + let domain_lo = c6_root_public + .get(C6_ROOT_DOMAIN_HI + 1) + .cloned() + .ok_or_else(|| ZkError::InvalidInput("C6 root proof is missing domain_lo".into()))?; + let ciphertext_commitment = c6_root_public + .get(C6_ROOT_COLUMNS_START + (2 * c6_total_slots)) .cloned() .ok_or_else(|| { ZkError::InvalidInput( - "C6 fold proof is missing the ciphertext commitment column".into(), + "C6 root proof is missing the ciphertext commitment column".into(), ) })?; let witness = DecryptionAggregatorWitness { - c6_fold_vk: c6_fold_vk.verification_key.clone(), - c6_fold_vk_hash: c6_fold_vk.key_hash.clone(), - c6_fold_proof: proof_field_strings(&c6_fold)?, - c6_fold_public, + c6_root_vk: c6_circuits.root.verification_key.clone(), + c6_root_vk_hash: c6_circuits.root.key_hash.clone(), + c6_root_proof: proof_field_strings(&c6_root)?, + c6_root_public, c7_vk: c7_vk.verification_key.clone(), c7_proof: proof_field_strings(job.c7_proof)?, c7_public: proof_public_field_strings(job.c7_proof)?, + // The C6 tree anchor keeps its `c6_fold` artifact path. c6_fold_key_hash: vk::load_vk_tree_hash( &prover.circuits_dir(CircuitVariant::Default, artifacts_dir), CircuitName::C6Fold, diff --git a/crates/zk/prover/src/lib.rs b/crates/zk/prover/src/lib.rs index 862b10dde5..fcbb16d734 100644 --- a/crates/zk/prover/src/lib.rs +++ b/crates/zk/prover/src/lib.rs @@ -32,7 +32,7 @@ pub use domain::commitment_links::default_links; pub use backend::{BBPath, SetupStatus, ZkBackend}; pub use circuits::aggregation::c2_chain::{final_circuit_inputs, ChunkCircuits}; pub use circuits::aggregation::c3_chonk::generate_c3_chonk_chain; -pub use circuits::aggregation::c6_accumulator::generate_sequential_c6_fold; +pub use circuits::aggregation::c6_chonk::generate_c6_chonk_root; pub use circuits::aggregation::chain_keys::chunk_circuits; pub use circuits::aggregation::node_dkg_fold::{ prove_decryption_aggregation_jobs, prove_dkg_aggregation, prove_node_dkg_fold, diff --git a/crates/zk/prover/src/test_utils.rs b/crates/zk/prover/src/test_utils.rs index ad96a749c8..056b4e83b5 100644 --- a/crates/zk/prover/src/test_utils.rs +++ b/crates/zk/prover/src/test_utils.rs @@ -17,6 +17,7 @@ pub use crate::circuits::aggregation::c3_chonk::{ generate_c3_chonk_accumulate, generate_c3_chonk_chain_with_substituted_key, generate_c3_chonk_tubes, }; +pub use crate::circuits::aggregation::c6_chonk::generate_c6_chonk_root_with_substituted_key; pub use crate::circuits::vk::load_vk_artifacts; /// Repository root for prover tests and their shared artifacts. diff --git a/crates/zk/prover/tests/common/helpers.rs b/crates/zk/prover/tests/common/helpers.rs index 4248d56012..f173eb46e3 100644 --- a/crates/zk/prover/tests/common/helpers.rs +++ b/crates/zk/prover/tests/common/helpers.rs @@ -187,6 +187,39 @@ pub async fn setup_c3_chonk_circuits(backend: &ZkBackend) { } } +/// Installs the C6 Chonk circuits: the four stack circuits from the `chonk` workspace, then the +/// tube and root rollups, and the C6 tree anchor. +#[allow(dead_code)] +pub async fn setup_c6_chonk_circuits(backend: &ZkBackend) { + setup_default_recursive_circuits( + backend, + &[ + CircuitName::C6ChonkApp, + CircuitName::C6ChonkInitKernel, + CircuitName::C6ChonkTailKernel, + CircuitName::C6ChonkHidingKernel, + ], + ) + .await; + for circuit in [CircuitName::C6ChonkTube, CircuitName::C6ChonkRoot] { + setup_recursive_aggregation_fold_circuit(backend, circuit).await; + } + // The C6 tree anchor keeps the retired `c6_fold` artifact path. + let anchor = backend + .circuits_dir + .join("insecure-64") + .join("minimum") + .join("default") + .join(CircuitName::C6Fold.dir_path()); + fs::create_dir_all(&anchor).await.unwrap(); + fs::copy( + circuits_build_root().join("recursive_aggregation/c6_fold/target/c6_fold.vk_tree_hash"), + anchor.join("c6_fold.vk_tree_hash"), + ) + .await + .expect("C6 VK-tree anchor; run pnpm build:circuits"); +} + /// Installs `circuits` in the `default` variant only, from their workspace's shared target /// directory. async fn setup_default_recursive_circuits(backend: &ZkBackend, circuits: &[CircuitName]) { @@ -263,7 +296,7 @@ pub async fn setup_recursive_aggregation_fold_circuit(backend: &ZkBackend, circu .unwrap(); } - if matches!(circuit, CircuitName::NodesFold | CircuitName::C6Fold) { + if circuit == CircuitName::NodesFold { fs::copy( target_dir.join(format!("{pkg}.vk_tree_hash")), default_dir.join(format!("{pkg}.vk_tree_hash")), diff --git a/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs b/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs index 85ca589b15..5fe78eaf2e 100644 --- a/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs +++ b/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs @@ -5,10 +5,10 @@ // or FITNESS FOR A PARTICULAR PURPOSE. //! Accumulation integration tests: a node's C3 batch through the C3 Chonk stacks, tubes and -//! accumulate proofs ([`generate_c3_chonk_chain`]), and sequential [`generate_sequential_c6_fold`] -//! (prove + [`ZkProver::verify_fold_proof`]) with the slot count read from the compiled `c6_fold` -//! ABI and artifacts staged under [`CircuitVariant::Default`] (`noir-recursive-no-zk` VKs — see -//! `crates/zk/build`). +//! accumulate proofs ([`generate_c3_chonk_chain`]), and a decryption's C6 column through the C6 +//! Chonk stack, tube and root ([`generate_c6_chonk_root`]), proven and verified natively under +//! [`CircuitVariant::Default`] (`noir-recursive-no-zk` VKs — see `crates/zk/build`), with slot +//! counts read from the compiled circuits. //! //! The node-fold pipeline ([`CircuitName::C2abFold`] … [`CircuitName::NodeFold`]), which consumes //! the C3 Chonk chains, is proven in `node_fold_correlated_e2e_tests.rs`. @@ -20,16 +20,21 @@ //! - [`c3_chonk_accumulate_and_c3ab_reject_children_of_the_wrong_kind`]: an accumulator merges a //! third tube as the left child; the accumulate step and `c3ab_fold` reject children of the //! wrong kind, and a tube under the accumulator's key. -//! - [`c6_fold_sequential_proves_and_verifies`]: two inner `ThresholdShareDecryption` proofs → [`generate_sequential_c6_fold`]. +//! - [`c6_chonk_root_proves_and_binds_the_decryption_aggregator`]: `T + 1` inner +//! `ThresholdShareDecryption` proofs → [`generate_c6_chonk_root`], whose key list hashes to the +//! anchored C6 tree the decryption aggregator pins; a root under another key cannot claim it. +//! - [`c6_chonk_rejects_a_corrupted_leaf_or_a_substituted_key`]: a leaf whose claimed row differs +//! from its proof, or a stack stage handed another stage's key, never yields a root. +//! - [`c6_chonk_app_rejects_a_shared_slot_an_out_of_range_slot_and_a_foreign_domain`]: the app +//! constrains slots and the domain, each next to an honest twin that solves. mod common; +#[allow(dead_code)] #[path = "common/recursive_vk_substitution.rs"] mod recursive_vk_substitution; -use std::path::PathBuf; - use common::{ - find_bb, setup_c3_chonk_circuits, setup_compiled_circuit, + find_bb, setup_c3_chonk_circuits, setup_c6_chonk_circuits, setup_compiled_circuit, setup_recursive_aggregation_fold_circuit, setup_test_prover, }; use e3_committee::CiphernodesCommitteeSize; @@ -40,389 +45,18 @@ use e3_zk_config::MAX_MSG_NON_ZERO_COEFFS; use e3_zk_config::{CircuitName, CircuitVariant}; use e3_zk_prover::test_utils::{ fold_witness_field_strings, generate_c3_chonk_accumulate, - generate_c3_chonk_chain_with_substituted_key, generate_c3_chonk_tubes, load_vk_artifacts, + generate_c3_chonk_chain_with_substituted_key, generate_c3_chonk_tubes, + generate_c6_chonk_root_with_substituted_key, load_vk_artifacts, }; use e3_zk_prover::{ - generate_c3_chonk_chain, generate_sequential_c6_fold, Provable, ZkBackend, ZkError, ZkProver, + generate_c3_chonk_chain, generate_c6_chonk_root, Provable, ZkBackend, ZkError, ZkProver, }; use e3_zk_prover::{ ShareEncryptionCircuit, ThresholdShareDecryptionCircuit as ShareDecryptionCircuit, }; -use e3_zk_witness::threshold::share_decryption::ShareDecryptionCircuitData; -use recursive_vk_substitution::{assert_fold_rejected, fields, substitute_proof, vk_hash, witness}; +use recursive_vk_substitution::{fields, substitute_proof, vk_hash, witness}; use serde_json::json; -fn c6_fold_json_path() -> PathBuf { - e3_zk_prover::test_utils::workspace_root() - .join("circuits/bin/recursive_aggregation/c6_fold/target/c6_fold.json") -} - -/// Reads slot count from the compiled `c6_fold` ABI -/// (`acc_public_inputs` length is `7 + 4 * slots`: five fold parameters and two domain limbs). -fn c6_fold_total_slots_from_compiled_json() -> usize { - let path = c6_fold_json_path(); - let raw = std::fs::read_to_string(&path).unwrap_or_else(|e| { - panic!( - "read {}: {} (run `pnpm build:circuits --group recursive_aggregation`)", - path.display(), - e - ) - }); - let v: serde_json::Value = - serde_json::from_str(&raw).unwrap_or_else(|e| panic!("parse {}: {}", path.display(), e)); - let len = v["abi"]["parameters"] - .as_array() - .and_then(|ps| { - ps.iter() - .find(|p| { - p.get("name") == Some(&serde_json::Value::String("acc_public_inputs".into())) - }) - .and_then(|p| p.get("type")?.get("length")?.as_u64()) - }) - .expect("c6_fold.json: abi.parameters.acc_public_inputs.length") as usize; - assert!( - len >= 7 && (len - 7).is_multiple_of(4), - "unexpected acc_public_inputs length {} (expected 7 + 4 * slots)", - len - ); - (len - 7) / 4 -} - -/// Expected C6 fold slot count when circuits are compiled for the minimum committee (N=3, T=1). -const MINIMUM_C6_FOLD_SLOTS: usize = 2; - -fn assert_recursive_vk_binding( - prover: &ZkProver, - fold: CircuitName, - kernel: CircuitName, - inners: &[Proof], - folded: &Proof, - total_slots: usize, - artifacts_dir: &str, -) { - let default_dir = prover.circuits_dir(CircuitVariant::Default, artifacts_dir); - let recursive_dir = prover.circuits_dir(CircuitVariant::Recursive, artifacts_dir); - let leaf_vk = load_vk_artifacts(&recursive_dir, inners[0].circuit).unwrap(); - let fold_vk = load_vk_artifacts(&default_dir, fold).unwrap(); - let kernel_vk = load_vk_artifacts(&default_dir, kernel).unwrap(); - let fold_path = default_dir - .join(fold.dir_path()) - .join(format!("{}.json", fold.as_str())); - let kernel_path = default_dir - .join(kernel.dir_path()) - .join(format!("{}.json", kernel.as_str())); - // The kernel proves the chain's first leaf at slot 0. - let mut input = json!({ - "inner_vk": leaf_vk.verification_key, - "inner_proof": fold_witness_field_strings(&inners[0].data).unwrap(), - "acc_vk": kernel_vk.verification_key, - "acc_proof": vec!["0"; folded.data.len() / 32], - "acc_public_inputs": vec!["0"; fields(folded).len()], - "inner_key_hash": leaf_vk.key_hash, - "fold_key_hash": fold_vk.key_hash, - "kernel_key_hash": kernel_vk.key_hash, - "is_first_step": true, - "slot_index": 0, - }); - input["c6_public_inputs"] = json!(fields(&inners[0])); - let kernel_witness = witness(&kernel_path, &input).expect("honest genesis witness"); - let genesis = prover - .generate_recursive_aggregation_bin_proof( - kernel, - &kernel_witness, - "vk-binding-genesis", - artifacts_dir, - ) - .expect("honest genesis proof"); - - // The first fold step adds the second leaf at slot 1 on top of the kernel proof. - input["acc_proof"] = json!(fold_witness_field_strings(&genesis.data).unwrap()); - input["acc_public_inputs"] = json!(fields(&genesis)); - input["inner_proof"] = json!(fold_witness_field_strings(&inners[1].data).unwrap()); - input["c6_public_inputs"] = json!(fields(&inners[1])); - input["slot_index"] = json!(1); - let first_witness = witness(&fold_path, &input).expect("honest first-step witness"); - let first = prover - .generate_recursive_aggregation_bin_proof( - fold, - &first_witness, - "vk-binding-first", - artifacts_dir, - ) - .expect("honest first-step proof"); - - let mut reused_slot = input.clone(); - reused_slot["slot_index"] = json!(0); - assert!( - witness(&fold_path, &reused_slot).is_err(), - "the first fold step must not refill the kernel's slot" - ); - - // A substituted predecessor carries the honest predecessor's public inputs, so the step's own - // constraints, slot 1 still empty included, hold: the witness solves, and only the recursive - // verification of the predecessor under its VK can reject it. - let fake_kernel = substitute_proof( - prover, - kernel, - CircuitVariant::Default, - &fields(&genesis), - None, - "kernel-predecessor", - ); - let mut fake_genesis = input.clone(); - fake_genesis["acc_vk"] = json!(fake_kernel.vk); - fake_genesis["acc_proof"] = json!(fold_witness_field_strings(&fake_kernel.proof.data).unwrap()); - fake_genesis["acc_public_inputs"] = json!(fields(&fake_kernel.proof)); - witness(&fold_path, &fake_genesis).expect("a substituted kernel leaves the step satisfiable"); - assert_fold_rejected( - prover, - fold, - &fold_path, - &fake_genesis, - artifacts_dir, - "substituted-genesis", - ); - - let fake_acc = substitute_proof( - prover, - fold, - CircuitVariant::Default, - &fields(&first), - None, - "predecessor", - ); - - // With a third slot, a continuation verifies a fold predecessor under the fold key. - let mut steps = vec![(input.clone(), 1)]; - if total_slots >= 3 { - let mut continuation = input.clone(); - continuation["acc_vk"] = json!(fold_vk.verification_key); - continuation["acc_proof"] = json!(fold_witness_field_strings(&first.data).unwrap()); - continuation["acc_public_inputs"] = json!(fields(&first)); - continuation["inner_proof"] = json!(fold_witness_field_strings(&inners[0].data).unwrap()); - continuation["c6_public_inputs"] = json!(fields(&inners[0])); - continuation["is_first_step"] = json!(false); - continuation["slot_index"] = json!(2); - witness(&fold_path, &continuation).expect("honest continuation witness"); - - let mut fake_prior = continuation.clone(); - fake_prior["acc_vk"] = json!(fake_acc.vk); - fake_prior["acc_proof"] = json!(fold_witness_field_strings(&fake_acc.proof.data).unwrap()); - fake_prior["acc_public_inputs"] = json!(fields(&fake_acc.proof)); - witness(&fold_path, &fake_prior) - .expect("a substituted fold predecessor leaves the step satisfiable"); - assert_fold_rejected( - prover, - fold, - &fold_path, - &fake_prior, - artifacts_dir, - "substituted-predecessor", - ); - steps.push((continuation, 0)); - } - - for (step, leaf) in steps { - let fake_leaf = substitute_proof( - prover, - inners[leaf].circuit, - CircuitVariant::Recursive, - &fields(&inners[leaf]), - None, - "leaf", - ); - let mut changed_leaf = step.clone(); - changed_leaf["inner_vk"] = json!(fake_leaf.vk); - changed_leaf["inner_proof"] = - json!(fold_witness_field_strings(&fake_leaf.proof.data).unwrap()); - changed_leaf["inner_key_hash"] = json!(fake_leaf.key_hash); - assert!( - witness(&fold_path, &changed_leaf).is_err(), - "a fold step must retain its predecessor's leaf VK hash" - ); - for key in ["fold_key_hash", "kernel_key_hash"] { - let mut changed_key = step.clone(); - changed_key[key] = json!(fake_acc.key_hash); - assert!( - witness(&fold_path, &changed_key).is_err(), - "a fold step must retain its predecessor's {key}" - ); - } - } -} - -fn assert_final_c6_tree_binding( - prover: &ZkProver, - inner: &Proof, - folded: &Proof, - artifacts_dir: &str, -) { - let default_dir = prover.circuits_dir(CircuitVariant::Default, artifacts_dir); - let leaf_vk = load_vk_artifacts( - &prover.circuits_dir(CircuitVariant::Recursive, artifacts_dir), - inner.circuit, - ) - .unwrap(); - let fold_vk = load_vk_artifacts(&default_dir, CircuitName::C6Fold).unwrap(); - let kernel_vk = load_vk_artifacts(&default_dir, CircuitName::C6FoldKernel).unwrap(); - let fold_path = default_dir.join("recursive_aggregation/c6_fold/c6_fold.json"); - let kernel_path = default_dir.join("recursive_aggregation/c6_fold_kernel/c6_fold_kernel.json"); - let final_path = - default_dir.join("recursive_aggregation/decryption_aggregator/decryption_aggregator.json"); - let canonical_tree = format!( - "0x{}", - hex::encode( - std::fs::read(default_dir.join("recursive_aggregation/c6_fold/c6_fold.vk_tree_hash")) - .unwrap() - ) - ); - let leaf_public = fields(inner); - let fake_leaf = substitute_proof( - prover, - inner.circuit, - CircuitVariant::Recursive, - &leaf_public, - None, - "c6-tree-leaf", - ); - let mut genesis_public = vec!["0".to_owned(); fields(folded).len()]; - genesis_public[..3].clone_from_slice(&[ - leaf_vk.key_hash.clone(), - fold_vk.key_hash.clone(), - kernel_vk.key_hash.clone(), - ]); - // Every fold step checks the predecessor's domain and keeps its rows, the first one included, so - // the substituted genesis carries the leaf in slot 0 as a real kernel proof would. Layout: seven - // prefix fields, then the sk, e_sm, ct and d columns of `slots` entries each. - genesis_public[5] = leaf_public[3].clone(); - genesis_public[6] = leaf_public[4].clone(); - let slots = (genesis_public.len() - 7) / 4; - for (column, leaf_field) in [0, 1, 2, 5].into_iter().enumerate() { - genesis_public[7 + column * slots] = leaf_public[leaf_field].clone(); - } - let fake_genesis = substitute_proof( - prover, - CircuitName::C6FoldKernel, - CircuitVariant::Default, - &genesis_public, - Some(2), - "c6-tree-genesis", - ); - - // This alternate C7 relation isolates the C6 tree boundary. The EVM suite checks the separate C7 pin. - let mut c7_public = vec![ - leaf_public[5].clone(), - leaf_public[5].clone(), - "1".into(), - "2".into(), - ]; - c7_public.extend(vec!["0".to_owned(); MAX_MSG_NON_ZERO_COEFFS]); - let c7 = substitute_proof( - prover, - CircuitName::DecryptedSharesAggregation, - CircuitVariant::Default, - &c7_public, - None, - "c6-tree-c7", - ); - let addresses: Vec<_> = (1..=3) - .map(|i| alloy::primitives::Address::from_word(alloy::primitives::U256::from(i).into())) - .collect(); - let (committee_hi, committee_lo) = e3_committee_hash::committee_hash_field_hex(&addresses); - - for replace_genesis in [true, false] { - let mut step = json!({ - "inner_vk": if replace_genesis { &leaf_vk.verification_key } else { &fake_leaf.vk }, - "inner_proof": fold_witness_field_strings(if replace_genesis { &inner.data } else { &fake_leaf.proof.data }).unwrap(), - "c6_public_inputs": leaf_public, - "acc_vk": kernel_vk.verification_key, - "acc_proof": vec!["0"; folded.data.len() / 32], - "acc_public_inputs": vec!["0"; fields(folded).len()], - "inner_key_hash": if replace_genesis { &leaf_vk.key_hash } else { &fake_leaf.key_hash }, - "fold_key_hash": fold_vk.key_hash, - "kernel_key_hash": if replace_genesis { &fake_genesis.key_hash } else { &kernel_vk.key_hash }, - "is_first_step": true, - "slot_index": 0, - }); - let genesis = if replace_genesis { - fake_genesis.proof.clone() - } else { - let kernel_witness = witness(&kernel_path, &step).unwrap(); - prover - .generate_recursive_aggregation_bin_proof( - CircuitName::C6FoldKernel, - &kernel_witness, - "c6-tree-kernel", - artifacts_dir, - ) - .unwrap() - }; - step["acc_vk"] = if replace_genesis { - json!(fake_genesis.vk) - } else { - json!(kernel_vk.verification_key) - }; - // The first fold step fills the second slot on top of the genesis proof. - step["acc_proof"] = json!(fold_witness_field_strings(&genesis.data).unwrap()); - step["acc_public_inputs"] = json!(fields(&genesis)); - step["slot_index"] = json!(1); - let second_witness = witness(&fold_path, &step).unwrap(); - let changed_fold = prover - .generate_recursive_aggregation_bin_proof( - CircuitName::C6Fold, - &second_witness, - "c6-tree-second", - artifacts_dir, - ) - .unwrap(); - assert!(prover - .verify_fold_proof(&changed_fold, "c6-tree-second", 0, artifacts_dir) - .unwrap()); - let public = fields(&changed_fold); - let tree = vk_hash(&[ - fold_vk.key_hash.clone(), - public[2].clone(), - public[0].clone(), - ]); - assert_ne!(tree, canonical_tree); - let mut final_input = json!({ - "c6_fold_vk": fold_vk.verification_key, - "c6_fold_vk_hash": fold_vk.key_hash, - "c6_fold_proof": fold_witness_field_strings(&changed_fold.data).unwrap(), - "c6_fold_public": public, - "c7_vk": c7.vk, - "c7_proof": fold_witness_field_strings(&c7.proof.data).unwrap(), - "c7_public": fields(&c7.proof), - "c6_fold_key_hash": tree, - "c7_key_hash": c7.key_hash, - "committee_members": ["1", "2", "3"], - "committee_hash_hi": committee_hi, - "committee_hash_lo": committee_lo, - "domain_hi": leaf_public[3], - "domain_lo": leaf_public[4], - "ciphertext_commitment": leaf_public[2], - }); - let control_witness = - witness(&final_path, &final_input).expect("alternate tree is internally consistent"); - let control = prover - .generate_recursive_aggregation_bin_proof( - CircuitName::DecryptionAggregator, - &control_witness, - "c6-tree-final", - artifacts_dir, - ) - .unwrap(); - assert!(prover - .verify_fold_proof(&control, "c6-tree-final", 0, artifacts_dir) - .unwrap()); - final_input["c6_fold_key_hash"] = json!(canonical_tree); - assert!( - witness(&final_path, &final_input).is_err(), - "a substituted leaf or genesis must not claim the deployment's canonical tree anchor" - ); - } -} - /// Expected C3 slot count when circuits are compiled for the minimum committee (N=3, T=1): one /// slot per party and insecure-64 threshold modulus (3 × 3). const MINIMUM_C3_SLOTS: usize = 9; @@ -835,127 +469,366 @@ async fn c3_chonk_accumulate_and_c3ab_reject_children_of_the_wrong_kind() { } } -async fn setup_c6_fold_with_inner_threshold_share_decryption() -> Option<( - ZkBackend, - tempfile::TempDir, - ZkProver, - ShareDecryptionCircuit, - ShareDecryptionCircuitData, - ShareDecryptionCircuitData, - BfvPreset, -)> { +/// Expected C6 slot count when circuits are compiled for the minimum committee (N=3, T=1): one slot +/// per party that reconstructs, `T + 1`. +const MINIMUM_C6_SLOTS: usize = 2; + +/// Reads `T + 1` from the compiled `c6_chonk_app` ABI (the length of `slot_indices`). +fn c6_total_slots_from_compiled_json() -> usize { + let path = e3_zk_prover::test_utils::workspace_root() + .join("circuits/bin/chonk/target/c6_chonk_app.json"); + let raw = std::fs::read_to_string(&path).unwrap_or_else(|e| { + panic!( + "read {}: {} (run `pnpm build:circuits --group chonk`)", + path.display(), + e + ) + }); + let v: serde_json::Value = + serde_json::from_str(&raw).unwrap_or_else(|e| panic!("parse {}: {}", path.display(), e)); + v["abi"]["parameters"] + .as_array() + .and_then(|ps| { + ps.iter() + .find(|p| p.get("name") == Some(&serde_json::Value::String("slot_indices".into()))) + .and_then(|p| p.get("type")?.get("length")?.as_u64()) + }) + .expect("c6_chonk_app.json: abi.parameters.slot_indices.length") as usize +} + +/// A prover with the C6 Chonk circuits set up, and one inner C6 proof. +struct C6Fixture { + prover: ZkProver, + inner: Proof, + total_slots: usize, + artifacts_dir: String, + _backend: ZkBackend, + _temp: tempfile::TempDir, +} + +async fn c6_fixture() -> C6Fixture { let committee = CiphernodesCommitteeSize::Minimum.values(); let preset = BfvPreset::InsecureThreshold64; - let bb = find_bb().await?; + let bb = find_bb() + .await + .expect("missing required test prerequisite: bb not found"); let (backend, temp) = setup_test_prover(&bb).await; - setup_compiled_circuit(&backend, "threshold", "share_decryption").await; - setup_recursive_aggregation_fold_circuit(&backend, CircuitName::C6Fold).await; - setup_recursive_aggregation_fold_circuit(&backend, CircuitName::C6FoldKernel).await; setup_recursive_aggregation_fold_circuit(&backend, CircuitName::DecryptionAggregator).await; - - let (params, _) = preset.build_pair().ok()?; - let sample_a = - e3_zk_samples::threshold::share_decryption::generate(¶ms, preset, committee.clone()) - .ok()?; - let sample_b = - e3_zk_samples::threshold::share_decryption::generate(¶ms, preset, committee).ok()?; + setup_c6_chonk_circuits(&backend).await; let prover = ZkProver::new(&backend); - Some(( - backend, - temp, - prover, - ShareDecryptionCircuit, - sample_a, - sample_b, - preset, - )) -} - -#[tokio::test] -#[ignore = "requires prepared integration artifacts; run pnpm rust:test:proofs"] -async fn c6_fold_sequential_proves_and_verifies() { - let Some((_backend, _temp, prover, circuit, sample_a, sample_b, preset)) = - setup_c6_fold_with_inner_threshold_share_decryption().await - else { - panic!("missing required test prerequisite: bb not found or prerequisites missing"); - }; - - let total_slots = c6_fold_total_slots_from_compiled_json(); - if total_slots != MINIMUM_C6_FOLD_SLOTS { - panic!( - "c6_fold_sequential_proves_and_verifies: circuits compiled for \ - non-minimum committee (total_slots={total_slots}, expected {MINIMUM_C6_FOLD_SLOTS}). \ - Rebuild with `pnpm build:circuits --committee minimum` to run this test." - ); - } + let total_slots = c6_total_slots_from_compiled_json(); + assert_eq!( + total_slots, MINIMUM_C6_SLOTS, + "circuits compiled for a non-minimum committee; rebuild with `pnpm build:circuits --committee minimum`" + ); let artifacts_dir = preset.artifacts_dir_for_committee("minimum"); - let inner_e3_a = "e3-c6fold-inner-0"; - let inner_e3_b = "e3-c6fold-inner-1"; - let fold_e3 = "e3-c6fold-step"; - - let inner_a = circuit + let (params, _) = preset.build_pair().unwrap(); + let sample = + e3_zk_samples::threshold::share_decryption::generate(¶ms, preset, committee).unwrap(); + let inner = ShareDecryptionCircuit .prove_with_variant( &prover, &e3_zk_config::threshold::share_decryption::Configs::for_preset(preset).unwrap(), - &sample_a, - inner_e3_a, + &sample, + "e3-c6chonk-inner", CircuitVariant::Recursive, &artifacts_dir, ) - .expect("inner ThresholdShareDecryption proof 0"); - assert_eq!(inner_a.circuit, CircuitName::ThresholdShareDecryption); + .expect("inner ThresholdShareDecryption proof"); + assert_eq!(inner.circuit, CircuitName::ThresholdShareDecryption); + C6Fixture { + prover, + inner, + total_slots, + artifacts_dir, + _backend: backend, + _temp: temp, + } +} - let inner_b = circuit - .prove_with_variant( - &prover, - &e3_zk_config::threshold::share_decryption::Configs::for_preset(preset).unwrap(), - &sample_b, - inner_e3_b, - CircuitVariant::Recursive, - &artifacts_dir, - ) - .expect("inner ThresholdShareDecryption proof 1"); - assert_eq!(inner_b.circuit, CircuitName::ThresholdShareDecryption); +/// One inner proof in every slot, so every slot commits to the same ciphertext. +fn c6_leaves(f: &C6Fixture) -> (Vec, Vec) { + ( + vec![f.inner.clone(); f.total_slots], + (0..f.total_slots as u32).collect(), + ) +} - let inners = [inner_a, inner_b]; - let folded = generate_sequential_c6_fold( - &prover, +/// The root of a decryption's `T + 1` leaves carries their columns and a key list hashing to the +/// anchored C6 tree, which `decryption_aggregator` pins. A root under another key verifies in the +/// aggregator's own constraints but cannot claim that tree. +#[tokio::test] +#[ignore = "requires prepared integration artifacts; run pnpm rust:test:proofs"] +async fn c6_chonk_root_proves_and_binds_the_decryption_aggregator() { + let f = c6_fixture().await; + let default_dir = f + .prover + .circuits_dir(CircuitVariant::Default, &f.artifacts_dir); + let final_path = + default_dir.join("recursive_aggregation/decryption_aggregator/decryption_aggregator.json"); + let canonical_tree = format!( + "0x{}", + hex::encode( + std::fs::read(default_dir.join("recursive_aggregation/c6_fold/c6_fold.vk_tree_hash")) + .unwrap() + ) + ); + let (inners, slots) = c6_leaves(&f); + let root = generate_c6_chonk_root( + &f.prover, &inners, - &[0u32, 1u32], - total_slots, - fold_e3, - &artifacts_dir, + &slots, + f.total_slots, + "e3-c6chonk-root", + &f.artifacts_dir, ) - .expect("c6_fold sequential fold"); - assert_eq!(folded.circuit, CircuitName::C6Fold); + .expect("C6 Chonk root"); + assert_eq!(root.circuit, CircuitName::C6ChonkRoot); assert!( - !folded.data.is_empty(), - "fold proof data should not be empty" + f.prover + .verify_fold_proof(&root, "e3-c6chonk-root", 0, &f.artifacts_dir) + .expect("verify_fold_proof invocation"), + "the root proof should verify under its VK" + ); + + // The root exposes the key list hash, the domain limbs, then the sk, esm, ct and d columns. + let leaf = fields(&f.inner); + let public = fields(&root); + assert_eq!(public.len(), 3 + 4 * f.total_slots); + assert_eq!(public[1..3], leaf[3..5]); + for (column, field) in [0, 1, 2, 5].into_iter().enumerate() { + for slot in 0..f.total_slots { + assert_eq!( + public[3 + column * f.total_slots + slot], + leaf[field], + "column {column}, slot {slot}" + ); + } + } + let root_vk = load_vk_artifacts(&default_dir, CircuitName::C6ChonkRoot).unwrap(); + assert_eq!( + vk_hash(&[root_vk.key_hash.clone(), public[0].clone()]), + canonical_tree, + "the real C6 Chonk circuits must hash to the anchored C6 tree" ); + + // This alternate C7 relation isolates the C6 tree boundary. The EVM suite checks the separate + // C7 pin. + let mut c7_public = vec![leaf[5].clone(); f.total_slots]; + c7_public.extend((1..=f.total_slots).map(|id| id.to_string())); + c7_public.extend(vec!["0".to_owned(); MAX_MSG_NON_ZERO_COEFFS]); + let c7 = substitute_proof( + &f.prover, + CircuitName::DecryptedSharesAggregation, + CircuitVariant::Default, + &c7_public, + None, + "c6-tree-c7", + ); + let addresses: Vec<_> = (1..=3) + .map(|i| alloy::primitives::Address::from_word(alloy::primitives::U256::from(i).into())) + .collect(); + let (committee_hi, committee_lo) = e3_committee_hash::committee_hash_field_hex(&addresses); + let final_input = |vk: &[String], vk_hash: &str, proof: &Proof, tree: &str| { + json!({ + "c6_root_vk": vk, + "c6_root_vk_hash": vk_hash, + "c6_root_proof": fold_witness_field_strings(&proof.data).unwrap(), + "c6_root_public": fields(proof), + "c7_vk": c7.vk, + "c7_proof": fold_witness_field_strings(&c7.proof.data).unwrap(), + "c7_public": fields(&c7.proof), + "c6_fold_key_hash": tree, + "c7_key_hash": c7.key_hash, + "committee_members": ["1", "2", "3"], + "committee_hash_hi": committee_hi, + "committee_hash_lo": committee_lo, + "domain_hi": leaf[3], + "domain_lo": leaf[4], + "ciphertext_commitment": leaf[2], + }) + }; + witness( + &final_path, + &final_input( + &root_vk.verification_key, + &root_vk.key_hash, + &root, + &canonical_tree, + ), + ) + .expect("the real C6 Chonk root claims the canonical tree"); + + let fake_root = substitute_proof( + &f.prover, + CircuitName::C6ChonkRoot, + CircuitVariant::Default, + &public, + None, + "c6-tree-root", + ); + let fake_tree = vk_hash(&[fake_root.key_hash.clone(), public[0].clone()]); + witness( + &final_path, + &final_input( + &fake_root.vk, + &fake_root.key_hash, + &fake_root.proof, + &fake_tree, + ), + ) + .expect("a substituted root is internally consistent under its own tree"); + assert_witness_rejected( + witness( + &final_path, + &final_input( + &fake_root.vk, + &fake_root.key_hash, + &fake_root.proof, + &canonical_tree, + ), + ), + "a substituted C6 root must not claim the deployment's canonical tree anchor", + ); + f.prover.cleanup("e3-c6chonk-inner").unwrap(); +} + +/// A stack cannot carry a leaf whose claimed row differs from what it proved, nor a stage passed +/// off under another stage's key: bb rejects the stack, or cannot even accumulate it. +#[tokio::test] +#[ignore = "requires prepared integration artifacts; run pnpm rust:test:proofs"] +async fn c6_chonk_rejects_a_corrupted_leaf_or_a_substituted_key() { + let f = c6_fixture().await; + let (inners, slots) = c6_leaves(&f); + + // The leaf's last public signal is its `d_commitment`, a column the stack writes for it. + let mut signals = f.inner.public_signals.extract_bytes(); + *signals.last_mut().unwrap() ^= 1; + let corrupted = Proof::new( + f.inner.circuit, + f.inner.data.clone(), + e3_utils::ArcBytes::from_bytes(&signals), + ); + let mut with_corrupted = inners.clone(); + with_corrupted[f.total_slots - 1] = corrupted; + let error = generate_c6_chonk_root( + &f.prover, + &with_corrupted, + &slots, + f.total_slots, + "c6-corrupted-leaf", + &f.artifacts_dir, + ) + .expect_err("a leaf whose claimed row differs from its proof must not reach a root"); assert!( - !folded.public_signals.is_empty(), - "fold public signals should not be empty" + matches!(&error, ZkError::ProofRejected(message) + if message.contains("Failed to verify the generated proof")), + "{error:?}" ); - let party_id = 1u64; - let ok = prover - .verify_fold_proof(&folded, fold_e3, party_id, &artifacts_dir) - .expect("verify_fold_proof invocation"); - assert!(ok, "c6_fold proof should verify under Default VK layout"); - assert_recursive_vk_binding( - &prover, - CircuitName::C6Fold, - CircuitName::C6FoldKernel, + // The init kernel's key has a different number of public inputs than the app's, so bb cannot + // accumulate the stack. The kernels share a shape: the stack proves, and bb rejects it. + let error = generate_c6_chonk_root_with_substituted_key( + &f.prover, &inners, - &folded, - total_slots, - &artifacts_dir, + &slots, + f.total_slots, + (0, 1), + "c6-key-0-as-1", + &f.artifacts_dir, + ) + .expect_err("the app claimed under the init kernel's key must not reach a root"); + assert!( + matches!(&error, ZkError::ProveFailed(message) if message.contains("IO size mismatch")), + "{error:?}" ); - assert_final_c6_tree_binding(&prover, &inners[0], &folded, &artifacts_dir); + for (stage, from) in [(1, 2), (2, 1)] { + let error = generate_c6_chonk_root_with_substituted_key( + &f.prover, + &inners, + &slots, + f.total_slots, + (stage, from), + &format!("c6-key-{stage}-as-{from}"), + &f.artifacts_dir, + ) + .expect_err("a kernel claimed under the other kernel's key must not reach a root"); + assert!( + matches!(&error, ZkError::ProofRejected(message) + if message.contains("Failed to verify the generated proof")), + "stage {stage} as {from}: {error:?}" + ); + } + + // The honest leaves, unchanged but for those edits, make a root that verifies. + let root = generate_c6_chonk_root( + &f.prover, + &inners, + &slots, + f.total_slots, + "c6-honest-twin", + &f.artifacts_dir, + ) + .expect("honest twin"); + assert!(f + .prover + .verify_fold_proof(&root, "c6-honest-twin", 0, &f.artifacts_dir) + .unwrap()); + f.prover.cleanup("e3-c6chonk-inner").unwrap(); +} - prover.cleanup(inner_e3_a).unwrap(); - prover.cleanup(inner_e3_b).unwrap(); - prover.cleanup(fold_e3).unwrap(); +/// The app places each leaf in its own slot of `0..T + 1` and takes one domain for all of them. +/// The checks are constraints of the circuit, so each witness fails where its honest twin, which +/// differs in the one edit under test, solves. +#[tokio::test] +#[ignore = "requires prepared integration artifacts; run pnpm rust:test:proofs"] +async fn c6_chonk_app_rejects_a_shared_slot_an_out_of_range_slot_and_a_foreign_domain() { + let f = c6_fixture().await; + let leaf_vk = load_vk_artifacts( + &f.prover + .circuits_dir(CircuitVariant::Recursive, &f.artifacts_dir), + CircuitName::ThresholdShareDecryption, + ) + .unwrap(); + let app_path = e3_zk_prover::test_utils::workspace_root() + .join("circuits/bin/chonk/target/c6_chonk_app.json"); + let leaf = fields(&f.inner); + let app_input = |publics: Vec>, slots: Vec| { + json!({ + "leaf_vk": leaf_vk.verification_key, + "leaf_key_hash": leaf_vk.key_hash, + "proofs": vec![fold_witness_field_strings(&f.inner.data).unwrap(); f.total_slots], + "c6_public_inputs": publics, + "slot_indices": slots, + }) + }; + let honest_publics = vec![leaf.clone(); f.total_slots]; + let honest_slots: Vec = (0..f.total_slots as u32).collect(); + witness( + &app_path, + &app_input(honest_publics.clone(), honest_slots.clone()), + ) + .expect("honest app witness"); + + let mut shared = honest_slots.clone(); + shared[1] = shared[0]; + assert_witness_rejected( + witness(&app_path, &app_input(honest_publics.clone(), shared)), + "two leaves cannot share a slot", + ); + let mut out_of_range = honest_slots.clone(); + out_of_range[1] = f.total_slots as u32; + assert_witness_rejected( + witness(&app_path, &app_input(honest_publics.clone(), out_of_range)), + "a slot past the last is rejected", + ); + let mut foreign = honest_publics.clone(); + foreign[1][4] = "1".to_owned(); + assert_witness_rejected( + witness(&app_path, &app_input(foreign, honest_slots)), + "every leaf must carry the first leaf's domain", + ); + f.prover.cleanup("e3-c6chonk-inner").unwrap(); } diff --git a/docs/architecture/circuit-artifacts.md b/docs/architecture/circuit-artifacts.md index 831d2da8ac..91624bd8cc 100644 --- a/docs/architecture/circuit-artifacts.md +++ b/docs/architecture/circuit-artifacts.md @@ -187,18 +187,19 @@ it. ## Verifier and deployment compatibility Complete pair builds generate `nodes_fold.vk_tree_hash`/`c6_fold.vk_tree_hash` from all recursive -keys. Subset builds, skip-VK, or any circuit failure remove **both** pair/bin anchors to prevent -stale pins. Cache markers and release validation require both; hydration copies them. Final wrappers -pin these tree hashes at input zero and C5/C7 separately, not an immediate fold VK hash. +keys. The C6 anchor keeps the retired `c6_fold` path, although C6 now runs over Chonk. Subset +builds, skip-VK, or any circuit failure remove **both** pair/bin anchors to prevent stale pins. +Cache markers and release validation require both; hydration copies them. Final wrappers pin these +tree hashes at input zero and C5/C7 separately, not an immediate fold VK hash. The builder writes the `.vk_hash` of every Chonk app, kernel, and hiding circuit, not bb: `write_vk --scheme chonk` writes a key only, and the hash is `e3_safe::bb_poseidon2_hash` over its -fields. A bb upgrade must recheck these hashes against bb's in-circuit VK-hash check. The C3 stacks -are proven through `bb prove --scheme chonk --ivc_inputs_path` with the msgpack input layout of that -bb version, which is part of the pinned bb interface. `qualify-vk-commitments` re-derives Chonk keys -with bb but recomputes their hashes with the same builder function, so it detects stale files, not a -hash-algorithm change; that evidence is the `e3-safe` bb 6.0.0 fixture test and real C3 Chonk -proofs. +fields. A bb upgrade must recheck these hashes against bb's in-circuit VK-hash check. The C3 and C6 +stacks are proven through `bb prove --scheme chonk --ivc_inputs_path` with the msgpack input layout +of that bb version, which is part of the pinned bb interface. `qualify-vk-commitments` re-derives +Chonk keys with bb but recomputes their hashes with the same builder function, so it detects stale +files, not a hash-algorithm change; that evidence is the `e3-safe` bb 6.0.0 fixture test and real C3 +and C6 Chonk proofs. Each supported pair has concrete BfvPkVerifier/BfvDecryptionVerifier; immutable routers dispatch by public-input length and VK anchors. Selecting an already installed matching pair needs no diff --git a/docs/architecture/proof-statements.md b/docs/architecture/proof-statements.md index 3c26cc93eb..808740d281 100644 --- a/docs/architecture/proof-statements.md +++ b/docs/architecture/proof-statements.md @@ -473,13 +473,12 @@ CRT reconstruction. Host validation is not a substitute for those circuit constr ## Recursive trust and exported values -Sequential C6 and nodes folds keep `(leaf, fold, kernel)` VK hashes constant across predecessors. -The kernel proves the chain's first leaves at their slots; every fold step carries its predecessor's -rows forward, the kernel's included, and adds its leaves to empty slots. A C6 step takes one leaf, -so a chain of `n >= 2` leaves is one kernel and `n - 1` fold proofs; a nodes step takes up to three. -The first step verifies the kernel; continuation verifies the fold; the final consumer binds the -declared fold hash to the verified VK. C3ab covers both complete C3 chains. Node-fold covers child -folds and their nested keys. DKG aggregation requires one node-tree hash across every selected row. +The sequential nodes fold keeps `(leaf, fold, kernel)` VK hashes constant across predecessors. The +kernel proves the chain's first leaves at their slots; every fold step carries its predecessor's +rows forward, the kernel's included, and adds up to three leaves to empty slots. The first step +verifies the kernel; continuation verifies the fold; the final consumer binds the declared fold hash +to the verified VK. C3ab covers both complete C3 chains. Node-fold covers child folds and their +nested keys. DKG aggregation requires one node-tree hash across every selected row. `nodes_fold_kernel` and `nodes_fold` verify three `node_fold` proofs per step (`lib::math::nodes_fold`); a row must be all zero before it is written. An empty place in a step @@ -491,19 +490,18 @@ once all their proofs are buffered, and `nodes_fold_step_len` fixes that count s its response handler agree without extra state. A chain of at most three nodes splits one and the rest, so it never ends on the kernel. -C3 chains do not fold sequentially: they run over Chonk (`lib::math::chonk`). A stack is -`c3_chonk_app`, which verifies `C3_CHONK_LEAVES` (24) C3 proofs, then the init, tail and hiding -kernels; `c3_chonk_tube` verifies the stack's Chonk proof as a rollup proof, and -`c3_chonk_accumulate` merges an accumulator or tube on the left with a tube on the right. -`c3ab_fold` verifies each chain's last accumulator as a root rollup, which closes its IPA claim. -Every stage verifies against a witness key and appends that key's hash to the data it passes on, so -each tube or accumulator exposes seven key hashes: its own, the tube, the hiding kernel's Chonk key, -then C3, app, init and tail. Merging requires equal keys on both sides; `c3ab_fold` hashes each -chain's seven keys into the C3 tree, which the anchor pins. The Chonk and Mega key hashes are -Barretenberg's Poseidon2 hash of the key fields, which the builder writes beside -`write_vk --scheme chonk --circuit_kind app|kernel|hiding` output (bb 6 derives app, kernel and -hiding keys against separate Mega flavors). A chain has at least two stacks, so it ends on an -accumulator, and `c3ab_fold` rejects a chain that ends on a bare tube. +C3 chains run over Chonk (`lib::math::chonk`). A stack is `c3_chonk_app`, which verifies +`C3_CHONK_LEAVES` (24) C3 proofs, then the init, tail and hiding kernels; `c3_chonk_tube` verifies +the stack's Chonk proof as a rollup proof, and `c3_chonk_accumulate` merges an accumulator or tube +on the left with a tube on the right. `c3ab_fold` verifies each chain's last accumulator as a root +rollup, which closes its IPA claim. Every stage verifies against a witness key and appends that +key's hash to the data it passes on, so each tube or accumulator exposes seven key hashes: its own, +the tube, the hiding kernel's Chonk key, then C3, app, init and tail. Merging requires equal keys on +both sides; `c3ab_fold` hashes each chain's seven keys into the C3 tree, which the anchor pins. The +Chonk and Mega key hashes are Barretenberg's Poseidon2 hash of the key fields, which the builder +writes beside `write_vk --scheme chonk --circuit_kind app|kernel|hiding` output (bb 6 derives app, +kernel and hiding keys against separate Mega flavors). A chain has at least two stacks, so it ends +on an accumulator, and `c3ab_fold` rejects a chain that ends on a bare tube. Slot indices are private app witnesses; only the rows they place are public. A place with nothing to verify carries the sentinel slot `C3_SLOTS` and writes nothing. Its proof position still needs a @@ -511,6 +509,18 @@ proof that verifies under the leaf key; the prover repeats the stack's first lea does not require that choice, and the place adds no row. Within a stack every written slot must be empty, and merging rejects a slot filled on both sides, so no row is overwritten or duplicated. +A decryption's C6 proofs run over the same Chonk stack design, all in one stack: `c6_chonk_app` +verifies all `T + 1` of them, checks they share the first leaf's domain and places their sk, esm, ct +and d commitments by slot (`lib::math::c6_chonk_rows`), so `T + 1` must stay within the stack's +ECCVM bound (24 C3-sized proofs). `c6_chonk_tube` verifies the stack as a rollup proof and +`c6_chonk_root` closes its IPA claim. A root rollup closes exactly two claims, so the root takes the +tube twice under the tube key and states only the first; its final IPA check fails unless both +claims are valid. The root ends by exposing the hash of the tube's seven key hashes before the data. +The decryption aggregator verifies the root and requires `hash(root key, key-list hash)` to equal +the anchored C6 tree, and the ciphertext commitment in every slot, so no slot stays empty. The C6 +tree anchor keeps the retired `c6_fold` artifact path, which `BfvDecryptionVerifier` deployments +read. + The trust tree uses ordered SAFE `DS_VK_HASH` hashing: ```text @@ -522,7 +532,8 @@ C3 tree = hash(C3a chain, C3b chain) C4 tree = hash(C4a, C4b) node tree = hash(C0, C1, c2ab_fold, C2 tree, c3ab_fold, C3 tree, c4ab_fold, C4 tree) nodes tree = hash(nodes_fold, nodes_fold_kernel, node_fold, node tree) -C6 tree = hash(c6_fold, c6_fold_kernel, C6) +C6 chain = hash(c6_chonk_tube, c6_chonk_tube, hiding kernel, C6, app, init, tail) +C6 tree = hash(c6_chonk_root, C6 chain) ``` Final public input zero is the complete nodes/C6 tree, pinned immutably from `.vk_tree_hash`, not diff --git a/docs/architecture/threshold-decryption.md b/docs/architecture/threshold-decryption.md index 4dd00fedc2..aad0679bca 100644 --- a/docs/architecture/threshold-decryption.md +++ b/docs/architecture/threshold-decryption.md @@ -70,7 +70,7 @@ sequence; never write under the earlier result sequence or chain-independent `Ef context. The active aggregator reconstructs from exactly T+1 verified shares. A retry batch may contain more; -native reconstruction, C7, and the C6 fold must select the same T+1 lowest runtime party IDs. C7 +native reconstruction, C7, and the C6 stack must select the same T+1 lowest runtime party IDs. C7 witness construction refuses any other share/party count. Sort runtime IDs and convert **once** to one-based Shamir coordinates `party_id + 1`; zero, duplicate, unordered, and out-of-range coordinates fail. The wrapper subtracts one to locate registry slots. C7 proves every plaintext diff --git a/docs/pages/build/noir-circuits.mdx b/docs/pages/build/noir-circuits.mdx index 253e1aca89..92983518fb 100644 --- a/docs/pages/build/noir-circuits.mdx +++ b/docs/pages/build/noir-circuits.mdx @@ -72,6 +72,10 @@ All binary packages depend on one shared library. The Nargo package name of the + + + + @@ -79,8 +83,8 @@ All binary packages depend on one shared library. The Nargo package name of the - - + + @@ -99,7 +103,7 @@ All binary packages depend on one shared library. The Nargo package name of the | `lib/src/configs` | The BFV presets (`insecure`, `secure`) and the committee sizes. `default/mod.nr` and `committee/active.nr` select the active pair. The build script writes both files. | | `bin/dkg` | Nargo workspace: `pk` (C0), `sk_share_computation` (C2a), `e_sm_share_computation` (C2b), `share_encryption` (C3), `share_decryption` (C4), and the C2 chunk circuits those two verify. | | `bin/threshold` | Nargo workspace: `pk_generation` (C1), `pk_aggregation` (C5), `user_data_encryption` (P3), `share_decryption` (C6), `decrypted_shares_aggregation` (C7). | -| `bin/chonk` | Nargo workspace: the app and three kernels of the C3 Chonk stacks. | +| `bin/chonk` | Nargo workspace: the app and three kernels of the C3 and C6 Chonk stacks. | | `bin/recursive_aggregation` | Twelve packages that fold proofs together. The two final circuits are `dkg_aggregator` and `decryption_aggregator`. | | `bin/config` | Package `validate_secure_configs`. It checks the secure preset constants (CRT moduli and bounds). | | `benchmarks` | Timing scripts and reports. | @@ -133,9 +137,10 @@ proofs go on-chain. C3 runs over Chonk: `c3_chonk_app` verifies a batch of C3 proofs and three kernels close the stack, `c3_chonk_tube` verifies the stack's Chonk proof, `c3_chonk_accumulate` merges the tubes, and `c3ab_fold` closes the chain. The decryption path is shorter. The C6 proofs of the committee go -through `c6_fold`, and `decryption_aggregator` adds C7. The `*_fold_kernel` packages make the first -proof of each sequential fold (`c6_fold`, `nodes_fold`). The `c3_chonk_*_kernel` packages are Chonk -kernels, not fold kernels. +through one Chonk stack (`c6_chonk_app` and three kernels), `c6_chonk_tube` verifies the stack's +Chonk proof, `c6_chonk_root` closes it, and `decryption_aggregator` adds C7. `nodes_fold_kernel` +makes the first proof of the sequential `nodes_fold`. The `c3_chonk_*_kernel` and +`c6_chonk_*_kernel` packages are Chonk kernels, not fold kernels. The Solidity verifiers for the two aggregators are committed to the repository as `DkgAggregatorVerifier.sol` and `DecryptionAggregatorVerifier.sol`. `BfvPkVerifier` and diff --git a/docs/pages/internals/dkg.mdx b/docs/pages/internals/dkg.mdx index 5fd9aa8145..5e8d4f817f 100644 --- a/docs/pages/internals/dkg.mdx +++ b/docs/pages/internals/dkg.mdx @@ -118,8 +118,8 @@ proofs. | `node_fold` | `NodeFold` | Folds C0, C1, `c2ab_fold`, `c3ab_fold`, and `c4ab_fold` for one node. | | `nodes_fold`, `nodes_fold_kernel` | `NodesFold`, `NodesFoldKernel` | Folds the H `node_fold` proofs in sequence. | | `dkg_aggregator` | `DkgAggregator` | Verifies `nodes_fold` and C5. Its EVM proof goes to `publishCommittee`. | -| `c6_fold`, `c6_fold_kernel` | `C6Fold`, `C6FoldKernel` | Folds the T + 1 C6 proofs of one ciphertext. | -| `decryption_aggregator` | `DecryptionAggregator` | Verifies `c6_fold` and C7. Its EVM proof goes to `publishPlaintextOutput`. | +| `c6_chonk_*` | `C6Chonk*` | Verifies the T + 1 C6 proofs of one ciphertext in one Chonk stack and closes it. | +| `decryption_aggregator` | `DecryptionAggregator` | Verifies `c6_chonk_root` and C7. Its EVM proof goes to `publishPlaintextOutput`. | ### Proof count per E3 @@ -543,11 +543,11 @@ the DKG and one for the decryption. Production nodes always aggregate. The EVM w single ciphertext output only. It refuses to publish an E3 result that has more than one decrypted output. -| `ZkRequest` | Made by | Output | -| ----------------------- | ------------------ | ---------------------------------------------------------------------- | -| `NodeDkgFold` | Each roster member | A `NodeFold` proof. The node then signs a fold attestation. | -| `DkgAggregation` | Active aggregator | `NodesFold`, C5, and the `DkgAggregator` EVM proof | -| `DecryptionAggregation` | Active aggregator | `C6Fold`, C7, and the `DecryptionAggregator` EVM proof for each output | +| `ZkRequest` | Made by | Output | +| ----------------------- | ------------------ | ------------------------------------------------------------------------------- | +| `NodeDkgFold` | Each roster member | A `NodeFold` proof. The node then signs a fold attestation. | +| `DkgAggregation` | Active aggregator | `NodesFold`, C5, and the `DkgAggregator` EVM proof | +| `DecryptionAggregation` | Active aggregator | The C6 Chonk root, C7, and the `DecryptionAggregator` EVM proof for each output | ### Committee hash @@ -687,7 +687,7 @@ public inputs: | Index | Value | | --------------- | ---------------------------------------------------- | -| 0, 1 | `c6_fold` and C7 VK hashes | +| 0, 1 | C6 tree and C7 VK hashes | | 2, 3 | `committee_hash_hi`, `committee_hash_lo` | | 4, 5 | `domain_hi`, `domain_lo` | | 6 | `ciphertext_commitment` | diff --git a/docs/pages/learn/cryptography.mdx b/docs/pages/learn/cryptography.mdx index 4aa379504e..488beb6450 100644 --- a/docs/pages/learn/cryptography.mdx +++ b/docs/pages/learn/cryptography.mdx @@ -206,8 +206,8 @@ in `circuits/bin/recursive_aggregation/` then fold the proofs: | `node_fold` | `NodeFold` | One member's chain from C0 to C4 | | `nodes_fold`, `nodes_fold_kernel` | `NodesFold`, `NodesFoldKernel` | The H `node_fold` proofs, in sequence | | `dkg_aggregator` | `DkgAggregator` | `nodes_fold` and C5 | -| `c6_fold`, `c6_fold_kernel` | `C6Fold`, `C6FoldKernel` | The T + 1 C6 proofs, in sequence | -| `decryption_aggregator` | `DecryptionAggregator` | `c6_fold` and C7 | +| `c6_chonk_*` | `C6Chonk*` | The T + 1 C6 proofs, in one Chonk stack | +| `decryption_aggregator` | `DecryptionAggregator` | `c6_chonk_root` and C7 | Only two proofs go on-chain for each E3: diff --git a/scripts/circuits/lint.sh b/scripts/circuits/lint.sh index 3f05e0a322..3468e0a422 100755 --- a/scripts/circuits/lint.sh +++ b/scripts/circuits/lint.sh @@ -15,8 +15,8 @@ DIRS=( "lib" "bin/config" "bin/recursive_aggregation/c2ab_fold" - "bin/recursive_aggregation/c6_fold" - "bin/recursive_aggregation/c6_fold_kernel" + "bin/recursive_aggregation/c6_chonk_tube" + "bin/recursive_aggregation/c6_chonk_root" "bin/recursive_aggregation/c3ab_fold" "bin/recursive_aggregation/c3_chonk_tube" "bin/recursive_aggregation/c3_chonk_accumulate" From b80d00cbffcf5e6a41682a810ed7dd5e7ac8b4d1 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:41:12 +0000 Subject: [PATCH 02/19] docs(blueprint): follow the C6 Chonk circuits --- scripts/blueprint/curated.mjs | 10 +++--- scripts/blueprint/facts/05-zk.json | 2 +- scripts/blueprint/facts/11-circuits.json | 46 ++++++++++++------------ scripts/blueprint/refs/D-circuits.json | 24 ++++++------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/scripts/blueprint/curated.mjs b/scripts/blueprint/curated.mjs index d26a189017..ea18db3e0d 100644 --- a/scripts/blueprint/curated.mjs +++ b/scripts/blueprint/curated.mjs @@ -672,10 +672,10 @@ function circuits() { y: 820, w: 320, h: 80, - title: 'c6_fold', + title: 'C6 Chonk → c6_chonk_root', lines: ['C6 of the T + 1 selected members'], mono: true, - ref: `${CIR}/recursive_aggregation/c6_fold/src/main.nr@43@verify_honk_proof(inner_vk, inner_proof, c6_public_inputs`, + ref: `${CIR}/chonk/c6_chonk_app/src/main.nr@30@verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k]`, }, { id: 'c7', @@ -695,9 +695,9 @@ function circuits() { w: 280, h: 220, title: 'decryption_aggregator', - lines: ['c6_fold + C7', 'one decryption proof'], + lines: ['C6 root + C7', 'one decryption proof'], mono: true, - ref: `${CIR}/recursive_aggregation/decryption_aggregator/src/main.nr@89@verify_honk_proof_non_zk(c6_fold_vk, c6_fold_proof`, + ref: `${CIR}/recursive_aggregation/decryption_aggregator/src/main.nr@85@verify_honk_proof_non_zk(c6_root_vk, c6_root_proof`, }, { id: 'decver', @@ -750,7 +750,7 @@ function circuits() { { from: 'c5', to: 'dkgagg', fs: 'r', ts: 'l', ta: 0.25, refs: ev('D7', 'D14') }, { from: 'dkgagg', to: 'dkgver', fs: 'r', ts: 'l', tip: 'Checked in publishCommittee, through BfvPkVerifier', refs: ev('D9') }, { from: 'c6', to: 'c6f', fs: 'r', ts: 'l', refs: ev('D4', 'D16') }, - { from: 'c6f', to: 'decagg', fs: 'r', ts: 'l', ta: (860 - 780) / 220, label: 'folded C6', refs: ev('D8') }, + { from: 'c6f', to: 'decagg', fs: 'r', ts: 'l', ta: (860 - 780) / 220, label: 'C6 root', refs: ev('D8') }, { from: 'c7', to: 'decagg', fs: 'r', ts: 'l', ta: (955 - 780) / 220, refs: ev('D8', 'D15') }, { from: 'decagg', diff --git a/scripts/blueprint/facts/05-zk.json b/scripts/blueprint/facts/05-zk.json index cb0cea986d..3b8d15a0b4 100644 --- a/scripts/blueprint/facts/05-zk.json +++ b/scripts/blueprint/facts/05-zk.json @@ -386,7 +386,7 @@ { "pattern": "enum-match", "note": "CircuitName maps static identities to artifact names without runtime dependencies.", - "ref": "crates/zk/config/src/circuit.rs@195@CircuitName::PkBfv => \"pk\"," + "ref": "crates/zk/config/src/circuit.rs@207@CircuitName::PkBfv => \"pk\"," } ], "depends_on": ["e3-committee", "e3-fhe-params", "e3-polynomial", "e3-polynomial-fhe"], diff --git a/scripts/blueprint/facts/11-circuits.json b/scripts/blueprint/facts/11-circuits.json index 952d657126..d3298d9704 100644 --- a/scripts/blueprint/facts/11-circuits.json +++ b/scripts/blueprint/facts/11-circuits.json @@ -838,79 +838,79 @@ "ref": "circuits/bin/recursive_aggregation/dkg_aggregator/src/main.nr@65@committee_hash_lo: pub Field" }, { - "name": "private: c6_fold_vk", + "name": "private: c6_root_vk", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@69@c6_fold_vk: UltraHonkVerificationKey" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@65@c6_root_vk: UltraHonkVerificationKey" }, { - "name": "private: c6_fold_proof", + "name": "private: c6_root_proof", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@70@c6_fold_proof: UltraHonkProof" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@66@c6_root_proof: UltraHonkProof" }, { - "name": "private: c6_fold_public", + "name": "private: c6_root_public", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@71@c6_fold_public: [Field; C6_FOLD_PUBLIC_LEN]" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@67@c6_root_public: [Field; C6_ROOT_PUBLIC_LEN]" }, { - "name": "private: c6_fold_vk_hash", + "name": "private: c6_root_vk_hash", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@72@c6_fold_vk_hash: Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@68@c6_root_vk_hash: Field" }, { "name": "private: c7_vk", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@73@c7_vk: UltraHonkVerificationKey" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@69@c7_vk: UltraHonkVerificationKey" }, { "name": "private: c7_proof", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@74@c7_proof: UltraHonkProof" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@70@c7_proof: UltraHonkProof" }, { "name": "private: c7_public", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@75@c7_public: [Field; C7_PUBLIC_LEN]" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@71@c7_public: [Field; C7_PUBLIC_LEN]" }, { "name": "public: c6_fold_key_hash", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@76@c6_fold_key_hash: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@72@c6_fold_key_hash: pub Field" }, { "name": "public: c7_key_hash", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@77@c7_key_hash: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@73@c7_key_hash: pub Field" }, { "name": "private: committee_members", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@78@committee_members: [Field; N_PARTIES]" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@74@committee_members: [Field; N_PARTIES]" }, { "name": "public: committee_hash_hi", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@79@committee_hash_hi: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@75@committee_hash_hi: pub Field" }, { "name": "public: committee_hash_lo", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@80@committee_hash_lo: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@76@committee_hash_lo: pub Field" }, { "name": "public: domain_hi", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@81@domain_hi: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@77@domain_hi: pub Field" }, { "name": "public: domain_lo", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@82@domain_lo: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@78@domain_lo: pub Field" }, { "name": "public: ciphertext_commitment", "by": "decryption_aggregator", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@83@ciphertext_commitment: pub Field" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@79@ciphertext_commitment: pub Field" } ], "emits": [], @@ -938,11 +938,11 @@ }, { "why": "decryption_aggregator entry point: the plaintext proof the contract verifies", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@68@fn main(" + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@64@fn main(" }, { - "why": "decryption_aggregator checks the C6 fold proof and the C7 proof in-circuit", - "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@89@verify_honk_proof_non_zk(c6_fold_vk, c6_fold_proof, c6_fold_public, c6_fold_vk_hash);" + "why": "decryption_aggregator checks the C6 Chonk root proof and the C7 proof in-circuit", + "ref": "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@85@verify_honk_proof_non_zk(c6_root_vk, c6_root_proof, c6_root_public, c6_root_vk_hash);" }, { "why": "node_fold entry point: one member's C0 to C4 proofs and their same-party links", @@ -954,7 +954,7 @@ "tests": "dkg_aggregator has 7 #[test] functions, decryption_aggregator 7 and node_fold 3, all in their main.nr; the other folds have none. circuits/README.md runs nargo test on these packages through scripts/circuits/test.sh.", "unverified": [ "On-chain verification of the final aggregator proofs is stated in the circuit doc comments and in docs/architecture/threshold-decryption.md; no Solidity source was read.", - "The earlier flow description said C7 is checked with ZK, but decryption_aggregator calls verify_honk_proof_non_zk for it (decryption_aggregator/src/main.nr@90); docs/architecture/proof-statements.md describes the trust boundary rather than that older wrapper wording.", + "The earlier flow description said C7 is checked with ZK, but decryption_aggregator calls verify_honk_proof_non_zk for it (decryption_aggregator/src/main.nr@86); docs/architecture/proof-statements.md describes the trust boundary rather than that older wrapper wording.", "circuits/README.md lists recursive_aggregation/fold and wrapper paths that are not in this snapshot; this unit follows the directory listing." ] }, diff --git a/scripts/blueprint/refs/D-circuits.json b/scripts/blueprint/refs/D-circuits.json index d0fe63d801..1d495cb852 100644 --- a/scripts/blueprint/refs/D-circuits.json +++ b/scripts/blueprint/refs/D-circuits.json @@ -50,18 +50,18 @@ "id": "D4", "supported": true, "refs": [ - "circuits/bin/recursive_aggregation/c6_fold/src/main.nr@43@verify_honk_proof(inner_vk, inner_proof, c6_public_inputs", - "circuits/bin/recursive_aggregation/c6_fold/src/main.nr@52@verify_honk_proof_non_zk(acc_vk, acc_proof", - "circuits/bin/recursive_aggregation/c6_fold_kernel/src/main.nr@40@verify_honk_proof(inner_vk, inner_proof, c6_public_inputs", - "crates/zk/prover/src/circuits/aggregation/c6_accumulator.rs@121@if proof.circuit != CircuitName::ThresholdShareDecryption {" + "circuits/bin/chonk/c6_chonk_app/src/main.nr@30@verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k]", + "circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr@22@std::verify_proof_with_type(", + "circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr@30@verify_root_rolluphonk_proof(tube_vk, tube_proofs[k]", + "crates/zk/prover/src/circuits/aggregation/c6_chonk.rs@29@if proof.circuit != CircuitName::ThresholdShareDecryption {" ], "line_text": [ - "verify_honk_proof(inner_vk, inner_proof, c6_public_inputs, inner_key_hash);", - "verify_honk_proof_non_zk(acc_vk, acc_proof, acc_public_inputs, acc_key_hash);", - "verify_honk_proof(inner_vk, inner_proof, c6_public_inputs, inner_key_hash);", + "verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k], leaf_key_hash);", + "std::verify_proof_with_type(", + "verify_root_rolluphonk_proof(tube_vk, tube_proofs[k], tube_publics[k], tube_key);", "if proof.circuit != CircuitName::ThresholdShareDecryption {" ], - "note": "c6_fold verifies each inner ThresholdShareDecryption (C6) proof plus the previous accumulator, and c6_fold_kernel verifies only the inner C6 proof for the genesis step." + "note": "c6_chonk_app verifies all T + 1 C6 proofs of a decryption in one Chonk stack; c6_chonk_tube verifies the stack's Chonk proof as a rollup and c6_chonk_root closes its IPA claim (taking the tube twice, as a root rollup closes two claims). The prover's c6_chonk module drives it." }, { "id": "D5", @@ -107,14 +107,14 @@ "id": "D8", "supported": true, "refs": [ - "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@89@verify_honk_proof_non_zk(c6_fold_vk, c6_fold_proof", - "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@90@verify_honk_proof_non_zk(c7_vk, c7_proof" + "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@85@verify_honk_proof_non_zk(c6_root_vk, c6_root_proof", + "circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr@86@verify_honk_proof_non_zk(c7_vk, c7_proof" ], "line_text": [ - "verify_honk_proof_non_zk(c6_fold_vk, c6_fold_proof, c6_fold_public, c6_fold_vk_hash);", + "verify_honk_proof_non_zk(c6_root_vk, c6_root_proof, c6_root_public, c6_root_vk_hash);", "verify_honk_proof_non_zk(c7_vk, c7_proof, c7_public, c7_key_hash);" ], - "note": "decryption_aggregator verifies the c6_fold proof (line 89) and the C7 decrypted-shares aggregation proof (line 90), so C7 is in the final decryption proof." + "note": "decryption_aggregator verifies the c6_chonk_root proof and the C7 decrypted-shares aggregation proof, so C7 is in the final decryption proof." }, { "id": "D9", From 7652065cdc69e5461dbe3fd33550258677c46308 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:43:32 +0000 Subject: [PATCH 03/19] refactor(zk): remove the sequential fold helpers C6 no longer uses The C6 chain and the nodes fold no longer fold one leaf per step, so the Rust sequential_fold driver and the Noir sequential_fold_vk_hash have no callers. --- circuits/lib/src/math/recursive_vk.nr | 11 ------ .../src/circuits/aggregation/helpers.rs | 34 ------------------- 2 files changed, 45 deletions(-) diff --git a/circuits/lib/src/math/recursive_vk.nr b/circuits/lib/src/math/recursive_vk.nr index 0441aac562..91e7f2f112 100644 --- a/circuits/lib/src/math/recursive_vk.nr +++ b/circuits/lib/src/math/recursive_vk.nr @@ -4,8 +4,6 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -use crate::math::commitments::compute_vk_hash; - /// Keep the leaf, fold, and kernel VK hashes constant throughout a sequential fold. pub fn predecessor_key_hash( inner_key_hash: Field, @@ -22,15 +20,6 @@ pub fn predecessor_key_hash( } } -/// Commit to the ordered fold, kernel, and leaf verification keys. -pub fn sequential_fold_vk_hash( - fold_key_hash: Field, - kernel_key_hash: Field, - inner_key_hash: Field, -) -> Field { - compute_vk_hash([fold_key_hash, kernel_key_hash, inner_key_hash].as_vector()) -} - #[test] fn kernel_and_continuation_select_the_expected_key() { assert(predecessor_key_hash(11, 22, 33, true, [11, 22, 33]) == 33); diff --git a/crates/zk/prover/src/circuits/aggregation/helpers.rs b/crates/zk/prover/src/circuits/aggregation/helpers.rs index 02e48dccc2..cef4ef19d6 100644 --- a/crates/zk/prover/src/circuits/aggregation/helpers.rs +++ b/crates/zk/prover/src/circuits/aggregation/helpers.rs @@ -107,37 +107,3 @@ pub fn parse_acc_public_field_strings_flat( } Ok(v) } - -/// Sequential fold driver: applies `step(inner, prior_acc, slot_index)` per inner proof, -/// threading each step's output as the next step's accumulator. -/// -/// The first step returns the chain's kernel proof, so a fold proof needs at least two inner -/// proofs; with one, the chain would end on the kernel. -pub fn sequential_fold( - label: &str, - inner_proofs: &[Proof], - slot_indices: &[u32], - mut step: F, -) -> Result -where - F: FnMut(&Proof, Option<&Proof>, u32) -> Result, -{ - if inner_proofs.len() < 2 { - return Err(ZkError::InvalidInput(format!( - "{label}: need at least two inner proofs, got {}", - inner_proofs.len() - ))); - } - if inner_proofs.len() != slot_indices.len() { - return Err(ZkError::InvalidInput(format!( - "{label}: inner_proofs and slot_indices length mismatch ({} vs {})", - inner_proofs.len(), - slot_indices.len() - ))); - } - let mut acc: Option = None; - for (i, inner) in inner_proofs.iter().enumerate() { - acc = Some(step(inner, acc.as_ref(), slot_indices[i])?); - } - Ok(acc.expect("loop body executed at least once on non-empty input")) -} From 39e5a40aa61e0a4ed5e5f07da29bcd58e2d26e4d Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:48:01 +0000 Subject: [PATCH 04/19] fix(zk-build): count the C6 Chonk anchor keys in the manifest test C6 over Chonk replaces two anchor keys (c6_fold, c6_fold_kernel) with six (the tube, the root and four stack keys), so the build test seeds 27 keys and the manifest holds 45 files. --- crates/zk/build/src/artifacts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/zk/build/src/artifacts.rs b/crates/zk/build/src/artifacts.rs index 3f96a797e8..563725778a 100644 --- a/crates/zk/build/src/artifacts.rs +++ b/crates/zk/build/src/artifacts.rs @@ -1436,9 +1436,9 @@ mod tests { let manifest: serde_json::Value = serde_json::from_slice(&fs::read(root.join("dist/circuits/checksums.json")).unwrap()) .unwrap(); - // The json, vk and vk_hash of pk and pk_generation in three variants (18), plus the 23 + // The json, vk and vk_hash of pk and pk_generation in three variants (18), plus the 27 // seeded anchor keys the build does not write. - assert_eq!(manifest["files"].as_object().unwrap().len(), 41); + assert_eq!(manifest["files"].as_object().unwrap().len(), 45); let hash = identity::source_hash(root, &request(), Some("insecure-64"), Some("minimum")).unwrap(); let built_stamp = read_stamp(&pair.join(".build-stamp.json")) From a04728cb47965f0cc83d5fdff9c338a6ec8f8a67 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:13:11 +0000 Subject: [PATCH 05/19] fix(zk-build): derive the C6 Chonk tube key as a rollup key --- crates/zk/build/src/artifacts.rs | 5 +++-- crates/zk/prover/src/prover.rs | 4 ++-- docs/pages/build/noir-circuits.mdx | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/zk/build/src/artifacts.rs b/crates/zk/build/src/artifacts.rs index 563725778a..ffe17839b3 100644 --- a/crates/zk/build/src/artifacts.rs +++ b/crates/zk/build/src/artifacts.rs @@ -496,10 +496,11 @@ pub fn variants(circuit: &Circuit) -> Vec<(&'static str, &'static str, &'static return vec![("default", CHONK_TARGET, "vk_recursive")]; } if circuit.group == "recursive_aggregation" { - // The tube and accumulate proofs carry an IPA claim that `c3ab_fold` closes. + // The tube and accumulate proofs carry an IPA claim that a root rollup (`c3ab_fold`, + // `c6_chonk_root`) closes. if matches!( circuit.name.as_str(), - "c3_chonk_tube" | "c3_chonk_accumulate" + "c3_chonk_tube" | "c3_chonk_accumulate" | "c6_chonk_tube" ) { return vec![("default", "noir-rollup-no-zk", "vk_recursive")]; } diff --git a/crates/zk/prover/src/prover.rs b/crates/zk/prover/src/prover.rs index 8dc5758d18..e7ec3de968 100644 --- a/crates/zk/prover/src/prover.rs +++ b/crates/zk/prover/src/prover.rs @@ -523,8 +523,8 @@ impl ZkProver { /// Verifies a rollup bin proof (`noir-rollup-no-zk`, Default variant), as /// [`Self::generate_rollup_proof`] proves it. bb checks the pairing and then the proof's IPA /// claim against its appended IPA proof (`UltraVerifier_::verify_ipa`, bb v6.0.0). In the - /// protocol no node verifies a rollup proof natively: the root rollup (`c3ab_fold`) closes the - /// claim in-circuit. + /// protocol no node verifies a rollup proof natively: a root rollup (`c3ab_fold`, + /// `c6_chonk_root`) closes the claim in-circuit. pub fn verify_rollup_proof( &self, proof: &Proof, diff --git a/docs/pages/build/noir-circuits.mdx b/docs/pages/build/noir-circuits.mdx index 92983518fb..8c2bdb59bb 100644 --- a/docs/pages/build/noir-circuits.mdx +++ b/docs/pages/build/noir-circuits.mdx @@ -270,9 +270,9 @@ For each pair, the Rust build owner does these steps (`crates/zk/build`): `bin/recursive_aggregation` with `nargo compile`. 5. It writes verification keys with `bb write_vk`. Each base circuit gets `evm`, `noir-recursive-no-zk`, and `noir-recursive` keys. Each fold circuit gets a - `noir-recursive-no-zk` key, and the two aggregators also get an `evm` key. The C3 Chonk app and - kernels get `--scheme chonk` keys with a Poseidon2 key hash, and `c3_chonk_tube` and - `c3_chonk_accumulate` get `noir-rollup-no-zk` keys. + `noir-recursive-no-zk` key, and the two aggregators also get an `evm` key. The C3 and C6 Chonk + apps and kernels get `--scheme chonk` keys with a Poseidon2 key hash, and `c3_chonk_tube`, + `c3_chonk_accumulate` and `c6_chonk_tube` get `noir-rollup-no-zk` keys. 6. It copies the artifacts to `dist/circuits///`, with one directory for each variant (`default`, `recursive`, `evm`). Then it writes `SHA256SUMS` and `checksums.json`. From fff20ca47e1cfc06840d0d83e50e5792d5308f4c Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:13:45 +0000 Subject: [PATCH 06/19] fix(contracts): read the C6 Chonk root key in the VK binding test The retired c6_fold circuit no longer builds, so the immediate-key check read a file that does not exist. Also drop the C6 fold wording from the BfvDecryptionVerifier docs. --- .../verifiers/bfv/BfvDecryptionVerifier.sol | 16 +++++++++------- .../test/BfvVkBindingIntegration.spec.ts | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol b/packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol index edcaa4db79..67b0c2e459 100644 --- a/packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol +++ b/packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol @@ -15,7 +15,7 @@ import { BfvDecryptionLayout } from "../../lib/BfvDecryptionLayout.sol"; /** * @title BfvDecryptionVerifier * @notice Verifies the DecryptionAggregator (EVM) proof produced by the - * recursive aggregation pipeline (C6 folds + C7/decrypted_shares + * recursive aggregation pipeline (C6 over Chonk + C7/decrypted_shares * verified internally) and binds it to the full on-chain call context. * @dev Used when the Interfold is configured with encryptionSchemeId * keccak256("fhe.rs:BFV"). Constructor `threshold` must match the @@ -44,9 +44,10 @@ import { BfvDecryptionLayout } from "../../lib/BfvDecryptionLayout.sol"; * with some self-declared commitment, so this binds that commitment to * the address-signed DKG output actually recorded for this E3. * - * Each secret-bearing C6 proof commits to the same domain limbs. C6Fold - * preserves them, and DecryptionAggregator exposes them here, so an - * aggregator cannot re-label an existing proof for another E3. + * Each secret-bearing C6 proof commits to the same domain limbs. The C6 + * Chonk stack and root preserve them, and DecryptionAggregator exposes + * them here, so an aggregator cannot re-label an existing proof for + * another E3. * * The domain prevents cross-context replay, the SAFE ciphertext commitment * binds the final proof to the stored circuit-compatible commitment, and @@ -108,9 +109,10 @@ contract BfvDecryptionVerifier is IDecryptionVerifier { /// `party_ids`/`expected_sk`/`expected_esm` outputs must match. ICiphernodeRegistry public immutable ciphernodeRegistry; - /// @notice SAFE commitment to the C6 fold, genesis, and leaf VKs. - /// Expected at `publicInputs[0]`. The builder writes - /// `c6_fold.vk_tree_hash` from the complete artifact pair. + /// @notice SAFE commitment to the C6 Chonk root key and the keys of the + /// stack below it. Expected at `publicInputs[0]`. The builder + /// writes it as `c6_fold.vk_tree_hash` from the complete artifact + /// pair; the name is kept for deployment tooling. bytes32 public immutable expectedC6FoldKeyHash; /// @notice Barretenberg hash of the C7 non-ZK recursive VK. diff --git a/packages/interfold-contracts/test/BfvVkBindingIntegration.spec.ts b/packages/interfold-contracts/test/BfvVkBindingIntegration.spec.ts index b2bc4098ec..6c973e417b 100644 --- a/packages/interfold-contracts/test/BfvVkBindingIntegration.spec.ts +++ b/packages/interfold-contracts/test/BfvVkBindingIntegration.spec.ts @@ -458,7 +458,7 @@ describe("BfvVkBindingIntegration", function () { const immediateC6Hash = readVkRecursiveHash( path.join( repoRoot, - "circuits/bin/recursive_aggregation/c6_fold/target/c6_fold.vk_recursive_hash", + "circuits/bin/recursive_aggregation/c6_chonk_root/target/c6_chonk_root.vk_recursive_hash", ), ); expect(immediateNodesHash).not.to.equal(expectedNodesFoldKeyHash); From acb97f317c911200d0b1a585ecccebc1160ea1b2 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:15:56 +0000 Subject: [PATCH 07/19] refactor(zk-prover): load the C6 tube and root circuits once per aggregation --- crates/zk/prover/src/circuits/aggregation/c6_chonk.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs b/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs index 9f979adf1b..29e025f85c 100644 --- a/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs +++ b/crates/zk/prover/src/circuits/aggregation/c6_chonk.rs @@ -16,6 +16,7 @@ use crate::circuits::utils::bytes_to_field_strings; use crate::circuits::vk::{self, VkArtifacts}; use crate::error::ZkError; use crate::prover::ZkProver; +use crate::witness::CompiledCircuit; use e3_events::Proof; use e3_zk_config::{CircuitName, CircuitVariant}; use serde::Serialize; @@ -48,7 +49,9 @@ pub(crate) struct C6ChonkCircuits { leaf: VkArtifacts, stack: ChonkStack, tube: VkArtifacts, + tube_compiled: CompiledCircuit, pub(crate) root: VkArtifacts, + root_compiled: CompiledCircuit, } impl C6ChonkCircuits { @@ -70,7 +73,9 @@ impl C6ChonkCircuits { ], )?, tube: vk::load_vk_artifacts(&default, CircuitName::C6ChonkTube)?, + tube_compiled: load_compiled(prover, CircuitName::C6ChonkTube, artifacts_dir)?, root: vk::load_vk_artifacts(&default, CircuitName::C6ChonkRoot)?, + root_compiled: load_compiled(prover, CircuitName::C6ChonkRoot, artifacts_dir)?, }) } } @@ -170,7 +175,7 @@ pub(crate) fn generate_c6_chonk( )?; let tube_witness = witness( - &load_compiled(prover, CircuitName::C6ChonkTube, artifacts_dir)?, + &circuits.tube_compiled, &TubeInput { chonk_vk: circuits.stack.chonk_key().verification_key.clone(), chonk_key_hash: circuits.stack.chonk_key().key_hash.clone(), @@ -189,7 +194,7 @@ pub(crate) fn generate_c6_chonk( let tube_proof = bytes_to_field_strings(&tube.data)?; let tube_public = bytes_to_field_strings(&tube.public_signals)?; let root_witness = witness( - &load_compiled(prover, CircuitName::C6ChonkRoot, artifacts_dir)?, + &circuits.root_compiled, &RootInput { tube_vk: circuits.tube.verification_key.clone(), tube_proofs: [tube_proof.clone(), tube_proof], From 66b8bb90f36b111951ad7b8361eaf1dad8767beb Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:15:56 +0000 Subject: [PATCH 08/19] docs(circuits): drop the retired C6 fold from comments --- .../recursive_aggregation/decryption_aggregator/src/main.nr | 4 ++-- circuits/lib/src/core/threshold/share_decryption.nr | 2 +- crates/zk/prover/README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr b/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr index 339b32f8ed..ac0c30ef38 100644 --- a/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr +++ b/circuits/bin/recursive_aggregation/decryption_aggregator/src/main.nr @@ -99,8 +99,8 @@ fn main( assert(c6_root_public[C6_ROOT_CT_OFFSET + i] == ciphertext_commitment); } - // Cross-circuit C6 to C7: each folded `d_commitment` column entry must match `c7_public[i]` - // (leading `T + 1` words of `c7_public`). + // Cross-circuit C6 to C7: each `d_commitment` column entry of the C6 root must match + // `c7_public[i]` (leading `T + 1` words of `c7_public`). for i in 0..(T + 1) { assert(c6_root_public[C6_ROOT_D_OFFSET + i] == c7_public[C7_D_COMMITMENT_OFFSET + i]); } diff --git a/circuits/lib/src/core/threshold/share_decryption.nr b/circuits/lib/src/core/threshold/share_decryption.nr index fbfce85c00..127d88e8af 100644 --- a/circuits/lib/src/core/threshold/share_decryption.nr +++ b/circuits/lib/src/core/threshold/share_decryption.nr @@ -78,7 +78,7 @@ pub struct ShareDecryption; L], } diff --git a/crates/zk/prover/README.md b/crates/zk/prover/README.md index f3063d34eb..e682ad0194 100644 --- a/crates/zk/prover/README.md +++ b/crates/zk/prover/README.md @@ -23,7 +23,7 @@ define a second owner. | [`request_execution.rs`](src/request_execution.rs) | Correlated C0–C7, batch verification and recursive request execution, including local witness decryption. | | [`proof_request/`](src/proof_request), [`proof_verification/`](src/proof_verification) | Local proof planning/signing and authenticated key-proof verification/recovery. | | [`share_verification/`](src/share_verification), [`node_proof_aggregation/`](src/node_proof_aggregation) | Signed share bundles, per-batch outcomes, and node-fold accumulation/recovery. | -| [`circuits/aggregation/`](src/circuits/aggregation), [`commitment_links/`](src/commitment_links) | Recursive folds, C3 Chonk chains, and cross-proof links. | +| [`circuits/aggregation/`](src/circuits/aggregation), [`commitment_links/`](src/commitment_links) | Recursive folds, C3 and C6 Chonk aggregation, and cross-proof links. | | [`tests/`](tests) | Prepared local, recursive-fold, network/download, and proof-to-slash suites. | A capability actor records a proof/verification plan and requests compute work. Shared workers From dab6c1c6889ae8978e28c6979f1442f509a2510d Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:16:42 +0000 Subject: [PATCH 09/19] docs(blueprint): follow the moved C6 Chonk prover reference --- scripts/blueprint/refs/D-circuits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/blueprint/refs/D-circuits.json b/scripts/blueprint/refs/D-circuits.json index 1d495cb852..310b5e1ffc 100644 --- a/scripts/blueprint/refs/D-circuits.json +++ b/scripts/blueprint/refs/D-circuits.json @@ -53,7 +53,7 @@ "circuits/bin/chonk/c6_chonk_app/src/main.nr@30@verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k]", "circuits/bin/recursive_aggregation/c6_chonk_tube/src/main.nr@22@std::verify_proof_with_type(", "circuits/bin/recursive_aggregation/c6_chonk_root/src/main.nr@30@verify_root_rolluphonk_proof(tube_vk, tube_proofs[k]", - "crates/zk/prover/src/circuits/aggregation/c6_chonk.rs@29@if proof.circuit != CircuitName::ThresholdShareDecryption {" + "crates/zk/prover/src/circuits/aggregation/c6_chonk.rs@30@if proof.circuit != CircuitName::ThresholdShareDecryption {" ], "line_text": [ "verify_honk_proof(leaf_vk, proofs[k], c6_public_inputs[k], leaf_key_hash);", From 050993f6a9265e854d6c12b2d44ebb2e8d9a8b97 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:24:10 +0000 Subject: [PATCH 10/19] docs(blueprint): follow the decryption verifier call the NatSpec edit moved --- scripts/blueprint/refs/D-circuits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/blueprint/refs/D-circuits.json b/scripts/blueprint/refs/D-circuits.json index 310b5e1ffc..eb6d6af316 100644 --- a/scripts/blueprint/refs/D-circuits.json +++ b/scripts/blueprint/refs/D-circuits.json @@ -133,7 +133,7 @@ "refs": [ "packages/interfold-contracts/contracts/Interfold.sol@487@address(e3.decryptionVerifier),", "packages/interfold-contracts/contracts/lib/InterfoldLifecycle.sol@332@IDecryptionVerifier(verifierAddress).verify(", - "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@218@circuitVerifier.verify(rawProof, publicInputs)", + "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@223@circuitVerifier.verify(rawProof, publicInputs)", "packages/interfold-contracts/contracts/verifiers/bfv/honk/DecryptionAggregatorVerifier.sol@3248@contract DecryptionAggregatorVerifier is" ], "line_text": [ @@ -142,7 +142,7 @@ "if (!circuitVerifier.verify(rawProof, publicInputs)) {", "contract DecryptionAggregatorVerifier is" ], - "note": "Interfold passes its decryption verifier to InterfoldLifecycle, which calls verify (line 332), and BfvDecryptionVerifier forwards the proof to the DecryptionAggregatorVerifier Honk contract (line 218)." + "note": "Interfold passes its decryption verifier to InterfoldLifecycle, which calls verify (line 332), and BfvDecryptionVerifier forwards the proof to the DecryptionAggregatorVerifier Honk contract (line 223)." }, { "id": "D12", From 8c486252b7cbbc2852498473fb2622b8509a94e1 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:50:43 +0000 Subject: [PATCH 11/19] fix(zk-build): hydrate and stage the C6 tree anchor at its retired path The C6 tree anchor keeps the `c6_fold` path, but `c6_fold` holds no circuit now, so `discover` no longer lists it. `hydrate` and `stage_bin` placed anchors with the circuits they walk, so `--hydrate-bin-only` and `--skip-if-built` left `circuits/bin` without `c6_fold.vk_tree_hash` (or with a stale one), and a staged pair had none. - Place both anchors by name in `refresh_anchors`, `hydrate`, `stage_bin` and `bin_markers`. - Cover the C6 anchor in the staging test. --- crates/zk/build/src/artifacts.rs | 76 +++++++++++++++++++++----------- crates/zk/build/src/tests.rs | 41 +++++++++++------ 2 files changed, 77 insertions(+), 40 deletions(-) diff --git a/crates/zk/build/src/artifacts.rs b/crates/zk/build/src/artifacts.rs index ffe17839b3..c6377319cb 100644 --- a/crates/zk/build/src/artifacts.rs +++ b/crates/zk/build/src/artifacts.rs @@ -235,7 +235,6 @@ const BIN_EXTENSIONS: [(&str, &[(&str, &str)]); 3] = [ ("json", "json"), ("vk", "vk_recursive"), ("vk_hash", "vk_recursive_hash"), - ("vk_tree_hash", "vk_tree_hash"), ], ), ("evm", &[("vk", "vk"), ("vk_hash", "vk_hash")]), @@ -245,6 +244,26 @@ const BIN_EXTENSIONS: [(&str, &[(&str, &str)]); 3] = [ ), ]; +/// The VK-tree anchors, by the name each is published under. An anchor is placed by this name and +/// not with a circuit [`discover`] lists: the C6 tree anchor keeps the retired `c6_fold` path, which +/// holds no circuit. +const ANCHORS: [&str; 2] = ["nodes_fold", "c6_fold"]; + +/// Where the anchor `name` is published in `pair`. +fn published_anchor(pair: &Path, name: &str) -> PathBuf { + pair.join("default/recursive_aggregation") + .join(name) + .join(format!("{name}.vk_tree_hash")) +} + +/// Where a build or [`hydrate`] leaves the anchor `name` under `bin` (`circuits/bin`). +fn built_anchor(bin: &Path, name: &str) -> PathBuf { + bin.join("recursive_aggregation") + .join(name) + .join("target") + .join(format!("{name}.vk_tree_hash")) +} + /// The required artifacts of a pair. A pair is complete, current or hydratable only with all of /// them: a tree built before the inventory gained an artifact must not pass. pub fn dist_markers(pair: &Path) -> Vec { @@ -267,6 +286,9 @@ pub(crate) fn bin_markers(root: &Path) -> Result> { let (package, extension) = file .split_once('.') .with_context(|| format!("Required artifact {required} has no extension"))?; + if extension == "vk_tree_hash" { + return Ok(built_anchor(&root.join("circuits/bin"), name)); + } let extension = if extension == "json" { "json" } else { @@ -394,6 +416,19 @@ pub fn hydrate(root: &Path, pair: &Path, request: &Request, stamp: &Stamp) -> Re } } } + // `clean_targets` reaches only the targets of circuits, so an anchor at a path that holds no + // circuit is replaced here. + for name in ANCHORS { + let built = built_anchor(&root.join("circuits/bin"), name); + if built.exists() { + fs::remove_file(&built)?; + } + let published = published_anchor(pair, name); + if published.is_file() { + fs::create_dir_all(built.parent().context("Anchor parent")?)?; + fs::copy(published, built)?; + } + } active_stamp(root, &stamp.preset, &stamp.committee, &stamp.source_hash) } @@ -559,21 +594,21 @@ pub fn stage_bin(root: &Path, pair: &Path) -> Result<()> { let dist = pair.join(variant).join(&circuit.group).join(&circuit.name); fs::create_dir_all(&dist)?; fs::copy(&compiled, dist.join(format!("{}.json", circuit.package)))?; - let mut files = vk_files(extension).to_vec(); - if variant == "default" { - // Only the folding circuits carry a VK-tree anchor. - let anchor = target.join(format!("{}.vk_tree_hash", circuit.package)); - if anchor.is_file() { - files.push(("vk_tree_hash", "vk_tree_hash".to_string())); - } - } - for (file, suffix) in files { + for (file, suffix) in vk_files(extension) { let source = target.join(format!("{}.{suffix}", circuit.package)); fs::copy(&source, dist.join(format!("{}.{file}", circuit.package))) .with_context(|| format!("Cannot stage {}", source.display()))?; } } } + for name in ANCHORS { + let built = built_anchor(&root.join("circuits/bin"), name); + if built.is_file() { + let published = published_anchor(pair, name); + fs::create_dir_all(published.parent().context("Anchor parent")?)?; + fs::copy(built, published)?; + } + } Ok(()) } @@ -690,16 +725,8 @@ pub fn refresh_anchors( fs::remove_file(stamp)?; } } - for name in ["nodes_fold", "c6_fold"] { - for path in [ - pair.join("default/recursive_aggregation") - .join(name) - .join(format!("{name}.vk_tree_hash")), - bin.join("recursive_aggregation") - .join(name) - .join("target") - .join(format!("{name}.vk_tree_hash")), - ] { + for name in ANCHORS { + for path in [published_anchor(pair, name), built_anchor(&bin, name)] { if path.exists() { fs::remove_file(path)?; } @@ -707,12 +734,9 @@ pub fn refresh_anchors( } if complete { for (name, bytes) in vk_tree::hashes(pair)? { - for directory in [ - pair.join("default/recursive_aggregation").join(name), - bin.join("recursive_aggregation").join(name).join("target"), - ] { - fs::create_dir_all(&directory)?; - fs::write(directory.join(format!("{name}.vk_tree_hash")), bytes)?; + for path in [published_anchor(pair, name), built_anchor(&bin, name)] { + fs::create_dir_all(path.parent().context("Anchor parent")?)?; + fs::write(path, bytes)?; } } } diff --git a/crates/zk/build/src/tests.rs b/crates/zk/build/src/tests.rs index e6fbdeaa01..bac7e1865d 100644 --- a/crates/zk/build/src/tests.rs +++ b/crates/zk/build/src/tests.rs @@ -1372,8 +1372,8 @@ fn bin_current_requires_every_required_artifact() { } /// Staging `circuits/bin` back into a pair reproduces the layout `hydrate` read it from: every -/// variant's VK and VK hash under its published name, the compiled program in every variant, and the -/// VK-tree anchor only where the folding circuit has one. +/// variant's VK and VK hash under its published name, the compiled program in every variant, and +/// both VK-tree anchors, the C6 one at a path no circuit has. #[test] fn staging_bin_reproduces_the_published_pair_layout() { let temp = tempfile::tempdir().unwrap(); @@ -1401,11 +1401,15 @@ fn staging_bin_reproduces_the_published_pair_layout() { } } } - write( - &published, - "default/recursive_aggregation/nodes_fold/nodes_fold.vk_tree_hash", - "nodes_fold-anchor", - ); + // The C6 tree anchor keeps the retired `c6_fold` path, which holds no circuit. + let anchors = ["nodes_fold", "c6_fold"]; + for name in anchors { + write( + &published, + &format!("default/recursive_aggregation/{name}/{name}.vk_tree_hash"), + format!("{name}-anchor"), + ); + } let stamp = artifacts::Stamp { preset: "insecure-64".into(), committee: "minimum".into(), @@ -1413,6 +1417,13 @@ fn staging_bin_reproduces_the_published_pair_layout() { built_at: "time".into(), }; artifacts::hydrate(root, &published, &request(), &stamp).unwrap(); + assert_eq!( + fs::read_to_string( + root.join("circuits/bin/recursive_aggregation/c6_fold/target/c6_fold.vk_tree_hash") + ) + .unwrap(), + "c6_fold-anchor" + ); let staged = root.join("staged/insecure-64/minimum"); artifacts::stage_bin(root, &staged).unwrap(); @@ -1441,13 +1452,15 @@ fn staging_bin_reproduces_the_published_pair_layout() { } } assert!(!staged.join("evm/recursive_aggregation/nodes_fold").exists()); - assert_eq!( - read( - &staged, - "default/recursive_aggregation/nodes_fold/nodes_fold.vk_tree_hash".into() - ), - "nodes_fold-anchor" - ); + for name in anchors { + assert_eq!( + read( + &staged, + format!("default/recursive_aggregation/{name}/{name}.vk_tree_hash") + ), + format!("{name}-anchor") + ); + } assert!(!staged.join("default/dkg/pk/pk.vk_tree_hash").exists()); } From ae2785cfbf3d9da7395fe86eb06750a9b6c1343a Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:50:43 +0000 Subject: [PATCH 12/19] docs: describe the C6 key list in the VK tree paragraph C6 no longer folds sequentially: its Chonk stages append key hashes and `c6_chonk_root` hashes the list. --- docs/pages/learn/cryptography.mdx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/pages/learn/cryptography.mdx b/docs/pages/learn/cryptography.mdx index 488beb6450..fa3c7280fc 100644 --- a/docs/pages/learn/cryptography.mdx +++ b/docs/pages/learn/cryptography.mdx @@ -247,11 +247,12 @@ anchors, which the on-chain decryption verifier compares. Domain-separation labels (`DS_*` in `circuits/lib/src/math/commitments.nr`) keep different kinds of commitments apart. -Recursive verification also binds the complete VK tree. Each sequential fold (C6, nodes) carries -fixed leaf, fold, and kernel key hashes. Each C3 Chonk stage appends the hash of the key it -verified, and `c3ab_fold` hashes each chain's seven-key list. The final proof commits to every -nested key at public input zero. Deployment pins that commitment from the matching artifact pair's -`.vk_tree_hash`, so a prover cannot substitute another circuit within the proof tree. +Recursive verification also binds the complete VK tree. The sequential nodes fold carries fixed +leaf, fold, and kernel key hashes. Each C3 and C6 Chonk stage appends the hash of the key it +verified. `c3ab_fold` hashes each C3 chain's seven-key list, and `c6_chonk_root` hashes the C6 +list. The final proof commits to every nested key at public input zero. Deployment pins that +commitment from the matching artifact pair's `.vk_tree_hash`, so a prover cannot substitute another +circuit within the proof tree. ## BFV presets From 506d9c261bfe07978280b82f215eb5cd94ead4ee Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:51:19 +0000 Subject: [PATCH 13/19] docs: rewrap the VK tree paragraph Prettier wraps prose at the column the previous commit missed. --- docs/pages/learn/cryptography.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/pages/learn/cryptography.mdx b/docs/pages/learn/cryptography.mdx index fa3c7280fc..77d09cbef2 100644 --- a/docs/pages/learn/cryptography.mdx +++ b/docs/pages/learn/cryptography.mdx @@ -249,10 +249,10 @@ commitments apart. Recursive verification also binds the complete VK tree. The sequential nodes fold carries fixed leaf, fold, and kernel key hashes. Each C3 and C6 Chonk stage appends the hash of the key it -verified. `c3ab_fold` hashes each C3 chain's seven-key list, and `c6_chonk_root` hashes the C6 -list. The final proof commits to every nested key at public input zero. Deployment pins that -commitment from the matching artifact pair's `.vk_tree_hash`, so a prover cannot substitute another -circuit within the proof tree. +verified. `c3ab_fold` hashes each C3 chain's seven-key list, and `c6_chonk_root` hashes the C6 list. +The final proof commits to every nested key at public input zero. Deployment pins that commitment +from the matching artifact pair's `.vk_tree_hash`, so a prover cannot substitute another circuit +within the proof tree. ## BFV presets From c9291e2de7de39b24a88cac6bb90aeb0f722d9d3 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:54:11 +0000 Subject: [PATCH 14/19] docs(contracts): name the C6 Chonk root in the decryption verifier NatSpec --- .../contracts/interfaces/IDecryptionVerifier.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/interfold-contracts/contracts/interfaces/IDecryptionVerifier.sol b/packages/interfold-contracts/contracts/interfaces/IDecryptionVerifier.sol index 862c3204f8..eb90b4efac 100644 --- a/packages/interfold-contracts/contracts/interfaces/IDecryptionVerifier.sol +++ b/packages/interfold-contracts/contracts/interfaces/IDecryptionVerifier.sol @@ -8,7 +8,7 @@ pragma solidity 0.8.28; /** * @title IDecryptionVerifier * @notice Interface for the DecryptionAggregator (EVM) proof verifier. - * @dev The DecryptionAggregator circuit internally verifies the C6-fold and C7 + * @dev The DecryptionAggregator circuit internally verifies the c6_chonk_root and C7 * (decrypted_shares_aggregation) sub-proofs; this on-chain wrapper verifies * the final EVM proof and enforces: * - the immutable recursive sub-circuit VK hashes From 51f532702ff2e55de6546e9a88c1f9ad28e9a082 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:14:20 +0000 Subject: [PATCH 15/19] docs(blueprint): follow predecessor_key_hash after the C6 fold hash removal --- scripts/blueprint/facts/11-circuits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/blueprint/facts/11-circuits.json b/scripts/blueprint/facts/11-circuits.json index d3298d9704..dc149d1255 100644 --- a/scripts/blueprint/facts/11-circuits.json +++ b/scripts/blueprint/facts/11-circuits.json @@ -924,7 +924,7 @@ { "name": "predecessor_key_hash", "what": "checks the prior keys are the leaf, fold and genesis keys, then returns the genesis key on step one and the fold key after", - "ref": "circuits/lib/src/math/recursive_vk.nr@10@pub fn predecessor_key_hash(" + "ref": "circuits/lib/src/math/recursive_vk.nr@8@pub fn predecessor_key_hash(" } ], "read_first": [ From 97513fd81c19e0b227ae588ca05af335f92efc03 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:38:48 +0000 Subject: [PATCH 16/19] test(zk-prover): accept both nargo forms of an unsatisfied constraint The C6 anchor equality with the key-list hash fails as an unsolvable program, because the failing opcode carries no assertion payload; the other rejection cases fail as a failed assertion. Both mean that the witness breaks a circuit constraint. --- .../prover/tests/fold_accumulators_e2e_tests.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs b/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs index 5fe78eaf2e..13ffbe789e 100644 --- a/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs +++ b/crates/zk/prover/tests/fold_accumulators_e2e_tests.rs @@ -288,14 +288,19 @@ async fn c3_chonk_rejects_a_corrupted_leaf_or_a_substituted_key() { } } -/// The witness fails on a constraint of the circuit. The solver reports only that an assertion +/// The witness fails on a constraint of the circuit. The solver reports only that a constraint /// failed, so each case also solves its honest twin, which differs in the one edit under test. +/// nargo reports an unsatisfied constraint as a failed assertion when the opcode carries an +/// assertion payload, and as an unsolvable program when the compiler merged the `assert` into an +/// opcode without one (for example an equality with a hash output). fn assert_witness_rejected(result: Result, ZkError>, case: &str) { match result { - Err(ZkError::WitnessGenerationFailed(message)) => { - assert_eq!(message, "Failed assertion", "{case}") - } - other => panic!("{case}: expected a failed assertion, got {other:?}"), + Err(ZkError::WitnessGenerationFailed(message)) => assert!( + message == "Failed assertion" + || message == "Failed to solve program: 'Cannot satisfy constraint'", + "{case}: expected an unsatisfied constraint, got {message}" + ), + other => panic!("{case}: expected an unsatisfied constraint, got {other:?}"), } } From 05bf0bf32a9024e6a204741278d08a2af810e903 Mon Sep 17 00:00:00 2001 From: ctrlc03 Date: Sat, 21 Nov 2026 12:08:13 +0000 Subject: [PATCH 17/19] docs(blueprint): follow the C6 refs moved by the rebase onto main --- scripts/blueprint/facts/05-zk.json | 2 +- scripts/blueprint/facts/10-contracts.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/blueprint/facts/05-zk.json b/scripts/blueprint/facts/05-zk.json index 3b8d15a0b4..9bcd8d3a9f 100644 --- a/scripts/blueprint/facts/05-zk.json +++ b/scripts/blueprint/facts/05-zk.json @@ -386,7 +386,7 @@ { "pattern": "enum-match", "note": "CircuitName maps static identities to artifact names without runtime dependencies.", - "ref": "crates/zk/config/src/circuit.rs@207@CircuitName::PkBfv => \"pk\"," + "ref": "crates/zk/config/src/circuit.rs@241@CircuitName::PkBfv => \"pk\"," } ], "depends_on": ["e3-committee", "e3-fhe-params", "e3-polynomial", "e3-polynomial-fhe"], diff --git a/scripts/blueprint/facts/10-contracts.json b/scripts/blueprint/facts/10-contracts.json index 40a4e71af0..d898468066 100644 --- a/scripts/blueprint/facts/10-contracts.json +++ b/scripts/blueprint/facts/10-contracts.json @@ -1450,12 +1450,12 @@ { "name": "BfvDecryptionVerifier.ciphernodeRegistry: source of the DKG anchors", "where": "chain", - "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@108@ICiphernodeRegistry public immutable ciphernodeRegistry;" + "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@110@ICiphernodeRegistry public immutable ciphernodeRegistry;" }, { "name": "BfvDecryptionVerifier.expectedC6FoldKeyHash: VK anchor for the decryption circuit", "where": "chain", - "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@113@bytes32 public immutable expectedC6FoldKeyHash;" + "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@116@bytes32 public immutable expectedC6FoldKeyHash;" }, { "name": "BfvPkVerifierRouter.routes: verifier builds the router can dispatch to", @@ -1477,7 +1477,7 @@ }, { "why": "the decryption proof check and its public input layout", - "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@54@contract BfvDecryptionVerifier is IDecryptionVerifier {" + "ref": "packages/interfold-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.sol@57@contract BfvDecryptionVerifier is IDecryptionVerifier {" }, { "why": "how the router chooses a build by VK anchors", From 1c0cc837a2ad7389513e587af4da9c90296a679c Mon Sep 17 00:00:00 2001 From: ctrlc03 Date: Sat, 21 Nov 2026 14:19:34 +0000 Subject: [PATCH 18/19] test(zk-build): probe an SS-only circuit in the synchronized selection tests The tests asserted that a synchronized build rejects decryption_aggregator, but main's synchronized definition now includes that circuit, so both tests failed. They now probe c6_chonk_root, which only the SS build has, keeping the never-fall-back-to-SS guard. --- crates/zk/build/src/artifacts.rs | 2 +- crates/zk/build/src/tests.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/zk/build/src/artifacts.rs b/crates/zk/build/src/artifacts.rs index c6377319cb..539ee87f56 100644 --- a/crates/zk/build/src/artifacts.rs +++ b/crates/zk/build/src/artifacts.rs @@ -1086,7 +1086,7 @@ mod tests { before, "wildcard sync dry-run wrote files" ); - dry.circuits = vec!["decryption_aggregator".into()]; + dry.circuits = vec!["c6_chonk_root".into()]; assert!(build(root, &dry).is_err()); assert_eq!(crate::tests::snapshot(root), before); let manifest = circuit.path.join("Nargo.toml"); diff --git a/crates/zk/build/src/tests.rs b/crates/zk/build/src/tests.rs index bac7e1865d..1f82c57d66 100644 --- a/crates/zk/build/src/tests.rs +++ b/crates/zk/build/src/tests.rs @@ -397,7 +397,8 @@ fn synchronized_sources_and_targets_are_isolated_and_missing_descendants_never_f } full.circuits = vec!["e_sm_share_computation".into()]; assert!(artifacts::discover(&repo, &full).is_err()); - full.circuits = vec!["decryption_aggregator".into()]; + // `c6_chonk_root` is SS-only; a sync selection must not fall back to its SS definition. + full.circuits = vec!["c6_chonk_root".into()]; assert!(artifacts::discover(&repo, &full).is_err()); let mut ss = request(); ss.circuits = vec!["pk".into()]; From ce89d83b624960afe73d7612b41d650e4d238dc8 Mon Sep 17 00:00:00 2001 From: ctrlc03 Date: Sat, 21 Nov 2026 14:20:06 +0000 Subject: [PATCH 19/19] docs: record C6 over Chonk in the cutover and place its circuits in the README --- circuits/README.md | 2 +- docs/architecture/upgrades.md | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/circuits/README.md b/circuits/README.md index e0eb27ce03..0478260baf 100644 --- a/circuits/README.md +++ b/circuits/README.md @@ -86,7 +86,7 @@ C2a and C2b proofs and hashes each one's chunk key tree into its key hash. | `node_fold` | `NodeFold` | Folds C0, C1, `c2ab_fold`, `c3ab_fold`, and `c4ab_fold` for one node. | | `nodes_fold`, `nodes_fold_kernel` | `NodesFold`, `NodesFoldKernel` | Folds the H `node_fold` proofs in sequence. | | `dkg_aggregator` | `DkgAggregator` | Verifies `nodes_fold` and C5. Its EVM proof goes to `publishCommittee`. | -| `c6_chonk_*` | `C6Chonk*` | Verifies the T + 1 C6 proofs of one ciphertext in one Chonk stack and closes it. | +| `c6_chonk_tube`, `c6_chonk_root` | `C6ChonkTube`, `C6ChonkRoot` | Close one ciphertext's C6 Chonk stack; its app and kernels are in `bin/chonk/`. | | `decryption_aggregator` | `DecryptionAggregator` | Verifies `c6_chonk_root` and C7. Its EVM proof goes to `publishPlaintextOutput`. | For recursive trust and public-input bindings, see diff --git a/docs/architecture/upgrades.md b/docs/architecture/upgrades.md index b7879b530e..17b26a4b81 100644 --- a/docs/architecture/upgrades.md +++ b/docs/architecture/upgrades.md @@ -218,8 +218,9 @@ the governance batch that raises the required protocol version, and upgrade ever resume. Persisted peer proofs from in-flight E3s are not foldable under bb 6; drain them first. The cutover also carries chunked C2: the C2a, C2b, and `c2ab_fold` keys and the C2 branch of the VK tree change, and final C2 proofs gain a trailing key-tree public field. Stored C2 proofs from in-flight -E3s can be neither folded nor link-checked, so drain them first too. Storage schema and gossip/sync -wire majors are unchanged. +E3s can be neither folded nor link-checked, so drain them first too. C6 now aggregates over Chonk: +the `decryption_aggregator` key, the C6 tree anchor and every `BfvDecryptionVerifier` change, and no +event encoding changes. Storage schema and gossip/sync wire majors are unchanged. The cutover also carries three-node `nodes_fold` steps. `nodes_fold` and `nodes_fold_kernel` change their public layout, so their keys, the `dkg_aggregator` key, the nodes-tree anchor, and the DKG