From 247e0f94d15b06005d48c12492eb89d33f4e4b03 Mon Sep 17 00:00:00 2001 From: Domas Kalinauskas Date: Sun, 7 Jan 2024 20:07:43 +0200 Subject: [PATCH] switch to constantine-public-sys branch --- Cargo.lock | 6 +- constantine/Cargo.toml | 6 +- constantine/src/mixed_kzg/mixed_eip_4844.rs | 8 +- constantine/src/types/fp.rs | 6 +- constantine/src/types/fr.rs | 12 +- constantine/src/types/g1.rs | 42 +++++-- constantine/src/types/g2.rs | 130 ++++++++++---------- 7 files changed, 124 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 631ccee7..5efd2356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -397,7 +397,7 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "constantine-core" version = "0.1.0" -source = "git+https://github.com/lynxcs/constantine.git?branch=rust-kzg-changes#d00c6f9b1ed1c3e0d8b68340d05bd861aa69cd35" +source = "git+https://github.com/mratsim/constantine.git?branch=constantine-public-sys#6bdb0897ff5f22d4a4f05425b426e85336eb0712" dependencies = [ "constantine-sys", ] @@ -405,7 +405,7 @@ dependencies = [ [[package]] name = "constantine-ethereum-kzg" version = "0.1.0" -source = "git+https://github.com/lynxcs/constantine.git?branch=rust-kzg-changes#d00c6f9b1ed1c3e0d8b68340d05bd861aa69cd35" +source = "git+https://github.com/mratsim/constantine.git?branch=constantine-public-sys#6bdb0897ff5f22d4a4f05425b426e85336eb0712" dependencies = [ "constantine-core", "constantine-sys", @@ -414,7 +414,7 @@ dependencies = [ [[package]] name = "constantine-sys" version = "0.1.0" -source = "git+https://github.com/lynxcs/constantine.git?branch=rust-kzg-changes#d00c6f9b1ed1c3e0d8b68340d05bd861aa69cd35" +source = "git+https://github.com/mratsim/constantine.git?branch=constantine-public-sys#6bdb0897ff5f22d4a4f05425b426e85336eb0712" [[package]] name = "cpufeatures" diff --git a/constantine/Cargo.toml b/constantine/Cargo.toml index eaca6e5b..6078fdaf 100644 --- a/constantine/Cargo.toml +++ b/constantine/Cargo.toml @@ -8,9 +8,9 @@ blst = "0.3.11" kzg = { path = "../kzg", default-features = false } libc = { version = "0.2.148", default-features = false } once_cell = { version = "1.18.0", features = ["critical-section"], default-features = false } -constantine-ethereum-kzg = { 'git' = 'https://github.com/lynxcs/constantine.git' , branch='rust-kzg-changes' } -constantine-sys = { 'git' = 'https://github.com/lynxcs/constantine.git' , branch='rust-kzg-changes' } -constantine-core = { 'git' = 'https://github.com/lynxcs/constantine.git' , branch='rust-kzg-changes' } +constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' } +constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' } +constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' } rand = { version = "0.8.5", optional = true } rayon = { version = "1.8.0", optional = true } smallvec = { version = "1.11.1", features = ["const_generics"] } diff --git a/constantine/src/mixed_kzg/mixed_eip_4844.rs b/constantine/src/mixed_kzg/mixed_eip_4844.rs index 88a775fe..db331f16 100644 --- a/constantine/src/mixed_kzg/mixed_eip_4844.rs +++ b/constantine/src/mixed_kzg/mixed_eip_4844.rs @@ -82,9 +82,11 @@ pub fn compute_kzg_proof_mixed( let blob_bytes = blob_fr_to_byte(blob)?; #[cfg(feature = "parallel")] - let res = ctt_context - .ctx - .compute_kzg_proof_parallel(&ctt_context.pool, &blob_bytes, &z.to_bytes()); + let res = ctt_context.ctx.compute_kzg_proof_parallel( + &ctt_context.pool, + &blob_bytes, + &z.to_bytes(), + ); #[cfg(not(feature = "parallel"))] let res = ctt_context diff --git a/constantine/src/types/fp.rs b/constantine/src/types/fp.rs index adbc3619..ac66b3ac 100644 --- a/constantine/src/types/fp.rs +++ b/constantine/src/types/fp.rs @@ -69,7 +69,11 @@ impl G1Fp for CtFp { } fn from_underlying_arr(arr: &[u64; 6]) -> Self { - Self(bls12_381_fp { limbs: *arr }) + unsafe { + Self(bls12_381_fp { + limbs: core::mem::transmute(*arr), + }) + } } fn neg_assign(&mut self) { diff --git a/constantine/src/types/fr.rs b/constantine/src/types/fr.rs index bdb696dd..a2f43eac 100644 --- a/constantine/src/types/fr.rs +++ b/constantine/src/types/fr.rs @@ -38,11 +38,19 @@ impl Eq for CtFr {} impl CtFr { pub fn from_blst_fr(fr: blst::blst_fr) -> Self { - Self(bls12_381_fr { limbs: fr.l }) + unsafe { + Self(bls12_381_fr { + limbs: core::mem::transmute(fr.l), + }) + } } pub fn to_blst_fr(&self) -> blst_fr { - blst_fr { l: self.0.limbs } + unsafe { + blst_fr { + l: core::mem::transmute(self.0.limbs), + } + } } } diff --git a/constantine/src/types/g1.rs b/constantine/src/types/g1.rs index 99c6ce67..8f76f7bd 100644 --- a/constantine/src/types/g1.rs +++ b/constantine/src/types/g1.rs @@ -56,18 +56,34 @@ impl CtG1 { } pub const fn from_blst_p1(p1: blst::blst_p1) -> Self { - Self(bls12_381_g1_jac { - x: bls12_381_fp { limbs: p1.x.l }, - y: bls12_381_fp { limbs: p1.y.l }, - z: bls12_381_fp { limbs: p1.z.l }, - }) + unsafe { + Self(bls12_381_g1_jac { + x: bls12_381_fp { + limbs: core::mem::transmute(p1.x.l), + }, + y: bls12_381_fp { + limbs: core::mem::transmute(p1.y.l), + }, + z: bls12_381_fp { + limbs: core::mem::transmute(p1.z.l), + }, + }) + } } pub const fn to_blst_p1(&self) -> blst::blst_p1 { - blst::blst_p1 { - x: blst::blst_fp { l: self.0.x.limbs }, - y: blst::blst_fp { l: self.0.y.limbs }, - z: blst::blst_fp { l: self.0.z.limbs }, + unsafe { + blst::blst_p1 { + x: blst::blst_fp { + l: core::mem::transmute(self.0.x.limbs), + }, + y: blst::blst_fp { + l: core::mem::transmute(self.0.y.limbs), + }, + z: blst::blst_fp { + l: core::mem::transmute(self.0.z.limbs), + }, + } } } } @@ -357,8 +373,12 @@ impl G1Affine 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()), g1.len()); + unsafe { + constantine::ctt_bls12_381_g1_jac_batch_affine( + core::mem::transmute(out.as_mut_ptr()), + core::mem::transmute(g1.as_ptr()), + g1.len(), + ); } } diff --git a/constantine/src/types/g2.rs b/constantine/src/types/g2.rs index 1ee153f0..fa50da02 100644 --- a/constantine/src/types/g2.rs +++ b/constantine/src/types/g2.rs @@ -27,72 +27,76 @@ pub struct CtG2(pub bls12_381_g2_jac); impl CtG2 { pub const fn from_blst_p2(p2: blst::blst_p2) -> Self { - Self(bls12_381_g2_jac { - x: bls12_381_fp2 { - c: [ - bls12_381_fp { - limbs: p2.x.fp[0].l, - }, - bls12_381_fp { - limbs: p2.x.fp[1].l, - }, - ], - }, - y: bls12_381_fp2 { - c: [ - bls12_381_fp { - limbs: p2.y.fp[0].l, - }, - bls12_381_fp { - limbs: p2.y.fp[1].l, - }, - ], - }, - z: bls12_381_fp2 { - c: [ - bls12_381_fp { - limbs: p2.z.fp[0].l, - }, - bls12_381_fp { - limbs: p2.z.fp[1].l, - }, - ], - }, - }) + unsafe { + Self(bls12_381_g2_jac { + x: bls12_381_fp2 { + c: [ + bls12_381_fp { + limbs: core::mem::transmute(p2.x.fp[0].l), + }, + bls12_381_fp { + limbs: core::mem::transmute(p2.x.fp[1].l), + }, + ], + }, + y: bls12_381_fp2 { + c: [ + bls12_381_fp { + limbs: core::mem::transmute(p2.y.fp[0].l), + }, + bls12_381_fp { + limbs: core::mem::transmute(p2.y.fp[1].l), + }, + ], + }, + z: bls12_381_fp2 { + c: [ + bls12_381_fp { + limbs: core::mem::transmute(p2.z.fp[0].l), + }, + bls12_381_fp { + limbs: core::mem::transmute(p2.z.fp[1].l), + }, + ], + }, + }) + } } pub const fn to_blst_p2(&self) -> blst::blst_p2 { - blst::blst_p2 { - x: blst::blst_fp2 { - fp: [ - blst::blst_fp { - l: self.0.x.c[0].limbs, - }, - blst::blst_fp { - l: self.0.x.c[1].limbs, - }, - ], - }, - y: blst::blst_fp2 { - fp: [ - blst::blst_fp { - l: self.0.y.c[0].limbs, - }, - blst::blst_fp { - l: self.0.y.c[1].limbs, - }, - ], - }, - z: blst::blst_fp2 { - fp: [ - blst::blst_fp { - l: self.0.z.c[0].limbs, - }, - blst::blst_fp { - l: self.0.z.c[1].limbs, - }, - ], - }, + unsafe { + blst::blst_p2 { + x: blst::blst_fp2 { + fp: [ + blst::blst_fp { + l: core::mem::transmute(self.0.x.c[0].limbs), + }, + blst::blst_fp { + l: core::mem::transmute(self.0.x.c[1].limbs), + }, + ], + }, + y: blst::blst_fp2 { + fp: [ + blst::blst_fp { + l: core::mem::transmute(self.0.y.c[0].limbs), + }, + blst::blst_fp { + l: core::mem::transmute(self.0.y.c[1].limbs), + }, + ], + }, + z: blst::blst_fp2 { + fp: [ + blst::blst_fp { + l: core::mem::transmute(self.0.z.c[0].limbs), + }, + blst::blst_fp { + l: core::mem::transmute(self.0.z.c[1].limbs), + }, + ], + }, + } } } }