Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading POW for edge bits 59 and higher #3069

Merged
merged 2 commits into from Oct 2, 2019

Conversation

@hashmap
Copy link
Member

commented Oct 1, 2019

It requires reading more than 8 bytes

It requires reading more than 8 bytes
@hashmap hashmap requested a review from tromp Oct 1, 2019
core/src/pow/types.rs Outdated Show resolved Hide resolved
core/src/pow/types.rs Outdated Show resolved Hide resolved
core/src/pow/types.rs Outdated Show resolved Hide resolved
core/src/pow/types.rs Outdated Show resolved Hide resolved
core/src/pow/types.rs Outdated Show resolved Hide resolved
@@ -391,21 +391,39 @@ impl Proof {
}
}

#[inline(always)]
fn extract_bits(bits: &Vec<u8>, bit_start: usize, bit_count: usize, read_from: usize) -> u64 {
let mut buf: [u8; 8] = [0; 8];

This comment has been minimized.

Copy link
@tromp

tromp Oct 1, 2019

Contributor

Is it possible in rust to directly assign

let bits64 = u64::from_le_bytes(&bits[read_from..read_from + 8]);

?
if so, that would be much preferable over the extra buffer and copying....

This comment has been minimized.

Copy link
@tromp

tromp Oct 1, 2019

Contributor

Other than that, this PR looks fine to me.

This comment has been minimized.

Copy link
@hashmap

hashmap Oct 2, 2019

Author Member

Array and slice are different types in Rust, so we can't directly use bits in from_le_bytes

This comment has been minimized.

Copy link
@tromp

tromp Oct 2, 2019

Contributor

and there's no function or method we can call on the slice to convert to array?

This comment has been minimized.

Copy link
@tromp

tromp Oct 2, 2019

Contributor

btw, remaining comments are just about aesthetics (can always be reconsidered later) and should not hold up this PR...

let mut v = Vec::with_capacity(42);
for _ in 0..42 {
v.push(rng.gen_range(
u64::pow(2, bits - 1),

This comment has been minimized.

Copy link
@tromp

tromp Oct 1, 2019

Contributor

btw, isn't it easier to write 1 << (bits - 1) than u64::pow(2, bits - 1) ?

This comment has been minimized.

Copy link
@DavidBurkett

DavidBurkett Oct 1, 2019

Contributor

I think it's easier to read u64::pow(2, bits - 1), so personally prefer it iff there's no performance hit.

@hashmap hashmap merged commit 7861a40 into mimblewimble:master Oct 2, 2019
10 checks passed
10 checks passed
mimblewimble.grin Build #20191001.5 succeeded
Details
mimblewimble.grin (linux api/util/store) linux api/util/store succeeded
Details
mimblewimble.grin (linux chain/core/keychain) linux chain/core/keychain succeeded
Details
mimblewimble.grin (linux pool/p2p/src) linux pool/p2p/src succeeded
Details
mimblewimble.grin (linux release) linux release succeeded
Details
mimblewimble.grin (linux servers) linux servers succeeded
Details
mimblewimble.grin (macos release) macos release succeeded
Details
mimblewimble.grin (macos test) macos test succeeded
Details
mimblewimble.grin (windows release) windows release succeeded
Details
mimblewimble.grin (windows test) windows test succeeded
Details
@hashmap hashmap deleted the cyclefortytwo:fix-read-number branch Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.