Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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