You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when prev-target (x) is too large, y = x * U256::from(actual) will overflow.
A Proposed Solution
Pseudocode as following:
let x = U512::from_little_endian(&prev_target_le_bytes);let y = x *U512::from(actual);let z_tmp = y / U512::from(expected);if z_tmp > U512::from(U256::MAX){panic!();}let z = z_tmp asU256;
Affected Scope
Bitcoin mainnet and Bitcoin testnet don't have such large target.
So, we can ignore it temporary.
But I strongly suggest fixing it when upgrade the production contract next time.
How to Reproduce
Modify this unit test, to calculate the next bitcoin target for following headers, directly.
Issue
Causes "arithmetic operation overflow" on Bitcoin dev chain.
Reason
In the following code:
https://github.com/ckb-cell/ckb-bitcoin-spv/blob/a3c43fd5fb70044ad438f703212b255af5024476/verifier/src/utilities/bitcoin.rs#L29-L35
when
prev-target
(x
) is too large,y = x * U256::from(actual)
will overflow.A Proposed Solution
Pseudocode as following:
Affected Scope
Bitcoin mainnet and Bitcoin testnet don't have such large target.
So, we can ignore it temporary.
But I strongly suggest fixing it when upgrade the production contract next time.
How to Reproduce
Modify this unit test, to calculate the next bitcoin target for following headers, directly.
Header 2016:
Header 4031:
These data could be added to as a unit test after fixing it.
References
The text was updated successfully, but these errors were encountered: