Skip to content

Commit

Permalink
Minor refactor for CROO gas charge
Browse files Browse the repository at this point in the history
  • Loading branch information
bvrooman committed Feb 14, 2024
1 parent c958e89 commit c7c8c11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
5 changes: 5 additions & 0 deletions fuel-vm/src/interpreter/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ where
}

pub(crate) fn code_root(&mut self, a: Word, b: Word) -> IoResult<(), S::DataError> {
let contract_id = CheckedMemConstLen::<{ ContractId::LEN }>::new(b)?;
let contract_id = ContractId::from_bytes_ref(contract_id.read(&self.memory));
let code_size = contract_size(&self.storage, contract_id)? as Word;
let gas_cost = self.gas_costs().croo.resolve(code_size);
self.gas_charge(gas_cost)?;
let owner = self.ownership_registers();
CodeRootCtx {
memory: &mut self.memory,
Expand Down
15 changes: 1 addition & 14 deletions fuel-vm/src/interpreter/executors/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ use fuel_asm::{
RawInstruction,
RegId,
};
use fuel_types::{
ContractId,
Word,
};
use fuel_types::Word;

use crate::{
constraints::CheckedMemConstLen,
interpreter::contract::contract_size,
};
use core::ops::Div;

impl<S, Tx, Ecal> Interpreter<S, Tx, Ecal>
Expand Down Expand Up @@ -775,12 +768,6 @@ where

Instruction::CROO(croo) => {
let (a, b) = croo.unpack();
let contract_id = CheckedMemConstLen::<{ ContractId::LEN }>::new(r!(b))?;
let contract_id =
ContractId::from_bytes_ref(contract_id.read(&self.memory));
let code_size = contract_size(&self.storage, contract_id)? as Word;
let gas_cost = self.gas_costs().croo.resolve(code_size);
self.gas_charge(gas_cost)?;
self.code_root(r!(a), r!(b))?;
}

Expand Down

0 comments on commit c7c8c11

Please sign in to comment.