diff --git a/rusk/CHANGELOG.md b/rusk/CHANGELOG.md index 42cf93a34..6b4b82812 100644 --- a/rusk/CHANGELOG.md +++ b/rusk/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change dependencies declarations enforce bytecheck [#1371] - Fixed tests passing incorrect arguments [#1371] - Adjusted deployment charging [#2207] +- Change `max_value` computation to handle overflow error [#3206] ### Added @@ -215,6 +216,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add linking between Rusk and Protobuff structs - Add build system that generates keys for circuits and caches them. +[#3206]: https://github.com/dusk-network/rusk/issues/3206 [#2597]: https://github.com/dusk-network/rusk/issues/2597 [#2536]: https://github.com/dusk-network/rusk/issues/2536 [#2207]: https://github.com/dusk-network/rusk/issues/2207 diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index e6b7b6f31..fdcff50b5 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -161,8 +161,13 @@ impl VMExecution for Rusk { anyhow::anyhow!("Cannot check account: {e}") })?; - let max_value = - tx.value() + tx.deposit() + tx.gas_limit() * tx.gas_price(); + let max_value = tx + .gas_limit() + .checked_mul(tx.gas_price()) + .and_then(|v| v.checked_add(tx.value())) + .and_then(|v| v.checked_add(tx.deposit())) + .ok_or(anyhow::anyhow!("Value spent will overflow"))?; + if max_value > account_data.balance { return Err(anyhow::anyhow!( "Value spent larger than account holds"