A fast, low-overhead, Ed25519 signature verification library for the Solana SVM.
| 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.
- Verifies Ed25519 signatures within the program, at run-time
- Fully supports dynamically generated messages
- No extra lamports required
Signature verification roughly follows RFC 8032
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"])?;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_sysvarto 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.
The implementation was pulled from code-vm (MIT-licensed), which was written and maintained by the author of this crate.
- Reviewed as part of the code-vm audit by OtterSec
- Peer reviewed by @stegaBOB and @deanmlittle
- Many CU optimizations by @deanmlittle
- Small optimizations by @crypt0miester
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.
Contributions are welcome! Please open issues or PRs on the GitHub repo.