diff --git a/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs b/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs index f97411f3ee..da80c29f9c 100644 --- a/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs +++ b/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs @@ -39,7 +39,6 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { // Add 7,000 base units to make sure the we do not undercharge for WASM execution, // which might lead to system exploitation. // This is especially important in corner-cases such as `costing::spin_loop_v2` benchmark. - // Use larger cost unit buffer to call `consume_wasm_execution_exceeding_buffer` // less frequently. 7000 }; @@ -55,7 +54,6 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { wasm_execution_units_base, } } - pub fn parse_blueprint_id( package_address: Vec, blueprint_name: Vec, @@ -74,9 +72,9 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { ) -> Result<(), InvokeError> { assert!(n > self.wasm_execution_units_buffer); let n_remaining_after_buffer_used = n - self.wasm_execution_units_buffer; - let amount_to_request = n_remaining_after_buffer_used - .checked_add(WASM_EXECUTION_COST_UNITS_BUFFER) - .unwrap_or(u32::MAX); + let amount_to_request = + n_remaining_after_buffer_used.saturating_add(WASM_EXECUTION_COST_UNITS_BUFFER); + self.api .consume_cost_units(ClientCostingEntry::RunWasmCode { package_address: &self.package_address, @@ -416,9 +414,7 @@ impl<'y, Y: SystemApi> WasmRuntime for ScryptoRuntime<'y, Y> { &mut self, n: u32, ) -> Result<(), InvokeError> { - let n = n - .checked_add(self.wasm_execution_units_base) - .unwrap_or(u32::MAX); + let n = n.saturating_add(self.wasm_execution_units_base); if n <= self.wasm_execution_units_buffer { self.wasm_execution_units_buffer -= n;