Skip to content

Commit

Permalink
Avoid overflowing u32 during contract preparation (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksymZavershynskyi authored Jan 13, 2020
1 parent e21c93a commit 37646f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 2 additions & 1 deletion runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ impl<'a> VMLogic<'a> {
/// * If we exceed usage limit imposed on burnt gas returns `GasLimitExceeded`;
/// * If we exceed the `prepaid_gas` then returns `GasExceeded`.
pub fn gas(&mut self, gas_amount: u32) -> Result<()> {
self.gas_counter.deduct_gas(Gas::from(gas_amount), Gas::from(gas_amount))
let value = Gas::from(gas_amount) * Gas::from(self.config.regular_op_cost);
self.gas_counter.deduct_gas(value, value)
}

// ################
Expand Down
3 changes: 1 addition & 2 deletions runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl<'a> ContractModule<'a> {

fn inject_gas_metering(self) -> Result<Self, PrepareError> {
let Self { module, config } = self;
let gas_rules = rules::Set::new(config.regular_op_cost, Default::default())
.with_grow_cost(config.grow_mem_cost);
let gas_rules = rules::Set::new(1, Default::default()).with_grow_cost(config.grow_mem_cost);
let module = pwasm_utils::inject_gas_counter(module, &gas_rules)
.map_err(|_| PrepareError::GasInstrumentation)?;
Ok(Self { module, config })
Expand Down

0 comments on commit 37646f4

Please sign in to comment.