UPA protocol specification
Version 1.0.0
Overview
Application developers register Groth16 verification keys (VKs) for their circuits with the UpaProofReceiver
contract. Upon registration, each VK is assigned a (the Poseidon hash of the VK).
Application Clients submit proofs and public inputs (PIs) to the UpaProofReceiver
contract as tuples, where is expected to be a proof that is an instance of the circuit with circuit id .
A single call to the contract submits an ordered list (of any size up to some implementation-defined maximum ) of these tuples. This ordered list of tuples is referred to as a Submission. Submissions of more than 1 proof allow the client to amortize the cost of submitting proofs. Note that there is no requirement for the s to match. A single Submission may contain proofs for multiple application circuits.
Each tuple in a submission is assigned:
- a unique proof id (equal to the Keccak hash of the circuit ID and PIs), and
- a proof index (a simple incrementing counter, used later for censorship resistance).
Each submission is assigned:
a Submission Id , computed as the Merkle root of the list of s, padded to the nearest power of 2 with
bytes32(0)
.a submission index , a simple incrementing counter of submissions, used later for censorship resistance.
Note that:
for submissions that consist of a single proof, , and the submitted proof can be referenced by , whereas
for submissions of multiple proofs, each proof is referred to by along with an index (or location) of the proof within the submission. Where required, a Merkle proof can be used to show that a proof with is indeed at the given index within the submission .
The proof and public inputs are not stored on-chain. Instead, events are emitted containing the proof and public input data for aggregators to monitor and receive. The contract stores information about the submission (including , and some further metadata), indexed by the .
Aggregators aggregate batches of proofs with increasing proof index values. A batch can aggregate proofs for many different circuits. In the case where invalid proofs have been submitted, aggregators may skip only submissions containing invalid proofs. Aggregators that skip valid submissions will be punished (see Censorship Resistance).
As UPA receives and verifies batches, the UpaVerifier
contract marks the corresponding proof ids as verified. Note that, for proofs that are part of a multi-proof submission, the contract actually records the fact that the proof at index of submission was verified.
An application client can then submit a transaction to the application circuit (optionally with some ProofReference
metadata), and the application contract can verify the existence of an associated valid ZKP as follows:
The application computes the public inputs for the proof, exactly as it would in the absence of UPA.
The application contract calls
isVerified
on theUpaVerifier
contract, passing in the public inputs , the circuit Id , and anyProofReference
metadata.The
UpaVerifier
contract computes from the public inputs.If the proof was submitted by itself, is equal to the submission ID, and the contract can immediately check whether a valid proof has been seen as part of an aggregated proof.
If the proof was part of a multi-proof submission, the
ProofReference
metadata includes the , index of the proof within the submission , and a Merkle proof that is indeed the -th leaf of the submission. After checking this Merkle proof, the contract can immediately verify that proof of submission has been seen as part of an aggregated proof batch.
The
UpaVerifier
returnstrue
if it has marked as verified andfalse
otherwise.
Protocol
Circuit registration
The application developer submits a transaction calling the registerVK
method on the UpaProofReceiver
contract, passing their verification key .
The circuit's is computed as
(We assume is serialized using SnarkJS or by following exactly the same protocol as SnarkJS).
is stored on the contract (for censorship resistance), indexed by , and aggregators (who are assumed to be monitoring the contract) are notified via an event.
NOTE: The Poseidon hash is expensive to compute in the EVM, but this operation is only performed once at registration time. This will be used to reference the circuit for future operations.
Proof submission
The application client creates the parameters for its smart contract as normal, including one or more proofs and public inputs . It then passes these, along with the relevant (pre-registered) circuit Ids , to the submit
method on the UpaProofReceiver
contract, paying the aggregation fee in ether:
The UpaProofReceiver.submit
method:
computes for .
computes a
proofDigest
for each proof, ascomputes the submission Id as the Merkle root of the list (padded as required to the nearest power of 2)
computes the
digestRoot
as the Merkle root of the list (again padded as required to the nearest power of 2)rejects the tx if an entry for already exists
assigns a to the submission (using a single incrementing counter)
assigns a to each (using a single incrementing counter)
emits an event for each proof, including
updates the contract state to record the fact that a submission with id has been made, mapping it to
digestRoot
, , and the block number at submission time.
NOTE: Proof data itself does not appear in the input data used to compute . This is because when the proof is verified by the application, the application does not have access to (and does not require) any proof data. The application is only verifying the existence of a valid proof for the given circuit and public inputs.
NOTE: Application authors must ensure that the public inputs to their ZKPs contain some random or unpredictable elements (and in general this will already be the case for sound protocols, in order to prevent replay attacks). If the set of public inputs can be predicted by a malicious party, that malicious party can submit an invalid proof for the public inputs, preventing submission of further (valid) proofs for that same set of public inputs.
Aggregated proof submission
Aggregators submit aggregated proofs to the UpaVerifier.verifyAggregatedProof
method, Each aggregated proof demonstrates that a batch of previously submitted application proofs is valid. In return, aggregators receive batch submission fees.
The UpaVerifier
contract:
checks that
proof
is valid forproofIds
for each in
proofIds
:checks that has been submitted to the contract, and that proofs appear in the aggregated batch in the order of submission (see below)
marks as valid (see below)
emits an event indicating that has been verified
Specifically, the algorithm for verifying (in the correct order) submissions of proofIds
and marking them as verified, is as follows.
State: the contract holds
a dynamic array
uint16[] numVerifiedInSubmission
of counters, where the -th entry corresponds to the number of proofs that have been verified (in order) of the submission withthe submission index
lastVerifiedSubmissionIdx
of the last submission from which a proof was verified.
Given a list of proofIds
and submissionProofs
, the contract verifies that proofIds
appear in previous submissions as follows:
For each in
proofIds
:Attempt to lookup the submission data (see Proof Submission) for a submission whose is the same as . If such a submission exists:
The proof was submitted as a single-proof submission. The contract extracts the from the submission data and then checks that is greater than
lastVerifiedSubmissionIdx
. If not reject the transaction.The entry
numVerifiedInSubmission[
]
should logically be 0 (this can be sanity checked by the contract). Set this entry to 1
Otherwise (if no submission data was found for )
the proof is expected to be part of a multi-proof submission with
lastVerifiedSubmissionIdx
.Note that equality here is possible if a previous aggregated proof verified a strict subset of the entries in the submission. In this case,
numVerifiedInSubmission[
]
should contain the number of entries already verified.
Take the next entry in
submissionProofs
. This includes the following information:the for the submission to be verified
a Merkle "interval" proof for a contiguous set of entries from that submission.
Determine the number
m
of entries inproofIds
, including the current , that belong to this submission, as follows:Let
numProofIdsRemaining
be the number of entries (including ) still unchecked inproofIds
.Look up the submission data for , in particular and .
Let
numUnverifiedFromSubmission =
- numVerifiedInSubmission[
]
.The number
m
of entries fromproofIds
to consider as part of is given byMin(numUnverifiedFromSubmission, numProofIdsRemaining)
.Use the submission Id and the Merkle "interval" proof from the submission proof, to check that the
m
next entries fromproofIds
(including ) indeed belong to the submission . Reject the transaction if this check fails.Increment the entry
numVerifiedInSubmission[
]
bym
, indicating thatm
additional proofs from the submission have been verified.
update
lastVerifiedSubmissionIdx
in the contract state
Proof verification by the application
The application client now creates the transaction calling the application's smart contract to perform the business logic. Since the proof has already been submitted to UPA, the proof is not required in this transaction. If the proof was submitted as part of a multi-entry submission, the client must compute and send a ProofReference
structure indicating which submission the proof belongs to, and its "location" (or index) within it.
The application contract computes the public inputs, exactly as it otherwise would under normal operation, and queries the isVerified
on the UpaVerifier
contract (using the ProofReference
if given) to confirm the existence of a corresponding verified proof.
The isVerified
method:
computes from the public inputs
(using the
ProofReference
if necessary) confirms that belongs to a submission and reads the submission index .given and the index
i
of the proof within the submission (taken from theProofReference
, or implicitly0
for the single-entry submission case), the existence of a verified proof is given by the boolean value:numVerifiedInSubmission[
] > i
Censorship resistance
A censorship event is considered to have occurred for a submission with Id (with submission index , consisting of entries) if all of the following are satisfied:
a submission with Id has been made, and all proofs in the submission are valid for the corresponding public inputs and circuit Ids
some of the entries in remain unverified, namely
numVerifiedInSubmission[
] <
one or more proofs from submission with index greater than (the submission index of the submission with id ) have been included in an aggregated batch
namely, there exists s.t.
numVerifiedInSubmission[
] > 0
Note that, if one or more entries in a submission are invalid, aggregators are not obliged to verify any proofs from that submission.
Censorship by an aggregator can be proven by a claimant, by calling the method:
providing:
the valid tuple , or
circuitId
,proof
andpublicINputs
, the claimed next unverified entry in the submissionor
submissionId
or
laterSubmissionIdx
A Merkle proof that (computed from and belongs to the submission (at the "next index" - see below)
A Merkle proof that belongs to the submission's
proofDigest
entry (at the "next index" - see below)
On receipt of a transaction calling this method, the contract:
checks that the conditions above hold and that the provided proof has indeed been skipped
looks up the verification key using and performs the full proof verification for . The transaction is rejected if the proof is not valid.
increments the stored count
numVerifiedInSubmission[
]
The aggregator is punished only when all proofs in the submission have been shown to be valid. As such, after the above, the contract:
checks the condition
numVerifiedInSubmission[
] == n
(wheren
is the number of proofs in the original submission ).if this final condition holds then validity of all proofs in the submission has been shown and the aggregator is punished.
Note: proofDigest
is used here to prevent malicious clients from submitting invalid proofs, forcing aggregators to skip their proofs, and then later providing valid proofs for the same public inputs. This would otherwise be an attack vector since is not dependent on the proof data.
Circuit Statements
Batches of application proofs are verified in a batch verify circuit.
A keccak circuit computes all s of application proofs appearing in the batch verify proof, along with a final digest (the keccak hash of these s, used to reduce the public input size of the outer circuit below).
A collection of batch verify proofs along with the keccak proof for their s and final digest is verified in an outer circuit.
On-chain verification of an outer circuit proof thereby attests to the validity of application proofs with given s.
- inner batch size. Application proofs per batch verify circuit.
- outer batch size. Number of batch-verify circuits per outer proof.
- the maximum number of public inputs for an application circuit.
Batch Verify Circuit: Groth16 batch verifier
The batch verify circuit corresponds to the following relation:
Public inputs:
where
is the public inputs to the -th proof
is after zero-padded to extend it to length
Witness values:
- application verification keys, each padded to length
- application proofs
Statement:
Groth16.Verify
forwhere
is the truncation of the size verification key to a verification key of size , and
is the truncation of the public inputs to an array of size
Keccak Circuit: ProofIds and Final Digest
Computes the for each entry in each application proof in one or more verify circuit proofs.
Public inputs:
where
is the public inputs to the -th proof
is after zero-padded to extend it to length
(digest, which consists of 32 bytes and is represented by two field elements)
Witness values: (none)
Statement:
Outer Circuit: Recursive verification of Batch Verifier and Keccak circuits
This step aggregates batch verify proofs as well as a single corresponding Keccak proof .
Public Inputs:
- final 32-byte public input digest, encoded as
- overall KZG accumulator, encoded as 12 = 4 * \texttt{num_limbs} points of
Witness values:
: the number of public inputs, the circuit ID, padded public inputs and proof ID for the -th application proof in the -th BV proof.
for BV proofs
the Keccak proof for the public inputs
, and
"Equivalent Statement": (actual statement is shown as multiple sub-statements, given below)
All BV proofs are valid, and therefore there exist valid application proofs for each : for
Keccak proof is valid, and therefore is the final digest for all application PIs and vk hashes:
Actual Statement:
"Succinct" Plonk verification () namely "GWC Steps 1-11" using Shplonk, without final pairing, for random challenge scalar :
Verification: The EVM verifier does the following, given .
for random challenge scalar
Note that:
The same witness values are used to verify and , implying that is indeed the commitment to all application public inputs and circuit IDs.
The outer circuit does not include the pairing checks, therefore its statement is not that the BV/Keccak proofs are valid, but rather that they have been correctly accumulated into a single KZG accumulator . Checking that , for random scalar , therefore implies their validity.
Last updated