Skip to content

Commit

Permalink
code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
zac-williamson committed May 14, 2024
1 parent e435687 commit cf5d93d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ void ECCVMBoolsRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulat
using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>;
using View = typename Accumulator::View;

auto z1 = View(in.transcript_z1);
auto z2 = View(in.transcript_z2);
auto z1_zero = View(in.transcript_z1zero);
auto z2_zero = View(in.transcript_z2zero);
auto msm_count_zero_at_transition = View(in.transcript_msm_count_zero_at_transition);
Expand Down Expand Up @@ -68,20 +66,6 @@ void ECCVMBoolsRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulat
std::get<16>(accumulator) += msm_double * (msm_double - 1) * scaling_factor;
std::get<17>(accumulator) += msm_skew * (msm_skew - 1) * scaling_factor;
std::get<18>(accumulator) += precompute_select * (precompute_select - 1) * scaling_factor;

/**
* @brief Validate correctness of z1_zero, z2_zero.
* If z1_zero = 0 and operation is a MUL, we will write a scalar mul instruction into our multiplication table.
* If z1_zero = 1 and operation is a MUL, we will NOT write a scalar mul instruction.
* (same with z2_zero).
* z1_zero / z2_zero is user-defined.
* We constraint z1_zero such that if z1_zero == 1, we require z1 == 0. (same for z2_zero).
* We do *NOT* constrain z1 != 0 if z1_zero = 0. If the user sets z1_zero = 0 and z1 = 0,
* this will add a scalar mul instruction into the multiplication table, where the scalar multiplier is 0.
* This is inefficient but will still produce the correct output.
*/
std::get<19>(accumulator) += (z1 * z1_zero) * scaling_factor; // if z1_zero = 1, z1 must be 0
std::get<20>(accumulator) += (z2 * z2_zero) * scaling_factor;
}

template class ECCVMBoolsRelationImpl<grumpkin::fr>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ template <typename FF_> class ECCVMBoolsRelationImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 21> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
static constexpr std::array<size_t, 19> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
* this will add a scalar mul instruction into the multiplication table, where the scalar multiplier is 0.
* This is inefficient but will still produce the correct output.
*/
std::get<0>(accumulator) += (z1 * z1_zero) * scaling_factor; // if z1_zero = 1, z1 must be 0
std::get<1>(accumulator) += (z2 * z2_zero) * scaling_factor;
std::get<0>(accumulator) += (z1 * z1_zero) * scaling_factor; // if z1_zero = 1, z1 must be 0. degree 2
std::get<1>(accumulator) += (z2 * z2_zero) * scaling_factor; // degree 2

/**
* @brief Validate `op` opcode is well formed.
Expand All @@ -115,7 +115,7 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
tmp += q_eq;
tmp += tmp;
tmp += q_reset_accumulator;
std::get<2>(accumulator) += (tmp - op) * scaling_factor;
std::get<2>(accumulator) += (tmp - op) * scaling_factor; // degree 1

/**
* @brief Validate `pc` is updated correctly.
Expand All @@ -125,7 +125,7 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
*/
Accumulator pc_delta = pc - pc_shift;
auto num_muls_in_row = ((-z1_zero + 1) + (-z2_zero + 1)) * (-transcript_Pinfinity + 1);
std::get<3>(accumulator) += is_not_first_row * (pc_delta - q_mul * num_muls_in_row) * scaling_factor;
std::get<3>(accumulator) += is_not_first_row * (pc_delta - q_mul * num_muls_in_row) * scaling_factor; // degree 4

/**
* @brief Validate `msm_transition` is well-formed.
Expand All @@ -134,7 +134,7 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
* i.e. if q_mul == 1 and q_mul_shift == 0, msm_transition = 1, else is 0
* We also require that `msm_count + [current msm number] > 0`
*/
auto msm_transition_check = q_mul * (-q_mul_shift + 1);
auto msm_transition_check = q_mul * (-q_mul_shift + 1); // degree 2
// auto num_muls_total = msm_count + num_muls_in_row;
auto msm_count_zero_at_transition = View(in.transcript_msm_count_zero_at_transition);
auto msm_count_at_transition_inverse = View(in.transcript_msm_count_at_transition_inverse);
Expand All @@ -144,20 +144,20 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
auto msm_count_zero_at_transition_check = msm_count_zero_at_transition * msm_count_total;
msm_count_zero_at_transition_check +=
(msm_count_total * msm_count_at_transition_inverse - 1) * (-msm_count_zero_at_transition + 1);
std::get<4>(accumulator) += msm_transition_check * msm_count_zero_at_transition_check * scaling_factor;
std::get<4>(accumulator) += msm_transition_check * msm_count_zero_at_transition_check * scaling_factor; // degree 3

// Validate msm_transition_msm_count is correct
// ensure msm_transition is zero if count is zero
std::get<5>(accumulator) +=
(msm_transition - msm_transition_check * (-msm_count_zero_at_transition + 1)) * scaling_factor;
(msm_transition - msm_transition_check * (-msm_count_zero_at_transition + 1)) * scaling_factor; // degree 3

/**
* @brief Validate `msm_count` resets when we end a multiscalar multiplication.
* msm_count tracks the number of scalar muls in the current active multiscalar multiplication.
* (if no msm active, msm_count == 0)
* If current row ends an MSM, `msm_count_shift = 0` (msm_count value at next row)
*/
std::get<6>(accumulator) += (msm_transition * msm_count_shift) * scaling_factor;
std::get<6>(accumulator) += (msm_transition * msm_count_shift) * scaling_factor; // degree 2

/**
* @brief Validate `msm_count` updates correctly for mul operations.
Expand Down Expand Up @@ -193,9 +193,8 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
auto eq_y_diff = transcript_Py - transcript_accumulator_y;
auto eq_x_diff_relation = q_eq * (eq_x_diff * both_not_infinity + infinity_exclusion_check); // degree 4
auto eq_y_diff_relation = q_eq * (eq_y_diff * both_not_infinity + infinity_exclusion_check); // degree 4
std::get<9>(accumulator) += eq_x_diff_relation * scaling_factor;

std::get<10>(accumulator) += eq_y_diff_relation * scaling_factor;
std::get<9>(accumulator) += eq_x_diff_relation * scaling_factor; // degree 4
std::get<10>(accumulator) += eq_y_diff_relation * scaling_factor; // degree 4

/**
* @brief Initial condition check on 1st row.
Expand All @@ -205,8 +204,8 @@ void ECCVMTranscriptRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
* note...actually second row? bleurgh
* NOTE: we want pc = 0 at lagrange_last :o
*/
std::get<11>(accumulator) += lagrange_second * (-is_accumulator_empty + 1) * scaling_factor;
std::get<12>(accumulator) += lagrange_second * msm_count * scaling_factor;
std::get<11>(accumulator) += lagrange_second * (-is_accumulator_empty + 1) * scaling_factor; // degree 2
std::get<12>(accumulator) += lagrange_second * msm_count * scaling_factor; // degree 2

/**
* @brief On-curve validation checks.
Expand Down

0 comments on commit cf5d93d

Please sign in to comment.