Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charge for max length in LDC opcode #776

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading