Skip to content

Commit

Permalink
Add gas costs charge
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Nov 15, 2024
1 parent d455d86 commit cc22760
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
27 changes: 27 additions & 0 deletions fuel-tx/src/transaction/consensus_parameters/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,24 @@ impl GasCostsValues {
}
}

pub fn eadd(&self) -> Result<Word, GasCostNotDefined> {
match self {
GasCostsValues::V1(_) => Err(GasCostNotDefined),
GasCostsValues::V2(_) => Err(GasCostNotDefined),
GasCostsValues::V3(_) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.eadd),
}
}

pub fn emul(&self) -> Result<Word, GasCostNotDefined> {
match self {
GasCostsValues::V1(_) => Err(GasCostNotDefined),
GasCostsValues::V2(_) => Err(GasCostNotDefined),
GasCostsValues::V3(_) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.emul),
}
}

pub fn aloc(&self) -> DependentCost {
match self {
GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
Expand Down Expand Up @@ -1098,6 +1116,15 @@ impl GasCostsValues {
}
}

pub fn epar(&self) -> Result<DependentCost, GasCostNotDefined> {
match self {
GasCostsValues::V1(_v1) => Err(GasCostNotDefined),
GasCostsValues::V2(_v2) => Err(GasCostNotDefined),
GasCostsValues::V3(_v3) => Err(GasCostNotDefined),
GasCostsValues::V4(v4) => Ok(v4.epar),
}
}

pub fn contract_root(&self) -> DependentCost {
match self {
GasCostsValues::V1(v1) => v1.contract_root,
Expand Down
9 changes: 8 additions & 1 deletion fuel-vm/src/interpreter/executors/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,18 +919,25 @@ where
}

Instruction::EADD(eadd) => {
self.gas_charge(self.gas_costs().eadd().map_err(PanicReason::from)?)?;
let (a, b, c, d) = eadd.unpack();
self.ec_add(r!(a), r!(b), r!(c), r!(d))?;
}

Instruction::EMUL(emul) => {
self.gas_charge(self.gas_costs().emul().map_err(PanicReason::from)?)?;
let (a, b, c, d) = emul.unpack();
self.ec_mul(r!(a), r!(b), r!(c), r!(d))?;
}

Instruction::EPAR(epar) => {
let (a, b, c, d) = epar.unpack();
self.ec_pairing(r!(a), r!(b), r!(c), r!(d))?;
let len = r!(c);
self.dependent_gas_charge(
self.gas_costs().epar().map_err(PanicReason::from)?,
len,
)?;
self.ec_pairing(r!(a), r!(b), len, r!(d))?;
}
}

Expand Down

0 comments on commit cc22760

Please sign in to comment.