Onchain decider circuit for Protogalaxy (#145)

* Move r1cs and ccs to standalone folders

* Simplify type bounds of SparseMatrixVar

* Implement `EquivalenceGadget` trait for `FpVar` and `NonNativeUintVar`.

Together with the existing `MatrixGadget` and `VectorGadget`, we can now use the same logic for checking R1CS satisfiability of `R1CSVar` both natively and non-natively.

* Simplify trait bounds

* Implement `ArithGadget` for `R1CSMatricesVar` and `CCSMatricesVar`

* `PedersenGadget::commit` now takes slices as input

* Structs for proofs and auxiliary values in protogalaxy

* `u` in LCCCS should be `z[0]`

* `Inputize` trait

* Generic decider circuits

* Verifier should check the commitments in committed instances

* Update the comments according to the new docs

* Fix examples

* Add `DeciderEnabledNIFS::fold_group_elements_native` to wrap code for folding commitments

* Fix incorrect endian

* Format

* Get rid of `unwrap` when possible
This commit is contained in:
winderica
2024-11-04 17:34:50 +08:00
committed by GitHub
parent 6d8f297f11
commit b812dd66df
46 changed files with 2735 additions and 2408 deletions

View File

@@ -108,11 +108,19 @@ impl<F: PrimeField> CircomWrapper<F> {
// Converts a num_bigint::BigInt to a PrimeField::BigInt.
pub fn num_bigint_to_ark_bigint(&self, value: &BigInt) -> Result<F::BigInt, Error> {
let big_uint = value
.to_biguint()
.ok_or_else(|| Error::BigIntConversionError("BigInt is negative".to_string()))?;
let big_uint = value.to_biguint().ok_or_else(|| {
Error::ConversionError(
"BigInt".into(),
"BigUint".into(),
"BigInt is negative".into(),
)
})?;
F::BigInt::try_from(big_uint).map_err(|_| {
Error::BigIntConversionError("Failed to convert to PrimeField::BigInt".to_string())
Error::ConversionError(
"BigUint".into(),
"PrimeField::BigInt".into(),
"BigUint is too large to fit into PrimeField::BigInt".into(),
)
})
}

View File

@@ -16,6 +16,7 @@ use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use folding_schemes::{frontend::FCircuit, utils::PathOrBin, Error};
use noir_arkworks_backend::{
read_program_from_binary, read_program_from_file, sonobe_bridge::AcirCircuitSonobe,
FilesystemError,
};
#[derive(Clone, Debug)]
@@ -216,10 +217,12 @@ impl<F: PrimeField> FCircuit<F> for NoirFCircuit<F> {
}
}
pub fn load_noir_circuit<F: PrimeField>(path: String) -> Circuit<GenericFieldElement<F>> {
let program: Program<GenericFieldElement<F>> = read_program_from_file(path).unwrap();
pub fn load_noir_circuit<F: PrimeField>(
path: String,
) -> Result<Circuit<GenericFieldElement<F>>, FilesystemError> {
let program: Program<GenericFieldElement<F>> = read_program_from_file(path)?;
let circuit: Circuit<GenericFieldElement<F>> = program.functions[0].clone();
circuit
Ok(circuit)
}
#[cfg(test)]
@@ -241,7 +244,7 @@ mod tests {
"{}/src/noir/test_folder/test_circuit/target/test_circuit.json",
cur_path.to_str().unwrap()
);
let circuit = load_noir_circuit(circuit_path);
let circuit = load_noir_circuit(circuit_path).unwrap();
let noirfcircuit = NoirFCircuit {
circuit,
state_len: 2,
@@ -261,7 +264,7 @@ mod tests {
"{}/src/noir/test_folder/test_circuit/target/test_circuit.json",
cur_path.to_str().unwrap()
);
let circuit = load_noir_circuit(circuit_path);
let circuit = load_noir_circuit(circuit_path).unwrap();
let noirfcircuit = NoirFCircuit {
circuit,
state_len: 2,
@@ -285,7 +288,7 @@ mod tests {
"{}/src/noir/test_folder/test_no_external_inputs/target/test_no_external_inputs.json",
cur_path.to_str().unwrap()
);
let circuit = load_noir_circuit(circuit_path);
let circuit = load_noir_circuit(circuit_path).unwrap();
let noirfcircuit = NoirFCircuit {
circuit,
state_len: 2,