Skip to content

zfedoran/brine-ed25519

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

brine-ed25519

license crates.io

A fast, low-overhead, Ed25519 signature verification library for the Solana SVM.


⚡ Performance

Operation Feature flag CU (Approx.) Improvement
verify::<Sha512> default ~12,549 baseline
verify::<FastSha512> fast-sha512 ~12,252 -297 CU (~2.4%)

These values are measured inside the Solana SVM via test-program/ and depend on the message size. FastSha512 is available behind the fast-sha512 feature flag.


Features

  • Verifies Ed25519 signatures within the program, at run-time
  • Fully supports dynamically generated messages
  • No extra lamports required

Signature verification roughly follows RFC 8032


Quick Start

use brine_ed25519::*;
use brine_ed25519::hasher::Sha512;

let pubkey: [u8; 32] = [...];
let sig: [u8; 64] = [...];

// Single message
verify::<Sha512>(&pubkey, &sig, &[b"hello world"])?;

// Vectored message
verify::<Sha512>(&pubkey, &sig, &[b"hello", b" ", b"world"])?;

// Prehashed challenge (precomputed H(R || A || M))
verify_prehashed(&pubkey, &sig, &challenge)?;

Custom hash implementations are supported via the Hasher trait.

To opt into the faster SHA-512 path:

brine-ed25519 = { version = "0.6", features = ["fast-sha512"] }
use brine_ed25519::hasher::FastSha512;

verify::<FastSha512>(&pubkey, &sig, &[b"hello world"])?;

But why?

Q: Why not use the native Ed25519 program?

A: Solana does provide a Ed25519 pre-compile program for signature verification—but it comes with several downsides:

  • Charges an extra 5000 lamports per signature
  • Consumes additional transaction data
  • Requires the instruction_sysvar to be passed into your program
  • Only verifies signatures on data hardcoded into the transaction
  • Cannot be used with dynamically generated data inside your program
  • Has cumbersome devex

This crate, brine-ed25519, solves all of that.


Security

The implementation was pulled from code-vm (MIT-licensed), which was written and maintained by the author of this crate.

Big thanks to all reviewers for helpful suggestions and CU reductions!

Note

This crate has had multiple rounds of optimizations since the audits above. If you prefer the to use the audited version, use v0.2.0 or lower, but note that the CU is more than double.


Contributing

Contributions are welcome! Please open issues or PRs on the GitHub repo.

About

Ed25519 signature verification for Solana programs

Resources

License

Stars

35 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages