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

core: checked arithmetics #3074

Merged
merged 29 commits into from
May 9, 2024
Merged

core: checked arithmetics #3074

merged 29 commits into from
May 9, 2024

Conversation

tzemanovic
Copy link
Member

@tzemanovic tzemanovic commented Apr 12, 2024

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

  • I have added a changelog
  • Git history is in acceptable state

@tzemanovic tzemanovic changed the title WIP add a common lib header checked arithmetics Apr 12, 2024
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch 2 times, most recently from 6348ce5 to a1213b2 Compare April 16, 2024 18:00
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch from a1213b2 to aafb5d1 Compare April 19, 2024 16:44
@tzemanovic tzemanovic changed the title checked arithmetics core: checked arithmetics Apr 22, 2024
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch 2 times, most recently from a560edb to f7064f2 Compare April 23, 2024 08:10
@cwgoes cwgoes linked an issue Apr 24, 2024 that may be closed by this pull request
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch 3 times, most recently from 0f9e1e0 to a38747b Compare April 30, 2024 18:34
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch from a38747b to 0a001b5 Compare May 1, 2024 15:37
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch from 0a001b5 to 1569518 Compare May 2, 2024 10:27
@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch 2 times, most recently from 871ae3c to 128bf14 Compare May 3, 2024 13:41
Copy link

codecov bot commented May 3, 2024

Codecov Report

Attention: Patch coverage is 79.78385% with 318 lines in your changes are missing coverage. Please review.

Project coverage is 59.53%. Comparing base (9d4de02) to head (a78ec98).
Report is 12 commits behind head on main.

Files Patch % Lines
crates/sdk/src/queries/vp/pos.rs 0.00% 35 Missing ⚠️
crates/proof_of_stake/src/lib.rs 87.90% 26 Missing ⚠️
crates/core/src/uint.rs 87.62% 25 Missing ⚠️
crates/sdk/src/tx.rs 0.00% 23 Missing ⚠️
crates/sdk/src/masp.rs 0.00% 19 Missing ⚠️
crates/core/src/dec.rs 89.24% 17 Missing ⚠️
...ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs 0.00% 16 Missing ⚠️
crates/core/src/storage.rs 77.27% 15 Missing ⚠️
crates/core/src/voting_power.rs 71.42% 12 Missing ⚠️
crates/governance/src/utils.rs 86.81% 12 Missing ⚠️
... and 30 more
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.
📢 Have feedback on the report? Share it here.

@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch from 128bf14 to 30c5c50 Compare May 3, 2024 15:21
tzemanovic added a commit that referenced this pull request May 3, 2024
@tzemanovic tzemanovic marked this pull request as ready for review May 3, 2024 15:23
@tzemanovic tzemanovic requested a review from brentstone May 3, 2024 15:24
@cwgoes
Copy link
Collaborator

cwgoes commented May 6, 2024

@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,
Copy link
Collaborator

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

Copy link
Member Author

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

impl From<Dec> for Amount {
fn from(dec: Dec) -> Amount {
impl TryFrom<Dec> for Amount {
type Error = ();
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 70daab5

@tzemanovic tzemanovic force-pushed the tomas/checked-arith branch from 70daab5 to a78ec98 Compare May 8, 2024 10:40
tzemanovic added a commit that referenced this pull request May 8, 2024
* 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`
brentstone added a commit that referenced this pull request May 8, 2024
* 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`
@brentstone brentstone merged commit 2685f85 into main May 9, 2024
17 of 19 checks passed
@brentstone brentstone deleted the tomas/checked-arith branch May 9, 2024 03:53
@tzemanovic tzemanovic mentioned this pull request Jun 14, 2024
2 tasks
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

Successfully merging this pull request may close these issues.

Audit for all usage of unchecked arithmetic and update nomenclature
3 participants