Generate and deploy your verifier contract
Prepare your Groth16 verifying key
To deploy a groth16 verifier, you need the associated verifying key in .json format. Both BN254 and BLS12-381 are supported.
Snarkjs and Gnark jsons output are supported out of the box.
You can find a bunch of example of verifying keys that will work directly in the hydra/garaga/starknet/groth16_contract_generator/examples folder.
While Snarkjs jsons export are easy and working well, the gnark documentation is a bit outdated. Below we show a quick example on how to export the verifying key from your Gnark circuit .
Generate the Smart contract code
Using the Developer setup & guides or the Python package, you should now have access to the Garaga CLI from your terminal, using the command garaga
garagaOnce your verifying key is ready, you can use the following command :
garaga gen --system groth16 --vk vk.jsonYou should see an output like this :
The curve identifier is automatically detected from the content of your verifying key.
Build your contract
The generated template is as follows. The main endpoint is verify_groth16_proof_[curve_name].
The function takes a single full_proof_with_hints: Span<felt252> parameter (generated using the garaga calldata command or the SDK) and returns:
Result::Ok(public_inputs)if the proof is validResult::Err(error)if the proof is invalid
Declare and deploy your contract
When you are satisfied with your contract it's time to send it to Starknet!
The CLI provides utilities to simplify the process. Otherwise, it is a similar process than for every other contracts, please refer to Starknet documentation. You will to create a file containing the following variables, depending on if you want to declare & deploy on Starknet Sepolia or Starknet Mainnet. Create the following file and update its content.
Then, you can run the command garaga declare, which will build the contract and declare it to Starknet. If the class hash is already deployed, it will return it as well. Declaring the contract involves sending all its bytecode and it is quite an expensive operation. Make sure you dapp is properly tested before!
This command will return the class hash, used in the next step.
Finally, to deploy the contract, a use garaga deploy :
The contract address will be prompted. Be sure to save it! \
Last updated
Was this helpful?