KomodoPlatform / zebra

An ongoing Rust implementation of a Komodo node. 🦓
Apache License 2.0
3 stars 5 forks source link

Crash in interest calc on div op #28

Closed dimxy closed 1 year ago

dimxy commented 1 year ago

Crash when syncing PR #2 with mainnet The application panicked (crashed). Message: div should be ok: Constraint { value: 22252604240282685, range: 0..=20000000000000000 } Location: zebra-chain/src/interest.rs:109

this commit: 7ce0f2e482d641def26abeebbfb46f6cd184ac1e

DeckerSU commented 1 year ago

As I remember we are already discussed this case, to fix the issue, need to use one-line division instead of two divisions in succession, like change:

interest = Amount::<NonNegative>::try_from(numerator / denominator as u64).expect("div should be ok");
interest = (interest / COIN as u64).expect("div should be ok");

on

interest = Amount::<NonNegative>::try_from(numerator / denominator as u64 / COIN as u64).expect("div should be ok");

Could you plz make the following changes directly in your branch dimxy:dimxy-nn-hf? Or I can do such PR into it by myself.

dimxy commented 1 year ago

okay I will do myself

DeckerSU commented 1 year ago

I fixed the issue almost immediately before I read your answer, so please close the PR if it is no longer needed.

dimxy commented 1 year ago

added missed overflowing_mul in this commit too 7301d441c982320cc75f2e5585b4297ee64bd529