Proving
Proving with Pico CLI and SDK APIs
Overview
Pico provides CLI and SDK tools to recursively prove the program to the developers.
Pico CLI provides a complete toolchain for compiling the RISC-V program and using Pico to complete end-to-end proof. Refer to the installation page to install the CLI toolchain. CLI default use the KoalaBear field for the backend proving, if you want to switch to other fields, read more details in Proving Backends Page.
Like the CLI, the Pico-SDK includes lower-level APIs that can prove the program directly. The prover package of the template project repository provides an example of how to import and initialize the SDK and quickly generate a RISC-V proof using the Pico SDK. In the Proving Steps Section, you can read more about VM e2e proving and the Gnark EVM proof generation for On-chain verification
Let's quickly go through the Pico SDK usage and generate a Fibonacci RISC-V proof.
Import
pico-sdk
Execute the proving process and generate RISC-V proof.
Pico EmulatorStdin
Stdin Writer
Pico SDK supports writing the serializable object and bytes to Pico.
Examples:
CLI input option
The prove
command --input
option can take a hex string or a file path. the hex string must be match the length of the read type. For example, the input n = 100u32
; the hex string should be 0x0A000000
in little-endian format.
Read
Corresponding to the writer functions, there are read_as and read_slice tools for io reading the serializable object or bytes into the program.
SDK examples:
End-to-end Proving
This section introduces more advanced CLI options and SDK APIs to complete the end-to-end proving process. The Proving process consists of multiple stages, including RISCV, RECURSION, and EVM Phases. Pico SDK includes various ProverClients in different proving backends. Here, we use the KoalaBearProverClient (based on STARK on KoalaBear) in the example code.
RISCV-Phase
Prove RISC-V programs and generate an uncompressed proof with the --fast option. The command is mainly used to test and debug the program.
CLI:
For example, when executing the fast proving with inputs in the Fibonacci, the input n
is a u32
data received through pico::sdk::read_as
, and it must be in little-endian format and filled to 4 bytes.
SDK:
Fast proving is implemented by using only one FRI query which drastically reduces the theoretical security bits. DO NOT USE THIS OPTION IN PRODUCTION. ATTACKERS MAY BE ABLE TO COMMIT TO INVALID TRACES.
RECURSION-Phase
CLI:
Proving without the --fast
argument will execute the prover up to and including the EMBED-Phase. The resulting proof can then be verified by the Gnark
proof verification circuit, which can then be verified on-chain via contract.
options:
--field
Specify the field, When without this option, default to Koalabear field.
kb: Koalabear
bb: Babybear
--output
You can specify the output path to generate the files prepared for the Gnark
verification and default is in the project root target/pico_out/
SDK:
Outputs
constraints.json
: The schema of the stark proof constraints is used to transform to Gnark circuit constraints.groth16_witness.json
: input witnessness of Gnark circuit.
EVM-Phase
The Pico CLI provides an EVM option to generate the program Groth16 proof and verifier Contracts. You must ensure the Docker has been installed when using the evm option.
CLI:
SDK:
The outputs:
proof.data
: Groth16
proof generated by the Gnark Verifier Circuit.
pv_file
: The public values hex string; it's the input of Fibonacci
Contract
When executing EVM proving, the Gnark
Groth16
ProvingKey/VerificationKey is also generated at this step. The --setup
only needs to be executed once to make sure the PK/VK is generated.
EVM Verification
The generated inputs.json
format is as follows:
After parsing the input data, you can call the PicoVerifier.sol
as shown below:
The verifyPicoProof
function in PicoVerifier.sol
takes a RISC-V verification key, public values, and a Pico proof, using the Groth16 verifier to validate the proof and public inputs via the pairing algorithm. For the full implementation of the PicoVerifier, please refer to the repository here.
In production, you need to verify riscvVKey and parse the public values verified by PicoVerifier. You can refer to the Fibonacci.sol example in the repository here.
Last updated