-
Notifications
You must be signed in to change notification settings - Fork 47
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
Make UInt panic on overflow if overflow_checks
is enabled
#408
Comments
Is there a reason that using the |
As I said this requires me to depend on special clippy lints. But okay, this is your project, so feel free to close this issue if you want |
when writing consensus code, I would strongly recommend always using checked arithmetic, even with primitive number types, rather than panicking. Accidentally leaving reachable panics in consensus code can lead to network-wide DOS for now, closing this as |
Currently
UInt
wraps on overflow. Please, make it panic on overflow ifcfg(overflow_checks)
is enabled, i. e. exactly same thing rustc does with standard numbers. Here is why.First and foremost,
ruint
is used mainly for representing monetary values. Wrapping behavior is unnatural for monetary values. So,UInt
should panic on overflow. But still some users may want to skip checks for speed reasons. So, we should provide way to configure behavior. The most natural thing to do is to makeUInt
panic when standard numbers panic and wrap when standard types wrap. So, we should usecfg(overflow_checks)
.Of course, this is breaking change, so it should be done in 2.0.0.
I use
alloy
for managing my cryptocurrency, i. e. for transferring it around. Unnoticed overflows may cause loss of money, I absolutely don't want this.alloy
directly usesruint
'sUInt
. So, I plan to create my wrapper aroundU256
, which will panic on overflow. And I also will useclippy::arithmetic_side_effects
to make sure that I will not use arithmetic directly onruint
/alloy
'sU256
. But ideally this should be fixed inruint
itselfThe text was updated successfully, but these errors were encountered: