Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gas_impl.hpp
Go to the documentation of this file.
1// AUTOGENERATED FILE
2#pragma once
3
5
6namespace bb::avm2 {
7
8template <typename FF_>
9template <typename ContainerOverSubrelations, typename AllEntities>
10void gasImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
11 const AllEntities& in,
12 [[maybe_unused]] const RelationParameters<FF_>&,
13 [[maybe_unused]] const FF_& scaling_factor)
14{
15 using C = ColumnAndShifts;
16
17 PROFILE_THIS_NAME("accumulate/gas");
18
19 const auto execution_BASE_L2_GAS = in.get(C::execution_opcode_gas) + in.get(C::execution_addressing_gas);
20 const auto execution_DYNAMIC_L2_GAS_USED =
21 in.get(C::execution_dynamic_l2_gas) * in.get(C::execution_dynamic_l2_gas_factor);
22 const auto execution_DYNAMIC_DA_GAS_USED =
23 in.get(C::execution_dynamic_da_gas) * in.get(C::execution_dynamic_da_gas_factor);
24 const auto execution_TOTAL_L2_GAS_USED = execution_BASE_L2_GAS + execution_DYNAMIC_L2_GAS_USED;
25 const auto execution_TOTAL_DA_GAS_USED = in.get(C::execution_base_da_gas) + execution_DYNAMIC_DA_GAS_USED;
26 const auto execution_PREV_GAS_PLUS_USAGE_L2 = in.get(C::execution_prev_l2_gas_used) + execution_TOTAL_L2_GAS_USED;
27 const auto execution_LIMIT_GTE_USED_L2 = (in.get(C::execution_l2_gas_limit) - execution_PREV_GAS_PLUS_USAGE_L2);
28 const auto execution_LIMIT_LT_USED_L2 =
29 ((execution_PREV_GAS_PLUS_USAGE_L2 - in.get(C::execution_l2_gas_limit)) - FF(1));
30 const auto execution_PREV_GAS_PLUS_USAGE_DA = in.get(C::execution_prev_da_gas_used) + execution_TOTAL_DA_GAS_USED;
31 const auto execution_LIMIT_GTE_USED_DA = (in.get(C::execution_da_gas_limit) - execution_PREV_GAS_PLUS_USAGE_DA);
32 const auto execution_LIMIT_LT_USED_DA =
33 ((execution_PREV_GAS_PLUS_USAGE_DA - in.get(C::execution_da_gas_limit)) - FF(1));
34
35 {
36 using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>;
37 auto tmp = in.get(C::execution_sel_should_check_gas) * (FF(64) - in.get(C::execution_constant_64));
38 tmp *= scaling_factor;
39 std::get<0>(evals) += typename Accumulator::View(tmp);
40 }
41 {
42 using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>;
43 auto tmp = in.get(C::execution_out_of_gas_l2) * (FF(1) - in.get(C::execution_out_of_gas_l2));
44 tmp *= scaling_factor;
45 std::get<1>(evals) += typename Accumulator::View(tmp);
46 }
47 {
48 using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>;
49 auto tmp = in.get(C::execution_out_of_gas_da) * (FF(1) - in.get(C::execution_out_of_gas_da));
50 tmp *= scaling_factor;
51 std::get<2>(evals) += typename Accumulator::View(tmp);
52 }
53 { // L2_CMP_DIFF
54 using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>;
55 auto tmp =
56 (in.get(C::execution_limit_used_l2_cmp_diff) -
57 in.get(C::execution_sel_should_check_gas) *
58 ((execution_LIMIT_LT_USED_L2 - execution_LIMIT_GTE_USED_L2) * in.get(C::execution_out_of_gas_l2) +
59 execution_LIMIT_GTE_USED_L2));
60 tmp *= scaling_factor;
61 std::get<3>(evals) += typename Accumulator::View(tmp);
62 }
63 { // DA_CMP_DIFF
64 using Accumulator = typename std::tuple_element_t<4, ContainerOverSubrelations>;
65 auto tmp =
66 (in.get(C::execution_limit_used_da_cmp_diff) -
67 in.get(C::execution_sel_should_check_gas) *
68 ((execution_LIMIT_LT_USED_DA - execution_LIMIT_GTE_USED_DA) * in.get(C::execution_out_of_gas_da) +
69 execution_LIMIT_GTE_USED_DA));
70 tmp *= scaling_factor;
71 std::get<4>(evals) += typename Accumulator::View(tmp);
72 }
73 {
74 using Accumulator = typename std::tuple_element_t<5, ContainerOverSubrelations>;
75 auto tmp = (in.get(C::execution_sel_out_of_gas) - (FF(1) - (FF(1) - in.get(C::execution_out_of_gas_l2)) *
76 (FF(1) - in.get(C::execution_out_of_gas_da))));
77 tmp *= scaling_factor;
78 std::get<5>(evals) += typename Accumulator::View(tmp);
79 }
80 {
81 using Accumulator = typename std::tuple_element_t<6, ContainerOverSubrelations>;
82 auto tmp = (FF(1) - in.get(C::execution_sel_should_check_gas)) * in.get(C::execution_sel_out_of_gas);
83 tmp *= scaling_factor;
84 std::get<6>(evals) += typename Accumulator::View(tmp);
85 }
86}
87
88} // namespace bb::avm2
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const RelationParameters< FF > &, const FF &scaling_factor)
Definition gas_impl.hpp:10
ColumnAndShifts
Definition columns.hpp:35
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define PROFILE_THIS_NAME(name)
Definition op_count.hpp:16
Container for parameters used by the grand product (permutation, lookup) Honk relations.