Browse Source

feat: add deserialize_field2 function

pull/3/head
Georgios Konstantopoulos 3 years ago
parent
commit
29de734540
1 changed files with 9 additions and 8 deletions
  1. +9
    -8
      src/zkey.rs

+ 9
- 8
src/zkey.rs

@ -35,7 +35,7 @@ use std::{
io::{Read, Result as IoResult, Seek, SeekFrom}, io::{Read, Result as IoResult, Seek, SeekFrom},
}; };
use ark_bn254::{Bn254, Fq, Fq2, G1Affine, G2Affine};
use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G2Affine};
use ark_groth16::{ProvingKey, VerifyingKey}; use ark_groth16::{ProvingKey, VerifyingKey};
use num_traits::Zero; use num_traits::Zero;
@ -264,6 +264,12 @@ fn deserialize_field(reader: &mut R) -> IoResult {
Ok(Fq::new(bigint)) Ok(Fq::new(bigint))
} }
pub fn deserialize_field2<R: Read>(reader: &mut R) -> IoResult<Fq2> {
let c0 = deserialize_field(reader)?;
let c1 = deserialize_field(reader)?;
Ok(Fq2::new(c0, c1))
}
fn deserialize_g1<R: Read>(reader: &mut R) -> IoResult<G1Affine> { fn deserialize_g1<R: Read>(reader: &mut R) -> IoResult<G1Affine> {
let x = deserialize_field(reader)?; let x = deserialize_field(reader)?;
let y = deserialize_field(reader)?; let y = deserialize_field(reader)?;
@ -272,13 +278,8 @@ fn deserialize_g1(reader: &mut R) -> IoResult {
} }
fn deserialize_g2<R: Read>(reader: &mut R) -> IoResult<G2Affine> { fn deserialize_g2<R: Read>(reader: &mut R) -> IoResult<G2Affine> {
let c0 = deserialize_field(reader)?;
let c1 = deserialize_field(reader)?;
let f1 = Fq2::new(c0, c1);
let c0 = deserialize_field(reader)?;
let c1 = deserialize_field(reader)?;
let f2 = Fq2::new(c0, c1);
let f1 = deserialize_field2(reader)?;
let f2 = deserialize_field2(reader)?;
let infinity = f1.is_zero() && f2.is_zero(); let infinity = f1.is_zero() && f2.is_zero();
Ok(G2Affine::new(f1, f2, infinity)) Ok(G2Affine::new(f1, f2, infinity))
} }

Loading…
Cancel
Save