Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jan 12, 2024
1 parent 94dddef commit 7f24d40
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 123 deletions.
4 changes: 2 additions & 2 deletions constantine-rust/constantine-halo2-zal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/mratsim/constantine"
[dependencies]
constantine-sys = { path = "../constantine-sys" }
constantine-core = { path = "../constantine-core" }
halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-pse-exec-engine" }
halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "zal-on-0.3.2" }

[dev-dependencies]
ark-std = "0.3"
Expand All @@ -22,7 +22,7 @@ rand_xorshift = "0.3"
maybe-rayon = { version = "0.1.0", default-features = false }

# In CI "asm" needs to be disabled as some agents don't support ADX.
halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-pse-exec-engine", features = ["multicore"]}
halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "zal-on-0.3.2", features = ["multicore"]}

[[bench]]
name = "msm"
Expand Down
228 changes: 114 additions & 114 deletions constantine-rust/constantine-halo2-zal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,44 @@ impl MsmAccel<bn256::G1Affine> for CttEngine {
}
}

// Caching API
// -------------------------------------------------

type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, bn256::G1Affine>;
type BaseDescriptor<'b> = CttMsmBaseDesc<'b, bn256::G1Affine>;

fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [bn256::Fr]) -> Self::CoeffsDescriptor<'c> {
// Do expensive device/library specific preprocessing here
Self::CoeffsDescriptor { raw: coeffs }
}
fn get_base_descriptor<'b>(&self, base: &'b [bn256::G1Affine]) -> Self::BaseDescriptor<'b> {
// Do expensive device/library specific preprocessing here
Self::BaseDescriptor { raw: base }
}

fn msm_with_cached_scalars(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &[bn256::G1Affine],
) -> bn256::G1 {
self.msm(coeffs.raw, base)
}

fn msm_with_cached_base(
&self,
coeffs: &[bn256::Fr],
base: &Self::BaseDescriptor<'_>,
) -> bn256::G1 {
self.msm(coeffs, base.raw)
}

fn msm_with_cached_inputs(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &Self::BaseDescriptor<'_>,
) -> bn256::G1 {
self.msm(coeffs.raw, base.raw)
}
// // Caching API
// // -------------------------------------------------

// type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, bn256::G1Affine>;
// type BaseDescriptor<'b> = CttMsmBaseDesc<'b, bn256::G1Affine>;

// fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [bn256::Fr]) -> Self::CoeffsDescriptor<'c> {
// // Do expensive device/library specific preprocessing here
// Self::CoeffsDescriptor { raw: coeffs }
// }
// fn get_base_descriptor<'b>(&self, base: &'b [bn256::G1Affine]) -> Self::BaseDescriptor<'b> {
// // Do expensive device/library specific preprocessing here
// Self::BaseDescriptor { raw: base }
// }

// fn msm_with_cached_scalars(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &[bn256::G1Affine],
// ) -> bn256::G1 {
// self.msm(coeffs.raw, base)
// }

// fn msm_with_cached_base(
// &self,
// coeffs: &[bn256::Fr],
// base: &Self::BaseDescriptor<'_>,
// ) -> bn256::G1 {
// self.msm(coeffs, base.raw)
// }

// fn msm_with_cached_inputs(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &Self::BaseDescriptor<'_>,
// ) -> bn256::G1 {
// self.msm(coeffs.raw, base.raw)
// }
}

impl MsmAccel<pallas::Affine> for CttEngine {
Expand All @@ -113,44 +113,44 @@ impl MsmAccel<pallas::Affine> for CttEngine {
}
}

// Caching API
// -------------------------------------------------

type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, pallas::Affine>;
type BaseDescriptor<'b> = CttMsmBaseDesc<'b, pallas::Affine>;

fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [pallas::Scalar]) -> Self::CoeffsDescriptor<'c> {
// Do expensive device/library specific preprocessing here
Self::CoeffsDescriptor { raw: coeffs }
}
fn get_base_descriptor<'b>(&self, base: &'b [pallas::Affine]) -> Self::BaseDescriptor<'b> {
// Do expensive device/library specific preprocessing here
Self::BaseDescriptor { raw: base }
}

fn msm_with_cached_scalars(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &[pallas::Affine],
) -> pallas::Point {
self.msm(coeffs.raw, base)
}

fn msm_with_cached_base(
&self,
coeffs: &[pallas::Scalar],
base: &Self::BaseDescriptor<'_>,
) -> pallas::Point {
self.msm(coeffs, base.raw)
}

fn msm_with_cached_inputs(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &Self::BaseDescriptor<'_>,
) -> pallas::Point {
self.msm(coeffs.raw, base.raw)
}
// // Caching API
// // -------------------------------------------------

// type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, pallas::Affine>;
// type BaseDescriptor<'b> = CttMsmBaseDesc<'b, pallas::Affine>;

// fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [pallas::Scalar]) -> Self::CoeffsDescriptor<'c> {
// // Do expensive device/library specific preprocessing here
// Self::CoeffsDescriptor { raw: coeffs }
// }
// fn get_base_descriptor<'b>(&self, base: &'b [pallas::Affine]) -> Self::BaseDescriptor<'b> {
// // Do expensive device/library specific preprocessing here
// Self::BaseDescriptor { raw: base }
// }

// fn msm_with_cached_scalars(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &[pallas::Affine],
// ) -> pallas::Point {
// self.msm(coeffs.raw, base)
// }

// fn msm_with_cached_base(
// &self,
// coeffs: &[pallas::Scalar],
// base: &Self::BaseDescriptor<'_>,
// ) -> pallas::Point {
// self.msm(coeffs, base.raw)
// }

// fn msm_with_cached_inputs(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &Self::BaseDescriptor<'_>,
// ) -> pallas::Point {
// self.msm(coeffs.raw, base.raw)
// }
}

impl MsmAccel<vesta::Affine> for CttEngine {
Expand All @@ -169,42 +169,42 @@ impl MsmAccel<vesta::Affine> for CttEngine {
}
}

// Caching API
// -------------------------------------------------

type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, vesta::Affine>;
type BaseDescriptor<'b> = CttMsmBaseDesc<'b, vesta::Affine>;

fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [vesta::Scalar]) -> Self::CoeffsDescriptor<'c> {
// Do expensive device/library specific preprocessing here
Self::CoeffsDescriptor { raw: coeffs }
}
fn get_base_descriptor<'b>(&self, base: &'b [vesta::Affine]) -> Self::BaseDescriptor<'b> {
// Do expensive device/library specific preprocessing here
Self::BaseDescriptor { raw: base }
}

fn msm_with_cached_scalars(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &[vesta::Affine],
) -> vesta::Point {
self.msm(coeffs.raw, base)
}

fn msm_with_cached_base(
&self,
coeffs: &[vesta::Scalar],
base: &Self::BaseDescriptor<'_>,
) -> vesta::Point {
self.msm(coeffs, base.raw)
}

fn msm_with_cached_inputs(
&self,
coeffs: &Self::CoeffsDescriptor<'_>,
base: &Self::BaseDescriptor<'_>,
) -> vesta::Point {
self.msm(coeffs.raw, base.raw)
}
// // Caching API
// // -------------------------------------------------

// type CoeffsDescriptor<'c> = CttMsmCoeffsDesc<'c, vesta::Affine>;
// type BaseDescriptor<'b> = CttMsmBaseDesc<'b, vesta::Affine>;

// fn get_coeffs_descriptor<'c>(&self, coeffs: &'c [vesta::Scalar]) -> Self::CoeffsDescriptor<'c> {
// // Do expensive device/library specific preprocessing here
// Self::CoeffsDescriptor { raw: coeffs }
// }
// fn get_base_descriptor<'b>(&self, base: &'b [vesta::Affine]) -> Self::BaseDescriptor<'b> {
// // Do expensive device/library specific preprocessing here
// Self::BaseDescriptor { raw: base }
// }

// fn msm_with_cached_scalars(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &[vesta::Affine],
// ) -> vesta::Point {
// self.msm(coeffs.raw, base)
// }

// fn msm_with_cached_base(
// &self,
// coeffs: &[vesta::Scalar],
// base: &Self::BaseDescriptor<'_>,
// ) -> vesta::Point {
// self.msm(coeffs, base.raw)
// }

// fn msm_with_cached_inputs(
// &self,
// coeffs: &Self::CoeffsDescriptor<'_>,
// base: &Self::BaseDescriptor<'_>,
// ) -> vesta::Point {
// self.msm(coeffs.raw, base.raw)
// }
}
14 changes: 7 additions & 7 deletions constantine-rust/constantine-halo2-zal/tests/t_zal_msm_accel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ fn run_msm_zal(min_k: usize, max_k: usize) {

assert_eq!(e0, e1);

// Caching API
// -----------
let t2 = start_timer!(|| format!("CttEngine msm cached base k={}", k));
let base_descriptor = engine.get_base_descriptor(points);
let e2 = <CttEngine as MsmAccel<bn256::G1Affine>>::msm_with_cached_base(&engine, scalars, &base_descriptor);
end_timer!(t2);
// // Caching API
// // -----------
// let t2 = start_timer!(|| format!("CttEngine msm cached base k={}", k));
// let base_descriptor = engine.get_base_descriptor(points);
// let e2 = <CttEngine as MsmAccel<bn256::G1Affine>>::msm_with_cached_base(&engine, scalars, &base_descriptor);
// end_timer!(t2);

assert_eq!(e0, e2)
// assert_eq!(e0, e2)
}
}

Expand Down

0 comments on commit 7f24d40

Please sign in to comment.