mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 990 forks source link

bug in computing proof size rounded up to next higher 2-power #3762

Closed tromp closed 1 year ago

tromp commented 1 year ago

Describe the bug Line 264 of core/src/pow/cuckatoo.rs computes

    let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1

assuming that size of type usize is the same 64-bit size as u64::MAX. Which is the case on 64-bit platforms, but on 32-bit platforms the right shift falls short by 32, leaving mask with a wrong value, and these platforms fail to verify valid PoWs.

The fix could be as simple as change size to (size as u64).