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
I understand that bitcoin library is not a big int lib, however would like to share my experience of using it.
I have to do some U256 math in consensus-critical code in my library for the layers above Bitcoin (L2/L3), and this math is absent in Uint256 type of the bitcoin crate (like modulo division, or constructing from [u8] slice). For sure, I can use bigint crate, but I do not want to increase number of dependencies when the most of the required functionality is already in bitcoin and it's trivial to add the one that is absent.
So if you will find it useful to add to util::uint implementations for From<[u8; 32]> and std::ops::Rem (which are present in bigint) I will be happy to submit a PR.
The text was updated successfully, but these errors were encountered:
I'd be extremely wary of using the U256 type here for actual complicated math calcs.
Can you explain your use case?
For example, if you need to do multiplication modulo N, then you have a problem, because if it's wrapping then it's basically doing mod 2^256 which will screw up your own mod.
So you usually either want a more general purpose bigint lib or a more specialized one for the exact field you need.
The case is quite simple: I have to convert 256-bit hash into a U256 and do a modulo arithmetics on it. The reason is this: https://github.com/LNP-BP/lnpbps/blob/master/lnpbp-0004.md implies a bloom-type filtering, and modulo arithmetics is required for that (w/o multiplication).
Regardless adding or not modulo division, it seems to me that from_u64-like functions should be better changed on impl From<u64> for Uint256
I understand that bitcoin library is not a big int lib, however would like to share my experience of using it.
I have to do some U256 math in consensus-critical code in my library for the layers above Bitcoin (L2/L3), and this math is absent in
Uint256
type of the bitcoin crate (like modulo division, or constructing from [u8] slice). For sure, I can usebigint
crate, but I do not want to increase number of dependencies when the most of the required functionality is already in bitcoin and it's trivial to add the one that is absent.So if you will find it useful to add to
util::uint
implementations forFrom<[u8; 32]>
andstd::ops::Rem
(which are present inbigint
) I will be happy to submit a PR.The text was updated successfully, but these errors were encountered: