Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port zebra-chain::sapling to zebra-chain::orchard #1885

Merged
merged 84 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
d4f1978
Partway done with typing out Orchard chain types
dconnolly Mar 7, 2021
cb2d35a
Bunch more work implementing orchard, porting from sapling where appl…
dconnolly Mar 8, 2021
cccb8bb
Add sapling prf_ock and generate_trapdoor
dconnolly Mar 8, 2021
e2d7353
impl orchard SpendingKey::new()
dconnolly Mar 8, 2021
4936689
orchard: impl From<SpendingKey> for NullifierDerivingKey
dconnolly Mar 8, 2021
8487736
orchard: derive IncomingViewingKey from FullViewingKey
dconnolly Mar 8, 2021
15f88ea
orchard: DiversifierKey is a newtype refinement of 32 bytes
dconnolly Mar 8, 2021
e8ed650
Tidy
dconnolly Mar 10, 2021
8c89924
Most things are filled in, including a guess at Pallas-based Mixing P…
dconnolly Mar 11, 2021
0a85ea3
Cleanup
dconnolly Mar 11, 2021
155b368
Tidy impl From<SpendingKey> for IvkCommitRandomness
dconnolly Mar 11, 2021
d9752dd
Add redpallas::signing_key::SigningKey stub
dconnolly Mar 11, 2021
ffe6041
Action should use VerificationKeyBytes
dconnolly Mar 13, 2021
f1926c3
Tidy prf's
dconnolly Mar 13, 2021
4ec1558
Orchard: Tidy Debug impl's for keys, cast a pallas::Base into a palla…
dconnolly Mar 13, 2021
247d676
Orchard: Fix trait imports and Arbitrary for Action
dconnolly Mar 13, 2021
6f2734d
Orchard: tidy commitments etc
dconnolly Mar 14, 2021
541c3e7
Orchard: some Action (de)serialization fixes
dconnolly Mar 14, 2021
12a46ce
Orchard: borrow local.bytes for pallas::Affine serde helper
dconnolly Mar 14, 2021
160b377
Orchard: tidy nullifiers
dconnolly Mar 14, 2021
693d03a
Orchard: tidy
dconnolly Mar 14, 2021
706f9a3
Orchard: tidy keys
dconnolly Mar 15, 2021
3b63168
Sapling: use try_from turbofish inside prf_ock
dconnolly Mar 15, 2021
71335fd
Orchard: add a serde helper for pallas::Base
dconnolly Mar 15, 2021
83a8e31
Orchard: derive serde::{Deserialize, Serialize} by default on redpall…
dconnolly Mar 15, 2021
c585dac
Orchard: fix into() call inside extract_x
dconnolly Mar 15, 2021
2694315
Orchard: tidy
dconnolly Mar 15, 2021
dc54f8c
Orchard: remove unused imports
dconnolly Mar 15, 2021
cd04fc0
Orchard: update merkle_crh_orchard correctly
dconnolly Mar 15, 2021
5fd5905
Orchard: update nullifiers
dconnolly Mar 16, 2021
d3cab05
Orchard: remove unused imports, more warn(missing_docs) lint to orcha…
dconnolly Mar 16, 2021
62ae4a0
Orchard: update merkle_crh_orchard to use the appropriate l=10 bits, …
dconnolly Mar 16, 2021
decd79c
Orchard: fix some tests, etc
dconnolly Mar 17, 2021
bb7334e
Update diversify_hash and its use to match spec updates
dconnolly Mar 17, 2021
64c34de
Update zebra-chain/src/orchard/sinsemilla.rs
dconnolly Mar 18, 2021
c120672
Update zebra-chain/src/orchard/sinsemilla.rs
dconnolly Mar 18, 2021
7074c49
Update zebra-chain/src/orchard/sinsemilla.rs
dconnolly Mar 18, 2021
da8a4e6
Update zebra-chain/src/orchard/note/nullifiers.rs
dconnolly Mar 18, 2021
0e4821f
Update zebra-chain/src/orchard/keys.rs
dconnolly Mar 18, 2021
9521fb0
Update zebra-chain/src/orchard/keys.rs
dconnolly Mar 18, 2021
f22e735
Update zebra-chain/src/orchard/keys.rs
dconnolly Mar 18, 2021
f60ff1b
Update zebra-chain/src/orchard/keys.rs
dconnolly Mar 18, 2021
f67c02d
Update zebra-chain/src/orchard/keys.rs
dconnolly Mar 18, 2021
010ff33
Update zebra-chain/src/orchard/address.rs
dconnolly Mar 18, 2021
df027ea
Update zebra-chain/src/orchard/address.rs
dconnolly Mar 18, 2021
3047ff4
Remove commented out orchard::Address FromStr/Display test vector tes…
dconnolly Mar 18, 2021
badec89
Fix str match for key and addr decoding
dconnolly Mar 19, 2021
83f2d45
Orchard: fix typos
dconnolly Mar 19, 2021
2bc829b
Orchard: turns out you can't store 10 bits in a u8
dconnolly Mar 20, 2021
f8a9777
Revert making sapling::note::Nullifier inner value private
dconnolly Mar 20, 2021
350c4d2
Apply docstring suggestions from code review
dconnolly Mar 26, 2021
38a6c56
Flesh out Orchard note and nullifier derivation
dconnolly Mar 28, 2021
ff64e9a
Remove done TODO
dconnolly Mar 28, 2021
fcffe8c
Orchard: update Debug impl for commitments
dconnolly Mar 29, 2021
64cb43d
orchard: Better Debug impls for some keys
dconnolly Apr 3, 2021
f00dfb6
orchard: ValueCommit ops implementation tests
dconnolly Apr 5, 2021
277d616
Bump redjubjub
dconnolly Apr 5, 2021
bb9c863
Tried and discarded lazy_static! of value commitment generator points
dconnolly Apr 5, 2021
ca4203e
orchard: move IncomingViewingKey::from([u8; 32]) to a ::from_bytes([u…
dconnolly Apr 5, 2021
33c842c
Remove standalone Orchard address Display, FromStr impls and related …
dconnolly Apr 8, 2021
eee672f
Clippy lint to align order of members of redpallas::VerificationKey
dconnolly Apr 8, 2021
c535692
Clippy +nightly
dconnolly Apr 17, 2021
a6c462f
Add TODO
dconnolly Apr 20, 2021
fde2830
Refer to const generics issue
dconnolly Apr 20, 2021
4f5a0e1
Link to redpallas TODO
dconnolly Apr 20, 2021
f3a1dc2
Impl FullViewingKey::from_spending_key(SpendingKey, Network)
dconnolly Apr 20, 2021
b75b3b3
Add link to redpallas follow-up
dconnolly Apr 20, 2021
f3a66da
IncomingViewingKey inherits network when derived from FullViewingKey
dconnolly Apr 20, 2021
b1c1ad3
Add redpallas TODO
dconnolly Apr 21, 2021
ef22c96
Clean up Arbitray impl for Halo2Proof
dconnolly Apr 21, 2021
0c8c02e
Clean up orchard::tree tests for now
dconnolly Apr 21, 2021
37957b4
Remove Copy on ZkSnarkProof trait
dconnolly Apr 21, 2021
4cc8dc1
Tidy up network handling for Orchard keys/addresses
dconnolly Apr 24, 2021
bda1cdd
Add TODO for Poseidon hash implementation
dconnolly Apr 24, 2021
6af4749
Do not derive Hash for orchard::Nullifier as pallas::Base doesn't hav…
dconnolly Apr 24, 2021
1c43b8a
Move Value Commitment generator points into static via lazy_static
dconnolly Apr 26, 2021
36270b3
Add TODO to fill in the Sinsemilla test vectors from zcash-hackworks
dconnolly Apr 27, 2021
fe1a0c2
Doing math in u16 collector obviates passing of Bit(Slice/Vector)
dconnolly Apr 27, 2021
8635ea8
Rename all Orchard spec references to nu5.pdf
dconnolly Apr 27, 2021
15675cc
Add link to funty pin removal issue
dconnolly Apr 29, 2021
8478d3c
Pin halo2 commit and update usage of pasta_curves accordingly
dconnolly Apr 29, 2021
bd1ebbe
Remove FromStr impls for orchard keys for now, pending Unifed version…
dconnolly Apr 29, 2021
5caf5bb
Tidy up sinsemilla_hash_to_point() with bitvec
dconnolly Apr 30, 2021
7bcf779
Rebase tidies
dconnolly Apr 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]

default = []
proptest-impl = ["proptest", "proptest-derive", "itertools"]
bench = ["zebra-test"]

[dependencies]
aes = "0.6"
bech32 = "0.8.0"
bitflags = "1.2.1"
bitvec = "0.17.4"
Expand All @@ -23,8 +23,14 @@ bs58 = { version = "0.4", features = ["check"] }
byteorder = "1.4"
chrono = { version = "0.4", features = ["serde"] }
displaydoc = "0.2.1"
equihash = "0.1"
fpe = "0.4"
# Temporary workaround for https://github.com/myrrlyn/funty/issues/3
dconnolly marked this conversation as resolved.
Show resolved Hide resolved
# TODO: remove: https://github.com/ZcashFoundation/zebra/issues/2082
funty = "=1.1.0"
futures = "0.3"
group = "0.9"
# TODO: replace w/ crate version when released: https://github.com/ZcashFoundation/zebra/issues/2083
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "dda60a363001373d564156ad0334e2022d85a5b4"}
hex = "0.4"
jubjub = "0.6.0"
lazy_static = "1.4.0"
Expand All @@ -43,14 +49,14 @@ proptest-derive = { version = "0.3.0", optional = true }
itertools = { version = "0.10.0", optional = true }

