Skip to content

Commit

Permalink
Make JoinSplit descriptions generic over the proof system.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Nov 28, 2019
1 parent 2f3a7a0 commit 6950237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
9 changes: 5 additions & 4 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ mod transparent;
mod tests;

pub use hash::TransactionHash;
pub use joinsplit::{JoinSplitBctv14, JoinSplitGroth16, LegacyJoinSplitData, SaplingJoinSplitData};
pub use joinsplit::{JoinSplit, JoinSplitData, SproutInputNoteData, SproutOutputNoteData};
pub use shielded_data::{OutputDescription, ShieldedData, SpendDescription};
pub use transparent::{OutPoint, TransparentInput, TransparentOutput};

use crate::proofs::{Bctv14Proof, Groth16Proof};
use crate::types::{BlockHeight, LockTime};

/// A Zcash transaction.
Expand Down Expand Up @@ -49,7 +50,7 @@ pub enum Transaction {
/// chain.
lock_time: LockTime,
/// The JoinSplit data for this transaction, if any.
joinsplit_data: Option<LegacyJoinSplitData>,
joinsplit_data: Option<JoinSplitData<Bctv14Proof>>,
},
/// An Overwinter transaction (`version = 3`).
V3 {
Expand All @@ -63,7 +64,7 @@ pub enum Transaction {
/// The latest block height that this transaction can be added to the chain.
expiry_height: BlockHeight,
/// The JoinSplit data for this transaction, if any.
joinsplit_data: Option<LegacyJoinSplitData>,
joinsplit_data: Option<JoinSplitData<Bctv14Proof>>,
},
/// A Sapling transaction (`version = 4`).
V4 {
Expand All @@ -82,6 +83,6 @@ pub enum Transaction {
/// The shielded data for this transaction, if any.
shielded_data: Option<ShieldedData>,
/// The JoinSplit data for this transaction, if any.
joinsplit_data: Option<SaplingJoinSplitData>,
joinsplit_data: Option<JoinSplitData<Groth16Proof>>,
},
}
49 changes: 9 additions & 40 deletions zebra-chain/src/transaction/joinsplit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::proofs::ZkSnarkProof;

/// Describes input notes to a Sprout transaction.
///
/// The [protocol specification §7.2][ps] describes these fields as being encoded
Expand Down Expand Up @@ -41,12 +43,11 @@ pub struct SproutOutputNoteData {
pub enc_ciphertext: Vec<u8>,
}

/// A _JoinSplit Description_ using BCTV14 proofs, as described in [protocol
/// specification §7.2][ps].
/// A _JoinSplit Description_, as described in [protocol specification §7.2][ps].
///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#joinsplitencoding
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct JoinSplitBctv14 {
pub struct JoinSplit<P: ZkSnarkProof> {
/// A value that the JoinSplit transfer removes from the transparent value
/// pool.
///
Expand All @@ -57,64 +58,32 @@ pub struct JoinSplitBctv14 {
///
/// XXX refine to an Amount
vpub_new: u64,

/// A root of the Sprout note commitment tree at some block height in the
/// past, or the root produced by a previous JoinSplit transfer in this
/// transaction.
///
/// XXX refine type
anchor: [u8; 32],

/// An X25519 public key.
///
/// XXX refine to an x25519-dalek type?
ephemeral_key: [u8; 32],

/// A 256-bit seed that must be chosen independently at random for each
/// JoinSplit description.
random_seed: [u8; 32],

/// A sequence of input notes for this transaction.
input_notes: Vec<SproutInputNoteData>,

/// A sequence of output notes for this transaction.
output_notes: Vec<SproutOutputNoteData>,

/// A ZK JoinSplit proof using BCTV14.
///
/// XXX refine type
/// XXX this should be a [u8; 296] but trait impls.
zkproof: Vec<u8>,
}

/// A _JoinSplit Description_ using Groth16 proofs, as described in [protocol
/// specification §7.2][ps].
///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#joinsplitencoding
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct JoinSplitGroth16 {
// XXX use generic's
/// A ZK JoinSplit proof, either a [`Groth16Proof`] or a [`Bctv14Proof`].
zkproof: P,
}

/// Pre-Sapling JoinSplit data using Sprout-on-BCTV14 proofs.
/// A bundle of JoinSplit descriptions and signature data.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LegacyJoinSplitData {
pub struct JoinSplitData<P: ZkSnarkProof> {
/// A sequence of JoinSplit descriptions using BCTV14 proofs.
pub joinsplits: Vec<JoinSplitBctv14>,
/// The public key for the JoinSplit signature.
// XXX refine to a Zcash-flavored Ed25519 pubkey.
pub pub_key: [u8; 32],
/// The JoinSplit signature.
// XXX refine to a Zcash-flavored Ed25519 signature.
// for now it's [u64; 8] rather than [u8; 64] to get trait impls
pub sig: [u64; 8],
}

/// Post-Sapling JoinSplit data using Sprout-on-Groth16 proofs.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SaplingJoinSplitData {
/// A sequence of JoinSplit descriptions using Groth16 proofs.
pub joinsplits: Vec<JoinSplitGroth16>,
pub joinsplits: Vec<JoinSplit<P>>,
/// The public key for the JoinSplit signature.
// XXX refine to a Zcash-flavored Ed25519 pubkey.
pub pub_key: [u8; 32],
Expand Down

0 comments on commit 6950237

Please sign in to comment.