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> {