Skip to main content

Crate goldilocks_crypto

Crate goldilocks_crypto 

Source
Expand description

§Goldilocks Crypto

Rust implementation of ECgFp5 elliptic curve and Schnorr signatures over the Goldilocks field.

§⚠️ Security Warning

This library has NOT been audited and is provided as-is. Use with caution.

  • Prototype implementation focused on correctness
  • Not security audited - do not use in production without proper security review
  • While the implementation appears to work correctly, cryptographic software requires careful auditing
  • This is an open-source contribution and not an official Lighter Protocol library
  • Use at your own risk

§Overview

This crate provides elliptic curve cryptography primitives specifically designed for the Goldilocks field, including:

  • ECgFp5 Elliptic Curve: Point operations over the Fp5 extension field
  • Schnorr Signatures: Signature generation and verification using Poseidon2 hashing
  • Scalar Field: Efficient scalar operations for private keys and nonces
  • Point Arithmetic: Addition, multiplication, encoding, and decoding

§Dependencies

This crate depends on poseidon-hash for:

  • Goldilocks field arithmetic
  • Poseidon2 hash function
  • Fp5 extension field operations

§Example

use goldilocks_crypto::{ScalarField, Point, sign, verify_signature};

// Generate a random private key
let private_key = ScalarField::sample_crypto();
let private_key_bytes = private_key.to_bytes_le();

// Derive public key
let public_key = Point::generator().mul(&private_key);
let public_key_bytes = public_key.encode().to_bytes_le();

// Sign a message (nonce is generated internally)
let message = [0u8; 40];
let signature = sign(&private_key_bytes, &message).unwrap();

// Verify signature
let is_valid = verify_signature(&signature, &message, &public_key_bytes).unwrap();
assert!(is_valid);

Re-exports§

pub use scalar_field::ScalarField;
pub use schnorr::sign;
pub use schnorr::sign_with_nonce;
pub use schnorr::verify_signature;
pub use schnorr::validate_public_key;
pub use schnorr::sign_hashed_message;
pub use schnorr::Point;
pub use schnorr::AffinePoint;
pub use batch_verify::batch_verify;
pub use signature::Signature;
pub use keypair::KeyPair;

Modules§

batch_verify
Batch signature verification for improved throughput
keypair
KeyPair — a high-level wrapper combining a private scalar and its public key.
scalar_field
schnorr
signature
Signature — a typed wrapper around the raw 80-byte Schnorr signature.

Structs§

Fp5Element
Fp5 extension field element.
Goldilocks
Goldilocks field element.

Enums§

CryptoError
Errors that can occur during cryptographic operations.

Type Aliases§

Result
Result type for cryptographic operations.
WeierstrassPoint