Skip to main content

zebra_consensus/
lib.rs

1//! Implementation of Zcash consensus checks.
2//!
3//! More specifically, this crate implements *semantic* validity checks,
4//! as defined below.
5//!
6//! ## Verification levels.
7//!
8//! Zebra's implementation of the Zcash consensus rules is oriented
9//! around three telescoping notions of validity:
10//!
11//! 1. *Structural Validity*, or whether the format and structure of the
12//!    object are valid.  For instance, Sprout-on-BCTV14 proofs are not
13//!    allowed in version 4 transactions, and a transaction with a spend
14//!    or output description must include a binding signature.
15//!
16//! 2. *Semantic Validity*, or whether the object could potentially be
17//!    valid, depending on the chain state.  For instance, a transaction
18//!    that spends a UTXO must supply a valid unlock script; a shielded
19//!    transaction must have valid proofs, etc.
20//!
21//! 3. *Contextual Validity*, or whether a semantically valid
22//!    transaction is actually valid in the context of a particular
23//!    chain state.  For instance, a transaction that spends a
24//!    UTXO is only valid if the UTXO remains unspent; a
25//!    shielded transaction spending some note must reveal a nullifier
26//!    not already in the nullifier set, etc.
27//!
28//! *Structural validity* is enforced by the definitions of data
29//! structures in `zebra-chain`.  *Semantic validity* is enforced by the
30//! code in this crate.  *Contextual validity* is enforced in
31//! `zebra-state` when objects are committed to the chain state.
32
33#![doc(html_favicon_url = "https://zfnd.org/wp-content/uploads/2022/03/zebra-favicon-128.png")]
34#![doc(html_logo_url = "https://zfnd.org/wp-content/uploads/2022/03/zebra-icon.png")]
35#![doc(html_root_url = "https://docs.rs/zebra_consensus")]
36
37// Fuzzing switch: expose `block::check::equihash_solution_is_valid` to the
38// equihash fuzz harness. Private in normal builds; public only under `fuzzing`.
39#[cfg(not(feature = "fuzzing"))]
40mod block;
41#[cfg(feature = "fuzzing")]
42pub mod block;
43mod checkpoint;
44mod primitives;
45mod script;
46
47pub mod config;
48pub mod error;
49pub mod router;
50pub mod transaction;
51
52#[cfg(any(test, feature = "proptest-impl"))]
53pub use block::check::difficulty_is_valid;
54
55pub use block::{subsidy::funding_stream_address, Request, VerifyBlockError, MAX_BLOCK_SIGOPS};
56pub use checkpoint::{VerifyCheckpointError, MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP};
57pub use config::Config;
58pub use error::BlockError;
59pub use primitives::{
60    ed25519, groth16, halo2, redjubjub, redpallas, sapling::prover as sapling_prover,
61};
62pub use router::RouterError;
63
64/// A boxed [`std::error::Error`].
65pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;