Hi, I'm having trouble debugging my code that I think is correct, because Rust wouldn't recognize that the types of two data are actually same. I'm using Arkworks and Spartan (GitHub - arkworks-rs/spartan: Spartan on Arkworks) to write zkSNARKS.
type Fq = ark_bls12_381::Fq;
type JubJub = ark_ed_on_bw6_761::EdwardsProjective;
let inst = Instance::<Fq>::new(num_cons, num_vars, num_inputs, &a_flat, &b_flat, &c_flat).unwrap();
// Ignore other inputs to prove()
let proof = NIZK::<JubJub>::prove(&inst, instance_assignment, &witness_assignment, &gens, &mut prover_transcript);
prove()
expects inst
to be of type 'scalar field of JubJub (CurveGroup)'. The compiler says &inst
is a wrong argument to prove()
:
expected reference `&libspartan::Instance<Fp<MontBackend<ark_ed_on_bw6_761::FrConfig, _>, _>>` // this is JubJub
found reference `&libspartan::Instance<Fp<MontBackend<ark_bls12_381::FqConfig, _>, _>>` // this is Fq
So this error is correct, but technically, Fq
and the scalar field of JubJub
are both Fp384<MontBackend<FqConfig, 6>>
. The are literally defined like this in the source code:
pub type Fq = Fp384<MontBackend<FqConfig, 6>>; // Fq
pub struct EdwardsConfig; // JubJub
impl CurveConfig for EdwardsConfig {
type ScalarField = Fr;
}
pub type Fr = Fp384<MontBackend<FrConfig, 6>>;
How can I use them interchangeably as the same type - which they are?