Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
fixed PoW difficulty validation, #8397
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Aug 9, 2018
1 parent e2095d4 commit c21d5cd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ impl Ethash {
if d <= U256::one() {
U256::max_value()
} else {
((U256::one() << 255) / d) << 1
let rest = (U256::max_value() % d) + U256::one();
U256::max_value() / d + rest / d
}
}

Expand All @@ -463,7 +464,8 @@ impl Ethash {
if *difficulty <= U256::one() {
U256::max_value().into()
} else {
(((U256::one() << 255) / *difficulty) << 1).into()
let rest = (U256::max_value() % *difficulty) + U256::one();
(U256::max_value() / *difficulty + rest / *difficulty).into()
}
}
}
Expand Down Expand Up @@ -534,6 +536,15 @@ mod tests {
}
}

#[test]
fn test_difficulty() {
// edge case from https://github.com/paritytech/parity-ethereum/issues/8397
let source_difficulty = 307_293.into();
let boundary = Ethash::difficulty_to_boundary(&source_difficulty);
let difficulty = Ethash::boundary_to_difficulty(&boundary);
assert_eq!(source_difficulty, difficulty);
}

#[test]
fn on_close_block() {
let spec = test_spec();
Expand Down

0 comments on commit c21d5cd

Please sign in to comment.