-
Notifications
You must be signed in to change notification settings - Fork 992
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
core: checked arithmetics #3074
Conversation
6348ce5
to
a1213b2
Compare
a1213b2
to
aafb5d1
Compare
a560edb
to
f7064f2
Compare
0f9e1e0
to
a38747b
Compare
a38747b
to
0a001b5
Compare
0a001b5
to
1569518
Compare
871ae3c
to
128bf14
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3074 +/- ##
==========================================
+ Coverage 59.40% 59.53% +0.12%
==========================================
Files 298 298
Lines 92326 92613 +287
==========================================
+ Hits 54849 55138 +289
+ Misses 37477 37475 -2 ☔ View full report in Codecov by Sentry. |
128bf14
to
30c5c50
Compare
@tzemanovic Is the title of this PR still accurate? Looks like a bunch of crates beyond core are changed. Does this cover everything, everywhere or are there other sections still remaining to transition to checked arithemetic? |
let raw = I256::try_from(amt.raw_amount()) | ||
.map_err(|e| eyre!("Invalid raw amount: {e}"))?; | ||
let denom = I256(Uint::exp10( | ||
(POS_DECIMAL_PRECISION - NATIVE_MAX_DECIMAL_PLACES) as usize, |
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.
I'm sure we're safe to do this operation but figured I'd point it out as possibly unchecked
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.
it's ok as they're both consts and the fn is also covered by unit tests
crates/core/src/token.rs
Outdated
impl From<Dec> for Amount { | ||
fn from(dec: Dec) -> Amount { | ||
impl TryFrom<Dec> for Amount { | ||
type Error = (); |
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.
why ()
for the Error
type?
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.
ah, I'll switch it to use arith err
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.
fixed in 70daab5
70daab5
to
a78ec98
Compare
* tomas/checked-arith: changelog: add #3074 namada/pos: re-use into_tm_voting_power from pos crate wasm: update to non-panicking core API benches: update to non-panicking core API apps: update to non-panicking core API namada: update to non-panicking core API sdk: update to non-panicking core API eth_bridge: update to non-panicking core API ibc: update to non-panicking core API pos: update to non-panicking core API gov: update to non-panicking core API state: update to non-panicking core API shielded_token: update to non-panicking core API trans_token: update to non-panicking core API vote_ext: update to non-panicking core API controller: replacing panicking code storage/collections/lazy_map: add try_update storage: add conv from core::arith::Error for convenience test/core: fixes for checked arith core: clippy fixes core/dec: sanitize panicking code core/storage: sanitize panicking code core/token: sanitize panicking code core/uint: sanitize panicking code core: add `assert_matches` dev-dep core/voting_power: sanitize panicking code core: strict clippy arith deps: add smooth-operator and re-export from core/arith core: add arith mod with a custom `trait CheckedAdd`
* origin/tomas/checked-arith: changelog: add #3074 namada/pos: re-use into_tm_voting_power from pos crate wasm: update to non-panicking core API benches: update to non-panicking core API apps: update to non-panicking core API namada: update to non-panicking core API sdk: update to non-panicking core API eth_bridge: update to non-panicking core API ibc: update to non-panicking core API pos: update to non-panicking core API gov: update to non-panicking core API state: update to non-panicking core API shielded_token: update to non-panicking core API trans_token: update to non-panicking core API vote_ext: update to non-panicking core API controller: replacing panicking code storage/collections/lazy_map: add try_update storage: add conv from core::arith::Error for convenience test/core: fixes for checked arith core: clippy fixes core/dec: sanitize panicking code core/storage: sanitize panicking code core/token: sanitize panicking code core/uint: sanitize panicking code core: add `assert_matches` dev-dep core/voting_power: sanitize panicking code core: strict clippy arith deps: add smooth-operator and re-export from core/arith core: add arith mod with a custom `trait CheckedAdd`
Describe your changes
first part of #2555 addressing core crate
Indicate on which release or other PRs this topic is based on
v0.34.0
Checklist before merging to
draft