# ZF deps
ed25519-zebra = "2.2.0"
ed25519-zebra = "2"
equihash = "0.1"
redjubjub = "0.4"

zebra-test = { path = "../zebra-test/", optional = true }

[dev-dependencies]
bincode = "1"

color-eyre = "0.5.11"
criterion = { version = "0.3", features = ["html_reports"] }
spandoc = "0.2"
Expand Down
7 changes: 7 additions & 0 deletions zebra-chain/proptest-regressions/orchard/keys/tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 8ba80e3da74dc90c627f620bed08c47e7a13bb2e7762aad6e8c8f362237aed1b # shrinks to spending_key = SpendingKey { network: Mainnet, bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
11 changes: 11 additions & 0 deletions zebra-chain/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ impl<C> From<Amount<C>> for jubjub::Fr {
}
}

impl<C> From<Amount<C>> for halo2::pasta::pallas::Scalar {
fn from(a: Amount<C>) -> halo2::pasta::pallas::Scalar {
// TODO: this isn't constant time -- does that matter?
dconnolly marked this conversation as resolved.
Show resolved Hide resolved
if a.0 < 0 {
halo2::pasta::pallas::Scalar::from(a.0.abs() as u64).neg()
} else {
halo2::pasta::pallas::Scalar::from(a.0 as u64)
}
}
}

