From 55a29bfa86985122a3a0b8ae4bfcd9038a32aa29 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 9 Feb 2016 03:23:35 -0800 Subject: [PATCH] unordered verification --- ethcore/src/ethereum/ethash.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 7d99a456a..3e1d7c1bf 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -157,6 +157,11 @@ impl Engine for Ethash { } fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { + if header.seal.len() != self.seal_fields() { + return Err(From::from(BlockError::InvalidSealArity( + Mismatch { expected: self.seal_fields(), found: header.seal.len() } + ))); + } let result = self.pow.compute_light(header.number as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64()); let mix = Ethash::from_ethash(result.mix_hash); let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value)); @@ -387,7 +392,32 @@ mod tests { Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {}, _ => { panic!("should be invalid proof of work error"); } } + } + #[test] + fn can_do_seal_unordered_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let header: Header = Header::default(); + + let verify_result = engine.verify_block_unordered(&header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, + _ => { panic!("should be block seal mismatch error"); } + } + } + + #[test] + fn can_do_seal256_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]); + let verify_result = engine.verify_block_unordered(&header, None); + + match verify_result { + Err(Error::Block(BlockError::MismatchedH256SealElement(_))) => {}, + _ => { panic!("should be invalid proof of work error"); } + } } // TODO: difficulty test