Skip to content

Commit

Permalink
rusk: make max_value computation to handle overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle committed Dec 17, 2024
1 parent 6c28bcb commit 0fc5350
Show file tree
Hide file tree
Showing 2 changed files with 17 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
17 changes: 15 additions & 2 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,21 @@ 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()));

let max_value = match max_value {
Some(x) => x,
_ => {
return Err(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 0fc5350

Please sign in to comment.