ECDSA, Schnorr & EdDSA Signatures

All three signature schemes follow a similar pattern with a Cairo struct containing the signature data and hints for efficient verification. Garaga provides tooling in Python/Rust/JavaScript to generate the full expected Cairo struct given signature information.

All signature verification schemes work with all Supported Elliptic Curves in Garaga (except EdDSA which is specific to Ed25519), using the corresponding curve identifier.

Cairo Verification Functions

Verification functions take the public key as a separate parameter:

  • is_valid_ecdsa_signature_assuming_hash(signature, public_key, curve_id) -> bool

  • is_valid_schnorr_signature_assuming_hash(signature, public_key, curve_id) -> bool

  • is_valid_eddsa_signature(signature, Py_twisted) -> bool

Public Key Handling

The public key is always passed as a separate parameter to the verification function. This allows you to:

  1. Hardcode the public key in your contract if it's known at compile time

  2. Provide the public key dynamically at runtime

When generating calldata with the SDK, use the prepend_public_key parameter:

  • prepend_public_key=True (default): The public key is included in the serialized calldata, allowing you to deserialize both the signature and public key from the same array

  • prepend_public_key=False: Only the signature is serialized; you must provide the public key separately (useful when the public key is hardcoded in your contract)


ECDSA Signature Verification

Cairo Structs

Usage Example

Calldata Generation


Schnorr Signature Verification

Cairo Structs

BIP340 Requirement: The public key's y-coordinate must be even. The verification function will return false if the public key has an odd y-coordinate.

Usage Example

Calldata Generation


EdDSA Signature Verification (Ed25519)

EdDSA signatures use the Ed25519 curve following RFC 8032. The implementation explicitly rejects small-order points to prevent key-compromise and signature-malleability attacks.

Cairo Structs

Note: EdDSA takes the raw message bytes, not a hash. The verification function computes SHA-512(R || A || msg) internally as per RFC 8032.

Usage Example

Calldata Generation


Curve Identifiers

Curve ID
Value
Notes

BN254

0

-

BLS12_381

1

-

SECP256K1

2

Bitcoin/Ethereum

SECP256R1

3

P-256/NIST

ED25519

4

Only for EdDSA

GRUMPKIN

5

-

Last updated

Was this helpful?