ccurl icon indicating copy to clipboard operation
ccurl copied to clipboard

Loss of precision causes additional iterations and different pow result

Open obany opened this issue 7 years ago • 0 comments

If you are using the pure C implementation pearl_diver.c the signature for is_found_fast() causes loss of precision on it's return value.

https://github.com/iotaledger/ccurl/blob/94d74a492a7ff9494c73b7be2dcf80f3ce4d453f/src/lib/pearl_diver.c#L154

I have a case where the final lastMeasurement value within the is_found_fast() check is 4611686018427387904, but because the return value is an int it gets converted to 0, this in turn causes the whole outer loop to perform more iterations than is necessary.

By changing the return type to bc_trit_t fixes this issue.


Additionally the code which produces the nonce_output from the nonce_probe also has an issue.

https://github.com/iotaledger/ccurl/blob/94d74a492a7ff9494c73b7be2dcf80f3ce4d453f/src/lib/pearl_diver.c#L223-L239

The left shifts are performed as 1 << shift, but this is also truncated because there is not enough precision. This would not have been seen due to the other issue as we would only have ever had a nonce_probe within the 32 bit range. But now we have full precision the shift causes issues when the nonce_probe is in the 64 bit range.

e.g. 1 << 62 = 1073741824 // Wrong e.g. 1L << 62 = 4611686018427387904 // Correct

This also means that the nonce_output produces a different result for the pow trits.

obany avatar Feb 09 '18 11:02 obany