2021-01-20 12:30:35 -08:00
|
|
|
//! Structs related to bundles of Orchard actions.
|
|
|
|
|
2021-02-24 12:07:49 -08:00
|
|
|
use nonempty::NonEmpty;
|
|
|
|
|
2021-01-20 12:30:35 -08:00
|
|
|
use crate::{
|
|
|
|
circuit::Proof,
|
2021-04-19 15:26:58 -07:00
|
|
|
note::{EncryptedNote, ExtractedNoteCommitment, Nullifier},
|
2021-01-20 12:35:54 -08:00
|
|
|
primitives::redpallas::{self, Binding, SpendAuth},
|
2021-01-20 12:30:35 -08:00
|
|
|
tree::Anchor,
|
|
|
|
value::{ValueCommitment, ValueSum},
|
|
|
|
};
|
|
|
|
|
|
|
|
/// An action applied to the global ledger.
|
|
|
|
///
|
|
|
|
/// Externally, this both creates a note (adding a commitment to the global ledger),
|
|
|
|
/// and consumes some note created prior to this action (adding a nullifier to the
|
|
|
|
/// global ledger).
|
|
|
|
///
|
|
|
|
/// Internally, this may both consume a note and create a note, or it may do only one of
|
|
|
|
/// the two. TODO: Determine which is more efficient (circuit size vs bundle size).
|
|
|
|
#[derive(Debug)]
|
2021-03-03 09:35:25 -08:00
|
|
|
pub struct Action<T> {
|
2021-01-20 12:30:35 -08:00
|
|
|
/// The nullifier of the note being spent.
|
|
|
|
nf_old: Nullifier,
|
|
|
|
/// The randomized verification key for the note being spent.
|
2021-01-20 12:35:54 -08:00
|
|
|
rk: redpallas::VerificationKey<SpendAuth>,
|
2021-01-20 12:30:35 -08:00
|
|
|
/// A commitment to the new note being created.
|
2021-04-19 15:26:58 -07:00
|
|
|
cm_new: ExtractedNoteCommitment,
|
2021-01-20 12:30:35 -08:00
|
|
|
/// The encrypted output note.
|
|
|
|
encrypted_note: EncryptedNote,
|
|
|
|
/// A commitment to the net value created or consumed by this action.
|
|
|
|
cv_net: ValueCommitment,
|
2021-03-03 09:35:25 -08:00
|
|
|
/// The authorization for this action.
|
|
|
|
authorization: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Orchard-specific flags.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Flags {
|
|
|
|
spends_enabled: bool,
|
|
|
|
outputs_enabled: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Defines the authorization type of an Orchard bundle.
|
|
|
|
pub trait Authorization {
|
|
|
|
/// The authorization type of an Orchard action.
|
|
|
|
type SpendAuth;
|
2021-01-20 12:30:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A bundle of actions to be applied to the ledger.
|
|
|
|
#[derive(Debug)]
|
2021-03-03 09:35:25 -08:00
|
|
|
pub struct Bundle<T: Authorization> {
|
|
|
|
actions: NonEmpty<Action<T::SpendAuth>>,
|
|
|
|
flag: Flags,
|
2021-01-21 04:16:50 -08:00
|
|
|
value_balance: ValueSum,
|
2021-03-03 09:35:25 -08:00
|
|
|
anchor: Anchor,
|
|
|
|
authorization: T,
|
2021-01-20 12:30:35 -08:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:35:25 -08:00
|
|
|
impl<T: Authorization> Bundle<T> {
|
2021-01-20 12:30:35 -08:00
|
|
|
/// Computes a commitment to the effects of this bundle, suitable for inclusion within
|
|
|
|
/// a transaction ID.
|
|
|
|
pub fn commitment(&self) -> BundleCommitment {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:35:25 -08:00
|
|
|
/// Marker for an unauthorized bundle with no proofs or signatures.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Unauthorized {}
|
|
|
|
|
|
|
|
impl Authorization for Unauthorized {
|
|
|
|
type SpendAuth = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Authorizing data for a bundle of actions, ready to be committed to the ledger.
|
2021-01-20 12:30:35 -08:00
|
|
|
#[derive(Debug)]
|
2021-03-03 09:35:25 -08:00
|
|
|
pub struct Authorized {
|
2021-02-24 12:01:16 -08:00
|
|
|
proof: Proof,
|
2021-01-20 12:35:54 -08:00
|
|
|
binding_signature: redpallas::Signature<Binding>,
|
2021-01-20 12:30:35 -08:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:35:25 -08:00
|
|
|
impl Authorization for Authorized {
|
|
|
|
type SpendAuth = redpallas::Signature<SpendAuth>;
|
|
|
|
}
|
2021-01-20 12:30:35 -08:00
|
|
|
|
2021-03-03 09:35:25 -08:00
|
|
|
impl Bundle<Authorized> {
|
2021-01-20 12:30:35 -08:00
|
|
|
/// Computes a commitment to the authorizing data within for this bundle.
|
|
|
|
///
|
2021-03-03 09:35:25 -08:00
|
|
|
/// This together with `Bundle::commitment` bind the entire bundle.
|
2021-01-20 12:30:35 -08:00
|
|
|
pub fn authorizing_commitment(&self) -> BundleAuthorizingCommitment {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A commitment to a bundle of actions.
|
|
|
|
///
|
|
|
|
/// This commitment is non-malleable, in the sense that a bundle's commitment will only
|
|
|
|
/// change if the effects of the bundle are altered.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BundleCommitment;
|
|
|
|
|
|
|
|
/// A commitment to the authorizing data within a bundle of actions.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BundleAuthorizingCommitment;
|