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

fixed #1261, overflow when calculating work #1283

Merged
merged 4 commits into from Jun 15, 2016
Merged

fixed #1261, overflow when calculating work #1283

merged 4 commits into from Jun 15, 2016

Conversation

debris
Copy link
Collaborator

@debris debris commented Jun 14, 2016

@debris debris added the A0-pleasereview 🤓 Pull request needs code review. label Jun 14, 2016
@@ -509,5 +510,11 @@ mod tests {
}
}

#[test]
fn test_difficulty_to_boundary() {
let _ = Ethash::difficulty_to_boundary(&U256::from(0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not asserting the actuall result?

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jun 14, 2016
@gavofyork
Copy link
Contributor

waiting for the answer...

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Jun 14, 2016
@debris debris added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jun 14, 2016
@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jun 15, 2016
@@ -255,12 +255,14 @@ impl Ethash {

/// Convert an Ethash boundary to its original difficulty. Basically just `f(x) = 2^256 / x`.
pub fn boundary_to_difficulty(boundary: &H256) -> U256 {
U256::from((U512::one() << 256) / U256::from(boundary.as_slice()).into())
let d = cmp::max(U256::from(boundary), U256::one());
((U256::one() << 255) / d) << 1
Copy link
Contributor

@gavofyork gavofyork Jun 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will still overflow if boundary == d == U256::one() (returning the impossible boundary 0 as the tests confirm).

rather it should probably special-case boundary <= 1 and return !U256::zero(). see YP(160).

@gavofyork gavofyork added A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Jun 15, 2016
@debris debris added A0-pleasereview 🤓 Pull request needs code review. and removed A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. labels Jun 15, 2016
@debris
Copy link
Collaborator Author

debris commented Jun 15, 2016

updated

@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jun 15, 2016
@gavofyork gavofyork merged commit 549647b into master Jun 15, 2016
@gavofyork gavofyork deleted the 1261 branch June 15, 2016 14:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants