-
Notifications
You must be signed in to change notification settings - Fork 75
Use traits implemented for all Uint/Int types
#1008
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
Conversation
NewConcat/NewConcatMixedUint/Int types
1ad3d2e to
c7a2b4f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1008 +/- ##
==========================================
- Coverage 79.87% 79.86% -0.02%
==========================================
Files 163 162 -1
Lines 17593 17575 -18
==========================================
- Hits 14053 14036 -17
+ Misses 3540 3539 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8de22eb to
7273f8d
Compare
|
Definitely liking this overall direction |
|
@tarcieri I would like to implement Serialize/Deserialize for all Uints as well, there are two options:
What do you think is a better way? Actually, the second option may not be possible with Edit: yes, I don't think it will be possible. |
It's not prohibited (it's deny instead of forbid) and we do have unsafe a few places, however I would be a bit more concerned about adding an additional hard dependency, even if it is a widely used one. We can consider it, though.
It's possible with serde but not possible with the way serdect works, AFAIK |
|
Sorry, edited your comment by mistake at first...
How is it possible? |
|
@fjarri yes, that's what I meant, it's possible with |
|
Another option would be to make the There are a couple ways to do the linkage between const generics and typenum. One is |
dda386d to
a761bce
Compare
|
Implemented with |
|
Okay, that's fine for now. If you're done can you mark the PR ready for review? |
|
Ok, but let me check the thing with |
36ed440 to
e7a7cde
Compare
|
I replaced the strict type with a bound on |
e7a7cde to
c6161c2
Compare
|
@fjarri it seems like you're using
I guess I'm fine with that to get the feature implemented, but it seems like it should be fairly straightforward to remove and replace with something that calls the equivalent core functionality to do the same. |
|
Perhaps, but that would require an |
|
Yes, that's fine, there are other |
fe8dc26 to
01527dc
Compare
tarcieri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit but this seems like a big improvement
|
Checking out the changes required in One can argue that it just makes the algorithm deficiency immediately obvious to the library writer instead of the end user realizing their chosen (In my case, something like Edit: also, as I noted in the description, debugging the compile time failures is kind of hard since the compiler doesn't provide a "backtrace". Although it is probably much simpler in the new code where you can tell which change led to the error. |
|
@fjarri oof, I did ask about |
|
I'll think about it, but even if I do find a solution, other people might struggle with something else. The question is, is that because this PR makes such generic code "fail early", so to speak, or because the PR is fundamentally flawed. I'm leaning towards reverting and giving it more consideration. Honestly, these lacunas in the compiler functionality are the most frustrating things about Rust. |
I tried to find where this usage is in I would also like to use the same operation on my code (generic |
|
@Fethbita https://github.com/entropyxyz/crypto-primes/blob/master/src/hazmat/primecount.rs#L76 Actually, now that I look at it it just doubles the width of integers, which I guess is easier from the typing point of view, but it presents the same problems with this PR. |
|
@fjarri so what's the verdict? should we revert, or have you found a workaround? can you maybe put together a playground with a minimal example of the problem and I can ask around for some solutions? |
I saw that as well. What do you mean by |
|
@Fethbita , before the PR you could use the
Well, you'd have to have the second generic parameter (
I would vote for revert. I can work around this stuff, but I expect a lot of frustration from other downstream users. The thing is, the approach in this PR works when you have concrete types for inputs and outputs of concat/split; but if you want to temporarily extend and then shrink back an integer (like in the primecount link above), this does not work - the compiler cannot derive the extended type. Having said that, I will think about fixing the primecount function so that it doesn't rely on |
|
Opened #1015 to revert |
|
Can the encoding changes be separated out from the rest? They don't seem to be dependent. |
|
Good idea, see #1016 |
|
Btw, the removal of |
|
I was also wondering if |
|
For adding a fixed number of limbs, it could be more useful to expose the |
A part of #1008 that only deals with `Encoding`: - `Encoding` implemented for all `Uint`s. `Encoding::Repr` for `Uint` is now an `EncodedUint` struct instead of an array. - Macros deriving `Encoding` are removed. - Relaxed the bound on the error of `Encoding::Repr as TryFrom<&[u8]>` from a concrete type to a `core::error::Error` trait.
Closes #793
SplitandConcatreworked to be implementable for allUints generically.SplitMixedandConcatMixedremoved (SplitandConcatimplement their functionality).RemMixedremoved -Remalready allows custom rhs sizes. Moreover, the nameRemMixed/rem_mixed()was misleading because it actually used variable time division inside.Encodingimplemented for allUints.Encoding::ReprforUintis now anEncodedUintstruct instead of an array.Encoded,SplitMixed,ConcatMixed, andRemMixedare removed.Encoding::Repr as TryFrom<&[u8]>from a concrete type to acore::error::Errortrait.Notes:
panic!()(without another dependency), second, the compiler often does not say which monomorphization caused the error.Uint::to_le/be_bytes()are quite similar toUint::write_le/be_bytes(), the former beingconst fn, the latter being faster (since they can operate withWord-sized chunks instead of single bytes).extra_sizesfeature may be removed since now it only definesUintaliases and doesn't impl any traits.serdectfor constant-time serialization, so we are concerned about serializing secrets... ButEncodingmethods litter the stack with the serialized data (not introduced in this PR, it was the same before). Is that a concern as well?