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

Improvements to Uint type? #410

Closed
dr-orlovsky opened this issue Feb 13, 2020 · 3 comments
Closed

Improvements to Uint type? #410

dr-orlovsky opened this issue Feb 13, 2020 · 3 comments

Comments

@dr-orlovsky
Copy link
Collaborator

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.

@elichai
Copy link
Member

elichai commented Feb 13, 2020

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.

@dr-orlovsky
Copy link
Collaborator Author

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

@dr-orlovsky
Copy link
Collaborator Author

Closed by #436 and #435

Has a follow-up in #467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants