From 6dedb7e101071d6124cbac0a9289c2b583ddb409 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 4 Feb 2020 04:23:33 -0500 Subject: [PATCH] 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 44cc3723..55ca8116 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))