Skip to content

Commit

Permalink
switch to constantine-public-sys branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxcs committed Jan 7, 2024
1 parent 30b1aa6 commit dbf60f3
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 86 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions constantine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 5 additions & 3 deletions constantine/src/mixed_kzg/mixed_eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion constantine/src/types/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions constantine/src/types/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
}

Expand Down
42 changes: 31 additions & 11 deletions constantine/src/types/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}
}
}
Expand Down Expand Up @@ -357,8 +373,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()), 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(),
);
}
}

Expand Down
130 changes: 67 additions & 63 deletions constantine/src/types/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
],
},
}
}
}
}
Expand Down

0 comments on commit dbf60f3

Please sign in to comment.