From 1f7d4a911a9d866106d3533e27390923ca935985 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Fri, 1 Dec 2023 20:14:30 +0000 Subject: [PATCH] small comment updates --- .../relations/poseidon2_external_relation.hpp | 57 +++++++++---------- .../relations/poseidon2_internal_relation.hpp | 54 ++++++++---------- .../ultra_relation_consistency.test.cpp | 22 +++---- 3 files changed, 62 insertions(+), 71 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp index a0c4d65307bd..dc150d545ea5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp @@ -16,7 +16,7 @@ template class Poseidon2ExternalRelationImpl { /** * @brief Expression for the poseidon2 external round relation, based on E_i in Section 6 of * https://eprint.iacr.org/2023/323.pdf. - * @details This relation is defined as: + * @details This relation is defined as C(in(X)...) := * q_poseidon2_external * ( (v1 - w_1_shift) + \alpha * (v2 - w_2_shift) + * \alpha^2 * (v3 - w_3_shift) + \alpha^3 * (v4 - w_4_shift) ) = 0 where: * u1 := (w_1 + q_1)^5 @@ -80,41 +80,36 @@ template class Poseidon2ExternalRelationImpl { u4 *= s4; // matrix mul v = M_E * u with 14 additions - auto t0 = u1 + u2; // A + B - auto t1 = u3 + u4; // C + D - auto t2 = u2 + u2; // 2B - t2 += t1; // 2B + C + D - auto t3 = u4 + u4; // 2D - t3 += t0; // 2D + A + B + auto t0 = u1 + u2; // u_1 + u_2 + auto t1 = u3 + u4; // u_3 + u_4 + auto t2 = u2 + u2; // 2u_2 + t2 += t1; // 2u_2 + u_3 + u_4 + auto t3 = u4 + u4; // 2u_4 + t3 += t0; // u_1 + u_2 + 2u_4 auto v4 = t1 + t1; v4 += v4; - v4 += t3; // A + B + 4C + 6D + v4 += t3; // u_1 + u_2 + 4u_3 + 6u_4 auto v2 = t0 + t0; v2 += v2; - v2 += t2; // 4A + 6B + C + D - auto v1 = t3 + v2; // 5A + 7B + C + 3D - auto v3 = t2 + v4; // A + 3B + 5C + 7D + v2 += t2; // 4u_1 + 6u_2 + u_3 + u_4 + auto v1 = t3 + v2; // 5u_1 + 7u_2 + u_3 + 3u_4 + auto v3 = t2 + v4; // u_1 + 3u_2 + 5u_3 + 7u_4 - { - auto tmp = q_poseidon2_external * (v1 - w_l_shift); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - { - auto tmp = q_poseidon2_external * (v2 - w_r_shift); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - { - auto tmp = q_poseidon2_external * (v3 - w_o_shift); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - { - auto tmp = q_poseidon2_external * (v4 - w_4_shift); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } + auto tmp = q_poseidon2_external * (v1 - w_l_shift); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + + tmp = q_poseidon2_external * (v2 - w_r_shift); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + + tmp = q_poseidon2_external * (v3 - w_o_shift); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + + tmp = q_poseidon2_external * (v4 - w_4_shift); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; }; }; diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp index a826468cfaef..e67ee8519d9e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp @@ -18,7 +18,7 @@ template class Poseidon2InternalRelationImpl { /** * @brief Expression for the poseidon2 internal round relation, based on I_i in Section 6 of * https://eprint.iacr.org/2023/323.pdf. - * @details This relation is defined as: + * @details This relation is defined as C(in(X)...) := * q_poseidon2_internal * ( (v1 - w_1_shift) + \alpha * (v2 - w_2_shift) + * \alpha^2 * (v3 - w_3_shift) + \alpha^3 * (v4 - w_4_shift) ) = 0 where: * u1 := (w_1 + q_1)^5 @@ -66,34 +66,30 @@ template class Poseidon2InternalRelationImpl { // matrix mul with v = M_I * u 4 muls and 7 additions auto sum = u1 + u2 + u3 + u4; - { - auto v1 = u1 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[0]; - v1 += sum; - auto tmp = q_poseidon2_internal * (v1 - w_l_shift); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - { - auto v2 = u2 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[1]; - v2 += sum; - auto tmp = q_poseidon2_internal * (v2 - w_r_shift); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - { - auto v3 = u3 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[2]; - v3 += sum; - auto tmp = q_poseidon2_internal * (v3 - w_o_shift); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - { - auto v4 = u4 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[3]; - v4 += sum; - auto tmp = q_poseidon2_internal * (v4 - w_4_shift); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } + + auto v1 = u1 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[0]; + v1 += sum; + auto tmp = q_poseidon2_internal * (v1 - w_l_shift); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + + auto v2 = u2 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[1]; + v2 += sum; + tmp = q_poseidon2_internal * (v2 - w_r_shift); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + + auto v3 = u3 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[2]; + v3 += sum; + tmp = q_poseidon2_internal * (v3 - w_o_shift); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + + auto v4 = u4 * crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[3]; + v4 += sum; + tmp = q_poseidon2_internal * (v4 - w_4_shift); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; }; }; // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp index f692148f9f46..65d33ff8c731 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp @@ -597,21 +597,21 @@ TEST_F(UltraRelationConsistency, Poseidon2ExternalRelation) u4 *= u4; u4 *= s4; - // multiply with external matrix - auto t0 = u1 + u2; // A + B - auto t1 = u3 + u4; // C + D - auto t2 = u2 + u2; // 2B - t2 += t1; // 2B + C + D - auto t3 = u4 + u4; // 2D - t3 += t0; // 2D + A + B + // matrix mul v = M_E * u with 14 additions + auto t0 = u1 + u2; // u_1 + u_2 + auto t1 = u3 + u4; // u_3 + u_4 + auto t2 = u2 + u2; // 2u_2 + t2 += t1; // 2u_2 + u_3 + u_4 + auto t3 = u4 + u4; // 2u_4 + t3 += t0; // u_1 + u_2 + 2u_4 auto v4 = t1 + t1; v4 += v4; - v4 += t3; // A + B + 4C + 6D + v4 += t3; // u_1 + u_2 + 4u_3 + 6u_4 auto v2 = t0 + t0; v2 += v2; - v2 += t2; // 4A + 6B + C + D - auto v1 = t3 + v2; // 5A + 7B + C + 3D - auto v3 = t2 + v4; // A + 3B + 5C + 7D + v2 += t2; // 4u_1 + 6u_2 + u_3 + u_4 + auto v1 = t3 + v2; // 5u_1 + 7u_2 + u_3 + 3u_4 + auto v3 = t2 + v4; // u_1 + 3u_2 + 5u_3 + 7u_4 // output is { v1, v2, v3, v4 }