FuelLabs / fuel-vm

Fuel v2 interpreter in Rust
Other
358 stars 88 forks source link

Deny clippy::arithmetic_side_effects #725

Closed Dentosal closed 7 months ago

Dentosal commented 7 months ago

Work towards #170

This does the changes for all crates other than fuel-merkle, which will be done in a separate PR.

Denies the following lints:

The following bugs were fixed:

Some improvements were also done:

Some changes introduce Rust-level panics where normally an overflow would have only panicked on debug mode.

Memory offsets of several types were previously calculated using unchecked operations. This PR changes those to use saturating_* operations instead. This means that given incorrect consensus parameters, some operations that previously overflowed silently know instead give memory offsets outside VM ram, causing a VM-level panic on access. This is strictly an improvement over previous behavior, but still leaves a lot to be desired. I'm not sure if it's actually possible to do much better, though. Maybe with custom types? The current approach feels like the most sensible tradeoff.

Checklist

Before requesting review