From 20812f1974dacb4782130c920e86b8676a9b12a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= <88321181+rafal-ch@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:36:29 +0200 Subject: [PATCH] Protect against passing `i128::MIN` to `abs()` which causes overflow (#2241) ## Linked Issues Closes https://github.com/FuelLabs/fuel-core/issues/2210 ## Description This PR uses `saturating_abs()` instead of "raw" `abs()` inside the `da_change()` to prevent overflow on `i128::MIN`. ### Before requesting review - [X] I have reviewed the code myself --------- Co-authored-by: Mitchell Turner --- crates/fuel-gas-price-algorithm/src/v1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fuel-gas-price-algorithm/src/v1.rs b/crates/fuel-gas-price-algorithm/src/v1.rs index e517064e6da..11c555a7faa 100644 --- a/crates/fuel-gas-price-algorithm/src/v1.rs +++ b/crates/fuel-gas-price-algorithm/src/v1.rs @@ -356,7 +356,7 @@ impl AlgorithmUpdaterV1 { .saturating_mul(upcast_percent) .saturating_div(100) .into(); - let clamped_change = pd_change.abs().min(max_change); + let clamped_change = pd_change.saturating_abs().min(max_change); pd_change.signum().saturating_mul(clamped_change) }