diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 654ee3e1..b0093658 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 43223acd..d167b75d 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 f83923a5..9646ffa4 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"); }