-
Notifications
You must be signed in to change notification settings - Fork 829
Change param datatype for InputWeightPrediction functions #4584
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
base: master
Are you sure you want to change the base?
Change param datatype for InputWeightPrediction functions #4584
Conversation
Any value for `bytes_to_grind` that is larger than 62 will cause the subtraction for `der_signature_size` to be negative. However, `der_signature_size` must be positive when passed to the `InputWeightPrediction` constructor. Therefore there is no value in allowing values of size `usize` to be passed due to any value greater than 62 is invalid. It would be preferable to use `.into()` instead of `as` when casting to `usize` for the constructor call, however these functions are const context and therefore `.into()` is not readily available.
ef1ddc9
to
2ae65d6
Compare
Pull Request Test Coverage Report for Build 15357983492Details
💛 - Coveralls |
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.
ACK 2ae65d6
I'll begrudgingly go along with this, but TBH it seems like it'll make the user's life harder without any real benefit. Users may need to add casts where there previously weren't any (e.g. in const contexts) which increases the likelihood of bugs. This is also a gratuitous breaking change, though it is likely to be low-impact since this is an obscure function usually called with hardcoded constants. And it doesn't even help #4584 because |
I won't be too put out if this isn't accepted. Although I do like the principle of using datatypes that are the size they need to be, not just a default size. For example, OTOH casting from something small to something large should never be dangerous since you don't accidentally truncate data. I think people just get allergic to seeing |
If this makes some things worse and nothing really better then I rekon we close it. |
Maybe @Kixunil could weigh in on this since he was the prime motivator for this change. |
Unfortunately this doesn't matter. Rust still forces you to do it when you're going to/from ( |
My view is that we should generally use the smallest reasonable type. The ideal type is I don't think anyone will compute it from a slice, why would they? This parameter can greatly affect the computation time. At best someone might want to get it from the user. If we want to be super-stable, we can just take a dumb struct with almost no API and change it to |
Because the parameter represents an estimated size and they may already have a serialized form of (some of) the object that they are estimating the size of. |
I agree with this. My viewpoint is this makes the casts safe(er) if going from a smaller type to a larger if a cast is ever needed. |
The motivation for this was discussed here: #4574 (comment)
Any value for
bytes_to_grind
that is larger than 62 will cause the subtraction forder_signature_size
to be negative. However,der_signature_size
must be positive when passed to theInputWeightPrediction
constructor. Therefore there is no value in allowing values of sizeusize
to be passed due to any value greater than 62 is invalid.It would be preferable to use
.into()
instead ofas
when casting tousize
for the constructor call, however these functions are const context and therefore.into()
is not readily available.