impl<C> TryFrom<i64> for Amount<C>
where
C: Constraint,
Expand Down
10 changes: 4 additions & 6 deletions zebra-chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
//! Core Zcash data structures. 🦓
//!
//! This crate provides definitions of core datastructures for Zcash, such as
//! This crate provides definitions of core data structures for Zcash, such as
//! blocks, transactions, addresses, etc.

#![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")]
#![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")]
#![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_chain")]
// #![deny(missing_docs)]
#![allow(clippy::try_err)]
// The actual lints we want to disable
#![allow(clippy::unnecessary_wraps)]
// Disable some broken or unwanted clippy nightly lints
// Build without warnings on nightly 2021-01-17 and later and stable 1.51 and later
#![allow(unknown_lints)]
// Disable old lint warnings on nightly until 1.51 is stable
#![allow(renamed_and_removed_lints)]
// Use the old lint name to build without warnings on stable until 1.51 is stable
#![allow(clippy::unknown_clippy_lints)]
// The actual lints we want to disable
#![allow(clippy::unnecessary_wraps)]

#[macro_use]
extern crate serde;

pub mod amount;
pub mod block;
pub mod fmt;
pub mod orchard;
pub mod parameters;
pub mod primitives;
pub mod sapling;
Expand Down
20 changes: 20 additions & 0 deletions zebra-chain/src/orchard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Orchard-related functionality.

