use miden_core::deferred::PrecompileError;
use super::{CurvePoint, CurveSpec, ShortWeierstrassSpec, short_weierstrass};
use crate::math::{k1_base::K1Base, k1_scalar::K1Scalar, uint::Limbs};
pub const SECP256K1_ID: miden_core::Felt = miden_core::Felt::new_unchecked(1);
pub const SECP256K1_GENERATOR_X: Limbs = [
0x16f8_1798,
0x59f2_815b,
0x2dce_28d9,
0x029b_fcdb,
0xce87_0b07,
0x55a0_6295,
0xf9dc_bbac,
0x79be_667e,
];
pub const SECP256K1_GENERATOR_Y: Limbs = [
0xfb10_d4b8,
0x9c47_d08f,
0xa685_5419,
0xfd17_b448,
0x0e11_08a8,
0x5da4_fbfc,
0x26a3_c465,
0x483a_da77,
];
#[derive(Debug, Default, Clone, Copy)]
pub struct Secp256k1;
impl CurveSpec for Secp256k1 {
const ID: miden_core::Felt = SECP256K1_ID;
type BaseField = K1Base;
type ScalarField = K1Scalar;
const GENERATOR_X: Limbs = SECP256K1_GENERATOR_X;
const GENERATOR_Y: Limbs = SECP256K1_GENERATOR_Y;
fn point_from_affine(x: Limbs, y: Limbs) -> Result<CurvePoint, PrecompileError> {
short_weierstrass::point_from_affine::<Self>(x, y)
}
fn add(lhs: CurvePoint, rhs: CurvePoint) -> Result<CurvePoint, PrecompileError> {
short_weierstrass::add::<Self>(lhs, rhs)
}
fn neg(point: CurvePoint) -> Result<CurvePoint, PrecompileError> {
Ok(short_weierstrass::neg::<Self>(point))
}
fn mul_scalar(point: CurvePoint, scalar: Limbs) -> Result<CurvePoint, PrecompileError> {
short_weierstrass::mul_scalar::<Self>(point, scalar)
}
}
impl ShortWeierstrassSpec for Secp256k1 {
const A: Limbs = [0; 8];
const B: Limbs = [7, 0, 0, 0, 0, 0, 0, 0];
}