mirror of
https://github.com/privacy-scaling-explorations/halo2wrong.git
synced 2026-05-05 03:00:34 -04:00
Rename Secp256k1 + latest pairing lib traits
This commit is contained in:
@@ -4,5 +4,5 @@ members = [
|
||||
"integer",
|
||||
"ecc",
|
||||
"ecdsa/circuit",
|
||||
"ecdsa/secp256k1forhalo2"
|
||||
"ecdsa/secp256k1"
|
||||
]
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
secp256k1forhalo2 = { path = "../secp256k1forhalo2/", default-features = true, optional = true }
|
||||
secp256k1 = { path = "../secp256k1/", default-features = true, optional = true }
|
||||
ecc = { path = "../../ecc", default-features = false }
|
||||
num-bigint = { version = "0.4", features = ["rand"] }
|
||||
num-integer = "0.1"
|
||||
@@ -21,4 +21,4 @@ rand_core = { version = "0.6", default-features = false }
|
||||
default = ["zcash"]
|
||||
kzg = ["ecc/kzg"]
|
||||
zcash = ["ecc/zcash"]
|
||||
secp = ["secp256k1forhalo2/zcash"]
|
||||
secp = ["secp256k1/zcash"]
|
||||
|
||||
@@ -300,9 +300,9 @@ mod tests {
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "secp")] {
|
||||
use secp256k1forhalo2::Fp as Field;
|
||||
use secp256k1forhalo2::Secp256k1Affine as Curve;
|
||||
use secp256k1forhalo2::Secp256k1 as CurveProjective;
|
||||
use secp256k1::Fp as Field;
|
||||
use secp256k1::Secp256k1Affine as Curve;
|
||||
use secp256k1::Secp256k1 as CurveProjective;
|
||||
}
|
||||
else if #[cfg(feature = "kzg")] {
|
||||
use halo2::pairing::bn256::Fq as Field;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "secp256k1forhalo2"
|
||||
name = "secp256k1"
|
||||
description = "Implementation of the secp256k1 with halo2 (or pallas curves) traits"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
@@ -37,7 +37,7 @@ harness = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
maingate = { path = "../../maingate", default-features = false }
|
||||
halo2wrong = { path = "../../halo2wrong", default-features = false }
|
||||
blake2b_simd = { version = "0.5", default-features = false }
|
||||
ff = { version = "0.11", default-features = false }
|
||||
group = { version = "0.11", features = ["tests"] }
|
||||
@@ -51,6 +51,6 @@ cfg-if = "0.1"
|
||||
|
||||
[features]
|
||||
default = ["bits", "zcash"]
|
||||
kzg = ["maingate/kzg"]
|
||||
zcash = ["maingate/zcash"]
|
||||
zcash = ["halo2wrong/zcash"]
|
||||
kzg = ["halo2wrong/kzg"]
|
||||
bits = ["ff/bits"]
|
||||
@@ -5,7 +5,7 @@ use rand::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
use ff::{Field, PrimeField};
|
||||
use secp256k1forhalo2::Fp;
|
||||
use secp256k1::Fp;
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("Fp");
|
||||
@@ -8,7 +8,7 @@ mod fields;
|
||||
|
||||
pub(crate) use fields::*;
|
||||
|
||||
use maingate::halo2::arithmetic::FieldExt;
|
||||
use halo2wrong::halo2::arithmetic::FieldExt;
|
||||
|
||||
/// This represents an element of a group with basic operations that can be
|
||||
/// performed. This allows an FFT implementation (for example) to operate
|
||||
@@ -21,7 +21,7 @@ use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
use super::{Fp, Fq};
|
||||
|
||||
use maingate::halo2::arithmetic::{Coordinates, CurveAffine, CurveExt, Group};
|
||||
use halo2wrong::halo2::arithmetic::{Coordinates, CurveAffine, CurveExt, Group};
|
||||
|
||||
macro_rules! new_curve_impl {
|
||||
(($($privacy:tt)*), $name:ident, $name_affine:ident, $base:ident, $scalar:ident,
|
||||
@@ -6,7 +6,7 @@ use ff::PrimeField;
|
||||
use rand::RngCore;
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
use maingate::halo2::arithmetic::{FieldExt, Group};
|
||||
use halo2wrong::halo2::arithmetic::{FieldExt, Group};
|
||||
|
||||
use crate::arithmetic::{adc, mac, sbb};
|
||||
|
||||
@@ -17,10 +17,10 @@ use alloc::vec::Vec;
|
||||
use ff::{FieldBits, PrimeFieldBits};
|
||||
|
||||
#[cfg(not(feature = "kzg"))]
|
||||
use maingate::halo2::arithmetic::SqrtRatio;
|
||||
use halo2wrong::halo2::arithmetic::SqrtRatio;
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
use maingate::halo2::arithmetic::BaseExt;
|
||||
use halo2wrong::halo2::arithmetic::BaseExt;
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
use std::io::{self, Read, Write};
|
||||
@@ -645,14 +645,31 @@ impl BaseExt for Fp {
|
||||
const MODULUS: &'static str = MODULUS_STR;
|
||||
|
||||
fn write<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write(&self.to_bytes())?;
|
||||
let limb_bytes: Vec<[u8; 8]> = self.0.iter().map(|limb| u64::to_le_bytes(*limb)).collect();
|
||||
let mut result: [u8; 32] = [0 as u8; 32];
|
||||
let mut index = 0;
|
||||
limb_bytes.iter().for_each(|bytes| {
|
||||
for byte in bytes.iter() {
|
||||
result[index] = *byte;
|
||||
index += 1
|
||||
}
|
||||
});
|
||||
writer.write(&result)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reads a normalized, little endian represented field element from a
|
||||
/// buffer.
|
||||
fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
|
||||
let mut compressed = [0u8; 32];
|
||||
reader.read_exact(&mut compressed[..])?;
|
||||
Option::from(Self::from_bytes(&compressed)).ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof"))
|
||||
let mut bytes = [0u8; 32];
|
||||
reader.read_exact(&mut bytes[..])?;
|
||||
let result = Self::from_raw([
|
||||
u64::from_le_bytes(bytes[0..8].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[8..16].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[16..24].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[24..32].try_into().unwrap()),
|
||||
]);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn from_bytes_wide(bytes: &[u8; 64]) -> Fp {
|
||||
@@ -678,12 +695,6 @@ impl FieldExt for Fp {
|
||||
|
||||
const ZETA: Self = Self::zero();
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
const T_MINUS1_OVER2: [u64; 4] = [0 as u64; 4];
|
||||
#[cfg(feature = "kzg")]
|
||||
const RESCUE_ALPHA: u64 = 0 as u64;
|
||||
#[cfg(feature = "kzg")]
|
||||
const RESCUE_INVALPHA: [u64; 4] = [0 as u64; 4];
|
||||
fn from_u128(v: u128) -> Self {
|
||||
Fp::from_raw([v as u64, (v >> 64) as u64, 0, 0])
|
||||
}
|
||||
@@ -704,31 +715,6 @@ impl FieldExt for Fp {
|
||||
])
|
||||
}
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
fn to_bytes(&self) -> [u8; 32] {
|
||||
let limb_bytes: Vec<[u8; 8]> = self.0.iter().map(|limb| u64::to_le_bytes(*limb)).collect();
|
||||
let mut result: [u8; 32] = [0 as u8; 32];
|
||||
let mut index = 0;
|
||||
limb_bytes.iter().for_each(|bytes| {
|
||||
for byte in bytes.iter() {
|
||||
result[index] = *byte;
|
||||
index += 1
|
||||
}
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self> {
|
||||
let result = Self::from_raw([
|
||||
u64::from_le_bytes(bytes[0..8].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[8..16].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[16..24].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[24..32].try_into().unwrap()),
|
||||
]);
|
||||
CtOption::new(result, Choice::from(1 as u8))
|
||||
}
|
||||
|
||||
fn get_lower_128(&self) -> u128 {
|
||||
let tmp = Fp::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ use rand::RngCore;
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
use crate::arithmetic::{adc, mac, sbb};
|
||||
use maingate::halo2::arithmetic::{FieldExt, Group};
|
||||
use halo2wrong::halo2::arithmetic::{FieldExt, Group};
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
use alloc::vec::Vec;
|
||||
@@ -19,10 +19,10 @@ use ff::{FieldBits, PrimeFieldBits};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
#[cfg(not(feature = "kzg"))]
|
||||
use maingate::halo2::arithmetic::{SqrtRatio, SqrtTables};
|
||||
use halo2wrong::halo2::arithmetic::{SqrtRatio, SqrtTables};
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
use maingate::halo2::arithmetic::BaseExt;
|
||||
use halo2wrong::halo2::arithmetic::BaseExt;
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
use std::io::{self, Read, Write};
|
||||
@@ -661,16 +661,31 @@ impl BaseExt for Fq {
|
||||
const MODULUS: &'static str = MODULUS_STR;
|
||||
|
||||
fn write<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write(&self.to_bytes())?;
|
||||
let limb_bytes: Vec<[u8; 8]> = self.0.iter().map(|limb| u64::to_le_bytes(*limb)).collect();
|
||||
let mut result: [u8; 32] = [0 as u8; 32];
|
||||
let mut index = 0;
|
||||
limb_bytes.iter().for_each(|bytes| {
|
||||
for byte in bytes.iter() {
|
||||
result[index] = *byte;
|
||||
index += 1
|
||||
}
|
||||
});
|
||||
writer.write(&result)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reads a normalized, little endian represented field element from a
|
||||
/// buffer.
|
||||
fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
|
||||
let mut compressed = [0u8; 32];
|
||||
reader.read_exact(&mut compressed[..])?;
|
||||
Option::from(Self::from_bytes(&compressed)).ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof"))
|
||||
let mut bytes = [0u8; 32];
|
||||
reader.read_exact(&mut bytes[..])?;
|
||||
let result = Self::from_raw([
|
||||
u64::from_le_bytes(bytes[0..8].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[8..16].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[16..24].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[24..32].try_into().unwrap()),
|
||||
]);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn from_bytes_wide(bytes: &[u8; 64]) -> Self {
|
||||
@@ -696,42 +711,10 @@ impl FieldExt for Fq {
|
||||
|
||||
const ZETA: Self = Self::zero();
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
const T_MINUS1_OVER2: [u64; 4] = [0 as u64; 4];
|
||||
#[cfg(feature = "kzg")]
|
||||
const RESCUE_ALPHA: u64 = 0 as u64;
|
||||
#[cfg(feature = "kzg")]
|
||||
const RESCUE_INVALPHA: [u64; 4] = [0 as u64; 4];
|
||||
|
||||
fn from_u128(v: u128) -> Self {
|
||||
Fq::from_raw([v as u64, (v >> 64) as u64, 0, 0])
|
||||
}
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
fn to_bytes(&self) -> [u8; 32] {
|
||||
let limb_bytes: Vec<[u8; 8]> = self.0.iter().map(|limb| u64::to_le_bytes(*limb)).collect();
|
||||
let mut result: [u8; 32] = [0 as u8; 32];
|
||||
let mut index = 0;
|
||||
limb_bytes.iter().for_each(|bytes| {
|
||||
for byte in bytes.iter() {
|
||||
result[index] = *byte;
|
||||
index += 1
|
||||
}
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(feature = "kzg")]
|
||||
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self> {
|
||||
let result = Self::from_raw([
|
||||
u64::from_le_bytes(bytes[0..8].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[8..16].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[16..24].try_into().unwrap()),
|
||||
u64::from_le_bytes(bytes[24..32].try_into().unwrap()),
|
||||
]);
|
||||
CtOption::new(result, Choice::from(1 as u8))
|
||||
}
|
||||
|
||||
/// Converts a 512-bit little endian integer into
|
||||
/// a `Fq` by reducing by the modulus.
|
||||
#[cfg(not(feature = "kzg"))]
|
||||
Reference in New Issue
Block a user