12struct IntermediateGas {
16 IntermediateGas
operator+(
const IntermediateGas& other)
const
18 return IntermediateGas{ .l2_gas = this->l2_gas + other.l2_gas, .da_gas = this->da_gas + other.da_gas };
21 IntermediateGas
operator*(
const IntermediateGas& other)
const
23 return IntermediateGas{ .l2_gas =
l2_gas * other.l2_gas, .da_gas =
da_gas * other.da_gas };
28 assert(l2_gas <= std::numeric_limits<uint32_t>::max());
29 assert(da_gas <= std::numeric_limits<uint32_t>::max());
30 return Gas{ .l2_gas =
static_cast<uint32_t
>(
l2_gas), .da_gas =
static_cast<uint32_t
>(da_gas) };
34IntermediateGas to_intermediate_gas(
const Gas& gas)
36 return IntermediateGas{ .l2_gas =
static_cast<uint64_t
>(gas.l2_gas), .
da_gas =
static_cast<uint64_t
>(gas.da_gas) };
61 IntermediateGas base_actual_gas_used =
62 to_intermediate_gas(prev_gas_used) +
64 IntermediateGas gas_limit = to_intermediate_gas(
context.get_gas_limit());
66 bool oog_base_l2 = base_actual_gas_used.l2_gas > gas_limit.l2_gas;
67 bool oog_base_da = base_actual_gas_used.da_gas > gas_limit.da_gas;
75 IntermediateGas total_gas_used =
76 base_actual_gas_used +
77 (to_intermediate_gas(
Gas{ dynamic_l2_gas, dynamic_da_gas }) * to_intermediate_gas(dynamic_gas_factor));
85 if (oog_base_l2 || oog_base_da) {
87 base_actual_gas_used.l2_gas,
91 base_actual_gas_used.da_gas,
98 total_gas_used.l2_gas,
102 total_gas_used.da_gas,
108 context.set_gas_used(total_gas_used.to_gas());
122 .l2_gas = is_l2_gas_allocated_lt_left ? allocated_gas.
l2_gas : gas_left.
l2_gas,
123 .da_gas = is_da_gas_allocated_lt_left ? allocated_gas.
da_gas : gas_left.
da_gas,
Gas compute_gas_limit_for_call(const Gas &allocated_gas) override
GreaterThanInterface & greater_than
const ExecInstructionSpec & spec
void consume_gas(const Gas &dynamic_gas_factor={ 0, 0 }) override
GasTracker(GasEvent &gas_event, const Instruction &instruction, const InstructionInfoDBInterface &instruction_info_db, ContextInterface &context, GreaterThanInterface &greater_than)
virtual bool gt(const FF &a, const FF &b)=0
std::string format(Args... args)
InstructionInfoDB instruction_info_db
uint32_t compute_addressing_gas(uint16_t indirect_flag)
Univariate< Fr, domain_end > operator+(const Fr &ff, const Univariate< Fr, domain_end > &uv)
Univariate< Fr, domain_end > operator*(const Fr &ff, const Univariate< Fr, domain_end > &uv)
uint64_t total_gas_used_l2
uint64_t total_gas_used_da