Expand description
§Groth16 Solidity generator
A crate for generating Solidity verifier contracts for BN254 Groth16 proofs.
This crate uses the askama templating engine to render Solidity code based on
the provided verifying key and configuration options.
The solidity contract is based on the Groth16 verifier implementation from gnark, with minor modifications to be compatible with the askama crate.
§Example usage
Generation of the Solidity verifier contract can be done as follows and requires the template feature to be enabled, which it is by default.
If the features is enabled, the crate also re-exports askama for convenience.
use taceo_groth16_sol::{SolidityVerifierConfig, SolidityVerifierContext};
use taceo_groth16_sol::askama::Template;
let config = SolidityVerifierConfig::default();
let vk : ark_groth16::VerifyingKey<ark_bn254::Bn254> = load_verification_key();
let contract = SolidityVerifierContext {
vk,
config,
};
let rendered = contract.render().unwrap();
println!("{}", rendered);
// You can also write the rendered contract to a file, see askama documentation for details
let mut file = std::fs::File::create("Verifier.sol").unwrap();
contract.write_into(&mut file).unwrap();§Preparing proofs
The crate also provides utility functions to prepare Groth16 proofs for verification in the generated contract. The proofs can be prepared in either compressed or uncompressed format, depending on the specific deployment of the verifier contract. See https://2π.com/23/bn254-compression for explanation of the point compression scheme used and explanation of the gas tradeoffs.
let proof: ark_groth16::Proof<ark_bn254::Bn254> = load_proof();
let compressed_proof = taceo_groth16_sol::prepare_compressed_proof(&proof);
let uncompressed_proof = taceo_groth16_sol::prepare_uncompressed_proof(&proof);Re-exports§
pub use askama;
Structs§
- Invalid
Compressed Point - An error type representing an invalid compressed point during decompression.
- Solidity
Verifier Config - Configuration for the Solidity verifier contract generation.
- Solidity
Verifier Context - Context for generating a Solidity verifier contract for BN254 Groth16 proofs.
The context is passed to
askamafor template rendering. Parameters:
Functions§
- decompress_
proof - Decompress a Groth16 proof from its compressed representation.
- prepare_
compressed_ proof - Compress a Groth16 proofs by compressing the individual curve points. This method uses the point compression scheme described in the contract. See https://2π.com/23/bn254-compression for further explanation.
- prepare_
uncompressed_ proof - Prepare an uncompressed Groth16 proof for verification in the generated contract. The proof is represented as an array of 8 U256 values, corresponding to the x and y coordinates of the points A, B, and C in the proof.