A trait for interacting with Secp2561 curves. Provides operations needed to work with Secp256k1 and Secp256r1 elliptic curves. It includes methods for accessing curve parameters and creating curve points.

Signature

pub trait Secp256Trait

Examples

use starknet::secp256k1::Secp256k1Point;
use starknet::secp256_trait::Secp256Trait;
use starknet::SyscallResultTrait;

assert!(
    Secp256Trait::::get_curve_size() == 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141,
);

let generator = Secp256Trait::::get_generator_point();

let generator = Secp256Trait::::secp256_ec_new_syscall(
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8,
)
.unwrap_syscall();

let random_point = Secp256Trait::::secp256_ec_get_point_from_x_syscall(
0x4aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff3, true,
);

Trait functions

get_curve_size

Returns the order (size) of the curve’s underlying field. This is the number of points on the curve, also known as the curve order.

Signature

fn get_curve_size() -> u256

get_generator_point

Returns the generator point (G) for the curve. The generator point is a standard base point on the curve from which other points can be generated through scalar multiplication.

Signature

fn get_generator_point() -> Secp256Point

secp256_ec_new_syscall

Creates a new curve point from its x and y coordinates. Returns None if the provided coordinates don’t represent a valid point on the curve.

Signature

fn secp256_ec_new_syscall(
    x: u256, y: u256,
) -> Result, Array>

secp256_ec_get_point_from_x_syscall

Creates a curve point on the curve given its x-coordinate and y-parity.

Arguments

  • x - The x coordinate of the point
  • y_parity - If true, choose the odd y value; if false, choose the even y value

Returns

Returns Some(point) if a point exists with the given x coordinate, None otherwise.

Signature

fn secp256_ec_get_point_from_x_syscall(
    x: u256, y_parity: bool,
) -> Result, Array>