This document details the various gadgets used within the QED ZK circuits, primarily focusing on the User Proving Session (UPS) and Global User Tree Aggregation (GUTA) systems. Gadgets are reusable circuit components that enforce specific constraints and logic.
UPS Gadgets (User Proving Session)
These gadgets are components used within the circuits that users run locally to prove their sequence of transactions.
CorrectUPSHeaderHashesGadget
- File:
correct_header_hashes.rs - Purpose: To hold potentially modified hash roots from a previous UPS step header. This is specifically used when a transaction needs to alter the starting state assumptions for debt trees (e.g., paying back a deferred transaction before processing the current transaction's main logic).
- Key Inputs/Witness: Takes a
UserProvingSessionHeaderGadgetrepresenting the actual previous step. - Key Outputs/Computed Values:
previous_step_deferred_tx_debt_tree_root: The deferred debt root to assume as the starting point for the next step's logic.previous_step_inline_tx_debt_tree_root: The inline debt root to assume as the starting point for the next step's logic.
- Core Logic/Constraints: Primarily a data structure. Its values are used by other gadgets (like
UPSCFCStandardStateDeltaGadget) to override the default assumption that the starting debt roots are identical to the previous step's ending debt roots. - Assumptions: Assumes the input
previous_stepheader gadget is correctly formed (though its values might be overridden). - Role: Enables flexible handling of transaction debt repayment within the UPS flow, allowing debts to be settled before the main state delta logic runs, without breaking the constraint flow.
UPSVerifyCFCProofExistsAndValidGadget
- File:
ups_cfc_verify_inclusion.rs - Purpose: To verify that a specific Contract Function Call (CFC) proof exists within the user's current UPS proof tree and that the function being called is validly registered within the global contract structure.
- Key Inputs/Witness:
AttestTreeAwareProofInTreeInput: Witness for the CFC proof's existence and validity within the UPS proof tree.QEDCheckpointLeafCompactWithStateRoots: Witness for the relevant checkpoint state.QEDContractFunctionInclusionProof: Witness proving the function's fingerprint exists in the contract's function tree.ups_session_proof_tree_height: Parameter.
- Key Outputs/Computed Values:
attested_proof_tree_root: The root of the UPS proof tree the CFC proof is part of.checkpoint_leaf_hash: Hash of the checkpoint leaf used for context.cfc_fingerprint: The fingerprint (verifier data hash) of the CFC proof being verified.cfc_inner_public_inputs_hash: The hash of the CFC proof's internal public inputs (before wrapping with tree awareness).cfc_contract_id,cfc_method_id,cfc_num_inputs,cfc_num_outputs: Metadata about the contract function extracted from the inclusion proof.
- Core Logic/Constraints:
- Verifies the CFC proof using
AttestTreeAwareProofInTreeGadget. - Verifies the function's inclusion in the contract tree using
QEDContractFunctionInclusionProofGadget. - Connects the contract tree root from the inclusion proof to the one in the checkpoint state.
- Connects the CFC fingerprint from the proof attestation to the one in the inclusion proof.
- Verifies the CFC proof using
- Assumptions: Assumes the witness data provided (proofs, checkpoint state) is valid for the constraints to pass.
- Role: Ensures that the CFC proof being processed corresponds to a valid, registered function and exists within the user's current session proof tree. Links the specific CFC execution to the global contract state via the checkpoint.
UPSCFCStandardStateDeltaGadget
- File:
ups_standard_cfc_state_delta.rs - Purpose: Calculates the state changes to a user's UPS header based on executing a standard CFC transaction. It updates the user's contract state tree root, transaction debt trees, transaction count, and transaction hash stack.
- Key Inputs/Witness:
previous_step_header_gadget: The header state before this transaction.corrections: OptionalCorrectUPSHeaderHashesGadgetto override starting debt tree roots.contract_state_tree_height: The height of the specific CSTATE tree being modified.UPSCFCStandardStateDeltaInput: Witness containing the transaction input context (start/end states) and proofs for tree updates (user contract tree delta, debt tree pivots).
- Key Outputs/Computed Values:
new_header_gadget: TheUserProvingSessionHeaderGadgetrepresenting the state after this transaction.cfc_inner_public_inputs_hash: Hash of the CFC transaction input context (used for connecting to verification gadgets).cfc_contract_id,cfc_method_id,cfc_num_inputs,cfc_num_outputs: Metadata passed through.
- Core Logic/Constraints:
- Computes the expected
cfc_inner_public_inputs_hashfrom the transaction context witness. - Verifies the
user_contract_tree_update_proof(DeltaMerkleProofGadget):- Checks
old_rootmatches theuser_state_tree_rootin theprevious_step_header_gadget. - Checks
indexmatches thetx_in_contract_id. - Checks
old_valueconsistency (handles initialization from zero hash to default root based on height). - Checks
new_valuematches thetx_in_end_contract_state_tree_root.
- Checks
- Verifies
deferred_tx_debt_pivot_proof(HistoricalRootMerkleProofGadget):- Checks
historical_rootmatches the correctedprevious_step_deferred_tx_debt_tree_root. - Checks
current_rootmatchestx_in_end_deferred_tx_debt_tree_root.
- Checks
- Verifies
inline_tx_debt_pivot_proofsimilarly. - Checks consistency between previous header state (balance, event index) and transaction start context.
- Updates transaction count (
new_tx_count = old_tx_count + 1). - Pushes the transaction log item onto the
tx_hash_stack. - Constructs the
new_header_gadgetwith updated values.
- Computes the expected
- Assumptions: Assumes witness proofs and context are valid. Assumes the
previous_step_header_gadgetandcorrectionsare correctly provided. - Role: The core engine for calculating user state updates resulting from a standard contract call within the UPS.
UPSVerifyCFCStandardStepGadget
- File:
ups_cfc_standard.rs - Purpose: Combines the verification of a CFC proof's existence/validity (
UPSVerifyCFCProofExistsAndValidGadget) with the calculation of its resulting state changes (UPSCFCStandardStateDeltaGadget). It acts as the main gadget for processing a standard transaction step within a UPS circuit. - Key Inputs/Witness:
previous_step_header_gadget: Header state before this step.current_proof_tree_root: The root of the UPS proof tree this step belongs to.ups_session_proof_tree_height: Parameter.UPSVerifyCFCStandardStepInput: Witness containing inputs for both sub-gadgets.
- Key Outputs/Computed Values:
new_header_gadget: TheUserProvingSessionHeaderGadgetrepresenting the state after this transaction step.- (Internal gadgets expose their outputs too).
- Core Logic/Constraints:
- Instantiates
UPSVerifyCFCProofExistsAndValidGadgetandUPSCFCStandardStateDeltaGadget. - Connects
current_proof_tree_rootto theattested_proof_tree_rootof the verification gadget. - Connects the
checkpoint_leaf_hashbetween the verification gadget and theprevious_step_header_gadget. - Connects key metadata (
cfc_contract_id,cfc_method_id,cfc_num_inputs,cfc_num_outputs,cfc_inner_public_inputs_hash) between the verification gadget and the state delta gadget to ensure they operate on the same transaction.
- Instantiates
- Assumptions: Relies on the assumptions of its constituent gadgets. Assumes
current_proof_tree_rootis correctly provided. - Role: Represents a complete, verifiable step for processing one standard CFC transaction within the user's local proving session.
UPSVerifyPopDeferredTxStepGadget
- File:
ups_cfc_standard_pop_deferred_tx.rs - Purpose: Processes a transaction that pays back a previously incurred deferred transaction debt. It verifies the removal of the debt item from the deferred debt tree and then processes the CFC transaction itself (using the standard step gadget but with a corrected starting deferred debt state).
- Key Inputs/Witness:
previous_step_header_gadget: Header state before this step.current_proof_tree_root: The root of the UPS proof tree this step belongs to.ups_session_proof_tree_height: Parameter.UPSVerifyPopDeferredTxStepInput: Witness containing inputs for the standard CFC step and theDeltaMerkleProoffor removing the deferred transaction.
- Key Outputs/Computed Values:
- (Exposes outputs from
UPSVerifyCFCStandardStepGadget, notably thenew_header_gadget).
- (Exposes outputs from
- Core Logic/Constraints:
- Instantiates
DeltaMerkleProofGadget(ups_pop_deferred_tx_proof) for the deferred debt tree. - Connects
ups_pop_deferred_tx_proof.old_rootto thedeferred_tx_debt_tree_rootinprevious_step_header_gadget. - Asserts
ups_pop_deferred_tx_proof.new_valueis the zero hash (proving removal). - Computes the hash of the expected deferred transaction item based on the call data from the CFC being processed.
- Asserts
ups_pop_deferred_tx_proof.old_value(the item removed) matches the computed hash. - Creates a
CorrectUPSHeaderHashesGadget, settingprevious_step_deferred_tx_debt_tree_roottoups_pop_deferred_tx_proof.new_root. - Instantiates
UPSVerifyCFCStandardStepGadgetusing the corrected header hashes.
- Instantiates
- Assumptions: Relies on assumptions of sub-gadgets. Assumes witness data (proofs, context) is valid.
- Role: Enables verifiable settlement of deferred transaction debts within the UPS, ensuring the debt removed matches the transaction being executed.
QEDUserProvingSessionSignatureDataCompactGadget
- File:
ups_signature_data.rs - Purpose: Defines the data structure that gets signed by the user's private key (or equivalent signature scheme) to authorize the end of a User Proving Session.
- Key Inputs/Witness:
start_user_leaf_hash: Hash of the user leaf at the start of the session.end_user_leaf_hash: Hash of the user leaf at the end of the session.checkpoint_leaf_hash: Hash of the checkpoint leaf the session was based on.tx_stack_hash: Final hash of the transaction log stack.tx_count: Total number of transactions processed.
- Key Outputs/Computed Values:
ups_end_cap_sighash: The final hash (part of the signature pre-image) computed from the input data combined with network magic, user ID, and nonce.
- Core Logic/Constraints:
- Computes an intermediate hash combining start/end user leaves.
- Computes an intermediate hash combining tx stack and count.
- Computes an intermediate hash combining checkpoint leaf and user leaf combo.
- Computes the final data hash by combining the state context and tx combo hashes.
- Uses
compute_sig_action_hash_circuitto combine this data hash with network magic, user ID, nonce, and the specific signature action code (QED_SIG_ACTION_SIGN_UPS_END_CAP) to produce the finalups_end_cap_sighash.
- Assumptions: Assumes input hashes and targets are correctly provided.
- Role: Standardizes the data payload for UPS end cap signatures, ensuring all necessary state transition information is committed to before signing.
UPSEndCapResultCompactGadget
- File:
ups_end_cap_result.rs - Purpose: Defines the compact data structure representing the result of a completed UPS, which is submitted to the GUTA layer for aggregation.
- Key Inputs/Witness:
start_user_leaf_hash: Hash of the user leaf at the start of the session.end_user_leaf_hash: Hash of the user leaf at the end of the session.checkpoint_tree_root_hash: Root of the checkpoint tree the session was based on.user_id: The ID of the user.
- Key Outputs/Computed Values:
end_cap_result_hash: The hash representing this result structure.
- Core Logic/Constraints:
- Computes an intermediate hash combining user ID, start/end user leaves, and the global user tree height constant.
- Computes the final
end_cap_result_hashby hashing the intermediate hash with thecheckpoint_tree_root_hash.
- Assumptions: Assumes input hashes and targets are correctly provided.
- Role: Creates the standardized, hashable output data for a completed UPS, suitable for inclusion as a public input in the end cap proof and for verification by GUTA circuits.
UPSEndCapCoreGadget
- File:
ups_end_cap.rs - Purpose: Enforces the core constraints for finalizing a User Proving Session (End Cap). It connects the final UPS state to the signature proof and prepares the final output data (result and stats).
- Key Inputs/Witness:
last_header_gadget: The header state at the end of the UPS (after the last transaction).sig_proof_public_inputs_hash: Public inputs hash from the user's signature proof.sig_proof_fingerprint,sig_proof_param_hash: Hashes related to the signature circuit's verifier data and parameters (used to derive the expected public key).nonce: The nonce used in the signature, provided as witness.slots_modified: Total storage slots modified, provided as witness.network_magic,empty_deferred_tx_debt_tree_root,empty_inline_tx_debt_tree_root: Constants/parameters.
- Key Outputs/Computed Values:
sig_data_compact_gadget: The computed signature data payload.end_cap_result_gadget: The computed end cap result structure.guta_stats: The computed GUTA statistics for this session.
- Core Logic/Constraints:
- Checks nonce progression: Ensures the final
nonceis greater than the starting nonce and updates the user leaf nonce. - Verifies public key consistency:
- Derives the
expected_public_keyfrom the signature proof fingerprint/params. - Asserts the start and end user leaves have the same public key.
- Asserts this public key matches the
expected_public_key.
- Derives the
- Verifies user ID consistency.
- Instantiates
QEDUserProvingSessionSignatureDataCompactGadgetusing data from thelast_header_gadget. - Computes the expected
ups_end_cap_sighashusing the signature data gadget, network magic, user ID, and nonce. - Computes the expected
sig_proof_public_inputs_hashby hashing theups_end_cap_sighashwith thesig_proof_param_hash. - Asserts the computed
sig_proof_public_inputs_hashmatches the one provided as input. - Instantiates
UPSEndCapResultCompactGadgetwith final state data. - Checks checkpoint ID progression: Ensures the final user leaf's
last_checkpoint_idmatches the session's checkpoint ID and is greater than the starting leaf'slast_checkpoint_id. - Asserts final debt trees are empty by comparing their roots in
last_header_gadgetto the provided empty tree root constants. - Instantiates
GUTAStatsGadgetusing the final transaction count and providedslots_modified.
- Checks nonce progression: Ensures the final
- Assumptions: Assumes input hashes, targets, and the
last_header_gadgetare correct. Assumes the signature proof itself is valid (verification happens elsewhere or is implied). - Role: The central gadget for validating the conditions required to end a UPS, linking the final state to the signature authorization and generating the outputs needed for GUTA.
VerifyPreviousUPSStepProofInProofTreeGadget
- File:
verify_previous_ups_step.rs - Purpose: Verifies a ZK proof corresponding to the previous step in the User Proving Session's recursive chain. It ensures the proof is valid, exists in the expected UPS proof tree, used an allowed UPS circuit, and matches the expected previous header state.
- Key Inputs/Witness:
ups_session_proof_tree_height,ups_circuit_whitelist_tree_height: Parameters.VerifyPreviousUPSStepProofInProofTreeInput: Witness containing:AttestTreeAwareProofInTreeInput: Witness for the previous step's proof attestation.UserProvingSessionHeader: Witness for the header state that should be the public input of the previous proof.MerkleProof: Witness proving the previous proof's circuit fingerprint is in the UPS circuit whitelist.
- Key Outputs/Computed Values:
proof_attestation_gadget: The underlying attestation gadget.previous_step_header_gadget: The header gadget representing the public inputs of the verified proof.ups_circuit_whitelist_merkle_proof: The whitelist proof gadget.current_proof_tree_root: The root of the UPS proof tree identified by the attestation proof.ups_step_circuit_whitelist_root: The root of the UPS circuit whitelist tree.
- Core Logic/Constraints:
- Instantiates
AttestTreeAwareProofInTreeGadgetto verify the previous proof's existence in the tree. - Instantiates
UserProvingSessionHeaderGadgetfor the previous step's public inputs (header). - Instantiates
MerkleProofGadgetfor the circuit whitelist check. - Connects the
fingerprintfrom the proof attestation to thevaluein the whitelist proof. - Connects the
ups_step_circuit_whitelist_rootfrom the previous header gadget to therootof the whitelist proof gadget. - Computes the expected hash of the
previous_step_header_gadget. - Connects this expected hash to the
inner_public_inputs_hashfrom the proof attestation gadget.
- Instantiates
- Assumptions: Assumes witness data (proofs, headers) is valid for constraints to pass.
- Role: Crucial for the recursive nature of UPS. Each step verifies the previous step's proof, ensuring the integrity of the entire transaction chain generated locally by the user. Links the execution to the allowed set of UPS circuits.
VerifyPreviousUPSStepProofInProofTreePartialFromCurrentGadget
- File:
verify_previous_ups_step_partial_from_current.rs - Purpose: Similar to the full verification gadget, but optimized for cases where the current header's
session_start_contextis already known and fixed within the circuit. It only needs the previous step's state (UserProvingSessionCurrentStateGadget) as witness, reconstructing the full previous header internally. - Key Inputs/Witness:
current_header: The current step's header gadget (provided as input, not witness).ups_session_proof_tree_height,ups_circuit_whitelist_tree_height: Parameters.VerifyPreviousUPSStepProofInProofTreePartialInput: Witness containing:AttestTreeAwareProofInTreeInput: Witness for the previous proof attestation.UserProvingSessionCurrentState: Witness for the state portion of the previous header.MerkleProof: Witness for the UPS circuit whitelist proof.
- Key Outputs/Computed Values: Same as
VerifyPreviousUPSStepProofInProofTreeGadget. - Core Logic/Constraints:
- Similar logic to the full version, but it constructs the
previous_step_header_gadgetby combining the knownsession_start_contextfrom thecurrent_headerwith theprevious_step_stateprovided as witness. - Enforces the same connections for fingerprint, whitelist root, and inner public inputs hash.
- Adds a constraint connecting the
ups_step_circuit_whitelist_rootfrom the current header to the whitelist proof root.
- Similar logic to the full version, but it constructs the
- Assumptions: Assumes the provided
current_headergadget is correct. Assumes witness data is valid. - Role: An optimization for verifying previous steps within circuits where the session start context is constant (like the End Cap circuit). Reduces witness size.
UPSEndCapFromProofTreeGadget
- File:
ups_end_cap_tree.rs - Purpose: Orchestrates the entire End Cap process within a ZK circuit. It verifies the last UPS step proof, verifies the user's ZK signature proof, and enforces the final End Cap constraints.
- Key Inputs/Witness:
ups_session_proof_tree_height,ups_circuit_whitelist_tree_height: Parameters.network_magic: Parameter.UPSEndCapFromProofTreeGadgetInput: Witness containing:VerifyPreviousUPSStepProofInProofTreeInput: Witness for verifying the last UPS step.AttestProofInTreeInput: Witness for verifying the ZK signature proof.user_public_key_param: Hash representing signature parameters.nonce: The nonce used for signing.slots_modified: Total storage slots modified.
- Key Outputs/Computed Values:
end_cap_core_gadget: The core gadget performing final checks.current_proof_tree_root: The root of the UPS proof tree.
- Core Logic/Constraints:
- Instantiates
VerifyPreviousUPSStepProofInProofTreeGadgetto verify the last UPS step. - Instantiates
AttestProofInTreeGadgetto verify the ZK signature proof. - Connects the
attested_proof_tree_rootfrom the signature proof verification to thecurrent_proof_tree_rootfrom the previous step verification (ensuring both proofs are in the same tree). - Defines empty debt tree root constants.
- Instantiates
UPSEndCapCoreGadget, passing outputs from the verification gadgets (previous_step_header_gadget, signature proof hashes) and witness values (nonce,slots_modified,user_public_key_param) along with constants.
- Instantiates
- Assumptions: Relies on assumptions of sub-gadgets. Assumes witness data is valid.
- Role: The top-level gadget within the End Cap circuit, ensuring the final UPS state is valid, linked to the previous step, and properly authorized by a valid ZK signature, all within the same consistent UPS proof tree.
UPSStartStepGadget
- File:
ups_start.rs - Purpose: Initializes a User Proving Session. It takes the user's initial state (from the last finalized block's checkpoint) and sets up the starting header for the UPS circuit chain.
- Key Inputs/Witness:
UPSStartStepInput: Witness containing:UserProvingSessionHeader: The expected starting header.QEDCheckpointLeaf: Witness for the checkpoint leaf data.QEDCheckpointGlobalStateRoots: Witness for the global state roots within the checkpoint.MerkleProof: Proof linking the checkpoint leaf to the checkpoint tree root.MerkleProof: Proof linking the user's starting leaf hash to the global user tree root.
- Key Outputs/Computed Values:
header_gadget: The validated starting header gadget.
- Core Logic/Constraints:
- Constraint Set 1 (Start Session Context):
- Verifies
checkpoint_tree_proofconsistency withheader_gadget.session_start_context(root, leaf hash, ID). - Verifies consistency between
checkpoint_leaf_gadget,state_roots_gadget, and theheader_gadget(checkpoint leaf hash, global chain root). - Verifies
user_tree_proofroot matches theuser_tree_rootinstate_roots_gadget. - Verifies
user_tree_proofvalue matchesheader_gadget.session_start_context.start_session_user_leaf_hash. - Verifies
user_tree_proofindex matches theuser_idin the header's start leaf.
- Verifies
- Constraint Set 2 (Current State Initialization):
- Computes the hash of the expected current user leaf (start leaf with
last_checkpoint_idupdated to the session's checkpoint ID). - Asserts this computed hash matches the hash of the
header_gadget.current_state.user_leaf. - Asserts the
deferred_tx_debt_tree_rootandinline_tx_debt_tree_rootinheader_gadget.current_statematch the known empty tree root constants. - Asserts
tx_hash_stackis zero hash andtx_countis zero.
- Computes the hash of the expected current user leaf (start leaf with
- Constraint Set 1 (Start Session Context):
- Assumptions: Assumes the witness data (header, proofs, leaves, roots) is valid for constraints to pass. Assumes the empty tree root constants are correct.
- Role: Securely bootstraps the User Proving Session, anchoring the initial state to a verified checkpoint and user leaf from the last finalized block and ensuring the session starts with clean debt trees and transaction counts.
GUTA Gadgets (Global User Tree Aggregation)
These gadgets are components used within the circuits run by the decentralized proving network to aggregate proofs from multiple users into a single block proof.
GUTAStatsGadget
- File:
guta_stats.rs - Purpose: Represents and processes statistics aggregated during the GUTA process.
- Key Inputs/Witness:
fees_collected,user_ops_processed,total_transactions,slots_modified. - Key Outputs/Computed Values: Can compute a hash of the stats.
- Core Logic/Constraints: Primarily a data structure. Includes a
combine_withmethod to add stats from two gadgets together (used during aggregation).to_hashpacks the stats into aHashOutTarget. - Assumptions: Assumes input target values are correct.
- Role: Tracks key metrics about the aggregated user operations within a GUTA proof branch.
GlobalUserTreeAggregatorHeaderGadget
- File:
guta_header.rs - Purpose: Represents the public inputs (header) of a GUTA proof. It encapsulates the essential information about the aggregation step.
- Key Inputs/Witness:
guta_circuit_whitelist: Root hash of the allowed GUTA circuits.checkpoint_tree_root: Root hash of the checkpoint tree relevant to this aggregation step.state_transition: ASubTreeNodeStateTransitionGadgetrepresenting the change in the Global User Tree (GUSR) this proof covers.stats: AGUTAStatsGadgetcontaining aggregated statistics.
- Key Outputs/Computed Values: Computes the hash of the entire header.
- Core Logic/Constraints: Data structure.
to_hashcomputes the final header hash by combining hashes ofstate_transition,stats,checkpoint_tree_root, andguta_circuit_whitelist. - Assumptions: Assumes input targets/gadgets are correctly formed.
- Role: Defines the standard public interface for all GUTA circuits, ensuring consistent information is passed and verified during recursive aggregation.
VerifyEndCapProofGadget
- File:
verify_end_cap.rs - Purpose: Verifies a user's End Cap proof within the GUTA aggregation process. It checks the proof's validity, ensures it used the correct End Cap circuit, verifies the user's claimed checkpoint root is historical, and extracts the state transition and stats.
- Key Inputs/Witness:
proof_common_data,verifier_data_cap_height: Parameters for proof verification.known_end_cap_fingerprint_hash: Constant representing the hash of the official End Cap circuit's verifier data.UPSEndCapResultCompact: Witness for the result claimed by the End Cap proof.GUTAStats: Witness for the stats claimed by the End Cap proof.MerkleProofCore: Witness for the historical checkpoint root proof.ProofWithPublicInputs: The End Cap proof itself.VerifierOnlyCircuitData: Verifier data matching the proof.
- Key Outputs/Computed Values:
- (Implements
ToGUTAHeader) Outputs aGlobalUserTreeAggregatorHeaderGadgetrepresenting the state transition performed by this user.
- (Implements
- Core Logic/Constraints:
- Verifies the
proof_targetusing the providedverifier_data. - Computes the
proof_fingerprintfrom theverifier_data. - Asserts
proof_fingerprintmatchesknown_end_cap_fingerprint_hash. - Instantiates
UPSEndCapResultCompactGadgetandGUTAStatsGadgetfrom witness. - Computes the expected public inputs hash by hashing the result and stats gadgets.
- Asserts the computed hash matches the hash derived from
proof_target.public_inputs. - Verifies the
checkpoint_historical_merkle_proof, connecting itshistorical_rootto thecheckpoint_tree_root_hashfrom the end cap result gadget. - Constructs the output
GlobalUserTreeAggregatorHeaderGadget:- Uses a default/input
guta_circuit_whitelist. - Uses the
current_rootfrom the historical proof as thecheckpoint_tree_root. - Creates a
SubTreeNodeStateTransitionGadgetusing start/end user leaf hashes and user ID from the result gadget, marking the level asGLOBAL_USER_TREE_HEIGHT. - Includes the verified
guta_stats.
- Uses a default/input
- Verifies the
- Assumptions: Assumes witness data (proofs, results, stats) is valid. Assumes
known_end_cap_fingerprint_hashis correct. - Role: The entry point for incorporating a user's completed UPS into the GUTA aggregation tree. Verifies the user's session proof and translates its result into the standard GUTA header format for further aggregation.
VerifyGUTAProofGadget
- File:
verify_guta_proof.rs - Purpose: Verifies a GUTA proof generated by a lower level in the aggregation hierarchy. Checks the proof validity, ensures it used an allowed GUTA circuit, and extracts its header.
- Key Inputs/Witness:
proof_common_data,verifier_data_cap_height: Parameters.GlobalUserTreeAggregatorHeader: Witness for the header claimed by the proof being verified.MerkleProof: Witness proving the sub-proof's circuit fingerprint is in the GUTA circuit whitelist.ProofWithPublicInputs: The GUTA proof itself.VerifierOnlyCircuitData: Verifier data for the proof.
- Key Outputs/Computed Values:
guta_proof_header_gadget: The verified header gadget of the sub-proof.
- Core Logic/Constraints:
- Verifies the
proof_targetusing the providedverifier_data. - Computes the
proof_fingerprintfrom theverifier_data. - Verifies the
guta_whitelist_merkle_proof. - Connects the
guta_proof_header_gadget.guta_circuit_whitelistto theguta_whitelist_merkle_proof.root. - Computes the expected public inputs hash from the
guta_proof_header_gadget. - Asserts this matches the hash derived from
proof_target.public_inputs. - Asserts the
guta_whitelist_merkle_proof.valuematches the computedproof_fingerprint.
- Verifies the
- Assumptions: Assumes witness data is valid.
- Role: The core recursive verification step within GUTA. Allows aggregation circuits to securely incorporate results from lower-level GUTA proofs.
TwoNCAStateTransitionGadget
- File:
two_nca_state_transition.rs - Purpose: Combines the state transitions from two child GUTA proofs (
a_header,b_header) that modify different parts of the Global User Tree. It uses a Nearest Common Ancestor (NCA) proof to compute the resulting state transition at their common parent node in the tree. - Key Inputs/Witness:
a_header,b_header: The headers of the two child GUTA proofs.UpdateNearestCommonAncestorProof: Witness containing the NCA proof data.
- Key Outputs/Computed Values:
new_guta_header: The combined GUTA header representing the transition at the NCA.
- Core Logic/Constraints:
- Instantiates
UpdateNearestCommonAncestorProofOptGadget. - Connects
a_header.checkpoint_tree_roottob_header.checkpoint_tree_root. - Connects
a_header.guta_circuit_whitelisttob_header.guta_circuit_whitelist. - Connects
a_header.state_transitionfields (old/new value, index, level) to thechild_afields in the NCA proof gadget. - Connects
b_header.state_transitionfields similarly tochild_b. - Combines stats:
new_stats = a_header.stats.combine_with(b_header.stats). - Constructs
new_guta_header:- Uses whitelist/checkpoint root from children (they must match).
- Creates
state_transitionusing theold/new_nearest_common_ancestor_value,index, andlevelfrom the NCA proof gadget. - Includes the
new_stats.
- Instantiates
- Assumptions: Assumes input headers are valid (verified previously). Assumes the NCA proof witness is valid. Assumes children operate on the same checkpoint and whitelist.
- Role: A fundamental building block for parallel aggregation. Allows merging results from independent branches of the GUTA proof tree efficiently using NCA proofs.
GUTAHeaderLineProofGadget
- File:
guta_line.rs - Purpose: Aggregates a GUTA proof state transition upwards along a direct line towards the root of the Global User Tree realm. Used when a node only has one child contributing to the update in that part of the tree.
- Key Inputs/Witness:
global_user_tree_realm_height,global_user_tree_height: Parameters.child_proof_header: The header of the single child GUTA proof.siblings: Witness containing the Merkle sibling hashes needed to recompute the root along the path.
- Key Outputs/Computed Values:
new_guta_header: The GUTA header representing the state transition at the top of the line (realm root).
- Core Logic/Constraints:
- Instantiates
SubTreeNodeTopLineGadget, providing the child's state transition. This gadget internally performs the Merkle path hashing using the provided siblings. - Constructs
new_guta_header:- Copies whitelist/checkpoint root/stats from the child.
- Uses the
new_state_transitioncomputed by theSubTreeNodeTopLineGadget.
- Instantiates
- Assumptions: Assumes
child_proof_headeris valid. Assumes sibling hashes in the witness are correct. - Role: Efficiently propagates a state change up the GUTA tree when no merging (NCA) is required. Used to bring proofs to a common level before NCA or to reach the final realm root.
VerifyGUTAProofToLineGadget
- File:
verify_guta_proof_to_line.rs - Purpose: Combines verifying a lower-level GUTA proof with aggregating its state transition upwards using a line proof.
- Key Inputs/Witness:
proof_common_data,verifier_data_cap_height: Parameters.global_user_tree_realm_height,global_user_tree_height: Parameters.MerkleProofCore: GUTA whitelist proof witness.GlobalUserTreeAggregatorHeader: Child proof header witness.ProofWithPublicInputs,VerifierOnlyCircuitData: Child GUTA proof and verifier data witness.top_line_siblings: Sibling hashes for the line proof witness.
- Key Outputs/Computed Values:
new_guta_header: The final GUTA header at the top of the line.
- Core Logic/Constraints:
- Instantiates
VerifyGUTAProofGadgetto verify the child proof. - Instantiates
GUTAHeaderLineProofGadget, using the verified header from the first gadget as input.
- Instantiates
- Assumptions: Relies on assumptions of sub-gadgets. Assumes witness data is valid.
- Role: A common pattern in GUTA aggregation: verify a child proof and immediately propagate its result upwards via a line proof.
GUTARegisterUserCoreGadget
- File:
guta_register_user_core.rs - Purpose: Handles the core logic for registering a single new user in the Global User Tree (
GUSR). It verifies the update proof that inserts the new user leaf. - Key Inputs/Witness:
global_user_tree_realm_height,global_user_tree_height: Parameters.default_user_state_tree_root: Constant.input_height_target: Optional target for variable height proof.public_key: The public key hash for the new user (can be witness or input).DeltaMerkleProofCore: Witness for theGUSRtree update.
- Key Outputs/Computed Values:
user_id: The ID (index) of the newly registered user.user_leaf_hash: The hash of the newly created user leaf.state_transition: Represents the GUTA state transition for this single registration.
- Core Logic/Constraints:
- Instantiates
VariableHeightDeltaMerkleProofOptGadgetfor theGUSRupdate. - Asserts the
old_valuein the proof is the zero hash (ensuring it's an insertion into an empty slot). - Creates the default
QEDUserLeafGadgetusing the proof'sindex(user ID), thepublic_key, anddefault_user_state_tree_root. - Computes the
user_leaf_hash. - Asserts the
new_valuein the proof matches the computeduser_leaf_hash. - Calculates the
state_transitionbased on the delta proof's old/new roots, height, and computed parent index.
- Instantiates
- Assumptions: Assumes witness proof and public key (if witness) are valid. Assumes
default_user_state_tree_rootis correct. - Role: The lowest-level gadget for handling user registration state changes in GUTA.
GUTARegisterUserFullGadget
- File:
guta_register_user_full.rs - Purpose: Extends the core registration by adding verification against a user registration tree. This tree (presumably managed off-chain or via a separate mechanism) maps user IDs to public keys. This gadget ensures the public key used for registration matches the one committed to in the registration tree.
- Key Inputs/Witness:
- (Inherits inputs from Core gadget).
MerkleProofCore: Witness proving thepublic_keyexists at the correctindex(user ID) in theuser_registration_tree.
- Key Outputs/Computed Values:
- (Inherits outputs from Core gadget).
user_registration_tree_root: The root of the user registration tree.
- Core Logic/Constraints:
- Instantiates
MerkleProofGadgetfor the user registration tree. - Maps the proof's index bits to an expected user ID.
- Asserts the
value(public key) from the registration tree proof is non-zero. - Instantiates
GUTARegisterUserCoreGadget, passing thevaluefrom the registration proof as thepublic_key. - Asserts the
user_idfrom the Core gadget matches theexpected_user_idderived from the registration proof index.
- Instantiates
- Assumptions: Relies on Core gadget assumptions. Assumes the user registration tree proof witness is valid.
- Role: Adds a layer of validation, ensuring user registrations correspond to pre-committed public keys in a dedicated registration structure.
GUTARegisterUsersGadget
- File:
guta_register_users.rs - Purpose: Aggregates multiple user registration operations (using
GUTARegisterUserFullGadget) sequentially within a single circuit. Handles padding/disabling for a fixed maximum number of users. - Key Inputs/Witness:
- (Inherits inputs from Full gadget).
max_users: Parameter.GUTARegisterUserFullInput[]: Array witness for each potential user registration (proofs).register_user_count: Witness target indicating the actual number of users being registered (<=max_users).
- Key Outputs/Computed Values:
state_transition: The aggregate state transition covering all registered users.user_registration_tree_root: Root of the registration tree (taken from the first user, checked for consistency).
- Core Logic/Constraints:
- Instantiates
max_usersinstances ofGUTARegisterUserFullGadget. - Asserts
register_user_countis non-zero. - Iterates from the second user onwards:
- Compares loop index
iwithregister_user_countto determine if the current user slotis_disabled. - If not disabled:
- Connects the current user's
old_global_user_tree_rootto the previous user'snew_global_user_tree_root. - Connects the current user's
user_registration_tree_rootto the root from the first user (ensuring consistency). - Connects proof heights.
- Updates the aggregate
state_transition.new_node_valueto the current user'snew_global_user_tree_root.
- Connects the current user's
- Selects the final
new_node_valuebased on the last enabled user's output.
- Compares loop index
- Instantiates
- Assumptions: Relies on Full gadget assumptions. Assumes witness array and count are valid. Assumes dummy inputs are used correctly for padding.
- Role: Allows batching multiple user registrations into a single GUTA proof step, improving aggregation efficiency.
GUTAOnlyRegisterUsersGadget
- File:
guta_only_register_users_gadget.rs - Purpose: A specialized GUTA gadget that only performs user registration (using
GUTARegisterUsersGadget) and assumes no other state changes (zero stats). - Key Inputs/Witness:
guta_circuit_whitelist,checkpoint_tree_root: Inputs (likely from a previous step or constant).- (Inherits inputs for
GUTARegisterUsersGadget).
- Key Outputs/Computed Values:
new_guta_header: The GUTA header representing only the registration state change.
- Core Logic/Constraints:
- Instantiates
GUTARegisterUsersGadget. - Constructs
new_guta_header:- Uses input
guta_circuit_whitelistandcheckpoint_tree_root. - Uses the
state_transitionfrom theGUTARegisterUsersGadget. - Creates a zeroed
GUTAStatsGadget.
- Uses input
- Instantiates
- Assumptions: Relies on
GUTARegisterUsersGadgetassumptions. Assumes the provided whitelist/checkpoint roots are correct for this context. - Role: Provides a dedicated gadget for GUTA steps that solely involve registering new users.
GUTARegisterUsersBatchGadget
- File:
guta_register_users_batch.rs - Purpose: Combines verification of a previous GUTA proof (brought up to a certain tree level via a line proof) with a subsequent batch registration of new users.
- Key Inputs/Witness:
- (Inherits inputs for
VerifyGUTAProofToLineGadget). - (Inherits inputs for
GUTARegisterUsersGadget).
- (Inherits inputs for
- Key Outputs/Computed Values:
new_guta_header: The combined GUTA header.
- Core Logic/Constraints:
- Instantiates
VerifyGUTAProofToLineGadget(verify_to_line_gadget). - Instantiates
GUTARegisterUsersGadget(register_users_gadget). - Connects the state transitions:
line_state_transition.node_index==register_users_state_transiton.node_index.line_state_transition.node_level==register_users_state_transiton.node_level.line_state_transition.new_node_value==register_users_state_transiton.old_node_value(ensures the registration starts from the state reached by the verified line proof).
- Constructs
new_guta_header:- Uses whitelist/checkpoint root/stats from the line proof header.
- Creates combined
state_transition:old_node_valuefrom line,new_node_valuefrom registration, index/level from line (must match registration).
- Instantiates
- Assumptions: Relies on assumptions of sub-gadgets. Assumes witness data is valid.
- Role: Handles a common GUTA pattern: verifying a previous aggregation step and then applying a batch of user registrations originating from the state achieved by that previous step.
GUTANoChangeGadget
- File:
guta_no_change_gadget.rs - Purpose: Represents a GUTA step where the Global User Tree (
GUSR) does not change. It primarily serves to advance thecheckpoint_tree_rootbased on a new checkpoint. - Key Inputs/Witness:
guta_circuit_whitelist: Input constant/parameter.checkpoint_tree_height: Parameter.MerkleProofCore: Witness proving acheckpoint_leafexists in thecheckpoint_tree.QEDCheckpointLeafCompactWithStateRoots: Witness for the checkpoint leaf data.
- Key Outputs/Computed Values:
new_guta_header: GUTA header indicating no user tree change but potentially a new checkpoint root.
- Core Logic/Constraints:
- Verifies the
checkpoint_tree_proof(append-only). - Verifies the hash of
checkpoint_leaf_gadgetmatches thevaluein the proof. - Constructs
new_guta_header:- Uses input
guta_circuit_whitelist. - Uses the
checkpoint_tree_proof.rootas thecheckpoint_tree_root. - Creates a "no-op"
state_transition:old_node_valueandnew_node_valueare both set to theuser_tree_rootfrom thecheckpoint_leaf_gadget, with index/level zero. - Creates a zeroed
GUTAStatsGadget.
- Uses input
- Verifies the
- Assumptions: Assumes witness proof and leaf data are valid. Assumes
guta_circuit_whitelistis correct. - Role: Allows the GUTA aggregation to incorporate new checkpoints even if no user state changed during that period, keeping the aggregated checkpoint root up-to-date.
Circuit Definition Files (Higher Level)
These files define complete ZK circuits, orchestrating various gadgets to perform end-to-end tasks like starting a session, processing transactions, or finalizing a session.
UPSStartSessionCircuit
- File:
ups_start.rs(Circuit definition wrappingUPSStartStepGadget) - Purpose: The circuit executed to begin a User Proving Session.
- Core Logic: Primarily uses the
UPSStartStepGadgetto verify the initial state against a checkpoint and set up the starting header. Computes the final public inputs hash by wrapping the inner header hash (start_step_gadget.header_gadget.to_hash()) with tree awareness information (usingcompute_tree_aware_proof_public_inputs), assuming the proof tree starts empty (empty_ups_proof_tree_root_target). - What it Proves: That a valid starting
UserProvingSessionHeaderhas been constructed, correctly anchored to a specific, verified checkpoint and user leaf state from the last finalized block, and that the session starts with empty debt trees and zero transaction count. - Assumptions: Assumes the witness (
UPSStartStepInput) containing the starting header, proofs, and state roots is valid before constraints are applied. Assumes the providedempty_ups_proof_tree_rootconstant is correct. - Role: Securely initializes the recursive proof chain for a user's local transactions.
UPSCFCStandardTransactionCircuit
- File:
ups_cfc_standard.rs(Circuit definition wrappingVerifyPreviousUPSStepProofInProofTreeGadgetandUPSVerifyCFCStandardStepGadget) - Purpose: Processes a single, standard Contract Function Call (CFC) transaction within an ongoing User Proving Session.
- Core Logic:
- Uses
VerifyPreviousUPSStepProofInProofTreeGadgetto verify the proof of the previous UPS step. - Uses
UPSVerifyCFCStandardStepGadget(which internally uses verification and state delta gadgets) to:- Verify the CFC proof exists in the current proof tree.
- Verify the CFC function is valid.
- Calculate the state changes based on the CFC execution.
- Connects the
current_proof_tree_rootfrom the previous step verification to the standard step gadget. - Computes the final public inputs hash by wrapping the new header hash (
standard_cfc_step_gadget.new_header_gadget.to_hash()) with tree awareness information (current_proof_tree_root).
- Uses
- What it Proves: That given a valid previous UPS step proof and header, executing the specified CFC transaction (verified to exist and be valid) correctly transitions the UPS state to the new header state.
- Assumptions: Assumes the witness (
UPSCFCStandardTransactionCircuitInput) containing the previous step proof details, the current transaction details (proofs, context), and circuit whitelist proofs is valid. Relies on the validity of the previous UPS step proof (which is verified internally). - Role: The workhorse circuit for processing most user transactions locally within the recursive UPS chain.
UPSCFCDeferredTransactionCircuit
- File:
ups_cfc_deferred_tx.rs(Circuit definition wrappingVerifyPreviousUPSStepProofInProofTreeGadgetandUPSVerifyPopDeferredTxStepGadget) - Purpose: Processes a transaction that pays back a deferred transaction debt within an ongoing User Proving Session.
- Core Logic:
- Uses
VerifyPreviousUPSStepProofInProofTreeGadgetto verify the previous UPS step proof. - Uses
UPSVerifyPopDeferredTxStepGadgetto:- Verify the removal of the correct deferred transaction item from the debt tree.
- Process the CFC itself using corrected starting state assumptions.
- Connects the
current_proof_tree_rootappropriately. - Computes the final public inputs hash by wrapping the new header hash (
deferred_tx_cfc_step_gadget...new_header_gadget.to_hash()) with tree awareness information.
- Uses
- What it Proves: That given a valid previous UPS step, the specified deferred transaction debt was correctly removed, and executing the corresponding CFC transaction correctly transitions the UPS state to the new header state.
- Assumptions: Assumes the witness (
UPSCFCDeferredTransactionCircuitInput) is valid. Relies on the validity of the previous UPS step proof. - Role: Enables the settlement of deferred transaction debts within the user's local proof chain.
UPSStandardEndCapCircuit
- File:
end_cap.rs(Circuit definition wrappingUPSEndCapFromProofTreeGadgetand proof verification gadgets) - Purpose: The final circuit in a User Proving Session. It verifies the last UPS step, verifies the user's ZK signature proof, enforces final state conditions (e.g., empty debt trees), and generates the final public outputs (End Cap Result hash and GUTA Stats hash).
- Core Logic:
- Uses
UPSEndCapFromProofTreeGadgetwhich orchestrates:- Verification of the last UPS step proof (
VerifyPreviousUPSStepProofInProofTreeGadget). - Verification of the ZK signature proof (
AttestProofInTreeGadget). - Enforcement of final conditions via
UPSEndCapCoreGadget.
- Verification of the last UPS step proof (
- (Original
end_cap.rsalso includesVerifyAggProofGadget): Verifies a proof about the UPS proof tree itself (e.g., ensuring the tree was built using allowed aggregation circuits). This connects the user's session to the global proof aggregation infrastructure rules. - Connects the proof tree root from the UPS gadget to the state transition end of the verified aggregation proof.
- Connects the UPS circuit whitelist root from the UPS gadget to a known constant or input, ensuring the UPS steps used allowed circuits.
- Connects the proof tree aggregation circuit whitelist root to a known constant (ensuring the tree proof used allowed circuits).
- Computes the final public inputs hash by hashing the
end_cap_result_gadgethash and theguta_statshash.
- Uses
- What it Proves: That the entire User Proving Session was valid (by verifying the last step), the final state is consistent (empty debts, correct nonce/checkpoint progression), the session is authorized by a valid ZK signature corresponding to the user's key, the session used allowed UPS circuits, and the session's proof tree was built correctly using allowed aggregation circuits. It outputs the final state transition hash and stats hash.
- Assumptions: Assumes the witness (
UPSEndCapFromProofTreeGadgetInput, aggregation proof witnesses) is valid. Assumes the known whitelist root constants are correct. - Role: Securely concludes the user's local proving session, producing a verifiable proof and result ready for submission to the GUTA layer. Links the user's activity to global rules via whitelist checks.
Circuits.md
This document describes the end-to-end flow of circuits involved in processing user transactions and aggregating them into a final block proof within the QED system. It highlights the assumptions made at each stage and how they are progressively verified, ultimately enabling horizontal scalability.
Phase 1: User Proving Session (UPS) - Local Execution
This phase happens locally on the user's device (or via a delegated prover). The user builds a recursive chain of proofs for their transactions within a single block context.
1. UPSStartSessionCircuit
- Purpose: Initializes the proving session for a user based on the last finalized blockchain state.
- What it Proves:
- The starting
UserProvingSessionHeaderis valid. - This header is correctly anchored to a specific
checkpoint_leaf_hashwhich exists atcheckpoint_idwithin thecheckpoint_tree_rootfrom the last finalized block. - The
session_start_contextwithin the header accurately reflects the user's state (start_session_user_leaf_hash,user_id, etc.) as found in theuser_tree_rootassociated with the starting checkpoint. - The
current_statewithin the starting header is correctly initialized (user leaflast_checkpoint_idupdated, debt trees empty, tx count/stack zero).
- The starting
- Assumptions:
- The witness data (
UPSStartStepInput) provided by the user (fetching state from the last block) is correct initially. Constraints verify its consistency. - The constant
empty_ups_proof_tree_root(representing the start of the recursive proof tree for this session) is correct.
- The witness data (
- How Assumptions are Discharged: Internal consistency checks verify the relationships between the provided header, checkpoint leaf, state roots, user leaf, and the Merkle proofs linking them. The assumption about the previous block's
checkpoint_tree_rootbeing correct is implicitly carried forward, as this circuit uses it as the basis for initialization. - Contribution to Horizontal Scalability: Establishes a user-specific, isolated starting point based on globally finalized state, allowing this session to proceed independently of other users' sessions within the same new block.
- High-Level Functionality: Securely starts a user's transaction batch processing.
2. UPSCFCStandardTransactionCircuit (Executed potentially multiple times)
- Purpose: Processes a single standard transaction (contract call) within the user's ongoing session, extending the recursive proof chain.
- What it Proves:
- The ZK proof for the previous UPS step is valid.
- The previous step's proof was generated by a circuit listed in the
ups_circuit_whitelist_rootspecified in the previous step's header. - The public inputs (header hash) of the previous step's proof match the provided
previous_step_header. - The ZK proof for the current Contract Function Call (CFC) exists within the current
current_proof_tree_root. - This CFC proof corresponds to a function registered in the
GCONtree (via checkpoint context). - Executing this CFC correctly transitions the state from the
previous_step_headerto thenew_header_gadgetstate (updatingCSTATE->UCONroot, debt trees, tx count/stack).
- Assumptions:
- The witness data (
UPSCFCStandardTransactionCircuitInput) for this specific step (CFC proof, state delta witnesses, previous step proof info) is correct initially. - The
current_proof_tree_rootprovided matches the actual root of the recursive proof tree being built.
- The witness data (
- How Assumptions are Discharged:
- Verifies the previous step's proof using
VerifyPreviousUPSStepProofInProofTreeGadget. This discharges the assumption about the previous step's validity and its public inputs. - Verifies the CFC proof and its link to the contract state using
UPSVerifyCFCStandardStepGadget. - Verifies the state delta logic, ensuring the transition is correct based on witness data.
- The assumption about the
current_proof_tree_rootis passed implicitly to the next step or the End Cap circuit.
- Verifies the previous step's proof using
- Contribution to Horizontal Scalability: User processes transactions locally and serially for themselves, maintaining self-consistency without interacting with other users' current block activity.
- High-Level Functionality: Securely executes and proves individual smart contract interactions locally.
3. UPSCFCDeferredTransactionCircuit (Executed if applicable)
- Purpose: Processes a transaction that settles a deferred debt, then executes the main CFC logic.
- What it Proves: Similar to the standard circuit, but additionally proves:
- A specific deferred transaction item was removed from the
deferred_tx_debt_tree. - The item removed corresponds exactly to the call data of the CFC being executed.
- The subsequent CFC state transition starts from the state after the debt was removed.
- A specific deferred transaction item was removed from the
- Assumptions: Same as the standard circuit, plus assumes the witness for the deferred transaction removal proof (
DeltaMerkleProofGadget) is correct initially. - How Assumptions are Discharged: Verifies previous step proof. Verifies the debt removal proof and its consistency with the CFC call data. Verifies the subsequent state delta.
- Contribution to Horizontal Scalability: Same as standard transaction circuit (local serial execution).
- High-Level Functionality: Enables settlement of asynchronous transaction debts within the local proving flow.
4. UPSStandardEndCapCircuit
- Purpose: Finalizes the user's entire proving session for the block.
- What it Proves:
- The proof for the last UPS transaction step is valid and used an allowed circuit.
- The ZK proof for the user's signature (authorizing the session) is valid and exists in the same UPS proof tree.
- The signature corresponds to the user's registered public key (derived from signature proof parameters).
- The signature payload (
QEDUserProvingSessionSignatureDataCompact) correctly reflects the session's start/end user leaves, checkpoint, final tx stack, and tx count. - The nonce used in the signature is valid (incremented).
- The final UPS state shows both
deferred_tx_debt_tree_rootandinline_tx_debt_tree_rootare empty (all debts settled). - The
last_checkpoint_idin the final user leaf matches the session'scheckpoint_idand has progressed correctly. - (If aggregation proof verification included): The UPS proof tree itself was constructed using circuits from a known
proof_tree_circuit_whitelist_root.
- Assumptions:
- Witness data (
UPSEndCapFromProofTreeGadgetInput, potentially agg proof witness) is correct initially. - Known constants (
network_magic, empty debt roots,known_ups_circuit_whitelist_root,known_proof_tree_circuit_whitelist_root) are correct.
- Witness data (
- How Assumptions are Discharged:
- Verifies the last UPS step proof.
- Verifies the ZK signature proof.
- Connects signature data to the final UPS header state.
- Checks nonce, checkpoint ID, empty debt trees.
- Verifies proofs against whitelists using provided roots.
- The output of this circuit (the End Cap proof) now implicitly carries the assumption that the starting
checkpoint_tree_root(used in theUPSStartSessionCircuit) was correct. All internal UPS assumptions have been discharged.
- Contribution to Horizontal Scalability: Creates a single, verifiable proof representing all of a user's activity for the block. This proof can now be processed in parallel with proofs from other users by the GUTA layer.
- High-Level Functionality: Securely concludes a user's transaction batch, authorizes it, and packages it for network aggregation.
Phase 2: Global User Tree Aggregation (GUTA) - Parallel Network Execution
The Decentralized Proving Network (DPN) takes End Cap proofs (and potentially other GUTA proofs like user registrations) from many users and aggregates them in parallel. This involves specialized GUTA circuits.
(Note: The provided files focus heavily on UPS and GUTA gadgets. The exact structure of the GUTA circuits using these gadgets is inferred but follows standard recursive proof aggregation patterns.)
Example GUTA Circuits (Inferred):
5. GUTAProcessEndCapCircuit (Hypothetical)
- Purpose: To take a user's validated
UPSStandardEndCapCircuitproof and integrate its state change into the GUTA proof hierarchy. - Core Logic: Uses
VerifyEndCapProofGadget. - What it Proves:
- The End Cap proof is valid and used the correct circuit (
known_end_cap_fingerprint_hash). - The
checkpoint_tree_rootclaimed by the user in the End Cap result existed historically. - Outputs a standard
GlobalUserTreeAggregatorHeaderrepresenting the user'sGUSRtree state transition (start leaf hash -> end leaf hash at the user's ID index) and stats.
- The End Cap proof is valid and used the correct circuit (
- Assumptions:
- Witness (End Cap proof, result, stats, historical proof) is correct initially.
- The
known_end_cap_fingerprint_hashconstant is correct. - A
default_guta_circuit_whitelistroot is provided or known.
- How Assumptions are Discharged: Verifies the End Cap proof and historical checkpoint proof. Packages the result into a standard GUTA header. The assumption about the
default_guta_circuit_whitelistis passed upwards. The assumption about the currentcheckpoint_tree_root(from the historical proof) is passed upwards. - Contribution to Horizontal Scalability: Allows individual user session results to be verified independently and prepared for parallel aggregation.
- High-Level Functionality: Validates and incorporates user end-of-session proofs into the global aggregation process.
6. GUTARegisterUserCircuit (Hypothetical)
- Purpose: To process the registration of one or more new users.
- Core Logic: Uses
GUTAOnlyRegisterUsersGadget(which usesGUTARegisterUsersGadget,GUTARegisterUserFullGadget,GUTARegisterUserCoreGadget). - What it Proves:
- For each registered user, their
public_keywas correctly inserted at theiruser_idindex in theGUSRtree (transitioning from zero hash to the new user leaf hash). - The
public_keyused matches an entry in theuser_registration_tree_root. - Outputs a
GlobalUserTreeAggregatorHeaderrepresenting the aggregateGUSRstate transition for all registered users, with zero stats.
- For each registered user, their
- Assumptions:
- Witness (registration proofs, user count) is correct initially.
guta_circuit_whitelistandcheckpoint_tree_rootinputs are correct for this context.default_user_state_tree_rootconstant is correct.
- How Assumptions are Discharged: Verifies delta proofs for
GUSRinsertion and Merkle proofs against the registration tree. Outputs a standard GUTA header, passing assumptions about whitelist/checkpoint upwards. - Contribution to Horizontal Scalability: User registration can be batched and potentially processed in parallel branches of the GUTA tree.
- High-Level Functionality: Securely adds new users to the system state.
7. GUTAAggregationCircuit (Hypothetical - Multiple Variants)
- Purpose: To combine the results (headers) from two or more lower-level GUTA proofs (which could be End Cap results, registrations, or previous aggregations).
- Core Logic:
- Verifies each input GUTA proof using
VerifyGUTAProofGadget. - Ensures all input proofs used circuits from the same
guta_circuit_whitelistand reference the samecheckpoint_tree_root. - Combines the
state_transitions from the input proofs:- If transitions are on different branches, uses
TwoNCAStateTransitionGadgetwith an NCA proof. - If transitions are on the same branch (e.g., one input is a line proof output), connects them directly (
old_rootof current matchesnew_rootof previous). - If only one input, uses
GUTAHeaderLineProofGadgetto propagate upwards.
- If transitions are on different branches, uses
- Combines the
statsfrom input proofs usingGUTAStatsGadget.combine_with. - Outputs a single
GlobalUserTreeAggregatorHeaderrepresenting the combined state transition and stats.
- Verifies each input GUTA proof using
- What it Proves: That given valid input GUTA proofs operating under the same whitelist and checkpoint context, the combined state transition and stats represented by the output header are correct.
- Assumptions:
- Witness (input proofs, headers, NCA/sibling proofs) is correct initially.
- How Assumptions are Discharged: Verifies input proofs and their headers. Verifies the logic of combining state transitions (NCA/Line/Direct). Passes the common whitelist/checkpoint root assumptions upwards.
- Contribution to Horizontal Scalability: This is the core of parallel aggregation. Multiple instances of this circuit run concurrently across the DPN, merging proof branches in a tree structure (like MapReduce).
- High-Level Functionality: Securely and recursively combines verified state changes from multiple sources into larger, aggregated proofs.
8. GUTANoChangeCircuit (Hypothetical)
- Purpose: To handle cases where no user state changed but the checkpoint advanced.
- Core Logic: Uses
GUTANoChangeGadget. - What it Proves: That given a new
checkpoint_leafverified to be in thecheckpoint_tree_proof, theGUSRtree root remains unchanged, and stats are zero. Outputs a GUTA header reflecting this. - Assumptions: Witness (checkpoint proof, leaf) is correct initially. Input
guta_circuit_whitelistis correct. - How Assumptions are Discharged: Verifies checkpoint proof. Outputs a standard GUTA header passing assumptions upward.
- Contribution to Horizontal Scalability: Allows the aggregation process to stay synchronized with the checkpoint tree even during periods of inactivity for certain state trees.
- High-Level Functionality: Advances the aggregated checkpoint state reference.
Phase 3: Final Block Proof
9. Checkpoint Tree "Block" Circuit (Top-Level Aggregation)
- Purpose: The final aggregation circuit that combines proofs from the roots of all major state trees (like
GUSRvia the top-level GUTA proof,GCON, etc.) for the block. - Core Logic:
- Verifies the top-level GUTA proof (and proofs for other top-level trees if applicable).
- Takes the previous block's finalized
CHKProot as a public input. - Constructs the new
CHKPleaf based on the newly computed roots ofGUSR,GCON, etc., and other block metadata. - Computes the new
CHKProot. - The only external assumption verified here is that the input
previous_block_chkp_rootmatches the actual finalized root of the last block.
- What it Proves: That the entire state transition for the block, represented by the change from the
previous_block_chkp_rootto thenew_chkp_root, is valid, having recursively verified all constituent user transactions and aggregations according to protocol rules and circuit whitelists. - Assumptions: The only remaining input assumption is the hash of the previous block's
CHKProot. - How Assumptions are Discharged: All assumptions from lower levels (circuit whitelists, internal state consistencies) have been verified recursively. The final link to the previous block state is checked against the public input.
- Contribution to Horizontal Scalability: Represents the culmination of the massively parallel aggregation process, producing a single, succinct proof for the entire block's validity.
- High-Level Functionality: Creates the final, verifiable proof of state transition for the entire block, linking it cryptographically to the previous block. This proof can be efficiently verified by any node or light client.