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

Implement Sapling serialization in Transaction V5 #2020

Merged
merged 13 commits into from
Apr 18, 2021
Merged
10 changes: 10 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ redjubjub = "0.4"

[dev-dependencies]
bincode = "1"

color-eyre = "0.5.11"
spandoc = "0.2"
tracing = "0.1.25"

itertools = "0.10.0"

proptest = "0.10"
proptest-derive = "0.3"

Expand Down
22 changes: 18 additions & 4 deletions zebra-chain/src/block/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ proptest! {
let bytes = hash.zcash_serialize_to_vec()?;
let other_hash: Hash = bytes.zcash_deserialize_into()?;

prop_assert_eq![hash, other_hash];
prop_assert_eq![&hash, &other_hash];

let bytes2 = other_hash
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");
prop_assert_eq![bytes, bytes2, "bytes must be equal if structs are equal"];
}

#[test]
Expand All @@ -36,7 +41,12 @@ proptest! {
let bytes = header.zcash_serialize_to_vec()?;
let other_header = bytes.zcash_deserialize_into()?;

prop_assert_eq![header, other_header];
prop_assert_eq![&header, &other_header];

let bytes2 = other_header
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");
prop_assert_eq![bytes, bytes2, "bytes must be equal if structs are equal"];
}

#[test]
Expand Down Expand Up @@ -70,7 +80,6 @@ proptest! {
zebra_test::init();

let bytes = block.zcash_serialize_to_vec()?;
let bytes = &mut bytes.as_slice();

// Check the block commitment
let commitment = block.commitment(network);
Expand All @@ -84,7 +93,12 @@ proptest! {
// Check deserialization
let other_block = bytes.zcash_deserialize_into()?;

prop_assert_eq![block, other_block];
prop_assert_eq![&block, &other_block];

let bytes2 = other_block
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");
prop_assert_eq![bytes, bytes2, "bytes must be equal if structs are equal"];
} else {
let serialization_err = bytes.zcash_deserialize_into::<Block>()
.expect_err("blocks larger than the maximum size should fail");
Expand Down
7 changes: 4 additions & 3 deletions zebra-chain/src/block/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ fn deserialize_blockheader() {
}

#[test]
fn deserialize_block() {
fn round_trip_blocks() {
zebra_test::init();

// this one has a bad version field
// this one has a bad version field, but it is still valid
zebra_test::vectors::BLOCK_MAINNET_434873_BYTES
.zcash_deserialize_into::<Block>()
.expect("block test vector should deserialize");
.expect("bad version block test vector should deserialize");

// now do a round-trip test on all the block test vectors
for block_bytes in zebra_test::vectors::BLOCKS.iter() {
let block = block_bytes
.zcash_deserialize_into::<Block>()
Expand Down
8 changes: 4 additions & 4 deletions zebra-chain/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ mod address;
mod arbitrary;
mod commitment;
mod note;
mod output;
mod spend;
#[cfg(test)]
mod tests;

// XXX clean up these modules

pub mod keys;
pub mod output;
pub mod shielded_data;
pub mod spend;
pub mod tree;

pub use address::Address;
pub use commitment::{CommitmentRandomness, NoteCommitment, ValueCommitment};
pub use keys::Diversifier;
pub use note::{EncryptedNote, Note, Nullifier, WrappedNoteKey};
pub use output::{Output, OutputInTransactionV4};
pub use output::{Output, OutputInTransactionV4, OutputPrefixInTransactionV5};
pub use shielded_data::{
AnchorVariant, FieldNotPresent, PerSpendAnchor, SharedAnchor, ShieldedData,
};
pub use spend::Spend;
pub use spend::{Spend, SpendPrefixInTransactionV5};
Loading