Skip to content

Commit

Permalink
WIP unfinished changes
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Oct 16, 2024
1 parent 5c45e28 commit cb5ba68
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pczt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,68 @@
//! The Partially Created Zcash Transaction (PCZT) format.
//!
//! General flow for creating a shielded transaction:
//! - Create "unsigned transaction"
//! - In practice means deciding on the global parts of the transaction
//! - Collect each output
//! - Proofs can be created at this time
//! - Decide on an anchor
//! - All spends should use the same anchor for indistinguishability
//! - In a future transaction version, all spends will be required to do so
//! - Collect each spend
//! - Proofs can and should be created at this time
//! - Create proofs for each spend and output
//! - Data necessary for proofs can be stripped out of the format
//! - Collect proofs
//! - Distribute collected data to signers
//! - Signers must verify the transaction before signing, and reject if not satisfied.
//! - This is the no-turning-back point regarding spend authorization!
//! - Collect signatures
//! - Create binding signature
//! - The party that performs this does not need to be trusted, because each signer
//! has verified the transaction and signed it, so the bindingSig can only be
//! computed over the same data if a valid transaction is to be created.
//! - Extract final transaction
//!
//! Goal is to split up the parts of creating a transaction across distinct entities.
//! The entity roles roughly match BIP 174: Partially Signed Bitcoin Transaction Format.
//! - Creator
//! - Creates the base PCZT with no information about spends or outputs.
//! - Constructor
//! - Adds spends and outputs to the PCZT.
//! - Before any input or output may be added, the constructor must check the
//! PSBT_GLOBAL_TX_MODIFIABLE field. Inputs may only be added if the Inputs Modifiable
//! flag is True. Outputs may only be added if the Outputs Modifiable flag is True.
//! - A single entity is likely to be both a Creator and Constructor.
//! - IO Finalizer
//! - Sets the appropriate bits in PSBT_GLOBAL_TX_MODIFIABLE to 0. (TODO fix up)
//! - Inspects the inputs and outputs throughout the PCZT and picks a transaction
//! version that is compatible with all of them (or returns an error).
//! - Updates the various bsk values using the rcv information from spends and outputs.
//! - This can happen after each spend or output is added if they are added serially.
//! If spends and outputs are created in parallel, the IO Finalizer must act after
//! the Combiner.
//! - Updater
//! - Adds information necessary for subsequent entities to proceed, such as key paths
//! for signing spends.
//! - Redactor
//! - Removes information that is unnecessary for subsequent entities to proceed.
//! - This can be useful e.g. when creating a transaction that has inputs from multiple
//! independent Signers; each can receive a PCZT with just the information they need
//! to sign, but (e.g.) not the `alpha` values for other Signers.
//! - Prover
//! - Needs all private information for a single spend or output.
//! - In practice, the Updater that adds a given spend or output will either act as
//! the Prover themselves, or add the necessary data, offload to the Prover, and
//! then receive back the PCZT with private data stripped and proof added.
//! - Signer
//! - Needs the spend authorization randomizers to create signatures.
//! - Needs sufficient information to verify that the proof is over the correct data.
//! without needing to verify the proof itself.
//! - A Signer should only need to implement:
//! - Pedersen commitments using Jubjub arithmetic (for note and value commitments)
//! - BLAKE2b and BLAKE2s (and the various PRFs / CRHs they are used in)
//! - Nullifier check (using Jubjub arithmetic)
//! - KDF plus note decryption (AEAD_CHACHA20_POLY1305)
//! - SignatureHash algorithm
//! - Signatures (RedJubjub)
//! - A source of randomness.
Expand All @@ -34,6 +82,9 @@
//! the PCZT, with spendAuthSigs and bindingSig empty, and then enforcing equality.
//! - This is equivalent to BIP 147's equality definition (the partial transactions
//! must be identical).
//! - Spend Finalizer
//! - Currently unnecessary, but when shielded multisig is implemented, this would be the
//! entity that combines the separate signatures into a multisignature.
//! - Transaction Extractor
//! - Creates bindingSig and extracts the final transaction.
Expand Down
6 changes: 6 additions & 0 deletions pczt/src/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ pub(crate) struct Spend {
/// - After`zkproof` / `spend_auth_sig` has been set, this can be redacted.
pub(crate) alpha: Option<[u8; 32]>,

// TODO derivation path

// TODO FROST

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand Down Expand Up @@ -198,6 +202,8 @@ pub(crate) struct Output {
/// "None", to make the output unrecoverable from the chain by the sender.
pub(crate) ock: Option<[u8; 32]>,

// TODO derivation path

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand Down
6 changes: 6 additions & 0 deletions pczt/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ pub(crate) struct Spend {
/// - After`zkproof` / `spend_auth_sig` has been set, this can be redacted.
pub(crate) alpha: Option<[u8; 32]>,

// TODO derivation path

// TODO FROST

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand Down Expand Up @@ -182,6 +186,8 @@ pub(crate) struct Output {
/// "None", to make the output unrecoverable from the chain by the sender.
pub(crate) ock: Option<[u8; 32]>,

// TODO derivation path

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand Down
12 changes: 12 additions & 0 deletions pczt/src/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ pub(crate) struct Input {
pub(crate) value: u64,
pub(crate) script_pubkey: Vec<u8>,

/// A map from a pubkey to a signature created by it.
///
/// - Each entry is set by a Signer.
/// - These are required by the Spend Finalizer to assemble `script_sig`.
///
/// TODO: Decide on map key type.
pub(crate) signatures: BTreeMap<Vec<u8>, Vec<u8>>,

// TODO derivation path

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand All @@ -56,6 +66,8 @@ pub(crate) struct Output {
pub(crate) value: u64,
pub(crate) script_pubkey: Vec<u8>,

// TODO derivation path

pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}

Expand Down

0 comments on commit cb5ba68

Please sign in to comment.