#![warn(missing_docs)]

mod action;
mod address;
#[cfg(any(test, feature = "proptest-impl"))]
mod arbitrary;
mod commitment;
mod note;
mod sinsemilla;

pub mod keys;
pub mod tree;

pub use action::Action;
pub use address::Address;
pub use commitment::{CommitmentRandomness, NoteCommitment, ValueCommitment};
pub use keys::Diversifier;
pub use note::{EncryptedNote, Note, Nullifier};
72 changes: 72 additions & 0 deletions zebra-chain/src/orchard/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::io;

use halo2::pasta::pallas;

use crate::{
primitives::redpallas::{self, SpendAuth},
serialization::{
serde_helpers, ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize,
},
};

use super::{
commitment::{self, ValueCommitment},
keys,
note::{self, Nullifier},
};

/// An Action description, as described in the [Zcash specification §7.3][actiondesc].
///
/// Action transfers can optionally perform a spend, and optionally perform an
/// output. Action descriptions are data included in a transaction that
/// describe Action transfers.
///
/// [actiondesc]: https://zips.z.cash/protocol/nu5.pdf#actiondesc
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Action {
/// A value commitment to net value of the input note minus the output note
pub cv: commitment::ValueCommitment,
/// The nullifier of the input note being spent.
pub nullifier: note::Nullifier,
/// The randomized validating key for spendAuthSig,
pub rk: redpallas::VerificationKeyBytes<SpendAuth>,
/// The x-coordinate of the note commitment for the output note.
#[serde(with = "serde_helpers::Base")]
pub cm_x: pallas::Base,
/// An encoding of an ephemeral Pallas public key corresponding to the
/// encrypted private key in `out_ciphertext`.
pub ephemeral_key: keys::EphemeralPublicKey,
/// A ciphertext component for the encrypted output note.
pub enc_ciphertext: note::EncryptedNote,
/// A ciphertext component that allows the holder of a full viewing key to
/// recover the recipient diversified transmission key and the ephemeral
/// private key (and therefore the entire note plaintext).
pub out_ciphertext: note::WrappedNoteKey,
}

impl ZcashSerialize for Action {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
self.cv.zcash_serialize(&mut writer)?;
writer.write_all(&<[u8; 32]>::from(self.nullifier)[..])?;
writer.write_all(&<[u8; 32]>::from(self.rk)[..])?;
writer.write_all(&<[u8; 32]>::from(self.cm_x)[..])?;
self.ephemeral_key.zcash_serialize(&mut writer)?;
self.enc_ciphertext.zcash_serialize(&mut writer)?;
self.out_ciphertext.zcash_serialize(&mut writer)?;
Ok(())
}
}

impl ZcashDeserialize for Action {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
Ok(Action {
cv: ValueCommitment::zcash_deserialize(&mut reader)?,
nullifier: Nullifier::from(reader.read_32_bytes()?),
rk: reader.read_32_bytes()?.into(),
cm_x: pallas::Base::zcash_deserialize(&mut reader)?,
ephemeral_key: keys::EphemeralPublicKey::zcash_deserialize(&mut reader)?,
enc_ciphertext: note::EncryptedNote::zcash_deserialize(&mut reader)?,
out_ciphertext: note::WrappedNoteKey::zcash_deserialize(&mut reader)?,
})
}
}
Loading