diff --git a/src/ethereum/ethash.rs b/src/ethereum/ethash.rs index a677a86cc..019d764df 100644 --- a/src/ethereum/ethash.rs +++ b/src/ethereum/ethash.rs @@ -101,7 +101,7 @@ impl Engine for Ethash { fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { // check the seal fields. try!(UntrustedRlp::new(&header.seal[0]).as_val::()); - try!(UntrustedRlp::new(&header.seal[1]).as_val::()); + try!(UntrustedRlp::new(&header.seal[1]).as_val::()); let min_difficulty = decode(self.spec().engine_params.get("minimumDifficulty").unwrap()); if header.difficulty < min_difficulty { @@ -109,7 +109,7 @@ impl Engine for Ethash { } let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty( &Ethash::to_ethash(header.bare_hash()), - header.nonce(), + header.nonce().low_u64(), &Ethash::to_ethash(header.mix_hash())))); if difficulty < header.difficulty { return Err(From::from(BlockError::InvalidEthashDifficulty(Mismatch { expected: header.difficulty, found: difficulty }))); @@ -118,7 +118,7 @@ impl Engine for Ethash { } fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { - let result = self.pow.compute_light(header.number as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce()); + 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)); if mix != header.mix_hash() { @@ -208,7 +208,7 @@ impl Ethash { } impl Header { - fn nonce(&self) -> u64 { + fn nonce(&self) -> H64 { decode(&self.seal()[1]) } fn mix_hash(&self) -> H256 { diff --git a/src/tests/chain.rs b/src/tests/chain.rs index 661968764..97dc2767f 100644 --- a/src/tests/chain.rs +++ b/src/tests/chain.rs @@ -68,8 +68,8 @@ declare_test!{BlockchainTests_bcInvalidRLPTest, "BlockchainTests/bcInvalidRLPTes declare_test!{BlockchainTests_bcMultiChainTest, "BlockchainTests/bcMultiChainTest"} declare_test!{BlockchainTests_bcRPC_API_Test, "BlockchainTests/bcRPC_API_Test"} declare_test!{BlockchainTests_bcStateTest, "BlockchainTests/bcStateTest"} -declare_test!{BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"} // FAILS AGAIN? +declare_test!{BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"} // FAILS: ZeroPrefixed Int. declare_test!{BlockchainTests_bcUncleHeaderValiditiy, "BlockchainTests/bcUncleHeaderValiditiy"} declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"} -declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"} // STILL FAILS +declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"} declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"} diff --git a/util/src/hash.rs b/util/src/hash.rs index 0e4139f3c..e9241a71e 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -41,6 +41,8 @@ pub trait FixedHash: Sized + BytesConvertable + Populatable + FromStr + Default fn contains<'a>(&'a self, b: &'a Self) -> bool; /// TODO [debris] Please document me fn is_zero(&self) -> bool; + /// Return the lowest 8 bytes interpreted as a BigEndian integer. + fn low_u64(&self) -> u64; } fn clean_0x(s: &str) -> &str { @@ -71,8 +73,8 @@ macro_rules! impl_hash { &self.0 } } - impl DerefMut for $from { + impl DerefMut for $from { #[inline] fn deref_mut(&mut self) -> &mut [u8] { &mut self.0 @@ -190,6 +192,14 @@ macro_rules! impl_hash { fn is_zero(&self) -> bool { self.eq(&Self::new()) } + + fn low_u64(&self) -> u64 { + let mut ret = 0u64; + for i in 0..min($size, 8) { + ret |= (self.0[$size - 1 - i] as u64) << (i * 8); + } + ret + } } impl FromStr for $from {