From 8d3ec7b84a3d08dc3009e1f6c17356dce1feec27 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 29 Jan 2020 20:06:18 -0500 Subject: [PATCH 01/26] Little test to exercise sha256dWriter::flush() --- zebra-chain/src/sha256d_writer.rs | 17 +++++++++++++++++ zebra-network/src/protocol/external/codec.rs | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/zebra-chain/src/sha256d_writer.rs b/zebra-chain/src/sha256d_writer.rs index 5e835cdfc17..77dbec20caf 100644 --- a/zebra-chain/src/sha256d_writer.rs +++ b/zebra-chain/src/sha256d_writer.rs @@ -31,3 +31,20 @@ impl Write for Sha256dWriter { Ok(()) } } + +#[cfg(test)] +mod tests { + + use std::io::Write; + + use crate::sha256d_writer::Sha256dWriter; + + #[test] + fn sha256d_flush() { + let preimage = b"foo bar baz"; + let mut sha_writer = Sha256dWriter::default(); + let _ = sha_writer.write_all(preimage); + + assert_eq!(sha_writer.flush().unwrap(), ()); + } +} diff --git a/zebra-network/src/protocol/external/codec.rs b/zebra-network/src/protocol/external/codec.rs index 82e74f4fc83..e6d7b2393e1 100644 --- a/zebra-network/src/protocol/external/codec.rs +++ b/zebra-network/src/protocol/external/codec.rs @@ -475,7 +475,7 @@ impl Codec { Ok(Message::GetBlocks { version: Version(reader.read_u32::()?), block_locator_hashes: Vec::zcash_deserialize(&mut reader)?, - hash_stop: BlockHeaderHash(reader.read_32_bytes()?), + hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?, }) } @@ -492,7 +492,7 @@ impl Codec { Ok(Message::GetHeaders { version: Version(reader.read_u32::()?), block_locator_hashes: Vec::zcash_deserialize(&mut reader)?, - hash_stop: BlockHeaderHash(reader.read_32_bytes()?), + hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?, }) } From 9dead7783e9405ad013aae349bf98914e4b6e32c Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Thu, 30 Jan 2020 19:40:03 -0500 Subject: [PATCH 02/26] s/GetData/NotFound/ in read_notfound --- zebra-network/src/protocol/external/codec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-network/src/protocol/external/codec.rs b/zebra-network/src/protocol/external/codec.rs index e6d7b2393e1..d0217df503b 100644 --- a/zebra-network/src/protocol/external/codec.rs +++ b/zebra-network/src/protocol/external/codec.rs @@ -505,7 +505,7 @@ impl Codec { } fn read_notfound(&self, reader: R) -> Result { - Ok(Message::GetData(Vec::zcash_deserialize(reader)?)) + Ok(Message::NotFound(Vec::zcash_deserialize(reader)?)) } fn read_tx(&self, mut reader: R) -> Result { From 5b16670d614cc447a71cd1cf1733eb6d1ff97799 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Thu, 30 Jan 2020 20:57:31 -0500 Subject: [PATCH 03/26] Move transaction test vectors around Resolves #210 --- zebra-chain/src/transaction.rs | 2 + zebra-chain/src/transaction/test_vectors.rs | 131 ++++++++++++++++++ zebra-chain/src/transaction/tests.rs | 144 +------------------- 3 files changed, 135 insertions(+), 142 deletions(-) create mode 100644 zebra-chain/src/transaction/test_vectors.rs diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 63dc76bb2a8..651e684dbd3 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -6,6 +6,8 @@ mod serialize; mod shielded_data; mod transparent; +#[cfg(test)] +mod test_vectors; #[cfg(test)] mod tests; diff --git a/zebra-chain/src/transaction/test_vectors.rs b/zebra-chain/src/transaction/test_vectors.rs new file mode 100644 index 00000000000..1a427e9cb5a --- /dev/null +++ b/zebra-chain/src/transaction/test_vectors.rs @@ -0,0 +1,131 @@ +// Copied from librustzcash +// TxID: 64f0bd7fe30ce23753358fe3a2dc835b8fba9c0274c4e2c54a6f73114cb55639 +// From testnet block 280003. +pub const GENERIC_TESTNET_TX: [u8; 2005] = [ + 0x04, 0x00, 0x00, 0x80, 0x85, 0x20, 0x2f, 0x89, 0x01, 0x8f, 0x64, 0x29, 0x96, 0xdf, 0x1e, 0x93, + 0xa6, 0xd7, 0x9a, 0xe5, 0xba, 0xae, 0x34, 0x93, 0xf4, 0x23, 0xca, 0x6c, 0x82, 0xe9, 0x9f, 0x3e, + 0x8d, 0x95, 0x24, 0xfa, 0x78, 0xbc, 0xf1, 0x61, 0x67, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x48, 0x30, + 0x45, 0x02, 0x21, 0x00, 0xb6, 0x5e, 0x37, 0x22, 0x97, 0x07, 0xd9, 0xcd, 0x48, 0x39, 0x40, 0xd2, + 0xab, 0x8b, 0xdc, 0x0b, 0x74, 0xb1, 0x2d, 0xda, 0x66, 0xd0, 0x2d, 0xbd, 0xf3, 0x6f, 0xd3, 0x83, + 0xb9, 0x60, 0x2a, 0x51, 0x02, 0x20, 0x4b, 0xe7, 0xfd, 0x7a, 0x39, 0xa4, 0xa4, 0x2d, 0xff, 0x07, + 0x1a, 0x5a, 0x2b, 0xc5, 0x1b, 0x49, 0x2d, 0x33, 0xf0, 0xbc, 0x39, 0x4b, 0xc8, 0x78, 0x61, 0xe1, + 0xbc, 0xaa, 0xf2, 0xba, 0xc9, 0x3b, 0x01, 0x21, 0x02, 0x48, 0xe7, 0x8b, 0xdc, 0x18, 0xf1, 0xa8, + 0x31, 0x10, 0xc1, 0x2e, 0x40, 0x08, 0xb7, 0x64, 0x02, 0x69, 0x61, 0xb1, 0x68, 0xfe, 0x8d, 0x5a, + 0x8d, 0x94, 0x7e, 0xfe, 0x6a, 0xf8, 0x3c, 0xc8, 0x8e, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf0, 0xf2, + 0x70, 0x18, 0x02, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xa2, 0x84, 0xd0, 0x51, 0x1d, 0x0e, + 0x52, 0x0d, 0x36, 0xf4, 0x44, 0xa3, 0x6c, 0x10, 0xbf, 0x54, 0xb4, 0xb0, 0x17, 0xcd, 0x88, 0xac, + 0x00, 0x00, 0x00, 0x00, 0xd7, 0x45, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x13, 0x31, 0xa3, 0x05, 0x9e, 0x66, 0xaa, 0x6c, 0xa9, 0x7a, 0x62, 0xf5, 0x6e, + 0xa2, 0x34, 0x20, 0x75, 0x68, 0x56, 0x6f, 0x69, 0x71, 0xb3, 0x72, 0x2a, 0xe0, 0xdd, 0x82, 0xc0, + 0x03, 0x99, 0x69, 0x2a, 0xac, 0xb5, 0xfb, 0x12, 0xac, 0x58, 0x0a, 0xc2, 0x66, 0x24, 0xa8, 0xcf, + 0x0a, 0x90, 0x4c, 0xd6, 0xf4, 0xbf, 0xea, 0x55, 0x62, 0x52, 0x05, 0xcb, 0x58, 0xf0, 0x6b, 0x1c, + 0x19, 0x74, 0x23, 0x28, 0x0d, 0xea, 0xc7, 0x4e, 0xea, 0x97, 0x59, 0x8c, 0x43, 0x14, 0xd8, 0x99, + 0xa4, 0xfd, 0x85, 0x31, 0x1e, 0x04, 0x62, 0x57, 0xd2, 0xd4, 0xc2, 0x97, 0xf1, 0x40, 0x6c, 0xf7, + 0x09, 0xd9, 0x2a, 0x86, 0x07, 0xf7, 0x69, 0x8d, 0x45, 0xfe, 0x9f, 0x41, 0xde, 0xa3, 0xa0, 0x57, + 0x1c, 0x5d, 0xa5, 0xcf, 0xa7, 0x8e, 0x18, 0xeb, 0xf5, 0x80, 0xc3, 0x61, 0x79, 0xd9, 0xd6, 0xe6, + 0x32, 0x0a, 0x34, 0x8f, 0x14, 0x6c, 0x40, 0x7a, 0xda, 0xb4, 0xcb, 0x31, 0x03, 0x92, 0xa5, 0xf5, + 0xb5, 0xab, 0x28, 0x3b, 0x78, 0x34, 0x3b, 0xa9, 0x1a, 0xbc, 0x7c, 0x4b,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0c, + 0x42, 0x3a, 0xde, 0x23, 0x3d, 0x5d, 0x60, 0x68, 0x55, 0x24, 0xe8, 0xd8, 0x03, 0x2b, 0x86, 0x1b, + 0x4a, 0xad, 0x20, 0x02, 0xa8, 0xfd, 0x17, 0xc9, 0x28, 0x2b, 0x82, 0x5f, 0x02, 0xd3, 0x53, 0xe2, + 0x91, 0x37, 0x9c, 0xed, 0x00, 0xeb, 0xaa, 0x3c, 0x03, 0xe0, 0x1d, 0x9c, 0x59, 0xf4, 0x05, 0x09, + 0x9d, 0x1c, 0x34, 0x32, 0xba, 0xd0, 0x63, 0x58, 0xd6, 0xb1, 0x94, 0x2f, 0x0b, 0xaf, 0x71, 0x09, + 0x98, 0xd1, 0x0a, 0x22, 0xd1, 0x55, 0xb0, 0xfe, 0x84, 0x99, 0x52, 0x89, 0x31, 0x26, 0x94, 0x9f, + 0xf9, 0x2d, 0xe3, 0xa4, 0xc2, 0xee, 0xaf, 0xdf, 0x68, 0x84, 0x35, 0xe3, 0x25, 0xd8, 0x1c, 0x2c, + 0xe0, 0x08, 0xcf, 0x6c, 0x76, 0x03, 0x0d, 0x4d, 0x46, 0x34, 0x2a, 0xc3, 0x37, 0x2c, 0x73, 0x98, + 0x65, 0x60, 0xc4, 0xec, 0x35, 0xa6, 0xf6, 0x49, 0xef, 0x02, 0xc1, 0x19, 0x36, 0xb7, 0x03, 0x9b, + 0xc6, 0xf5, 0xd0, 0x94, 0x38, 0xdb, 0xe4, 0x76, 0x25, 0x1b, 0x59, 0x64, 0xb6, 0x8f, 0x02, 0xee, + 0xdf, 0xf7, 0xa9, 0xe0, 0xed, 0x3e, 0x30, 0x90, 0x96, 0x5a, 0x22, 0xf2, 0xc5, 0x52, 0xce, 0x3b, + 0x2b, 0x47, 0x4f, 0xd2, 0xfc, 0x06, 0xb5, 0x09, 0x27, 0x83, 0x0a, 0x05, 0xa3, 0x03, 0xfa, 0xff, + 0xd6, 0x84, 0x82, 0xd7, 0xb7, 0x85, 0x38, 0x43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 0xce, 0xea, + 0x76, 0xe1, 0x9b, 0x84, 0x2b, 0x67, 0xf6, 0x26, 0x74, 0x3f, 0xab, 0x29, 0x77, 0x76, 0xcc, 0x9c, + 0xf7, 0x9e, 0x90, 0xe8, 0xfc, 0xe1, 0x00, 0x17, 0x90, 0xc2, 0xe7, 0xd5, 0xc9, 0x58, 0x64, 0x7c, + 0xca, 0x5d, 0x33, 0x97, 0xd2, 0x0a, 0xfc, 0xf2, 0x9b, 0xa4, 0x4f, 0x62, 0xa7, 0xc6, 0x2e, 0x90, + 0x8d, 0x84, 0x8d, 0x81, 0xa7, 0x9f, 0xad, 0xbb, 0x37, 0x0a, 0xba, 0x93, 0xb0, 0x3e, 0x41, 0xd4, + 0xbc, 0x49, 0xe2, 0x99, 0xd6, 0xd3, 0x3f, 0xaf, 0x86, 0x9f, 0x36, 0x37, 0x14, 0x14, 0xce, 0x64, + 0x6f, 0xc2, 0xca, 0x6d, 0xcf, 0xf5, 0x5a, 0x6e, 0x06, 0x39, 0xd5, 0x0c, 0xae, 0xb1, 0x14, 0xc4, + 0x18, 0xc6, 0x26, 0xb8, 0x67, 0x15, 0x43, 0x64, 0x81, 0xd1, 0x92, 0x8d, 0x55, 0xa7, 0x56, 0xa6, + 0x03, 0xe7, 0x11, 0x0c, 0x3a, 0xfe, 0x96, 0x3c, 0x2b, 0x29, 0xa4, 0x78, 0xf9, 0xd4, 0x39, 0x7b, + 0x88, 0x5a, 0x67, 0xb0, 0x93, 0xa3, 0x45, 0x79, 0x62, 0x19, 0xc1, 0x11, 0xb7, 0xe9, 0x4d, 0xb3, + 0x90, 0xaa, 0x4b, 0xb7, 0x6b, 0x66, 0xa5, 0x34, 0xe5, 0xe2, 0x67, 0x9b, 0x27, 0xdb, 0x5f, 0x95, + 0xfd, 0x09, 0xa3, 0x6b, 0x05, +]; diff --git a/zebra-chain/src/transaction/tests.rs b/zebra-chain/src/transaction/tests.rs index 2db65d475ce..3619af930f9 100644 --- a/zebra-chain/src/transaction/tests.rs +++ b/zebra-chain/src/transaction/tests.rs @@ -118,147 +118,7 @@ impl Arbitrary for Transaction { #[test] fn librustzcash_tx_deserialize_and_round_trip() { - // Copied from librustzcash - // TxID: 64f0bd7fe30ce23753358fe3a2dc835b8fba9c0274c4e2c54a6f73114cb55639 - // From testnet block 280003. - let data = [ - 0x04, 0x00, 0x00, 0x80, 0x85, 0x20, 0x2f, 0x89, 0x01, 0x8f, 0x64, 0x29, 0x96, 0xdf, 0x1e, - 0x93, 0xa6, 0xd7, 0x9a, 0xe5, 0xba, 0xae, 0x34, 0x93, 0xf4, 0x23, 0xca, 0x6c, 0x82, 0xe9, - 0x9f, 0x3e, 0x8d, 0x95, 0x24, 0xfa, 0x78, 0xbc, 0xf1, 0x61, 0x67, 0x00, 0x00, 0x00, 0x00, - 0x6b, 0x48, 0x30, 0x45, 0x02, 0x21, 0x00, 0xb6, 0x5e, 0x37, 0x22, 0x97, 0x07, 0xd9, 0xcd, - 0x48, 0x39, 0x40, 0xd2, 0xab, 0x8b, 0xdc, 0x0b, 0x74, 0xb1, 0x2d, 0xda, 0x66, 0xd0, 0x2d, - 0xbd, 0xf3, 0x6f, 0xd3, 0x83, 0xb9, 0x60, 0x2a, 0x51, 0x02, 0x20, 0x4b, 0xe7, 0xfd, 0x7a, - 0x39, 0xa4, 0xa4, 0x2d, 0xff, 0x07, 0x1a, 0x5a, 0x2b, 0xc5, 0x1b, 0x49, 0x2d, 0x33, 0xf0, - 0xbc, 0x39, 0x4b, 0xc8, 0x78, 0x61, 0xe1, 0xbc, 0xaa, 0xf2, 0xba, 0xc9, 0x3b, 0x01, 0x21, - 0x02, 0x48, 0xe7, 0x8b, 0xdc, 0x18, 0xf1, 0xa8, 0x31, 0x10, 0xc1, 0x2e, 0x40, 0x08, 0xb7, - 0x64, 0x02, 0x69, 0x61, 0xb1, 0x68, 0xfe, 0x8d, 0x5a, 0x8d, 0x94, 0x7e, 0xfe, 0x6a, 0xf8, - 0x3c, 0xc8, 0x8e, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf0, 0xf2, 0x70, 0x18, 0x02, 0x00, 0x00, - 0x00, 0x19, 0x76, 0xa9, 0x14, 0xa2, 0x84, 0xd0, 0x51, 0x1d, 0x0e, 0x52, 0x0d, 0x36, 0xf4, - 0x44, 0xa3, 0x6c, 0x10, 0xbf, 0x54, 0xb4, 0xb0, 0x17, 0xcd, 0x88, 0xac, 0x00, 0x00, 0x00, - 0x00, 0xd7, 0x45, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x13, 0x31, 0xa3, 0x05, 0x9e, 0x66, 0xaa, 0x6c, 0xa9, 0x7a, 0x62, 0xf5, 0x6e, - 0xa2, 0x34, 0x20, 0x75, 0x68, 0x56, 0x6f, 0x69, 0x71, 0xb3, 0x72, 0x2a, 0xe0, 0xdd, 0x82, - 0xc0, 0x03, 0x99, 0x69, 0x2a, 0xac, 0xb5, 0xfb, 0x12, 0xac, 0x58, 0x0a, 0xc2, 0x66, 0x24, - 0xa8, 0xcf, 0x0a, 0x90, 0x4c, 0xd6, 0xf4, 0xbf, 0xea, 0x55, 0x62, 0x52, 0x05, 0xcb, 0x58, - 0xf0, 0x6b, 0x1c, 0x19, 0x74, 0x23, 0x28, 0x0d, 0xea, 0xc7, 0x4e, 0xea, 0x97, 0x59, 0x8c, - 0x43, 0x14, 0xd8, 0x99, 0xa4, 0xfd, 0x85, 0x31, 0x1e, 0x04, 0x62, 0x57, 0xd2, 0xd4, 0xc2, - 0x97, 0xf1, 0x40, 0x6c, 0xf7, 0x09, 0xd9, 0x2a, 0x86, 0x07, 0xf7, 0x69, 0x8d, 0x45, 0xfe, - 0x9f, 0x41, 0xde, 0xa3, 0xa0, 0x57, 0x1c, 0x5d, 0xa5, 0xcf, 0xa7,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, 0x19, 0x84, 0x3b, 0xbf, 0x34, 0xc2, 0xfe, 0x61, 0xb0, - 0xc3, 0xe3, 0x2a, 0xa7, 0x07, 0x8e, 0x83, 0xd4, 0xc1, 0x92, 0x9e, 0x1e, 0x1d, 0x86, 0x14, - 0x1c, 0xde, 0xb1, 0x89, 0x20, 0x91, 0x09, 0x75, 0xdb, 0x3a, 0x76, 0x26, 0x82, 0x05, 0x99, - 0x63, 0x0c, 0x42, 0x3a, 0xde, 0x23, 0x3d, 0x5d, 0x60, 0x68, 0x55, 0x24, 0xe8, 0xd8, 0x03, - 0x2b, 0x86, 0x1b, 0x4a, 0xad, 0x20, 0x02, 0xa8, 0xfd, 0x17, 0xc9, 0x28, 0x2b, 0x82, 0x5f, - 0x02, 0xd3, 0x53, 0xe2, 0x91, 0x37, 0x9c, 0xed, 0x00, 0xeb, 0xaa, 0x3c, 0x03, 0xe0, 0x1d, - 0x9c, 0x59, 0xf4, 0x05, 0x09, 0x9d, 0x1c, 0x34, 0x32, 0xba, 0xd0, 0x63, 0x58, 0xd6, 0xb1, - 0x94, 0x2f, 0x0b, 0xaf, 0x71, 0x09, 0x98, 0xd1, 0x0a, 0x22, 0xd1, 0x55, 0xb0, 0xfe, 0x84, - 0x99, 0x52, 0x89, 0x31, 0x26, 0x94, 0x9f, 0xf9, 0x2d, 0xe3, 0xa4, 0xc2, 0xee, 0xaf, 0xdf, - 0x68, 0x84, 0x35, 0xe3, 0x25, 0xd8, 0x1c, 0x2c, 0xe0, 0x08, 0xcf, 0x6c, 0x76, 0x03, 0x0d, - 0x4d, 0x46, 0x34, 0x2a, 0xc3, 0x37, 0x2c, 0x73, 0x98, 0x65, 0x60, 0xc4, 0xec, 0x35, 0xa6, - 0xf6, 0x49, 0xef, 0x02, 0xc1, 0x19, 0x36, 0xb7, 0x03, 0x9b, 0xc6, 0xf5, 0xd0, 0x94, 0x38, - 0xdb, 0xe4, 0x76, 0x25, 0x1b, 0x59, 0x64, 0xb6, 0x8f, 0x02, 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xb7, 0xe9, 0x4d, 0xb3, 0x90, 0xaa, 0x4b, 0xb7, 0x6b, 0x66, 0xa5, 0x34, 0xe5, 0xe2, 0x67, - 0x9b, 0x27, 0xdb, 0x5f, 0x95, 0xfd, 0x09, 0xa3, 0x6b, 0x05, - ]; - - let tx = Transaction::zcash_deserialize(&data[..]) + let tx = Transaction::zcash_deserialize(&test_vectors::GENERIC_TESTNET_TX[..]) .expect("transaction test vector from librustzcash should deserialize"); println!("{:?}", tx); @@ -266,7 +126,7 @@ fn librustzcash_tx_deserialize_and_round_trip() { let mut data2 = Vec::new(); tx.zcash_serialize(&mut data2).expect("tx should serialize"); - assert_eq!(&data[..], &data2[..]); + assert_eq!(&test_vectors::GENERIC_TESTNET_TX[..], &data2[..]); } #[cfg(test)] From 1c3f48171a8362784db51214dc05ca9245515e51 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 21:01:35 -0500 Subject: [PATCH 04/26] Make MerkleTreeRootHash wrapped array public --- zebra-chain/src/block/test_vectors.rs | 97 +++++++++++++++++++++++++++ zebra-chain/src/merkle_tree.rs | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 zebra-chain/src/block/test_vectors.rs diff --git a/zebra-chain/src/block/test_vectors.rs b/zebra-chain/src/block/test_vectors.rs new file mode 100644 index 00000000000..43223acd705 --- /dev/null +++ b/zebra-chain/src/block/test_vectors.rs @@ -0,0 +1,97 @@ +// Copied from librustzcash +// From mainnet block 415000. +pub const HEADER_MAINNET_415000: [u8; 1487] = [ + 0x04, 0x00, 0x00, 0x00, 0x52, 0x74, 0xb4, 0x3b, 0x9e, 0x4a, 0xd8, 0xf4, 0x3e, 0x93, 0xf7, 0x84, + 0x63, 0xd2, 0x4d, 0xcf, 0xe5, 0x31, 0xae, 0xb4, 0x71, 0x98, 0x19, 0xf4, 0xf9, 0x7f, 0x7e, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x66, 0x30, 0x73, 0xbc, 0x4b, 0xfa, 0x95, 0xc9, 0xbe, 0xc3, 0x6a, 0xad, + 0x72, 0x68, 0xa5, 0x73, 0x04, 0x97, 0x97, 0xbd, 0xfc, 0x5a, 0xa4, 0xc7, 0x43, 0xfb, 0xe4, 0x82, + 0x0a, 0xa3, 0x93, 0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa8, 0xbe, 0xcc, 0x5b, 0xe1, 0xab, 0x03, 0x1c, 0xc2, 0xfd, 0x60, 0x7c, + 0x77, 0x6a, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0xb2, 0x18, 0x19, 0xfd, 0x40, 0x05, 0x00, + 0x94, 0x9d, 0x55, 0xde, 0x0c, 0xc6, 0x33, 0xe0, 0xcc, 0xe4, 0x1e, 0x46, 0x49, 0xef, 0x4a, 0xa3, + 0x34, 0x9f, 0x01, 0x00, 0x29, 0x0f, 0xfe, 0x28, 0x1b, 0x94, 0x7b, 0x3b, 0x53, 0xfb, 0xd2, 0xf3, + 0x5b, 0x1c, 0xe2, 0x92, 0x64, 0x9b, 0x96, 0xac, 0x6e, 0x08, 0x83, 0xaf, 0x3a, 0x68, 0x44, 0xb9, + 0x55, 0x92, 0xe7, 0x45, 0x56, 0xda, 0x34, 0x4b, 0x47, 0x01, 0x96, 0x1c, 0xd4, 0x13, 0x0c, 0x68, + 0x21, 0x9c, 0xfa, 0x13, 0x41, 0xd5, 0xaf, 0xb5, 0x04, 0x9e, 0xb0, 0xe8, 0xbe, 0x4a, 0x2d, 0x92, + 0xd6, 0x78, 0xc4, 0x07, 0x85,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 0x80, 0x60, 0x48, 0x21, 0xd9, + 0x69, 0x24, 0xe3, 0xfa, 0x39, 0x7f, 0x35, 0x4a, 0x5e, 0xcc, 0xa3, 0x4f, 0x61, 0x4d, 0xa5, 0x45, + 0x6f, 0x9b, 0x36, 0x33, 0x8c, 0x37, 0xd8, 0xf6, 0xfb, 0xf6, 0x26, 0xbe, 0x98, 0x34, 0x77, 0x76, + 0x60, 0x22, 0x87, 0x27, 0x46, 0xda, 0x10, 0xa1, 0x77, 0x1c, 0xeb, 0x02, 0xdd, 0x8a, 0xac, 0x01, + 0xba, 0x18, 0x6b, 0xf1, 0x48, 0x86, 0x30, 0x47, 0x9e, 0x12, 0x84, 0xda, 0x01, 0x90, 0xfc, 0xe8, + 0xb5, 0x9a, 0xc6, 0xb0, 0xfd, 0x41, 0x6b, 0xee, 0x56, 0xb7, 0x2f, 0x0a, 0x58, 0x45, 0x15, 0x35, + 0x57, 0xff, 0x0f, 0x49, 0x50, 0xa0, 0xdc, 0x5b, 0xe6, 0x5c, 0xe9, 0x42, 0xd2, 0x2e, 0x18, 0x53, + 0x4c, 0x4e, 0x0e, 0xfa, 0xbb, 0x2d, 0x15, 0x25, 0xdc, 0x48, 0x58, 0xb9, 0xb0, 0xf7, 0x7d, 0x47, + 0x4a, 0x12, 0x5e, 0xbc, 0x25, 0x0e, 0x08, 0xfe, 0xdb, 0xfa, 0xa6, 0x6f, 0x45, 0x3d, 0x90, 0x93, + 0x2c, 0xab, 0x3f, 0xf4, 0x52, 0x21, 0x90, 0x99, 0x68, 0xe5, 0x1e, 0x6b, 0xc2, 0x54, 0xd5, 0x09, + 0xad, 0xeb, 0x75, 0xcb, 0xa7, 0x6d, 0x48, 0xfe, 0x02, 0x4e, 0x3e, 0x66, 0xd8, 0xdf, 0x5e, +]; diff --git a/zebra-chain/src/merkle_tree.rs b/zebra-chain/src/merkle_tree.rs index 72f2540ac0a..0e5e4f8a699 100644 --- a/zebra-chain/src/merkle_tree.rs +++ b/zebra-chain/src/merkle_tree.rs @@ -29,7 +29,7 @@ impl ZcashDeserialize for MerkleTree { /// A SHA-256d hash of the root node of a merkle tree of SHA256-d /// hashed transactions in a block. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct MerkleTreeRootHash([u8; 32]); +pub struct MerkleTreeRootHash(pub [u8; 32]); impl From> for MerkleTreeRootHash { fn from(merkle_tree: MerkleTree) -> Self { From 8b9c1a29cffce4d846b20e7f5811e064b0967589 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 21:02:02 -0500 Subject: [PATCH 05/26] Impl Zcash(De)Serialize for BlockHeader --- zebra-chain/src/block.rs | 44 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index a096bde8517..22a20dfdae9 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -1,12 +1,21 @@ //! Definitions of block datastructures. -use chrono::{DateTime, Utc}; +#[cfg(test)] +pub mod test_vectors; + +use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use chrono::{DateTime, TimeZone, Utc}; use hex; -use std::{fmt, io}; +use std::{ + fmt, + io::{self, Read}, +}; use crate::merkle_tree::MerkleTreeRootHash; use crate::note_commitment_tree::SaplingNoteTreeRootHash; -use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize}; +use crate::serialization::{ + ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, +}; use crate::sha256d_writer::Sha256dWriter; use crate::transaction::Transaction; @@ -112,14 +121,35 @@ pub struct BlockHeader { } impl ZcashSerialize for BlockHeader { - fn zcash_serialize(&self, _writer: W) -> Result<(), SerializationError> { - unimplemented!(); + fn zcash_serialize(&self, mut writer: W) -> Result<(), SerializationError> { + self.previous_block_hash.zcash_serialize(&mut writer)?; + writer.write_all(&self.merkle_root_hash.0[..])?; + writer.write_all(&self.final_sapling_root_hash.0[..])?; + writer.write_u32::(self.time.timestamp() as u32)?; + writer.write_u32::(self.bits as u32)?; + writer.write_all(&self.nonce[..])?; + writer.write_compactsize(self.solution.len() as u64)?; + writer.write_all(&self.solution[..])?; + Ok(()) } } impl ZcashDeserialize for BlockHeader { - fn zcash_deserialize(_reader: R) -> Result { - unimplemented!(); + fn zcash_deserialize(mut reader: R) -> Result { + Ok(BlockHeader { + previous_block_hash: BlockHeaderHash::zcash_deserialize(&mut reader)?, + merkle_root_hash: MerkleTreeRootHash(reader.read_32_bytes()?), + final_sapling_root_hash: SaplingNoteTreeRootHash(reader.read_32_bytes()?), + time: Utc.timestamp(reader.read_u32::()? as i64, 0), + bits: reader.read_u32::()?, + nonce: reader.read_32_bytes()?, + solution: { + let len = reader.read_compactsize()?; + let mut bytes = Vec::new(); + reader.take(len).read_to_end(&mut bytes)?; + bytes + }, + }) } } From a9aec65542871e29ad8570e4fc31950dc5189ef7 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 21:02:43 -0500 Subject: [PATCH 06/26] Add test for BlockHeaderHash::from(BlockHeader) --- zebra-chain/src/block.rs | 27 +++++++++++++++++++++++++-- zebra-chain/src/transaction/tests.rs | 6 ------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 22a20dfdae9..86326a7fa15 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -184,12 +184,13 @@ impl ZcashDeserialize for Block { #[cfg(test)] mod tests { + use chrono::NaiveDateTime; use std::io::Write; - use super::BlockHeaderHash; - use crate::sha256d_writer::Sha256dWriter; + use super::*; + #[test] fn blockheaderhash_debug() { let preimage = b"foo bar baz"; @@ -203,4 +204,26 @@ mod tests { "BlockHeaderHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")" ); } + + #[test] + fn blockheaderhash_from_blockheader() { + let some_bytes = [0; 32]; + + let blockheader = BlockHeader { + previous_block_hash: BlockHeaderHash(some_bytes), + merkle_root_hash: MerkleTreeRootHash(some_bytes), + final_sapling_root_hash: SaplingNoteTreeRootHash(some_bytes), + time: DateTime::::from_utc(NaiveDateTime::from_timestamp(61, 0), Utc), + bits: 0, + nonce: some_bytes, + solution: vec![0; 1344], + }; + + let hash = BlockHeaderHash::from(blockheader); + + assert_eq!( + format!("{:?}", hash), + "BlockHeaderHash(\"35be4a0f97803879ed642d4e10a146c3fba8727a1dca8079e3f107221be1e7e4\")" + ); + } } diff --git a/zebra-chain/src/transaction/tests.rs b/zebra-chain/src/transaction/tests.rs index 3619af930f9..2bb61b279a3 100644 --- a/zebra-chain/src/transaction/tests.rs +++ b/zebra-chain/src/transaction/tests.rs @@ -121,8 +121,6 @@ fn librustzcash_tx_deserialize_and_round_trip() { let tx = Transaction::zcash_deserialize(&test_vectors::GENERIC_TESTNET_TX[..]) .expect("transaction test vector from librustzcash should deserialize"); - println!("{:?}", tx); - let mut data2 = Vec::new(); tx.zcash_serialize(&mut data2).expect("tx should serialize"); @@ -135,16 +133,12 @@ proptest! { #[test] fn transaction_roundtrip(tx in any::()) { - println!("{:?}", tx); - let mut data = Vec::new(); tx.zcash_serialize(&mut data).expect("tx should serialize"); let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize"); - println!("{:?}", tx2); - prop_assert_eq![tx, tx2]; } } From 5289e7c2b9c12b8c4e35f50d88a26255b12705aa Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 21:09:46 -0500 Subject: [PATCH 07/26] Add BlockHeaderHash (de)serialization roundtrip proptest --- zebra-chain/src/block.rs | 24 +++++++++++++++++++++++- zebra-chain/src/types.rs | 1 - 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 86326a7fa15..fab67517efe 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -11,6 +11,9 @@ use std::{ io::{self, Read}, }; +#[cfg(test)] +use proptest_derive::Arbitrary; + use crate::merkle_tree::MerkleTreeRootHash; use crate::note_commitment_tree::SaplingNoteTreeRootHash; use crate::serialization::{ @@ -32,6 +35,7 @@ use crate::transaction::Transaction; /// for now I want to call it a `BlockHeaderHash` because that's /// more explicit. #[derive(Copy, Clone, Eq, PartialEq)] +#[cfg_attr(test, derive(Arbitrary))] pub struct BlockHeaderHash(pub [u8; 32]); impl fmt::Debug for BlockHeaderHash { @@ -184,8 +188,10 @@ impl ZcashDeserialize for Block { #[cfg(test)] mod tests { + use std::io::{Cursor, Write}; + use chrono::NaiveDateTime; - use std::io::Write; + use proptest::prelude::*; use crate::sha256d_writer::Sha256dWriter; @@ -226,4 +232,20 @@ mod tests { "BlockHeaderHash(\"35be4a0f97803879ed642d4e10a146c3fba8727a1dca8079e3f107221be1e7e4\")" ); } + + proptest! { + + #[test] + fn blockheaderhash_roundtrip(hash in any::()) { + let mut bytes = Cursor::new(Vec::new()); + hash.zcash_serialize(&mut bytes)?; + + bytes.set_position(0); + let other_hash = BlockHeaderHash::zcash_deserialize(&mut bytes)?; + + prop_assert_eq![hash, other_hash]; + } + + + } } diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs index af56c88cdf6..9c352301446 100644 --- a/zebra-chain/src/types.rs +++ b/zebra-chain/src/types.rs @@ -183,6 +183,5 @@ mod proptests { prop_assert_eq![script, other_script]; } - } } From 2e3a0b3ac772fc5549f5d83e0b34aad8f46bd0c0 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:26:02 -0500 Subject: [PATCH 08/26] Implement a bunch of traits for EquihashSolution --- zebra-chain/src/equihash_solution.rs | 71 +++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/zebra-chain/src/equihash_solution.rs b/zebra-chain/src/equihash_solution.rs index e0107619f10..5a97d5dba97 100644 --- a/zebra-chain/src/equihash_solution.rs +++ b/zebra-chain/src/equihash_solution.rs @@ -1,8 +1,11 @@ //! Equihash Solution and related items. -// use std::fmt; +use std::{fmt, io}; -// use hex::ToHex; +#[cfg(test)] +use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; + +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// The size of an Equihash solution in bytes (always 1344). const EQUIHASH_SOLUTION_SIZE: usize = 1344; @@ -15,8 +18,7 @@ const EQUIHASH_SOLUTION_SIZE: usize = 1344; /// /// The size of an Equihash solution in bytes is always 1344 so the /// length of this type is fixed. -#[derive(Clone)] -pub struct EquihashSolution([u8; EQUIHASH_SOLUTION_SIZE]); +pub struct EquihashSolution(pub [u8; EQUIHASH_SOLUTION_SIZE]); impl Default for EquihashSolution { fn default() -> Self { @@ -24,15 +26,62 @@ impl Default for EquihashSolution { } } -// TODO: fix hex crate import conflict with tracing-subscriber -// impl fmt::Debug for EquihashSolution { -// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { -// f.write_str(&self.0.encode_hex::()) -// } -// } - impl PartialEq for EquihashSolution { fn eq(&self, other: &EquihashSolution) -> bool { self.0.as_ref() == other.0.as_ref() } } + +impl fmt::Debug for EquihashSolution { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("EquihashSolution") + .field(&hex::encode(&self.0[..])) + .finish() + } +} + +// These impls all only exist because of array length restrictions. + +impl Copy for EquihashSolution {} + +impl Clone for EquihashSolution { + fn clone(&self) -> Self { + let mut bytes = [0; EQUIHASH_SOLUTION_SIZE]; + bytes[..].copy_from_slice(&self.0[..]); + Self(bytes) + } +} + +impl Eq for EquihashSolution {} + +impl ZcashSerialize for EquihashSolution { + fn zcash_serialize(&self, mut writer: W) -> Result<(), SerializationError> { + writer.write_all(&self.0[..])?; + Ok(()) + } +} + +impl ZcashDeserialize for EquihashSolution { + fn zcash_deserialize(mut reader: R) -> Result { + let mut bytes = [0; EQUIHASH_SOLUTION_SIZE]; + reader.read_exact(&mut bytes[..])?; + Ok(Self(bytes)) + } +} + +#[cfg(test)] +impl Arbitrary for EquihashSolution { + type Parameters = (); + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + (vec(any::(), EQUIHASH_SOLUTION_SIZE)) + .prop_map(|v| { + let mut bytes = [0; EQUIHASH_SOLUTION_SIZE]; + bytes.copy_from_slice(v.as_slice()); + return Self(bytes); + }) + .boxed() + } + + type Strategy = BoxedStrategy; +} From b19b808f77b5d60b7f0e1a2942452f299f51eb95 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:29:08 -0500 Subject: [PATCH 09/26] Add a roundtrip (de)serialization proptest for EquihashSolution --- zebra-chain/src/equihash_solution.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zebra-chain/src/equihash_solution.rs b/zebra-chain/src/equihash_solution.rs index 5a97d5dba97..af1ef59c127 100644 --- a/zebra-chain/src/equihash_solution.rs +++ b/zebra-chain/src/equihash_solution.rs @@ -85,3 +85,20 @@ impl Arbitrary for EquihashSolution { type Strategy = BoxedStrategy; } + +#[cfg(test)] +proptest! { + + #[test] + fn encrypted_ciphertext_roundtrip(solution in any::()) { + + let mut data = Vec::new(); + + solution.zcash_serialize(&mut data).expect("EquihashSolution should serialize"); + + let solution2 = EquihashSolution::zcash_deserialize(&data[..]).expect("randomized EquihashSolution should deserialize"); + + prop_assert_eq![solution, solution2]; + } + +} From 705c5cfa1b5a025576e3a6c71f9ff205301f235c Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:30:02 -0500 Subject: [PATCH 10/26] derive(Arbitrary) on MerkleTreeRootHash --- zebra-chain/src/merkle_tree.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/merkle_tree.rs b/zebra-chain/src/merkle_tree.rs index 0e5e4f8a699..1ed9b2f54a5 100644 --- a/zebra-chain/src/merkle_tree.rs +++ b/zebra-chain/src/merkle_tree.rs @@ -3,6 +3,9 @@ use std::io; +#[cfg(test)] +use proptest_derive::Arbitrary; + use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; use crate::sha256d_writer::Sha256dWriter; use crate::transaction::Transaction; @@ -28,7 +31,8 @@ impl ZcashDeserialize for MerkleTree { /// A SHA-256d hash of the root node of a merkle tree of SHA256-d /// hashed transactions in a block. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[cfg_attr(test, derive(Arbitrary))] pub struct MerkleTreeRootHash(pub [u8; 32]); impl From> for MerkleTreeRootHash { From ac95921b18b13ee2ad53f026868bfad8b0414f56 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:30:29 -0500 Subject: [PATCH 11/26] derive(Copy) on SaplingNoteTreeRootHash --- zebra-chain/src/note_commitment_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-chain/src/note_commitment_tree.rs b/zebra-chain/src/note_commitment_tree.rs index 4eba6a24114..32eb0bd2873 100644 --- a/zebra-chain/src/note_commitment_tree.rs +++ b/zebra-chain/src/note_commitment_tree.rs @@ -31,7 +31,7 @@ pub struct SaplingNoteCommitmentTree; /// commitment tree corresponding to the final Sapling treestate of /// this block. A root of a note commitment tree is associated with /// each treestate. -#[derive(Clone, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] #[cfg_attr(test, derive(Arbitrary))] pub struct SaplingNoteTreeRootHash(pub [u8; 32]); From c2c695fa82f7ec934b3507e67794916ce4dc6a16 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:31:30 -0500 Subject: [PATCH 12/26] Use updated EquihashSolution in BlockHeader --- zebra-chain/src/block.rs | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index fab67517efe..3ffb41a429e 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -6,19 +6,15 @@ pub mod test_vectors; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use chrono::{DateTime, TimeZone, Utc}; use hex; -use std::{ - fmt, - io::{self, Read}, -}; +use std::{fmt, io}; #[cfg(test)] use proptest_derive::Arbitrary; +use crate::equihash_solution::EquihashSolution; use crate::merkle_tree::MerkleTreeRootHash; use crate::note_commitment_tree::SaplingNoteTreeRootHash; -use crate::serialization::{ - ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, -}; +use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize}; use crate::sha256d_writer::Sha256dWriter; use crate::transaction::Transaction; @@ -76,7 +72,8 @@ impl ZcashDeserialize for BlockHeaderHash { /// backwards reference (previous header hash) present in the block /// header. Each block points backwards to its parent, all the way /// back to the genesis block (the first block in the blockchain). -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +//#[cfg_attr(test, derive(Arbitrary))] pub struct BlockHeader { /// A SHA-256d hash in internal byte order of the previous block’s /// header. This ensures no previous block can be changed without @@ -117,11 +114,7 @@ pub struct BlockHeader { nonce: [u8; 32], /// The Equihash solution. - // The solution size when serialized should be in bytes ('always - // 1344'). I first tried this as a [u8; 1344] but until const - // generics land we'd have to implement all our common traits - // manually, like in pzec. - solution: Vec, + solution: EquihashSolution, } impl ZcashSerialize for BlockHeader { @@ -130,30 +123,25 @@ impl ZcashSerialize for BlockHeader { writer.write_all(&self.merkle_root_hash.0[..])?; writer.write_all(&self.final_sapling_root_hash.0[..])?; writer.write_u32::(self.time.timestamp() as u32)?; - writer.write_u32::(self.bits as u32)?; + writer.write_u32::(self.bits)?; writer.write_all(&self.nonce[..])?; - writer.write_compactsize(self.solution.len() as u64)?; - writer.write_all(&self.solution[..])?; + self.solution.zcash_serialize(&mut writer)?; Ok(()) } } impl ZcashDeserialize for BlockHeader { fn zcash_deserialize(mut reader: R) -> Result { - Ok(BlockHeader { + let thing = BlockHeader { previous_block_hash: BlockHeaderHash::zcash_deserialize(&mut reader)?, merkle_root_hash: MerkleTreeRootHash(reader.read_32_bytes()?), final_sapling_root_hash: SaplingNoteTreeRootHash(reader.read_32_bytes()?), time: Utc.timestamp(reader.read_u32::()? as i64, 0), bits: reader.read_u32::()?, nonce: reader.read_32_bytes()?, - solution: { - let len = reader.read_compactsize()?; - let mut bytes = Vec::new(); - reader.take(len).read_to_end(&mut bytes)?; - bytes - }, - }) + solution: EquihashSolution::zcash_deserialize(reader)?, + }; + Ok(thing) } } @@ -164,6 +152,7 @@ impl ZcashDeserialize for BlockHeader { /// Block header: a data structure containing the block's metadata /// Transactions: an array (vector in Rust) of transactions #[derive(Clone, Debug, Eq, PartialEq)] +//#[cfg_attr(test, derive(Arbitrary))] pub struct Block { /// First 80 bytes of the block as defined by the encoding used by /// "block" messages. From a8df66d40fd896a1274f4a82e060ddef92c5448c Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:31:51 -0500 Subject: [PATCH 13/26] Impl Zcash(De)Serialization for Block --- zebra-chain/src/block.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 3ffb41a429e..bdf177452ce 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -163,14 +163,19 @@ pub struct Block { } impl ZcashSerialize for Block { - fn zcash_serialize(&self, _writer: W) -> Result<(), SerializationError> { - unimplemented!(); + fn zcash_serialize(&self, mut writer: W) -> Result<(), SerializationError> { + self.header.zcash_serialize(&mut writer)?; + self.transactions.zcash_serialize(&mut writer)?; + Ok(()) } } impl ZcashDeserialize for Block { - fn zcash_deserialize(_reader: R) -> Result { - unimplemented!(); + fn zcash_deserialize(mut reader: R) -> Result { + Ok(Block { + header: BlockHeader::zcash_deserialize(&mut reader)?, + transactions: Vec::zcash_deserialize(&mut reader)?, + }) } } From 93e1bb93bdbb467d33d45bc6b55e1afefa20d4e7 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 31 Jan 2020 23:32:31 -0500 Subject: [PATCH 14/26] Extend blockheaderhash unit test to check a single (de)serialization case roundtrip --- zebra-chain/src/block.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index bdf177452ce..90c3d0b9ad9 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -216,15 +216,26 @@ mod tests { time: DateTime::::from_utc(NaiveDateTime::from_timestamp(61, 0), Utc), bits: 0, nonce: some_bytes, - solution: vec![0; 1344], + solution: EquihashSolution([0; 1344]), }; let hash = BlockHeaderHash::from(blockheader); assert_eq!( format!("{:?}", hash), - "BlockHeaderHash(\"35be4a0f97803879ed642d4e10a146c3fba8727a1dca8079e3f107221be1e7e4\")" + "BlockHeaderHash(\"738948d714d44f3040c2b6809ba7dbc8f4ba673dad39fd755ea4aeaa514cc386\")" ); + + let mut bytes = Cursor::new(Vec::new()); + + // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? + blockheader.zcash_serialize(&mut bytes).unwrap(); + + bytes.set_position(0); + // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? + let other_header = BlockHeader::zcash_deserialize(&mut bytes).unwrap(); + + assert_eq!(blockheader, other_header); } proptest! { From 54424fd94361c2633460a4c7918ca39073c6fed0 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 1 Feb 2020 00:22:48 -0500 Subject: [PATCH 15/26] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 60ba9980014..bbf0f99bd06 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /target/ # Firebase caches (?) .firebase/ +# Emacs detritus +*~ From 5c40688b75c158014377d386ad83320c14889d37 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 1 Feb 2020 00:26:34 -0500 Subject: [PATCH 16/26] Remove derive(Arbitrary) on BlockHeader --- zebra-chain/src/block.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 90c3d0b9ad9..3f77a5cb43a 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -73,7 +73,6 @@ impl ZcashDeserialize for BlockHeaderHash { /// header. Each block points backwards to its parent, all the way /// back to the genesis block (the first block in the blockchain). #[derive(Clone, Copy, Debug, Eq, PartialEq)] -//#[cfg_attr(test, derive(Arbitrary))] pub struct BlockHeader { /// A SHA-256d hash in internal byte order of the previous block’s /// header. This ensures no previous block can be changed without From 393f6758545fdbf0e98268653820bace69e80e0b Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 1 Feb 2020 00:27:51 -0500 Subject: [PATCH 17/26] Move block type tests and proptest support impls to block::tests --- zebra-chain/src/block.rs | 80 +------------------ zebra-chain/src/block/tests.rs | 136 +++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 77 deletions(-) create mode 100644 zebra-chain/src/block/tests.rs diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 3f77a5cb43a..97ba7a4957b 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -2,6 +2,8 @@ #[cfg(test)] pub mod test_vectors; +#[cfg(test)] +mod tests; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use chrono::{DateTime, TimeZone, Utc}; @@ -151,7 +153,7 @@ impl ZcashDeserialize for BlockHeader { /// Block header: a data structure containing the block's metadata /// Transactions: an array (vector in Rust) of transactions #[derive(Clone, Debug, Eq, PartialEq)] -//#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct Block { /// First 80 bytes of the block as defined by the encoding used by /// "block" messages. @@ -177,79 +179,3 @@ impl ZcashDeserialize for Block { }) } } - -#[cfg(test)] -mod tests { - - use std::io::{Cursor, Write}; - - use chrono::NaiveDateTime; - use proptest::prelude::*; - - use crate::sha256d_writer::Sha256dWriter; - - use super::*; - - #[test] - fn blockheaderhash_debug() { - let preimage = b"foo bar baz"; - let mut sha_writer = Sha256dWriter::default(); - let _ = sha_writer.write_all(preimage); - - let hash = BlockHeaderHash(sha_writer.finish()); - - assert_eq!( - format!("{:?}", hash), - "BlockHeaderHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")" - ); - } - - #[test] - fn blockheaderhash_from_blockheader() { - let some_bytes = [0; 32]; - - let blockheader = BlockHeader { - previous_block_hash: BlockHeaderHash(some_bytes), - merkle_root_hash: MerkleTreeRootHash(some_bytes), - final_sapling_root_hash: SaplingNoteTreeRootHash(some_bytes), - time: DateTime::::from_utc(NaiveDateTime::from_timestamp(61, 0), Utc), - bits: 0, - nonce: some_bytes, - solution: EquihashSolution([0; 1344]), - }; - - let hash = BlockHeaderHash::from(blockheader); - - assert_eq!( - format!("{:?}", hash), - "BlockHeaderHash(\"738948d714d44f3040c2b6809ba7dbc8f4ba673dad39fd755ea4aeaa514cc386\")" - ); - - let mut bytes = Cursor::new(Vec::new()); - - // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? - blockheader.zcash_serialize(&mut bytes).unwrap(); - - bytes.set_position(0); - // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? - let other_header = BlockHeader::zcash_deserialize(&mut bytes).unwrap(); - - assert_eq!(blockheader, other_header); - } - - proptest! { - - #[test] - fn blockheaderhash_roundtrip(hash in any::()) { - let mut bytes = Cursor::new(Vec::new()); - hash.zcash_serialize(&mut bytes)?; - - bytes.set_position(0); - let other_hash = BlockHeaderHash::zcash_deserialize(&mut bytes)?; - - prop_assert_eq![hash, other_hash]; - } - - - } -} diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs new file mode 100644 index 00000000000..1e662bbb96f --- /dev/null +++ b/zebra-chain/src/block/tests.rs @@ -0,0 +1,136 @@ +use std::io::{Cursor, Write}; + +use chrono::NaiveDateTime; +use proptest::{ + arbitrary::{any, Arbitrary}, + collection::vec, + option, + prelude::*, +}; + +use crate::sha256d_writer::Sha256dWriter; + +use super::*; + +#[cfg(test)] +impl Arbitrary for BlockHeader { + type Parameters = (); + + fn arbitrary_with(_args: ()) -> Self::Strategy { + ( + any::(), + any::(), + any::(), + (0i64..4_294_967_296i64), + any::(), + any::<[u8; 32]>(), + any::(), + ) + .prop_map( + |( + block_hash, + merkle_root_hash, + sapling_root_hash, + timestamp, + bits, + nonce, + equihash_solution, + )| BlockHeader { + previous_block_hash: block_hash, + merkle_root_hash: merkle_root_hash, + final_sapling_root_hash: sapling_root_hash, + time: Utc.timestamp(timestamp, 0), + bits: bits, + nonce: nonce, + solution: equihash_solution, + }, + ) + .boxed() + } + + type Strategy = BoxedStrategy; +} + +#[test] +fn blockheaderhash_debug() { + let preimage = b"foo bar baz"; + let mut sha_writer = Sha256dWriter::default(); + let _ = sha_writer.write_all(preimage); + + let hash = BlockHeaderHash(sha_writer.finish()); + + assert_eq!( + format!("{:?}", hash), + "BlockHeaderHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")" + ); +} + +#[test] +fn blockheaderhash_from_blockheader() { + let some_bytes = [0; 32]; + + let blockheader = BlockHeader { + previous_block_hash: BlockHeaderHash(some_bytes), + merkle_root_hash: MerkleTreeRootHash(some_bytes), + final_sapling_root_hash: SaplingNoteTreeRootHash(some_bytes), + time: DateTime::::from_utc(NaiveDateTime::from_timestamp(61, 0), Utc), + bits: 0, + nonce: some_bytes, + solution: EquihashSolution([0; 1344]), + }; + + let hash = BlockHeaderHash::from(blockheader); + + assert_eq!( + format!("{:?}", hash), + "BlockHeaderHash(\"738948d714d44f3040c2b6809ba7dbc8f4ba673dad39fd755ea4aeaa514cc386\")" + ); + + let mut bytes = Cursor::new(Vec::new()); + + // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? + blockheader.zcash_serialize(&mut bytes).unwrap(); + + bytes.set_position(0); + // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? + let other_header = BlockHeader::zcash_deserialize(&mut bytes).unwrap(); + + assert_eq!(blockheader, other_header); +} + +proptest! { + + #[test] + fn blockheaderhash_roundtrip(hash in any::()) { + let mut bytes = Cursor::new(Vec::new()); + hash.zcash_serialize(&mut bytes)?; + + bytes.set_position(0); + let other_hash = BlockHeaderHash::zcash_deserialize(&mut bytes)?; + + prop_assert_eq![hash, other_hash]; + } + + #[test] + fn blockheader_roundtrip(header in any::()) { + let mut bytes = Cursor::new(Vec::new()); + header.zcash_serialize(&mut bytes)?; + + bytes.set_position(0); + let other_header = BlockHeader::zcash_deserialize(&mut bytes)?; + + prop_assert_eq![header, other_header]; + } + + #[test] + fn block_roundtrip(block in any::()) { + let mut bytes = Cursor::new(Vec::new()); + block.zcash_serialize(&mut bytes)?; + + bytes.set_position(0); + let other_block = Block::zcash_deserialize(&mut bytes)?; + + prop_assert_eq![block, other_block]; + } + +} From 2a27a580663b1e761ee1e83f064e350f46eaa578 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 1 Feb 2020 00:28:48 -0500 Subject: [PATCH 18/26] Add proptests-regressions/block/tests.txt --- zebra-chain/proptest-regressions/block/tests.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 zebra-chain/proptest-regressions/block/tests.txt diff --git a/zebra-chain/proptest-regressions/block/tests.txt b/zebra-chain/proptest-regressions/block/tests.txt new file mode 100644 index 00000000000..ae5bbef6281 --- /dev/null +++ b/zebra-chain/proptest-regressions/block/tests.txt @@ -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 1fcf1e08caccdafad9c9f51c46cd24b992cf7207f55cae605a54830868527baa # shrinks to header = BlockHeader { previous_block_hash: BlockHeaderHash("0000000000000000000000000000000000000000000000000000000000000000"), merkle_root_hash: MerkleTreeRootHash([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]), final_sapling_root_hash: SaplingNoteTreeRootHash([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]), time: 1969-12-31T23:59:59Z, bits: 0, nonce: [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], solution: EquihashSolution("000000000000000000000128fd6ffe028bf9b8e789cf2bf69845f52fddda4066064dd798670fd27ca39ab1a3a363ccd3aab31a6e3aaf168095acafbf6a95f01a651d0c1b799a8c3134838b78de78c7128b4280136f544792764a739e3f152e92a79e849d87db179f8aa6d565b5c9c5cb60f92acd669254c0a454ecc0d74d05e21135f5f9445dd18755bc2bd2af041ba3f903e22ceccf729825b382e95b0d90b6a8657645395caa9041a93e904505c762f57ed042cb8e3b69a7fbee5bb8d174fabd95fbae8e7c01e8ecfe69d32d3954c8bdf75f8a292b08358a74d67a63599c9c97a2af237cfe0a14fbe21d73676a097706836f31bfac1e269e050e8cd95ffa04f24553206df40b559ba59078053a19ca20e51fde2ed9bf3a6f2d64e50985abdb59843738296438fd1e0223f1bac8525f42ccbb8ca128436fd5fb936bf5819b2469334d2082120bcdd62e6b800bb64124dd7472e1a8fc14d8e022a4195ff7be3b93deb24f5cf2c54015fd3ba008d035f57c991dae92eb6ad4ddae0e115ab4bd1f36350688d1bbe44574dcf53f158ab3d2747764b5bbf962d66570ef2b25d9cca5dcca7c692c33d0999f916ec0c4f87816797fdb7d38152110008470755ccd74552d498962297c7f99e4a59aface18dfb626bd106043932d70ccb97aa17152cf2da8d30f252cdb42883376ab048f94b376b9f844a412900a41bb63e11af1ea6cb0387646665cb067ada754335c66f499008bf836a3ee08330e4cef1c8218c0af52cadb7caf11e970737f2b684409921969e5be75a3b3328a98528f1d5af263ba33555a9df47f055f5698ce5f02827e08ec56e17bca426e16ea75474be0c68a02c22a1a095821019e293d79d2cb39baea9d190b9c07b9c2961a1b87a20ca3b6bc078cd7f928062d37b4f39b43057196079a71148ea1c5ce60c78711d314e021dc378c00a66eb4190b19b1804241b01a2bb9577ea4532f31ed3b76772e91313fd2639d1ba0e238035fc1a1dfe3f83caa7b82a9fddbbf15cbf6266ab824bcbfbdd7d8684a1002aaa96d234f5bacc124b7df180fd743d9108848f2cd38fdd96493353b31cac694fba0f502fe8410659fdf77a3774959a3579e66eebe8a190361b7abbd5f761b8b5b3fc78f4f146b3ffb08560589d7d2e12d279f7720e0b4bf72dd396d8628e1a335c2260af81198b32345da6cae3f93f734f7faa8d7a025130443260c8dc0a3640256315839570a9745f3dd4c75a3dcac9ff7b0dd081e072dd2337e3461078ba09c51c477e4e0f64bdf3cf898df0e8add9f94618993242a147e3aa7a879fe8ced8b0e6421c700376757c32c5df309d45b986ea28733a5519f3b1b501951bbad2c4d4dc823b05233a6c957bdd336f74bc803d5cb6b001681eac90e4ce1ee1766419b2f2a1024d81b03c21699d61b0faeeba6325d429c5f338de675a9c0ebd2ef75f4ccd6fd0b46232368c8b59d574be2cf1c7ea01a5fd3f8f30f268ba858a0910bee8ce4345028a6e471fce6f28b98ae64b9609c8235adebd8cca87462cae60349bc4b61a8a86071025d0f6f314a8a00cd98bd2680e19441bdc124722ddc64833d29b26fb5c34819d6315fc05e4c362dd13e3221f78e251869abdf26d728ba0896897348a07407d5822928e724987998101a6d00e39c125b7b0d22f43aed8b7f15080b4d0fa056454392466bcd27e56d7d49dd35a86e0337c0bfb5efb14e3ebf353ee57d6631437881e42ed3da531737d6266550ea4a6ced3f9b53523e6233e95a8b5fa730d321b1618cb67488f82c6fe2b17b6483910e25cc7b6df22560694a185bea249d29ac0699edba45038713077589a3b3058e1a4bf4579f4b224dbe01e1e017c268dafde88a89e9cb29f999b8870ce704275e24861613188555") } From 2e206fa8f195a5ab8cb882ae5e48a0940d6fa291 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 1 Feb 2020 02:16:21 -0500 Subject: [PATCH 19/26] Cleanup --- zebra-chain/src/block/tests.rs | 2 -- zebra-chain/src/equihash_solution.rs | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs index 1e662bbb96f..85fffb626f0 100644 --- a/zebra-chain/src/block/tests.rs +++ b/zebra-chain/src/block/tests.rs @@ -3,8 +3,6 @@ use std::io::{Cursor, Write}; use chrono::NaiveDateTime; use proptest::{ arbitrary::{any, Arbitrary}, - collection::vec, - option, prelude::*, }; diff --git a/zebra-chain/src/equihash_solution.rs b/zebra-chain/src/equihash_solution.rs index af1ef59c127..44cc3723627 100644 --- a/zebra-chain/src/equihash_solution.rs +++ b/zebra-chain/src/equihash_solution.rs @@ -20,12 +20,6 @@ const EQUIHASH_SOLUTION_SIZE: usize = 1344; /// length of this type is fixed. pub struct EquihashSolution(pub [u8; EQUIHASH_SOLUTION_SIZE]); -impl Default for EquihashSolution { - fn default() -> Self { - EquihashSolution([0; EQUIHASH_SOLUTION_SIZE]) - } -} - impl PartialEq for EquihashSolution { fn eq(&self, other: &EquihashSolution) -> bool { self.0.as_ref() == other.0.as_ref() @@ -87,18 +81,24 @@ impl Arbitrary for EquihashSolution { } #[cfg(test)] -proptest! { +mod tests { - #[test] - fn encrypted_ciphertext_roundtrip(solution in any::()) { + use super::*; - let mut data = Vec::new(); + proptest! { - solution.zcash_serialize(&mut data).expect("EquihashSolution should serialize"); + #[test] + fn equihash_solution_roundtrip(solution in any::()) { - let solution2 = EquihashSolution::zcash_deserialize(&data[..]).expect("randomized EquihashSolution should deserialize"); + let mut data = Vec::new(); - prop_assert_eq![solution, solution2]; - } + solution.zcash_serialize(&mut data).expect("EquihashSolution should serialize"); + let solution2 = EquihashSolution::zcash_deserialize(&data[..]) + .expect("randomized EquihashSolution should deserialize"); + + prop_assert_eq![solution, solution2]; + } + + } } From ebfee99d94025d2c576424b0dfd1519fa4b6a9b6 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 3 Feb 2020 18:55:42 -0500 Subject: [PATCH 20/26] Remove debugging variable assignments --- zebra-chain/src/block.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 97ba7a4957b..654ee3e19b1 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -63,8 +63,7 @@ impl ZcashSerialize for BlockHeaderHash { impl ZcashDeserialize for BlockHeaderHash { fn zcash_deserialize(mut reader: R) -> Result { - let bytes = reader.read_32_bytes()?; - Ok(BlockHeaderHash(bytes)) + Ok(BlockHeaderHash(reader.read_32_bytes()?)) } } @@ -133,7 +132,7 @@ impl ZcashSerialize for BlockHeader { impl ZcashDeserialize for BlockHeader { fn zcash_deserialize(mut reader: R) -> Result { - let thing = BlockHeader { + Ok(BlockHeader { previous_block_hash: BlockHeaderHash::zcash_deserialize(&mut reader)?, merkle_root_hash: MerkleTreeRootHash(reader.read_32_bytes()?), final_sapling_root_hash: SaplingNoteTreeRootHash(reader.read_32_bytes()?), @@ -141,8 +140,7 @@ impl ZcashDeserialize for BlockHeader { bits: reader.read_u32::()?, nonce: reader.read_32_bytes()?, solution: EquihashSolution::zcash_deserialize(reader)?, - }; - Ok(thing) + }) } } From 836329b0858afed0964ab051b964df4effa7be28 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 3 Feb 2020 19:29:00 -0500 Subject: [PATCH 21/26] Use Result::expect() in test (de)serializations --- zebra-chain/src/block/tests.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs index 85fffb626f0..fc363dd5f20 100644 --- a/zebra-chain/src/block/tests.rs +++ b/zebra-chain/src/block/tests.rs @@ -86,12 +86,13 @@ fn blockheaderhash_from_blockheader() { let mut bytes = Cursor::new(Vec::new()); - // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? - blockheader.zcash_serialize(&mut bytes).unwrap(); + blockheader + .zcash_serialize(&mut bytes) + .expect("these bytes to serialize from a blockheader without issue"); bytes.set_position(0); - // rustc keeps telling me I can't use `?` here, but unwrap() works fine??? - let other_header = BlockHeader::zcash_deserialize(&mut bytes).unwrap(); + let other_header = BlockHeader::zcash_deserialize(&mut bytes) + .expect("these bytes to deserialize into a blockheader without issue"); assert_eq!(blockheader, other_header); } From 5a4c52afd249a74c6d08e702753c05ccdac211f7 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 3 Feb 2020 19:29:51 -0500 Subject: [PATCH 22/26] Add a simple test to check that our mainnet blockheader test vector deserializes without error --- zebra-chain/src/block/tests.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs index fc363dd5f20..f83923a5138 100644 --- a/zebra-chain/src/block/tests.rs +++ b/zebra-chain/src/block/tests.rs @@ -97,6 +97,14 @@ fn blockheaderhash_from_blockheader() { assert_eq!(blockheader, other_header); } +#[test] +fn deserialize_blockheader() { + // This deserializes without error but the result looks wrong. + // https://explorer.zcha.in/blocks/415000 + let header = BlockHeader::zcash_deserialize(&test_vectors::HEADER_MAINNET_415000[..]) + .expect("blockheader test vector should deserialize"); +} + proptest! { #[test] From fefa0576a7579f12ef48ed69f5f5ce3482e7833f Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 3 Feb 2020 20:02:30 -0500 Subject: [PATCH 23/26] Read and write the block header version, which is fixed at 4 --- zebra-chain/src/block.rs | 9 +++++++++ zebra-chain/src/block/test_vectors.rs | 1 + zebra-chain/src/block/tests.rs | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 654ee3e19b1..b0093658552 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -119,6 +119,8 @@ pub struct BlockHeader { impl ZcashSerialize for BlockHeader { fn zcash_serialize(&self, mut writer: W) -> Result<(), SerializationError> { + // "The current and only defined block version number for Zcash is 4." + writer.write_u32::(4)?; self.previous_block_hash.zcash_serialize(&mut writer)?; writer.write_all(&self.merkle_root_hash.0[..])?; writer.write_all(&self.final_sapling_root_hash.0[..])?; @@ -132,6 +134,13 @@ impl ZcashSerialize for BlockHeader { impl ZcashDeserialize for BlockHeader { fn zcash_deserialize(mut reader: R) -> Result { + // "The current and only defined block version number for Zcash is 4." + let version = reader.read_u32::()?; + + if version != 4 { + return Err(SerializationError::Parse("bad block header")); + } + Ok(BlockHeader { previous_block_hash: BlockHeaderHash::zcash_deserialize(&mut reader)?, merkle_root_hash: MerkleTreeRootHash(reader.read_32_bytes()?), diff --git a/zebra-chain/src/block/test_vectors.rs b/zebra-chain/src/block/test_vectors.rs index 43223acd705..d167b75de3f 100644 --- a/zebra-chain/src/block/test_vectors.rs +++ b/zebra-chain/src/block/test_vectors.rs @@ -1,5 +1,6 @@ // Copied from librustzcash // From mainnet block 415000. +// https://explorer.zcha.in/blocks/415000 pub const HEADER_MAINNET_415000: [u8; 1487] = [ 0x04, 0x00, 0x00, 0x00, 0x52, 0x74, 0xb4, 0x3b, 0x9e, 0x4a, 0xd8, 0xf4, 0x3e, 0x93, 0xf7, 0x84, 0x63, 0xd2, 0x4d, 0xcf, 0xe5, 0x31, 0xae, 0xb4, 0x71, 0x98, 0x19, 0xf4, 0xf9, 0x7f, 0x7e, 0x03, diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs index f83923a5138..9646ffa4590 100644 --- a/zebra-chain/src/block/tests.rs +++ b/zebra-chain/src/block/tests.rs @@ -81,7 +81,7 @@ fn blockheaderhash_from_blockheader() { assert_eq!( format!("{:?}", hash), - "BlockHeaderHash(\"738948d714d44f3040c2b6809ba7dbc8f4ba673dad39fd755ea4aeaa514cc386\")" + "BlockHeaderHash(\"e942461f17dd1daea4157df9ba7a2aa5c90a885ac205375a0161f682635da207\")" ); let mut bytes = Cursor::new(Vec::new()); @@ -99,9 +99,8 @@ fn blockheaderhash_from_blockheader() { #[test] fn deserialize_blockheader() { - // This deserializes without error but the result looks wrong. // https://explorer.zcha.in/blocks/415000 - let header = BlockHeader::zcash_deserialize(&test_vectors::HEADER_MAINNET_415000[..]) + let _header = BlockHeader::zcash_deserialize(&test_vectors::HEADER_MAINNET_415000[..]) .expect("blockheader test vector should deserialize"); } From 1c3c875f2174c9bf7d25ddea89d44b3aff575739 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 4 Feb 2020 03:49:56 -0500 Subject: [PATCH 24/26] Add comment around sha256d_flush test --- zebra-chain/src/sha256d_writer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zebra-chain/src/sha256d_writer.rs b/zebra-chain/src/sha256d_writer.rs index 77dbec20caf..4e4c14a34c6 100644 --- a/zebra-chain/src/sha256d_writer.rs +++ b/zebra-chain/src/sha256d_writer.rs @@ -40,6 +40,7 @@ mod tests { use crate::sha256d_writer::Sha256dWriter; #[test] + // Just checking that `flush()` succeeds without error. fn sha256d_flush() { let preimage = b"foo bar baz"; let mut sha_writer = Sha256dWriter::default(); From ecd5c29fb2c0bad8db3f564bc31c44475438ac3e Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 4 Feb 2020 04:23:33 -0500 Subject: [PATCH 25/26] Write and read the equihash solution compactsize on (de)serialize --- zebra-chain/src/equihash_solution.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/equihash_solution.rs b/zebra-chain/src/equihash_solution.rs index 44cc3723627..55ca811644e 100644 --- a/zebra-chain/src/equihash_solution.rs +++ b/zebra-chain/src/equihash_solution.rs @@ -5,7 +5,9 @@ use std::{fmt, io}; #[cfg(test)] use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; -use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; +use crate::serialization::{ + ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, +}; /// The size of an Equihash solution in bytes (always 1344). const EQUIHASH_SOLUTION_SIZE: usize = 1344; @@ -50,6 +52,7 @@ impl Eq for EquihashSolution {} impl ZcashSerialize for EquihashSolution { fn zcash_serialize(&self, mut writer: W) -> Result<(), SerializationError> { + writer.write_compactsize(EQUIHASH_SOLUTION_SIZE as u64)?; writer.write_all(&self.0[..])?; Ok(()) } @@ -57,6 +60,7 @@ impl ZcashSerialize for EquihashSolution { impl ZcashDeserialize for EquihashSolution { fn zcash_deserialize(mut reader: R) -> Result { + reader.read_compactsize()?; let mut bytes = [0; EQUIHASH_SOLUTION_SIZE]; reader.read_exact(&mut bytes[..])?; Ok(Self(bytes)) From f659e607a43faa7904abd2268327ae3b46769d64 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 4 Feb 2020 04:28:10 -0500 Subject: [PATCH 26/26] Update test block header hash --- zebra-chain/src/block/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-chain/src/block/tests.rs b/zebra-chain/src/block/tests.rs index 9646ffa4590..7f36d109da2 100644 --- a/zebra-chain/src/block/tests.rs +++ b/zebra-chain/src/block/tests.rs @@ -81,7 +81,7 @@ fn blockheaderhash_from_blockheader() { assert_eq!( format!("{:?}", hash), - "BlockHeaderHash(\"e942461f17dd1daea4157df9ba7a2aa5c90a885ac205375a0161f682635da207\")" + "BlockHeaderHash(\"39c92b8c6b582797830827c78d58674c7205fcb21991887c124d1dbe4b97d6d1\")" ); let mut bytes = Cursor::new(Vec::new());