QED ZK Circuit Journey: Tracing Proofs and Assumptions
This document provides a detailed walkthrough of the Zero-Knowledge proof lifecycle in QED, starting from a user's local actions to the final, globally verifiable block proof. We meticulously track what each circuit proves and, critically, the assumptions it makes and how those assumptions are discharged by subsequent circuits.
Goal: Illustrate the flow of cryptographic guarantees and the progressive reduction of trust assumptions, culminating in a block proof dependent only on the previous block's established state.
Key:
- Circuit: The specific ZK circuit being executed.
- High-Level Purpose: Why this circuit exists in the overall architecture.
- Proves (Technical Detail): Specific cryptographic guarantees and state relations enforced by the circuit's constraints.
- How: Key gadgets, hashing, and constraint mechanisms employed.
- Assumes
[A_]: Inputs or states treated as correct before this circuit's verification. - Discharges
[R_]: Assumptions remaining from previous steps that are verified by this circuit. - Remaining
[R_]: Assumptions still held true after this circuit's verification, passed to the next stage.
Phase 1: User Proving Session (UPS) - Local Execution
(User executes transactions and builds a local proof chain)
Step 1: Start Session
- Circuit:
UPSStartSessionCircuit - High-Level Purpose: To establish a cryptographically verified starting point for the user's transaction batch, ensuring it begins from a consistent and valid state relative to the last finalized global block. Prevents users from initiating proofs based on invalid or outdated personal states.
- Proves:
- The provided
UserProvingSessionHeaderwitness (ups_header) contains an internally consistentsession_start_contextandcurrent_state. session_start_context.checkpoint_tree_rootmatches the root of the verifiedcheckpoint_tree_proofwitness.session_start_context.checkpoint_leaf_hashmatches the value of thecheckpoint_tree_proof.session_start_context.checkpoint_idmatches the index of thecheckpoint_tree_proof.- The hash of the provided
checkpoint_leafwitness matchessession_start_context.checkpoint_leaf_hash. - The hash of the provided
state_rootswitness (global_chain_root) matchescheckpoint_leaf.global_chain_root. state_roots.user_tree_rootmatches the root of the verifieduser_tree_proofwitness.session_start_context.start_session_user_leaf.user_idmatches the index of theuser_tree_proof.- The hash of
session_start_context.start_session_user_leafmatches the value of theuser_tree_proof. current_state.user_leafmatchessession_start_context.start_session_user_leafexceptlast_checkpoint_idis updated tosession_start_context.checkpoint_id.current_state.deferred_tx_debt_tree_root == EMPTY_TREE_ROOT.current_state.inline_tx_debt_tree_root == EMPTY_TREE_ROOT.current_state.tx_count == 0.current_state.tx_hash_stack == ZERO_HASH.
- The provided
- How:
UPSStartStepGadgetusesMerkleProofGadgets to verify paths,QED...Leaf/RootsGadgets to hash witnesses and check consistency, direct comparisons and constant checks. Public inputs calculated viacompute_tree_aware_proof_public_inputs. - Assumes:
[A1.1]The root hash used in witness Merkle proofs (checkpoint_tree_rootinups_header.session_start_context) accurately reflects the globally finalized state of the previous block.[A1.4]The constantempty_ups_proof_tree_rootused for the tree-aware public inputs is correct for this session's start.[A1.5]The constantups_step_circuit_whitelist_rootembedded in the output header is the correct root for allowed UPS circuits.- (Initial correctness of witness data like proofs and leaves is assumed, then verified internally).
- Discharges: Internal consistency checks discharge assumptions about the relationships between the provided witness components (e.g., leaf data matches proof value).
- Remaining:
[R1.1]=[A1.1](Correctness of previous block'sCHKProot).[R1.4]=[A1.4](Correctness of session'sempty_ups_proof_tree_root).[R1.5]=[A1.5](Correctness ofups_step_circuit_whitelist_root).
Step 1.5: Execute Contract Function Circuit (CFC)
- Circuit:
DapenContractFunctionCircuit(Specific instance per function) - High-Level Purpose: To execute the specific smart contract logic defined by the developer for a single transaction call, locally generating a proof that this execution instance faithfully followed the code, given its specific inputs and assumed context. This decouples logic execution from state transition verification.
- Proves:
- The sequence of internal operations matches the compiled
DPNFunctionCircuitDefinition(fn_def). - Given the assumed
tx_ctx_headerwitness (containing start states likestart_contract_state_tree_root,start_deferred_tx_debt_tree_root, call arguments hash/length) and circuitinputs:- The simulated state commands (reads/writes to CST, debt tree interactions via
StateReaderGadget) produce theend_contract_state_tree_rootandend_deferred_tx_debt_tree_rootrecorded intx_ctx_header.transaction_end_ctx. - The computed
outputs_hashandoutputs_lengthmatch those recorded intx_ctx_header.transaction_end_ctx. - All
assertionswithin thefn_defhold true.
- The simulated state commands (reads/writes to CST, debt tree interactions via
- The public inputs hash (combining
session_proof_tree_rootandtx_ctx_headerhash) is correctly computed.
- The sequence of internal operations matches the compiled
- How:
QEDContractFunctionBuilderGadgetinterpretsfn_def, simulating execution usingSimpleDPNBuilderandStateReaderGadget. Connects computed vs witnessed values intx_ctx_header. - Assumes:
[A1.5.1]TheDapenContractFunctionCircuitInputwitness (esp.tx_input_ctx) accurately reflects the state before this CFC execution (derived from the previous UPS step's output) and the correct function inputs/outputs.[A1.5.3]Thesession_proof_tree_rootwitness correctly represents the root of the user's recursive proof tree at this point.
- Discharges: Internal consistency of the execution trace vs. the code definition (
fn_def). - Remaining:
[R1.5.1]Correctness of the assumedtx_input_ctx(start state, inputs/outputs).[R1.5.3]Correctness of the assumedsession_proof_tree_root.
- Output: A CFC Proof object.
Step 2: Verify CFC & Process UPS Delta
- Circuit:
UPSCFCStandardTransactionCircuit - High-Level Purpose: To integrate the result of a local CFC execution (Step 1.5) into the user's main proof chain. It verifies the CFC was executed correctly and that its claimed start/end states correctly link the previous UPS state to the next UPS state, while also proving the previous UPS step itself was valid.
- Proves:
- Previous Step Validity: Proof N-1 was valid & used a whitelisted UPS circuit (
[R(N-1).5]discharged). Public inputs match header hash. - CFC Validity: CFC proof (from Step 1.5) is valid & exists in the same UPS proof tree as Proof N-1 (
[R1.5.3]discharged). CFC function is registered globally (GCON/CFTcheck linked via[R(N-1).1]). - Context Link: The inner public inputs hash from the verified CFC proof matches the hash of the
UPSCFCStandardStateDeltaInputwitness used to calculate state changes ([R1.5.1]discharged). This is the critical link ensuring the state delta matches the verified computation. - State Delta Correctness: The UPS header transition from step N-1 to N is valid:
UCONroot updated correctly based onuser_contract_tree_update_proof.- Debt tree roots updated correctly based on
deferred/inline_tx_debt_pivot_proofs (starting from prev step's end state). tx_countincremented;tx_hash_stackupdated correctly.
- Previous Step Validity: Proof N-1 was valid & used a whitelisted UPS circuit (
- How:
VerifyPreviousUPSStepProofInProofTreeGadget,UPSVerifyCFCStandardStepGadgetconnectscfc_inner_public_inputs_hashbetweenUPSVerifyCFCProofExistsAndValidGadgetandUPSCFCStandardStateDeltaGadget. Delta/pivot proofs verified. - Assumes:
[A2.1]Witness data for this step (attestations, state delta proofs) is correct initially.[R(N-1).1](Prev Step) Last block'sCHKProot correctness (used for CFC inclusion context).[R(N-1).4](Prev Step) Session'sempty_ups_proof_tree_rootcorrectness (defines proof tree base).
- Discharges:
[R(N-1).5](Prev UPS whitelist),[R1.5.1](CFC Context),[R1.5.3](CFC Proof Tree Root). - Remaining:
[RN.1]=[R(N-1).1](Last block'sCHKProot).[RN.4]=[R(N-1).4](Session'sempty_ups_proof_tree_root).[RN.5](New) Current header'sups_step_circuit_whitelist_rootcorrectness.
(Repeat Step 1.5 & 2, or deferred variant, for all user transactions)
Step 3: End Session
- Circuit:
UPSStandardEndCapCircuit - High-Level Purpose: To securely conclude the user's local proving session, producing a single proof that attests to the validity of the entire sequence of transactions, authorized by the user's signature, and ready for network submission. It ensures the session ends in a clean state (no outstanding debts).
- Proves:
- Last UPS step proof valid & used correct whitelisted circuit (
[R_Last.5]discharged against constantknown_ups_circuit_whitelist_root). - ZK Signature proof valid & in same proof tree (
[R_Last.4]discharged). - Signature corresponds to user's key & authenticates
QEDUserProvingSessionSignatureDataCompactderived from final UPS header state. - Nonce incremented correctly.
last_checkpoint_idupdated correctly in finalUserLeaf.- Final debt tree roots are empty.
- (Optional) UPS proof tree aggregation used correct circuits (
known_proof_tree_circuit_whitelist_root). - Public Outputs (
end_cap_result_hash,guta_stats_hash) correctly computed.
- Last UPS step proof valid & used correct whitelisted circuit (
- How:
UPSEndCapFromProofTreeGadgetorchestrates verification of last step & signature,UPSEndCapCoreGadgetenforces final constraints. OptionalVerifyAggProofGadget. - Assumes:
[A3.1]Witness data correct initially.[A3.2]Constantknown_ups_circuit_whitelist_root.[A3.3]Constantknown_proof_tree_circuit_whitelist_root(if used).[R_Last.1](Last tx step) Correctness ofCHKProot used as session basis.
- Discharges:
[R_Last.5],[R_Last.4]. Potentially UPS tree agg assumptions. - Remaining:
[R3.1]=[R_Last.1](Correctness of initialCHKProot).
Output of Phase 1: End Cap Proof + Public Inputs + State Deltas from user
Phase 2: Network Aggregation - Parallel Execution (Realms & Coordinators)
(The Proving Network receives End Cap proofs + state deltas from users and aggregate them to prove the change in the blockchain state root)
Step 4: Process End Cap Proof(s) (GUTA Entry - Realm)
- Circuit(s):
GUTAVerifySingleEndCapCircuit(Handles a single End Cap, e.g., an odd leaf in aggregation)GUTAVerifyTwoEndCapCircuit(Handles pairs of End Cap proofs, typical base case)
- High-Level Purpose: To securely ingest user End Cap proofs into the GUTA process, verify their validity against the protocol and historical state, and translate them into the standard
GlobalUserTreeAggregatorHeaderformat needed for recursive aggregation. - Proves:
- Input End Cap proof(s) (
proof_target,child_a/b_proof) are valid ZK proofs. - The End Cap proof(s) were generated by the official End Cap circuit (fingerprint checked against
known_end_cap_fingerprint). - The public inputs of the End Cap proof(s) correctly match the claimed result/stats (
end_cap_result,guta_stats) provided as witness. - The
checkpoint_tree_rootclaimed by the user(s) existed historically in theCHKPtree (verified viacheckpoint_historical_merkle_proof). - (For TwoEndCap): The Nearest Common Ancestor (NCA) logic correctly combines the two individual user state transitions (
start_leaf->end_leafat user indices) into a single state transition at their parent node in theGUSRtree. Statistics are correctly summed. - Outputs a
GlobalUserTreeAggregatorHeaderrepresenting the state transition for the node processed (either a single user leaf or the NCA parent) and the combined stats.
- Input End Cap proof(s) (
- How:
VerifyEndCapProofGadget: Used internally (once or twice) to perform core End Cap proof verification, fingerprint check, public input matching, and historical checkpoint validation.TwoNCAStateTransitionGadget(inGUTAVerifyTwoEndCapCircuit): Combines the twoGUSRleaf transitions (derived from End Cap results) using an NCA proof witness.GUTAStatsGadget.combine_with: Sums stats (inGUTAVerifyTwoEndCapCircuit).- Constructs the output
GlobalUserTreeAggregatorHeader.
- Assumes:
[A4.1]Witness data (End Cap proof(s), results, stats, historical proofs, NCA proof if applicable) is correct initially.[A4.2]Constantknown_end_cap_fingerprint_hashis correct.[A4.3]Public Inputguta_circuit_whitelist_root_hashis correct.[R3.1](Implicit in End Cap) User session(s) based on valid pastCHKProot.
- Discharges:
[R3.1](viaVerifyEndCapProofGadget's historical proof check).- Validity of the input End Cap proof(s).
- Remaining:
[R4.1](New) Correctness of the current block'scheckpoint_tree_root(established bycheckpoint_historical_merkle_proof.current_rootand passed consistently upwards).[R4.3]=[A4.3](Correctness ofguta_circuit_whitelistroot).
Step 5: Aggregate GUTA Proofs (Recursive - Realm/Coordinator)
- Circuit(s):
GUTAVerifyTwoGUTACircuit(Aggregates two GUTA sub-proofs)GUTAVerifyLeftGUTARightEndCapCircuit(Aggregates GUTA sub-proof and a new End Cap proof)GUTAVerifyLeftEndCapRightGUTACircuit(Aggregates an End Cap proof and a GUTA sub-proof)
- High-Level Purpose: To recursively combine verified state transitions within the GUTA hierarchy. These circuits take proofs representing changes in subtrees (either previous GUTA aggregations or newly processed End Caps) and merge them into a proof for the parent node, typically using NCA logic.
- Proves:
- Both input proofs (Type A and Type B, where Type can be GUTA or EndCap) are valid ZK proofs.
- Input Proof A (if GUTA) used a whitelisted GUTA circuit (
[R(A).3]discharged viaVerifyGUTAProofGadget). - Input Proof A (if EndCap) used the whitelisted EndCap circuit (
[A5.EndCapFingerprint]check viaVerifyEndCapProofGadget). - Input Proof B processed similarly (
[R(B).3]or[A5.EndCapFingerprint]discharged). - Both input proofs' headers/results reference the same
checkpoint_tree_root([R(A).1]and[R(B).1]verified to be equal, discharging one, remaining[RN.1]). - Both input proofs' headers reference the same
guta_circuit_whitelistroot ([R(A).3]and[R(B).3]verified to be equal, discharging one, remaining[RN.3]). - Public inputs of each input proof match their respective headers/results.
- The NCA logic (
TwoNCAStateTransitionGadget) correctly combines the state transitions (SubTreeNodeStateTransitionfrom input GUTA headers or derived from EndCap results) based on the NCA proof witness. - Statistics are correctly summed (
GUTAStatsGadget.combine_with). - Outputs a
GlobalUserTreeAggregatorHeaderfor the parent NCA node.
- How:
VerifyGUTAProofGadget(for GUTA inputs).VerifyEndCapProofGadget(for EndCap inputs).TwoNCAStateTransitionGadget: Core aggregation logic using NCA proof witness.- Connections ensuring consistency of
checkpoint_tree_rootandguta_circuit_whitelistbetween inputs.
- Assumes:
[A5.1]Witness data (input proofs, headers/results, whitelist proofs, NCA proof) correct initially.[A5.EndCapFingerprint]Constantknown_end_cap_fingerprint_hash(if applicable).[R(A).1],[R(B).1](from inputs)CHKProot correctness.[R(A).3],[R(B).3](from inputs)GUTA whitelistcorrectness.
- Discharges: Validity/consistency of input proofs, their whitelist usage (
[R(A/B).3]), and consistency of their assumedCHKProots ([R(A).1]confirmed equal to[R(B).1]). - Remaining:
[RN.1]=[R(A).1](CommonCHKProot correctness).[RN.3]=[R(A).3](CommonGUTA whitelistcorrectness).
Step 5.5: Propagate GUTA Proof Upwards (Line Proof)
- Circuit:
GUTAVerifyGUTAToCapCircuit(May be used within Realm or by Coordinator) - High-Level Purpose: To efficiently propagate a verified state transition from a lower node up a direct path in the tree (where no merging is needed) to a higher level (e.g., the Realm root or the global root).
- Proves:
- The input GUTA proof is valid and used a whitelisted GUTA circuit (
[R_In.3]discharged). - The input proof references the correct
CHKProot ([R_In.1]). - The state transition is correctly recalculated from the input proof's node level up to the target level (e.g., level 0) using the provided
top_line_siblingswitness. - Outputs a
GlobalUserTreeAggregatorHeaderwith the state transition reflecting the change at the target level.
- The input GUTA proof is valid and used a whitelisted GUTA circuit (
- How:
VerifyGUTAProofToLineGadget(usesVerifyGUTAProofGadgetandGUTAHeaderLineProofGadgetwhich usesSubTreeNodeTopLineGadget). - Assumes:
[A5.5.1]Witness data (input proof, header, whitelist proof,top_line_siblings) correct initially.[R_In.1],[R_In.3](from input proof).
- Discharges:
[R_In.3](GUTA whitelist). Validity of input proof relative to[R_In.1]. - Remaining:
[R5.5.1]=[R_In.1](CommonCHKProot correctness).[R5.5.3]=[R_In.3](CommonGUTA whitelistcorrectness).
(Steps 5/5.5 repeat recursively until Realm roots are reached)
Step 5.N: Handle No GUTA Changes
- Circuit:
GUTANoChangeCircuit - High-Level Purpose: To allow the aggregation process to incorporate the latest checkpoint root even if no user activity (relevant to GUTA) occurred in a particular block or subtree. Maintains checkpoint consistency across the aggregation structure.
- Proves:
- A specific
checkpoint_leafexists in thecheckpoint_treeat the previouscheckpoint_id. - The
GUSRroot remained unchanged between the previous and current checkpoint (new_guta_header.state_transitionshowsold_node_value == new_node_valueat level 0). - Statistics are zero.
- Outputs a
GlobalUserTreeAggregatorHeaderreferencing the currentcheckpoint_tree_rootbut indicating noGUSRchange.
- A specific
- How:
GUTANoChangeGadget(usesMerkleProofGadgetfor checkpoint proof, constructs no-op transition). - Assumes:
[A5.N.1]Witness data correct initially.[A5.N.3]Public Inputguta_circuit_whitelistroot is correct.
- Discharges: Internal consistency of checkpoint proof/leaf.
- Remaining:
[R5.N.1](New) Correctness of the currentcheckpoint_tree_root(from the witness proof).[R5.N.3]=[A5.N.3](GUTA whitelist correctness).
Output of Phase 2: Aggregated GUTA proof(s) from each active Realm (or a NoChange proof), valid relative to [R_Realm.1] and [R_Realm.3].
Phase 3: Coordinator Level Aggregation - Network Execution
(Coordinator combines proofs from Realms and global tree updates)
Step 6: Process User Registrations
- Circuit:
BatchAppendUserRegistrationTreeCircuit - Proves: Correct batch append to
URT(output root valid given input root[A6.3]). Respectsregister_users_circuit_whitelist([A6.2]). - Assumes:
[A6.x](Witness, whitelist, inputURTroot). - Discharges: Internal append proof consistency.
- Remaining:
[R6.2](Whitelist),[R6.3](InputURTroot correctness).
Step 7: Process Contract Deployments
- Circuit:
BatchDeployContractsCircuit - Proves: Correct batch append to
GCON(output root valid given input root[A7.3]). Witness leaves match hashes. Respectsdeploy_contract_circuit_whitelist([A7.2]). - How:
BatchDeployContractsGadget. - Assumes:
[A7.x](Witness, whitelist, inputGCONroot). - Discharges: Internal append/leaf consistency.
- Remaining:
[R7.2](Whitelist),[R7.3](InputGCONroot correctness).
Step 8: Aggregate Part 1 (Combine UserReg + Deploy + GUTA)
- Circuit:
VerifyAggUserRegistartionDeployContractsGUTACircuit - Proves: Input proofs (Agg UserReg, Agg Deploy, Agg GUTA) valid & used respective whitelisted circuits (
[R6.2],[R7.2],[R_GUTA.3]discharged). All inputs based on sameCHKProot ([R_GUTA.1]verified across inputs). Output header correctly combines state transitions. - How:
VerifyAggUserRegistartionDeployContractsGUTAGadget. - Assumes:
[A8.1]Witness data correct initially.[R_GUTA.1](Implicit commonCHKProot from inputs).[R6.3](InputURTroot correctness).[R7.3](InputGCONroot correctness).
- Discharges: Whitelists (
[R6.2],[R7.2],[R_GUTA.3]). Input proof validity. Consistency ofCHKProot[R_GUTA.1]. - Remaining:
[R8.1]=[R_GUTA.1](CHKProot correctness).[R8.3]=[R6.3](InputURTroot correctness).[R8.4]=[R7.3](InputGCONroot correctness).
Output of Phase 3: Single "Part 1" proof, valid relative to [R8.1], [R8.3], [R8.4].
Phase 4: Final Block Proof - Network Execution
Step 9: Final Block Transition
- Circuit:
QEDCheckpointStateTransitionCircuit - High-Level Purpose: To generate the definitive proof for the block, verifying all aggregated work and cryptographically linking the block to its predecessor, thereby discharging all temporary assumptions made during parallel processing.
- Proves:
- Part 1 Agg proof (Step 8) valid & used correct circuit.
- New
CHKPLeaf computed correctly from Part 1 outputs (new global roots forURT([R8.3]discharged),GCON([R8.4]discharged),GUSR), stats, time, randomness. CHKPtree append operation correct, transitioning fromprevious_checkpoint_proof.root([R8.1]) tonew_checkpoint_tree_root.- Final Chain Link:
previous_checkpoint_proof.rootmatches the Public Inputprevious_block_chkp_root.
- How:
CheckpointStateTransitionChildProofsGadget,CheckpointStateTransitionCoreGadget. - Assumes:
[A9.1]Witness data correct initially.[A9.2]Public Inputprevious_block_chkp_root== previous block's finalizedCHKProot.
- Discharges:
[R8.1](CHKProot correctness discharged against public input[A9.2]).[R8.3](URTroot correctness),[R8.4](GCONroot correctness) implicitly discharged by relying on the verified Part 1 proof output. - Remaining Assumptions: None.
Output: Final Block Proof. Its verification confirms the entire block's state transition is valid, contingent only on the validity of the previous block's state hash ([A9.2]) and ZKP soundness.