17 releases (8 stable)

3.0.0 Oct 12, 2021
2.2.0 Sep 25, 2020
2.1.2 Aug 18, 2020
2.1.1 Jul 30, 2020
0.2.0 Jan 31, 2020

#30 in Cryptography

Download history 10986/week @ 2022-06-16 12460/week @ 2022-06-23 9873/week @ 2022-06-30 9940/week @ 2022-07-07 12648/week @ 2022-07-14 12985/week @ 2022-07-21 11090/week @ 2022-07-28 10703/week @ 2022-08-04 12540/week @ 2022-08-11 15114/week @ 2022-08-18 16946/week @ 2022-08-25 19037/week @ 2022-09-01 18708/week @ 2022-09-08 19024/week @ 2022-09-15 18362/week @ 2022-09-22 16819/week @ 2022-09-29

76,547 downloads per month
Used in 223 crates (12 directly)

MIT/Apache

49KB
797 lines

Build status dependency status

Zcash-flavored Ed25519 for use in Zebra.

Zcash uses Ed25519 for JoinSplit signatures with particular validation rules around edge cases in Ed25519 signatures. Ed25519, as specified in RFC8032, does not specify behaviour around these edge cases and so does not require conformant implementations to agree on whether a signature is valid. For most applications, these edge cases are irrelevant, but in Zcash, nodes must be able to reach consensus on which signatures would be valid, so these validation behaviors are consensus-critical.

Because the Ed25519 validation rules are consensus-critical for Zcash, Zebra requires an Ed25519 library that implements the Zcash-flavored validation rules specifically, and since it is unreasonable to expect an upstream dependency to maintain Zcash-specific behavior, this crate provides an Ed25519 implementation matching the Zcash consensus rules exactly.

However, this library may be of independent interest, as it implements ZIP215, a set of precisely specified validation rules for Ed25519 that make individual verification consistent with batch verification and are backwards-compatible with all existing Ed25519 signatures. Any non-Zcash users should use the ZIP215 rules:

ed25519-zebra = "3"

ZIP 215 and changes to Zcash-flavored Ed25519

Zcash Improvement Proposal 215 changes validation criteria for Ed25519 signatures in Zcash after its activation (currently scheduled for the Canopy network upgrade at block height 1046400). These changes remove the dependence on validation rules inherited from a specific point release of libsodium and make individual verification consistent with batch verification. More details and motivation are available in the text of ZIP215.

The 1.x series of this crate implements the legacy, pre-ZIP-215 validation criteria; the 2.x+ series of this crate implements the post-ZIP-215 validation criteria. Users (like Zebra or zcashd) who need to handle the upgrade can use both versions simultaneously using cargo renaming, e.g.,

ed25519-zebra-legacy = { package = "ed25519-zebra", version = "1" }
ed25519-zebra-zip215 = { package = "ed25519-zebra", version = "3" }

Example

use std::convert::TryFrom;
use rand::thread_rng;
use ed25519_zebra::*;

let msg = b"Zcash";

// Signer's context
let (vk_bytes, sig_bytes) = {
    // Generate a signing key and sign the message
    let sk = SigningKey::new(thread_rng());
    let sig = sk.sign(msg);

    // Types can be converted to raw byte arrays with From/Into
    let sig_bytes: [u8; 64] = sig.into();
    let vk_bytes: [u8; 32] = VerificationKey::from(&sk).into();

    (vk_bytes, sig_bytes)
};

// Verify the signature
assert!(
    VerificationKey::try_from(vk_bytes)
        .and_then(|vk| vk.verify(&sig_bytes.into(), msg))
        .is_ok()
);

License

ed25519-zebra is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT.

Dependencies

~2–2.6MB
~59K SLoC