From c7c8c11f71052a6aa6c953b06785f4e60be9dc83 Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Wed, 14 Feb 2024 12:09:35 -0500 Subject: [PATCH] Minor refactor for CROO gas charge --- fuel-vm/src/interpreter/blockchain.rs | 5 +++++ fuel-vm/src/interpreter/executors/instruction.rs | 15 +-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/fuel-vm/src/interpreter/blockchain.rs b/fuel-vm/src/interpreter/blockchain.rs index d43fb34d03..ecbf070ee1 100644 --- a/fuel-vm/src/interpreter/blockchain.rs +++ b/fuel-vm/src/interpreter/blockchain.rs @@ -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, diff --git a/fuel-vm/src/interpreter/executors/instruction.rs b/fuel-vm/src/interpreter/executors/instruction.rs index d76e4d4780..6a2e90d31b 100644 --- a/fuel-vm/src/interpreter/executors/instruction.rs +++ b/fuel-vm/src/interpreter/executors/instruction.rs @@ -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 Interpreter @@ -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))?; }