Submission and verification
Once you have registered your application's verifying key(s) you are ready to submit application proofs to NEBRA UPA. In this section you will learn how to submit and verify proofs using our SDK.
Steps to submit and verify proofs
Proofs are submitted to UPA on-chain by calling the submit
function in the NEBRA UPA contracts.
Each submission can contain one or more proofs. For convenience and type-safety, we recommend that you use our SDK to submit proofs instead of calling this function directly.
Step 1: Export proof data
SnarkJS
Let proofData
be the output of snarkjs' fullProve
function, i.e.
You may save the json serialization of proofData
into a file snarkjs_proof.json
if you intend to submit the proof with the upa
tool. You can generate a UPA-compatible proof data file with the following command
Alternatively, if you want to submit via the typescript sdk, you can easily extract the UPA-compatible proof and inputs from proofData
:
Gnark
You can modify your gnark circuit code to export the proof and the inputs as follows:
If you intend to submit the proof with the upa
tool, you may generate a UPA-compatible proof data file with the following command
Alternatively, if you want to submit via the typescript sdk, you can convert the gnark proofs and inputs to the UPA-compatible format as follows
where gnarkProof
and gnarkInputs
can be obtained from the gnark_proof.json
and gnark_inputs.json
files, respectively. For example
Note on gnark proofs
For gnark proofs with a LegoSNARK commitment point, the UPA only supports those which have been generated with keccak256
as the hash to field function. In other words, you must run the prover with the following options:
Note gnark
's default is the hash function RFC9380, which is not currently supported by NEBRA's UPA.
Step 2: Prepare proof data
Each proof is submitted along with its corresponding Circuit Id and public inputs as a CircuitIdProofsAndInputs.
Prepare an array CircuitIdProofsAndInputs[]
of the proofs you will submit.
Step 3: Submit proofs
Using your UpaClient
(see setup), submit your array CircuitIdProofsAndInputs[]
.
Be sure to keep the returned submissionHandle
as it contains information used by your application contract to check whether the proof has been verified by NEBRA UPA. It contains a Submission
object that stores the proof Ids for each submitted proof and a submission Id for the entire submission. See Single and multi-proof submissions for more details.
Fee estimation (optional)
NEBRA UPA charges a nominal fee for each proof submission. Your UpaClient
can estimate this fee.
This fee amount value
can then be passed as a PayableOverrides
option into upaClient.submitProofs
. If no value
is specified then the fee is computed automatically.
Proof submission via the upa
tool
upa
tool If you have a json file with UPA-compatible proof data such as proof.upa.json
generated in the previous step, you can also submit proofs with the following command:
The argument -i
above is optional and produces an output file with the proof id. Similarly, for multi-proof submissions:
where proofs.upa.json
consists an array of objects with three UPA-compatible components: verifying key, proof and a public inputs array. The arguments -i
and -s
are optional and produce output files with the proof ids and the submission data, respectively.
Step 4: Wait for proofs to be verified on NEBRA UPA
Wait for NEBRA UPA to verify your submission by awaiting waitForSubmissionVerified
from your UpaClient.
Once your submission has been verified, you can send a request to your application contract with inputs corresponding to your submission. This request uses the same inputs as before, but you will no longer need to pass in a proof when using NEBRA UPA. Your application contract will use NEBRA UPA to check the verification status of these inputs before executing the request.
Step 5: Application contract checks verification status
Your app smart contract will call isVerified
from the NEBRA UPA contracts to check whether a proof has been verified or not.
For single-proof submissions, your smart contract calls isVerified
as follows.
For multi-proof submissions, your application contract will also need to provide a ProofReference
to identify a specific proof in the submission (see Proof references).
If you used our typescript SDK for a multi-proof submission, your SubmissionHandle
can compute this proof reference which can then be passed to your application contract as part of your request.
What is a Proof Id?
UPA assigns a to each proof it receives. This is calculated as the Keccak hash of the proof's circuit id and public inputs:
Single and multi-proof submissions
The majority of the cost of single-proof submissions comes from storing metadata about each proof such as its . This storage cost may be significantly reduced by taking advantage of multi-proof submissions.
Multi-proof submissions store their corresponding s in a Merkle tree.
The of a multi-proof submission is the Merkle root of the s.
A single-proof submission's is the of its single proof.
A submission's proofs are either all accepted if all of them are valid, or they are all rejected if any proof is invalid.
An aggregated batch can contain proofs from different submissions.
Proof references
To check the verification status of the j
-th proof of a multi-proof submission identified by , you must provide its ProofReference
in addition to its . A ProofReference
is a Merkle proof that this is indeed the j
-th leaf of a Merkle tree with root .
Last updated