From be288b3b18c1f324e89c127318031436abb00583 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Jun 2023 16:00:17 +0000 Subject: [PATCH 1/4] Add new ops, change curve, make const, document. --- .../proof_system/op_queue/ecc_op_queue.hpp | 63 ++++++++++++------- .../op_queue/ecc_op_queue.test.cpp | 6 +- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp index 244762e758..74fc476549 100644 --- a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp +++ b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp @@ -1,29 +1,45 @@ #pragma once -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +#include "barretenberg/ecc/curves/bn254/bn254.hpp" namespace proof_system { +/** + * @brief Raw description of an ECC operation used to produce equivalent descriptions over different curves. + */ struct ECCOp { - bool add = false; - bool mul = false; - bool eq = false; - bool reset = false; - grumpkin::g1::affine_element base_point = grumpkin::g1::affine_element{ 0, 0 }; - uint256_t scalar_1 = 0; - uint256_t scalar_2 = 0; - grumpkin::fr mul_scalar_full = 0; + const bool add = false; + const bool mul = false; + const bool eq = false; + const bool reset = false; + const barretenberg::g1::affine_element base_point = barretenberg::g1::affine_element{ 0, 0 }; + const uint256_t scalar_1 = 0; + const uint256_t scalar_2 = 0; + const barretenberg::fr mul_scalar_full = 0; }; +/** + * @brief Used to construct executation trace representations of elliptic curve operations. + * + * @details Currently the targets in execution traces are: four advice wires in UltraCircuitBuilder and 5 wires in the + * ECCVM. In each case, the variable values are stored in this class, since the same values will need to be used later + * by the TranslationVMCircuitBuilder. The circuit builders will store witness indices which are indices in the + * untranslated (resp. translated) ops members of this class (rather than in the builder's variables array). + */ class ECCOpQueue { + using Point = curve::BN254::AffineElement; + Point point_at_infinity = curve::BN254::Group::affine_point_at_infinity; + using Fr = curve::BN254::ScalarField; + using Fq = curve::BN254::BaseField; // Grumpkin's scalar field public: - std::vector _data; + std::vector raw_ops; + std::vector> untranslated_ops; + std::vector> translated_ops; uint32_t get_number_of_muls() { uint32_t num_muls = 0; - for (auto& op : _data) { + for (auto& op : raw_ops) { if (op.mul) { if (op.scalar_1 != 0) { num_muls++; @@ -36,9 +52,9 @@ class ECCOpQueue { return num_muls; } - void add_accumulate(const grumpkin::g1::affine_element& to_add) + void add_accumulate(const Point& to_add) { - _data.emplace_back(ECCOp{ + raw_ops.emplace_back(ECCOp{ .add = true, .mul = false, .eq = false, @@ -50,15 +66,15 @@ class ECCOpQueue { }); } - void mul_accumulate(const grumpkin::g1::affine_element& to_mul, const grumpkin::fr& scalar) + void mul_accumulate(const Point& to_mul, const Fr& scalar) { - grumpkin::fr scalar_1 = 0; - grumpkin::fr scalar_2 = 0; + Fr scalar_1 = 0; + Fr scalar_2 = 0; auto converted = scalar.from_montgomery_form(); - grumpkin::fr::split_into_endomorphism_scalars(converted, scalar_1, scalar_2); + Fr::split_into_endomorphism_scalars(converted, scalar_1, scalar_2); scalar_1 = scalar_1.to_montgomery_form(); scalar_2 = scalar_2.to_montgomery_form(); - _data.emplace_back(ECCOp{ + raw_ops.emplace_back(ECCOp{ .add = false, .mul = true, .eq = false, @@ -69,9 +85,9 @@ class ECCOpQueue { .mul_scalar_full = scalar, }); } - void eq(const grumpkin::g1::affine_element& expected) + void eq(const Point& expected) { - _data.emplace_back(ECCOp{ + raw_ops.emplace_back(ECCOp{ .add = false, .mul = false, .eq = true, @@ -85,16 +101,17 @@ class ECCOpQueue { void empty_row() { - _data.emplace_back(ECCOp{ + raw_ops.emplace_back(ECCOp{ .add = false, .mul = false, .eq = false, .reset = false, - .base_point = grumpkin::g1::affine_point_at_infinity, + .base_point = point_at_infinity, .scalar_1 = 0, .scalar_2 = 0, .mul_scalar_full = 0, }); } }; + } // namespace proof_system \ No newline at end of file diff --git a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp index 04541423b9..7b1c160eb6 100644 --- a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp +++ b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp @@ -5,10 +5,10 @@ namespace proof_system::test_flavor { TEST(ECCOpQueueTest, Basic) { ECCOpQueue op_queue; - op_queue.add_accumulate(grumpkin::g1::affine_one); - EXPECT_EQ(op_queue._data[0].base_point, grumpkin::g1::affine_one); + op_queue.add_accumulate(barretenberg::g1::affine_one); + EXPECT_EQ(op_queue.raw_ops[0].base_point, barretenberg::g1::affine_one); op_queue.empty_row(); - EXPECT_EQ(op_queue._data[1].add, false); + EXPECT_EQ(op_queue.raw_ops[1].add, false); } } // namespace proof_system::test_flavor From 18995524c2288e7316e3926842daf45b881b5773 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Jun 2023 16:14:28 +0000 Subject: [PATCH 2/4] Rename ops --- cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp index 74fc476549..283592d6f2 100644 --- a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp +++ b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp @@ -24,7 +24,7 @@ struct ECCOp { * @details Currently the targets in execution traces are: four advice wires in UltraCircuitBuilder and 5 wires in the * ECCVM. In each case, the variable values are stored in this class, since the same values will need to be used later * by the TranslationVMCircuitBuilder. The circuit builders will store witness indices which are indices in the - * untranslated (resp. translated) ops members of this class (rather than in the builder's variables array). + * ultra (resp. eccvm) ops members of this class (rather than in the builder's variables array). */ class ECCOpQueue { using Point = curve::BN254::AffineElement; @@ -33,8 +33,8 @@ class ECCOpQueue { using Fq = curve::BN254::BaseField; // Grumpkin's scalar field public: std::vector raw_ops; - std::vector> untranslated_ops; - std::vector> translated_ops; + std::vector> ultra_ops; + std::vector> eccvm_ops; uint32_t get_number_of_muls() { From 1154795186c1de94cb69317989bf3f26a3fe00f9 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Jun 2023 16:21:00 +0000 Subject: [PATCH 3/4] Update aztec commit --- cpp/.aztec-packages-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/.aztec-packages-commit b/cpp/.aztec-packages-commit index 656b947ce1..96677a83ab 100644 --- a/cpp/.aztec-packages-commit +++ b/cpp/.aztec-packages-commit @@ -1 +1 @@ -3e16992198189112739e3710860e7d7717366108 \ No newline at end of file +master \ No newline at end of file From a0dfda40903468c44d0b8cfff5ffbb4922288893 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Jun 2023 16:27:27 +0000 Subject: [PATCH 4/4] Fix typo --- cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp index 283592d6f2..4a810a37e8 100644 --- a/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp +++ b/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp @@ -19,7 +19,7 @@ struct ECCOp { }; /** - * @brief Used to construct executation trace representations of elliptic curve operations. + * @brief Used to construct execution trace representations of elliptic curve operations. * * @details Currently the targets in execution traces are: four advice wires in UltraCircuitBuilder and 5 wires in the * ECCVM. In each case, the variable values are stored in this class, since the same values will need to be used later