chain: extract sprout code into sprout module.
This commit is contained in:
parent
e06f59ee21
commit
312c66264a
|
|
@ -1,4 +1,3 @@
|
|||
//! Address types.
|
||||
|
||||
pub mod sprout;
|
||||
pub mod transparent;
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
//! Note and value commitments and associated types.
|
||||
|
||||
pub mod sprout;
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
//! Key types.
|
||||
|
||||
pub mod sprout;
|
||||
pub mod transparent;
|
||||
|
|
|
|||
|
|
@ -14,11 +14,8 @@ extern crate serde;
|
|||
mod merkle_tree;
|
||||
|
||||
pub mod addresses;
|
||||
pub mod commitments;
|
||||
pub mod keys;
|
||||
pub mod notes;
|
||||
pub mod treestate;
|
||||
pub mod types;
|
||||
|
||||
pub mod amount;
|
||||
pub mod block;
|
||||
|
|
|
|||
|
|
@ -3,5 +3,3 @@
|
|||
#[cfg(test)]
|
||||
mod arbitrary;
|
||||
pub mod memo;
|
||||
|
||||
pub mod sprout;
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
//! Sprout-related functionality.
|
||||
|
||||
pub mod address;
|
||||
pub mod commitment;
|
||||
pub mod keys;
|
||||
pub mod note;
|
||||
pub mod tree;
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ use std::{fmt, io};
|
|||
use proptest::{arbitrary::Arbitrary, array, prelude::*};
|
||||
|
||||
use crate::{
|
||||
keys::sprout,
|
||||
parameters::Network,
|
||||
serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize},
|
||||
};
|
||||
|
||||
use super::keys;
|
||||
|
||||
/// Magic numbers used to identify what networks Sprout Shielded
|
||||
/// Addresses are associated with.
|
||||
mod magics {
|
||||
|
|
@ -24,8 +25,8 @@ mod magics {
|
|||
#[derive(Copy, Clone)]
|
||||
pub struct SproutShieldedAddress {
|
||||
network: Network,
|
||||
paying_key: sprout::PayingKey,
|
||||
transmission_key: sprout::TransmissionKey,
|
||||
paying_key: keys::PayingKey,
|
||||
transmission_key: keys::TransmissionKey,
|
||||
}
|
||||
|
||||
impl fmt::Debug for SproutShieldedAddress {
|
||||
|
|
@ -80,8 +81,8 @@ impl ZcashDeserialize for SproutShieldedAddress {
|
|||
|
||||
Ok(SproutShieldedAddress {
|
||||
network,
|
||||
paying_key: sprout::PayingKey(reader.read_32_bytes()?),
|
||||
transmission_key: sprout::TransmissionKey::from(reader.read_32_bytes()?),
|
||||
paying_key: keys::PayingKey(reader.read_32_bytes()?),
|
||||
transmission_key: keys::TransmissionKey::from(reader.read_32_bytes()?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -121,8 +122,8 @@ impl Arbitrary for SproutShieldedAddress {
|
|||
)
|
||||
.prop_map(|(network, paying_key_bytes, transmission_key_bytes)| Self {
|
||||
network,
|
||||
paying_key: sprout::PayingKey(paying_key_bytes),
|
||||
transmission_key: sprout::TransmissionKey::from(transmission_key_bytes),
|
||||
paying_key: keys::PayingKey(paying_key_bytes),
|
||||
transmission_key: keys::TransmissionKey::from(transmission_key_bytes),
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::notes::sprout::Note;
|
||||
use super::note::Note;
|
||||
|
||||
/// The randomness used in the Pedersen Hash for note commitment.
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
|
@ -6,15 +6,18 @@
|
|||
#[cfg(test)]
|
||||
mod arbitrary;
|
||||
mod ciphertexts;
|
||||
mod mac;
|
||||
mod nullifiers;
|
||||
|
||||
use crate::{
|
||||
amount::{Amount, NonNegative},
|
||||
commitments::sprout::CommitmentRandomness,
|
||||
keys::sprout::PayingKey,
|
||||
notes::memo::Memo,
|
||||
};
|
||||
|
||||
use super::{commitment::CommitmentRandomness, keys::PayingKey};
|
||||
|
||||
pub use mac::MAC;
|
||||
|
||||
pub use ciphertexts::EncryptedCiphertext;
|
||||
|
||||
pub use nullifiers::{Nullifier, NullifierSeed};
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
use proptest::{arbitrary::any, collection::vec, prelude::*};
|
||||
|
||||
use crate::notes::sprout;
|
||||
|
||||
impl Arbitrary for sprout::EncryptedCiphertext {
|
||||
impl Arbitrary for super::EncryptedCiphertext {
|
||||
type Parameters = ();
|
||||
|
||||
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
//! Newtype wrappers for primitive data types with semantic meaning.
|
||||
#![allow(clippy::unit_arg)]
|
||||
use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
use std::io::{self, Read};
|
||||
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::keys::sprout::SpendingKey;
|
||||
use super::super::keys::SpendingKey;
|
||||
|
||||
/// PRF^nf is used to derive a Sprout nullifer from the receiver's
|
||||
/// spending key a_sk and a nullifier seed ρ, instantiated using the
|
||||
|
|
@ -2,9 +2,8 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::{
|
||||
amount::{Amount, NonNegative},
|
||||
notes::sprout,
|
||||
sprout,
|
||||
primitives::{ed25519, x25519, ZkSnarkProof},
|
||||
treestate,
|
||||
};
|
||||
|
||||
/// A _JoinSplit Description_, as described in [protocol specification §7.2][ps].
|
||||
|
|
@ -22,25 +21,25 @@ pub struct JoinSplit<P: ZkSnarkProof> {
|
|||
/// 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.
|
||||
pub anchor: treestate::sprout::NoteTreeRootHash,
|
||||
pub anchor: sprout::tree::NoteTreeRootHash,
|
||||
/// A nullifier for the input notes.
|
||||
pub nullifiers: [crate::notes::sprout::Nullifier; 2],
|
||||
pub nullifiers: [sprout::note::Nullifier; 2],
|
||||
/// A note commitment for this output note.
|
||||
pub commitments: [crate::commitments::sprout::NoteCommitment; 2],
|
||||
pub commitments: [sprout::commitment::NoteCommitment; 2],
|
||||
/// An X25519 public key.
|
||||
pub ephemeral_key: x25519::PublicKey,
|
||||
/// A 256-bit seed that must be chosen independently at random for each
|
||||
/// JoinSplit description.
|
||||
pub random_seed: [u8; 32],
|
||||
/// A message authentication tag.
|
||||
pub vmacs: [crate::types::MAC; 2],
|
||||
pub vmacs: [sprout::note::MAC; 2],
|
||||
/// A ZK JoinSplit proof, either a
|
||||
/// [`Groth16Proof`](crate::primitives::Groth16Proof) or a
|
||||
/// [`Bctv14Proof`](crate::primitives::Bctv14Proof).
|
||||
#[serde(bound(serialize = "P: ZkSnarkProof", deserialize = "P: ZkSnarkProof"))]
|
||||
pub zkproof: P,
|
||||
/// A ciphertext component for this output note.
|
||||
pub enc_ciphertexts: [sprout::EncryptedCiphertext; 2],
|
||||
pub enc_ciphertexts: [sprout::note::EncryptedCiphertext; 2],
|
||||
}
|
||||
|
||||
// Because x25519_dalek::PublicKey does not impl PartialEq
|
||||
|
|
|
|||
|
|
@ -9,12 +9,11 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
commitments, notes,
|
||||
primitives::{Script, ZkSnarkProof},
|
||||
serialization::{
|
||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||
},
|
||||
treestate, types,
|
||||
sprout,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
|
@ -276,25 +275,25 @@ impl<P: ZkSnarkProof> ZcashDeserialize for JoinSplit<P> {
|
|||
Ok(JoinSplit::<P> {
|
||||
vpub_old: reader.read_u64::<LittleEndian>()?.try_into()?,
|
||||
vpub_new: reader.read_u64::<LittleEndian>()?.try_into()?,
|
||||
anchor: treestate::sprout::NoteTreeRootHash::from(reader.read_32_bytes()?),
|
||||
anchor: sprout::tree::NoteTreeRootHash::from(reader.read_32_bytes()?),
|
||||
nullifiers: [
|
||||
reader.read_32_bytes()?.into(),
|
||||
reader.read_32_bytes()?.into(),
|
||||
],
|
||||
commitments: [
|
||||
commitments::sprout::NoteCommitment::from(reader.read_32_bytes()?),
|
||||
commitments::sprout::NoteCommitment::from(reader.read_32_bytes()?),
|
||||
sprout::commitment::NoteCommitment::from(reader.read_32_bytes()?),
|
||||
sprout::commitment::NoteCommitment::from(reader.read_32_bytes()?),
|
||||
],
|
||||
ephemeral_key: x25519_dalek::PublicKey::from(reader.read_32_bytes()?),
|
||||
random_seed: reader.read_32_bytes()?,
|
||||
vmacs: [
|
||||
types::MAC::zcash_deserialize(&mut reader)?,
|
||||
types::MAC::zcash_deserialize(&mut reader)?,
|
||||
sprout::note::MAC::zcash_deserialize(&mut reader)?,
|
||||
sprout::note::MAC::zcash_deserialize(&mut reader)?,
|
||||
],
|
||||
zkproof: P::zcash_deserialize(&mut reader)?,
|
||||
enc_ciphertexts: [
|
||||
notes::sprout::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||
notes::sprout::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||
sprout::note::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||
sprout::note::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||
],
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,13 @@ use proptest::{arbitrary::any, array, collection::vec, option, prelude::*};
|
|||
use crate::{
|
||||
amount::{Amount, NonNegative},
|
||||
block::BlockHeight,
|
||||
commitments,
|
||||
notes::sprout,
|
||||
primitives::{Bctv14Proof, Groth16Proof, Script, ZkSnarkProof},
|
||||
sapling,
|
||||
sprout,
|
||||
transaction::{
|
||||
CoinbaseData, JoinSplit, JoinSplitData, LockTime, OutPoint, Output, ShieldedData, Spend,
|
||||
Transaction, TransparentInput, TransparentOutput,
|
||||
},
|
||||
treestate,
|
||||
};
|
||||
|
||||
impl Transaction {
|
||||
|
|
@ -125,14 +123,14 @@ impl<P: ZkSnarkProof + Arbitrary + 'static> Arbitrary for JoinSplit<P> {
|
|||
(
|
||||
any::<Amount<NonNegative>>(),
|
||||
any::<Amount<NonNegative>>(),
|
||||
any::<treestate::sprout::NoteTreeRootHash>(),
|
||||
array::uniform2(any::<sprout::Nullifier>()),
|
||||
array::uniform2(any::<commitments::sprout::NoteCommitment>()),
|
||||
any::<sprout::tree::NoteTreeRootHash>(),
|
||||
array::uniform2(any::<sprout::note::Nullifier>()),
|
||||
array::uniform2(any::<sprout::commitment::NoteCommitment>()),
|
||||
array::uniform32(any::<u8>()),
|
||||
array::uniform32(any::<u8>()),
|
||||
array::uniform2(any::<crate::types::MAC>()),
|
||||
array::uniform2(any::<sprout::note::MAC>()),
|
||||
any::<P>(),
|
||||
array::uniform2(any::<sprout::EncryptedCiphertext>()),
|
||||
array::uniform2(any::<sprout::note::EncryptedCiphertext>()),
|
||||
)
|
||||
.prop_map(
|
||||
|(
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
//! Treestate representations for Sprout and Sapling
|
||||
|
||||
// mod nullifier_set;
|
||||
pub mod sprout;
|
||||
Loading…
Reference in New Issue