Skip to content

Commit

Permalink
Charge for max length in LDC opcode (#776)
Browse files Browse the repository at this point in the history
* Release v0.54.0

* Charge for max length in LDC opcode

* Updated CHANGELOG.md
  • Loading branch information
xgreenx authored Jun 16, 2024
1 parent 9d7dd97 commit 7447144
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- [#776](https://github.com/FuelLabs/fuel-vm/pull/776): Charge for max length in LDC opcode.

## [Version 0.54.0]

### Added
Expand Down
9 changes: 5 additions & 4 deletions fuel-vm/src/interpreter/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,6 @@ where
return Err(PanicReason::ContractMaxSize.into())
}

let new_sp = ssp.saturating_add(length);
self.memory.grow_stack(new_sp)?;

self.input_contracts.check(&contract_id)?;

// Fetch the storage contract
Expand All @@ -619,16 +616,20 @@ where
profiler: self.profiler,
};
let contract_len = contract_size(&self.storage, &contract_id)?;
let charge_len = core::cmp::max(contract_len as u64, length);
dependent_gas_charge_without_base(
self.cgas,
self.ggas,
profiler,
self.gas_cost,
contract_len as u64,
charge_len,
)?;
let contract = super::contract::contract(self.storage, &contract_id)?;
let contract_bytes = contract.as_ref().as_ref();

let new_sp = ssp.saturating_add(length);
self.memory.grow_stack(new_sp)?;

// Set up ownership registers for the copy using old ssp
let owner =
OwnershipRegisters::only_allow_stack_write(new_sp, *self.ssp, *self.hp);
Expand Down

0 comments on commit 7447144

Please sign in to comment.