From 4624b2999fa2f92964503898260d6d19ccf97011 Mon Sep 17 00:00:00 2001 From: Stokalas Date: Tue, 19 Oct 2021 21:41:07 +0300 Subject: [PATCH 1/2] example of wrapper --- kzg10-rust/kzg/src/kzg10.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kzg10-rust/kzg/src/kzg10.rs b/kzg10-rust/kzg/src/kzg10.rs index 669a0310..9925dfb0 100644 --- a/kzg10-rust/kzg/src/kzg10.rs +++ b/kzg10-rust/kzg/src/kzg10.rs @@ -1,5 +1,7 @@ use std::{cmp::min, ops, iter}; use crate::data_types::{fr::*, g1::*, g2::*, gt::*}; +use crate::{BlstFr}; +use crate::data_converter::fr_converter::*; use crate::mcl_methods::{pairing, final_exp, mclBn_FrEvaluatePolynomial}; const G1_GEN_X: &str = "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"; @@ -199,7 +201,12 @@ impl Polynomial { self.coeffs.len() } - pub fn eval_at(&self, point: &Fr) -> Fr { + // pub fn eval_at(&self, point: &BlstFr) -> BlstFr { + // let pointFromBlst = frFromBlst(*point); + // return frToBlst(self.eval_at_mcl(&pointFromBlst)); + // } + + pub fn eval_at_mcl(&self, point: &Fr) -> Fr { let mut result = Fr::default(); unsafe { mclBn_FrEvaluatePolynomial(&mut result, self.coeffs.as_ptr(), self.order(), point) From 2c5c957283d5b79c1fc56aa4e881d8fb1cb34afc Mon Sep 17 00:00:00 2001 From: Stokalas Date: Tue, 19 Oct 2021 22:03:04 +0300 Subject: [PATCH 2/2] changed principle of Fr conversion --- .../kzg/src/data_converter/fr_converter.rs | 42 +++++++++++-------- kzg10-rust/kzg/src/data_types/fr.rs | 2 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/kzg10-rust/kzg/src/data_converter/fr_converter.rs b/kzg10-rust/kzg/src/data_converter/fr_converter.rs index 77c3ffb0..df3fa69a 100644 --- a/kzg10-rust/kzg/src/data_converter/fr_converter.rs +++ b/kzg10-rust/kzg/src/data_converter/fr_converter.rs @@ -1,18 +1,26 @@ -use crate::data_types::fr::Fr; -use crate::BlstFr; - -pub fn frFromBlst(fr: BlstFr) -> Fr { - let mut result = Fr::default(); - for i in 0..4 { - result.d[i] = fr.l[i]; - } - return result; -} - -pub fn frToBlst(fr: Fr) -> BlstFr { - let mut result = BlstFr::default(); - for i in 0..4 { - result.l[i] = fr.d[i]; - } - return result; +use crate::data_types::fr::Fr; +use crate::BlstFr; + +pub fn frFromBlst(fr: BlstFr) -> Fr { + let mut intValue: u64 = 0; + let frBlst = fr; + unsafe { + blst::blst_uint64_from_fr(&mut intValue, &frBlst); + } + let i32Value = intValue as i32;//could cause problems + return Fr::from_int(i32Value); + + // let mut result = Fr::default(); + // for i in 0..4 { + // result.d[i] = fr.l[i]; + // } + // return result; +} + +pub fn frToBlst(fr: Fr) -> BlstFr { + let mut result = BlstFr::default(); + for i in 0..4 { + result.l[i] = fr.d[i]; + } + return result; } \ No newline at end of file diff --git a/kzg10-rust/kzg/src/data_types/fr.rs b/kzg10-rust/kzg/src/data_types/fr.rs index cebea839..ff12b221 100644 --- a/kzg10-rust/kzg/src/data_types/fr.rs +++ b/kzg10-rust/kzg/src/data_types/fr.rs @@ -43,7 +43,7 @@ extern "C" { #[derive(Default, Debug, Clone)] #[repr(C)] pub struct Fr { - pub d: [u64; crate::MCLBN_FR_UNIT_SIZE], + d: [u64; crate::MCLBN_FR_UNIT_SIZE], } impl Fr { pub fn get_order() -> String {