Skip to content

Commit

Permalink
Updated rust toolchain version
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomTr committed Sep 11, 2024
1 parent 5350dc5 commit d4ed06b
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 180 deletions.
30 changes: 0 additions & 30 deletions arkworks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,3 @@ pub mod poly;
pub mod recover;
pub mod utils;
pub mod zero_poly;

trait Eq<T> {
fn equals(&self, other: &T) -> bool;
}

trait Inverse<T> {
fn inverse(&self) -> T;
}

trait Zero<T> {
fn is_zero(&self) -> bool;
}

impl Eq<P1> for P1 {
fn equals(&self, other: &P1) -> bool {
self.x.l.eq(&other.x.l) && self.y.l.eq(&other.x.l) && self.z.l.eq(&other.x.l)
}
}

impl Eq<Fr> for Fr {
fn equals(&self, other: &Fr) -> bool {
self.l.eq(&other.l)
}
}

impl Zero<Fr> for Fr {
fn is_zero(&self) -> bool {
self.l[0] == 0 && self.l[1] == 0 && self.l[2] == 0 && self.l[3] == 0
}
}
19 changes: 5 additions & 14 deletions arkworks/tests/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ mod tests {
compute_and_verify_blob_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_blob_kzg_proof_test,
compute_and_verify_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_kzg_proof_round_trip_test, compute_kzg_proof_test, compute_powers_test,
verify_kzg_proof_batch_fails_with_incorrect_proof_test, verify_kzg_proof_batch_test,
};
#[cfg(not(feature = "minimal-spec"))]
use kzg_bench::tests::eip_4844::{
compute_and_verify_kzg_proof_within_domain_test, test_vectors_blob_to_kzg_commitment,
compute_and_verify_kzg_proof_round_trip_test,
compute_and_verify_kzg_proof_within_domain_test, compute_kzg_proof_test,
compute_powers_test, test_vectors_blob_to_kzg_commitment,
test_vectors_compute_blob_kzg_proof, test_vectors_compute_kzg_proof,
test_vectors_verify_blob_kzg_proof, test_vectors_verify_blob_kzg_proof_batch,
test_vectors_verify_kzg_proof,
test_vectors_verify_kzg_proof, verify_kzg_proof_batch_fails_with_incorrect_proof_test,
verify_kzg_proof_batch_test,
};
use rust_kzg_arkworks::consts::SCALE2_ROOT_OF_UNITY;
use rust_kzg_arkworks::eip_4844::load_trusted_setup_filename_rust;
Expand Down Expand Up @@ -96,7 +94,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn compute_and_verify_kzg_proof_within_domain_test_() {
compute_and_verify_kzg_proof_within_domain_test::<
Expand Down Expand Up @@ -221,7 +218,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_blob_to_kzg_commitment_() {
test_vectors_blob_to_kzg_commitment::<
Expand All @@ -240,7 +236,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_kzg_proof_() {
test_vectors_compute_kzg_proof::<
Expand All @@ -259,7 +254,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_blob_kzg_proof_() {
test_vectors_compute_blob_kzg_proof::<
Expand All @@ -278,7 +272,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_kzg_proof_() {
test_vectors_verify_kzg_proof::<
Expand All @@ -293,7 +286,6 @@ mod tests {
>(&load_trusted_setup_filename_rust, &verify_kzg_proof_rust);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_() {
test_vectors_verify_blob_kzg_proof::<
Expand All @@ -312,7 +304,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_batch_() {
test_vectors_verify_blob_kzg_proof_batch::<
Expand Down
30 changes: 0 additions & 30 deletions arkworks3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,3 @@ pub mod poly;
pub mod recover;
pub mod utils;
pub mod zero_poly;

trait Eq<T> {
fn equals(&self, other: &T) -> bool;
}

trait Inverse<T> {
fn inverse(&self) -> T;
}

trait Zero<T> {
fn is_zero(&self) -> bool;
}

impl Eq<P1> for P1 {
fn equals(&self, other: &P1) -> bool {
self.x.l.eq(&other.x.l) && self.y.l.eq(&other.x.l) && self.z.l.eq(&other.x.l)
}
}

impl Eq<Fr> for Fr {
fn equals(&self, other: &Fr) -> bool {
self.l.eq(&other.l)
}
}

impl Zero<Fr> for Fr {
fn is_zero(&self) -> bool {
self.l[0] == 0 && self.l[1] == 0 && self.l[2] == 0 && self.l[3] == 0
}
}
19 changes: 5 additions & 14 deletions arkworks3/tests/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ mod tests {
compute_and_verify_blob_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_blob_kzg_proof_test,
compute_and_verify_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_kzg_proof_round_trip_test, compute_kzg_proof_test, compute_powers_test,
verify_kzg_proof_batch_fails_with_incorrect_proof_test, verify_kzg_proof_batch_test,
};
#[cfg(not(feature = "minimal-spec"))]
use kzg_bench::tests::eip_4844::{
compute_and_verify_kzg_proof_within_domain_test, test_vectors_blob_to_kzg_commitment,
compute_and_verify_kzg_proof_round_trip_test,
compute_and_verify_kzg_proof_within_domain_test, compute_kzg_proof_test,
compute_powers_test, test_vectors_blob_to_kzg_commitment,
test_vectors_compute_blob_kzg_proof, test_vectors_compute_kzg_proof,
test_vectors_verify_blob_kzg_proof, test_vectors_verify_blob_kzg_proof_batch,
test_vectors_verify_kzg_proof,
test_vectors_verify_kzg_proof, verify_kzg_proof_batch_fails_with_incorrect_proof_test,
verify_kzg_proof_batch_test,
};
use rust_kzg_arkworks3::consts::SCALE2_ROOT_OF_UNITY;
use rust_kzg_arkworks3::eip_4844::load_trusted_setup_filename_rust;
Expand Down Expand Up @@ -96,7 +94,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn compute_and_verify_kzg_proof_within_domain_test_() {
compute_and_verify_kzg_proof_within_domain_test::<
Expand Down Expand Up @@ -221,7 +218,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_blob_to_kzg_commitment_() {
test_vectors_blob_to_kzg_commitment::<
Expand All @@ -240,7 +236,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_kzg_proof_() {
test_vectors_compute_kzg_proof::<
Expand All @@ -259,7 +254,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_blob_kzg_proof_() {
test_vectors_compute_blob_kzg_proof::<
Expand All @@ -278,7 +272,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_kzg_proof_() {
test_vectors_verify_kzg_proof::<
Expand All @@ -293,7 +286,6 @@ mod tests {
>(&load_trusted_setup_filename_rust, &verify_kzg_proof_rust);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_() {
test_vectors_verify_blob_kzg_proof::<
Expand All @@ -312,7 +304,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_batch_() {
test_vectors_verify_blob_kzg_proof_batch::<
Expand Down
45 changes: 26 additions & 19 deletions blst/src/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,34 @@ pub unsafe extern "C" fn free_trusted_setup(s: *mut CKZGSettings) {

PRECOMPUTATION_TABLES.remove_precomputation(&*s);

let max_width = (*s).max_width as usize;
let roots = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).roots_of_unity,
max_width,
));
drop(roots);
(*s).roots_of_unity = null_mut();
if !(*s).roots_of_unity.is_null() {
let max_width = (*s).max_width as usize;
let roots = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).roots_of_unity,
max_width,
));
drop(roots);
(*s).roots_of_unity = null_mut();
}

let g1 = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).g1_values,
TRUSTED_SETUP_NUM_G1_POINTS,
));
drop(g1);
(*s).g1_values = null_mut();
if !(*s).g1_values.is_null() {
let g1 = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).g1_values,
TRUSTED_SETUP_NUM_G1_POINTS,
));
drop(g1);
(*s).g1_values = null_mut();
}

if !(*s).g2_values.is_null() {
let g2 = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).g2_values,
TRUSTED_SETUP_NUM_G2_POINTS,
));
drop(g2);
(*s).g2_values = null_mut();
}

let g2 = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).g2_values,
TRUSTED_SETUP_NUM_G2_POINTS,
));
drop(g2);
(*s).g2_values = null_mut();
(*s).max_width = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion constantine/src/types/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl G1Fp for CtFp {
fn from_underlying_arr(arr: &[u64; 6]) -> Self {
unsafe {
Self(bls12_381_fp {
limbs: core::mem::transmute(*arr),
limbs: core::mem::transmute::<[u64; 6], [usize; 6]>(*arr),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions constantine/src/types/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ impl CtFr {
pub fn from_blst_fr(fr: blst::blst_fr) -> Self {
unsafe {
Self(bls12_381_fr {
limbs: core::mem::transmute(fr.l),
limbs: core::mem::transmute::<[u64; 4], [usize; 4]>(fr.l),
})
}
}

pub fn to_blst_fr(&self) -> blst_fr {
unsafe {
blst_fr {
l: core::mem::transmute(self.0.limbs),
l: core::mem::transmute::<[usize; 4], [u64; 4]>(self.0.limbs),
}
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Fr for CtFr {
let mut scalar = constantine::big255::default();
unsafe {
constantine::ctt_big255_from_bls12_381_fr(&mut scalar, &self.0);
Scalar256::from_u64(core::mem::transmute(scalar.limbs))
Scalar256::from_u64(core::mem::transmute::<[usize; 4], [u64; 4]>(scalar.limbs))
}
}
}
20 changes: 12 additions & 8 deletions constantine/src/types/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ impl CtG1 {
unsafe {
Self(bls12_381_g1_jac {
x: bls12_381_fp {
limbs: core::mem::transmute(p1.x.l),
limbs: core::mem::transmute::<[u64; 6], [usize; 6]>(p1.x.l),
},
y: bls12_381_fp {
limbs: core::mem::transmute(p1.y.l),
limbs: core::mem::transmute::<[u64; 6], [usize; 6]>(p1.y.l),
},
z: bls12_381_fp {
limbs: core::mem::transmute(p1.z.l),
limbs: core::mem::transmute::<[u64; 6], [usize; 6]>(p1.z.l),
},
})
}
Expand All @@ -73,13 +73,13 @@ impl CtG1 {
unsafe {
blst::blst_p1 {
x: blst::blst_fp {
l: core::mem::transmute(self.0.x.limbs),
l: core::mem::transmute::<[usize; 6], [u64; 6]>(self.0.x.limbs),
},
y: blst::blst_fp {
l: core::mem::transmute(self.0.y.limbs),
l: core::mem::transmute::<[usize; 6], [u64; 6]>(self.0.y.limbs),
},
z: blst::blst_fp {
l: core::mem::transmute(self.0.z.limbs),
l: core::mem::transmute::<[usize; 6], [u64; 6]>(self.0.z.limbs),
},
}
}
Expand Down Expand Up @@ -353,8 +353,12 @@ impl G1Affine<CtG1, CtFp> for CtG1Affine {
fn into_affines_loc(out: &mut [Self], g1: &[CtG1]) {
unsafe {
constantine::ctt_bls12_381_g1_jac_batch_affine(
core::mem::transmute(out.as_mut_ptr()),
core::mem::transmute(g1.as_ptr()),
core::mem::transmute::<*mut CtG1Affine, *const constantine_sys::bls12_381_g1_aff>(
out.as_mut_ptr(),
),
core::mem::transmute::<*const CtG1, *const constantine_sys::bls12_381_g1_jac>(
g1.as_ptr(),
),
g1.len(),
);
}
Expand Down
Loading

0 comments on commit d4ed06b

Please sign in to comment.