Skip to content

Commit

Permalink
Fix balance and gas overflows in CrossContractCall
Browse files Browse the repository at this point in the history
  • Loading branch information
guidovranken committed Jan 9, 2024
1 parent 1213f2c commit 84bc698
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion engine-precompiles/src/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<I: IO> HandleBasedPrecompile for CrossContractCall<I> {
.try_to_vec()
.map_err(|_| ExitError::Other(Cow::from(consts::ERR_SERIALIZE)))?,
attached_balance: ZERO_YOCTO,
attached_gas: router_exec_cost + call_gas,
attached_gas: router_exec_cost.saturating_add(call_gas),
};
(promise, attached_near)
}
Expand Down
6 changes: 4 additions & 2 deletions engine-types/src/parameters/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl NearPromise {
pub fn total_gas(&self) -> NearGas {
match self {
Self::Simple(x) => x.total_gas(),
Self::Then { base, callback } => base.total_gas() + callback.total_gas(),
Self::Then { base, callback } => base.total_gas().saturating_add(callback.total_gas()),
Self::And(promises) => {
let total = promises.iter().map(|p| p.total_gas().as_u64()).sum();
NearGas::new(total)
Expand All @@ -134,7 +134,9 @@ impl NearPromise {
pub fn total_near(&self) -> Yocto {
match self {
Self::Simple(x) => x.total_near(),
Self::Then { base, callback } => base.total_near() + callback.total_near(),
Self::Then { base, callback } => {
base.total_near().saturating_add(callback.total_near())
}
Self::And(promises) => {
let total = promises.iter().map(|p| p.total_near().as_u128()).sum();
Yocto::new(total)
Expand Down

0 comments on commit 84bc698

Please sign in to comment.