Skip to content

Commit

Permalink
Merge pull request #3207 from dusk-network/overflow
Browse files Browse the repository at this point in the history
rusk: Handle spent value overflow
  • Loading branch information
xevisalle authored Dec 17, 2024
2 parents dd8c08b + be5df99 commit 0297c6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0297c6e

Please sign in to comment.