From 322836160b7f2f38c397a2c3a0100b2ebeda65a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Wed, 7 Feb 2024 17:16:00 +0100 Subject: [PATCH] piecrust: fix overflow in ICC gas limit calculation --- piecrust/CHANGELOG.md | 4 ++++ piecrust/src/imports.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/piecrust/CHANGELOG.md b/piecrust/CHANGELOG.md index 715df6ce..f88fff6f 100644 --- a/piecrust/CHANGELOG.md +++ b/piecrust/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgrade `dusk-wasmtime` to version `17` +### Fixed + +- Fix overflow in gas limit calculation in inter-contract call + ## [0.15.0] - 2024-01-24 ### Changed diff --git a/piecrust/src/imports.rs b/piecrust/src/imports.rs index 230036f1..51d6896c 100644 --- a/piecrust/src/imports.rs +++ b/piecrust/src/imports.rs @@ -209,7 +209,9 @@ pub(crate) fn c( let callee_limit = if gas_limit > 0 && gas_limit < caller_remaining { gas_limit } else { - caller_remaining * GAS_PASS_PCT / 100 + let div = caller_remaining / 100 * GAS_PASS_PCT; + let rem = caller_remaining % 100 * GAS_PASS_PCT / 100; + div + rem }; let with_memory = |memory: &mut [u8]| -> Result<_, Error> {