pub trait CurveSpec: Sized + 'static {
type BaseField: UintSpec;
type ScalarField: UintSpec;
const ID: Felt;
const GENERATOR_X: Limbs;
const GENERATOR_Y: Limbs;
// Required methods
fn point_from_affine(
x: Limbs,
y: Limbs,
) -> Result<CurvePoint, PrecompileError>;
fn add(
lhs: CurvePoint,
rhs: CurvePoint,
) -> Result<CurvePoint, PrecompileError>;
fn neg(point: CurvePoint) -> Result<CurvePoint, PrecompileError>;
// Provided methods
fn generator() -> CurvePoint { ... }
fn canonical_point(point: CurvePoint) -> Result<CurvePoint, PrecompileError> { ... }
fn is_on_curve(point: &CurvePoint) -> bool { ... }
fn sub(
lhs: CurvePoint,
rhs: CurvePoint,
) -> Result<CurvePoint, PrecompileError> { ... }
fn mul_scalar(
point: CurvePoint,
scalar: Limbs,
) -> Result<CurvePoint, PrecompileError> { ... }
}Expand description
Spec for one fixed curve.
This trait intentionally describes only the affine encoding and group operations needed by the
precompile dispatcher. It is curve-model-generic, not short-Weierstrass-specific;
curve-model-specific equations, coefficients, and formulas live behind narrower extension traits
such as ShortWeierstrassSpec.
Trust contract:
Self::point_from_affineandSelf::canonical_pointare checked boundary helpers. They validate and canonicalize raw affine coordinates before aCurvePointbecomes trusted.Self::add,Self::neg,Self::sub, andSelf::mul_scalarare trusted internal operations. Their point inputs must already be canonical valid points obtained from checked boundaries, canonical curveVALUEnodes, or previous curve operations.- Violating these preconditions is not memory-unsafe, but formulas may return invalid or
nonsensical arithmetic results, or fail with
InvalidPayload.
Required Associated Constants§
Sourceconst ID: Felt
const ID: Felt
Stable local curve selector used by host-side metadata.
Deferred curve VALUE tags carry fixed VM-owned group pointers, while operation tags use
zero immediates.
Sourceconst GENERATOR_X: Limbs
const GENERATOR_X: Limbs
Conventional generator x-coordinate, little-endian u32 limbs.
Sourceconst GENERATOR_Y: Limbs
const GENERATOR_Y: Limbs
Conventional generator y-coordinate, little-endian u32 limbs.
Required Associated Types§
Sourcetype ScalarField: UintSpec
type ScalarField: UintSpec
Scalar field associated with this curve.
Required Methods§
Sourcefn point_from_affine(x: Limbs, y: Limbs) -> Result<CurvePoint, PrecompileError>
fn point_from_affine(x: Limbs, y: Limbs) -> Result<CurvePoint, PrecompileError>
Checked boundary helper that constructs this curve’s canonical point from affine coordinates.
This is where raw affine limbs become a trusted CurvePoint. Implementations must
validate that x and y are canonical base-field elements and satisfy the curve
equation. They should also canonicalize any model-specific identity representation to
CurvePoint::Identity before the point is re-encoded as a graph VALUE node.
Sourcefn add(lhs: CurvePoint, rhs: CurvePoint) -> Result<CurvePoint, PrecompileError>
fn add(lhs: CurvePoint, rhs: CurvePoint) -> Result<CurvePoint, PrecompileError>
Trusted internal operation that adds two canonical valid points on this curve.
Preconditions: both operands must have come from Self::point_from_affine,
Self::canonical_point, a canonical curve VALUE node, or previous curve operations.
Release builds do not revalidate arbitrary coordinates before applying the curve formula.
Violating this contract is not memory-unsafe, but may produce invalid or nonsensical
results, or fail with InvalidPayload.
Sourcefn neg(point: CurvePoint) -> Result<CurvePoint, PrecompileError>
fn neg(point: CurvePoint) -> Result<CurvePoint, PrecompileError>
Trusted internal operation that negates a canonical valid point on this curve.
Precondition: point must have come from Self::point_from_affine,
Self::canonical_point, a canonical curve VALUE node, or previous curve operations.
Release builds do not revalidate arbitrary coordinates before applying the curve formula.
Violating this contract is not memory-unsafe, but may produce invalid or nonsensical
results, or fail with InvalidPayload.
Provided Methods§
Sourcefn generator() -> CurvePoint
fn generator() -> CurvePoint
Returns this curve’s conventional generator point.
Sourcefn canonical_point(point: CurvePoint) -> Result<CurvePoint, PrecompileError>
fn canonical_point(point: CurvePoint) -> Result<CurvePoint, PrecompileError>
Checked boundary helper that returns the canonical representation of point.
Affine inputs are revalidated through Self::point_from_affine; identity is accepted as
the already-canonical identity. Arithmetic methods below assume their inputs already
came from checked graph nodes or previous curve operations.
Sourcefn is_on_curve(point: &CurvePoint) -> bool
fn is_on_curve(point: &CurvePoint) -> bool
Returns whether point is a valid point on this curve.
Sourcefn sub(lhs: CurvePoint, rhs: CurvePoint) -> Result<CurvePoint, PrecompileError>
fn sub(lhs: CurvePoint, rhs: CurvePoint) -> Result<CurvePoint, PrecompileError>
Trusted internal operation that subtracts two canonical valid points on this curve.
Preconditions are the same as Self::add and Self::neg: operands must already be
canonical valid points from checked boundaries, canonical curve VALUE nodes, or previous
curve operations. Violating this contract is not memory-unsafe, but may produce invalid or
nonsensical results, or fail with InvalidPayload.
Sourcefn mul_scalar(
point: CurvePoint,
scalar: Limbs,
) -> Result<CurvePoint, PrecompileError>
fn mul_scalar( point: CurvePoint, scalar: Limbs, ) -> Result<CurvePoint, PrecompileError>
Trusted internal operation that multiplies a canonical valid point by a canonical scalar.
Precondition: point must already be a canonical valid point from a checked boundary,
canonical curve VALUE node, or previous curve operation. scalar must be canonical in
this curve’s scalar field. Violating the point precondition is not memory-unsafe, but may
produce invalid or nonsensical results, or fail with InvalidPayload.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".