-
Notifications
You must be signed in to change notification settings - Fork 615
refactor: op queue #5648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: op queue #5648
Changes from 16 commits
e138a4d
03f8586
828fa33
38f22e4
6414b0f
e9327e6
3d35d75
04e9626
1fcac04
eb1e5a9
2566209
750f027
8bccdf8
a86ea72
e1f2efc
8e6d944
d7b2540
90033a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,13 +116,12 @@ class ECCVMCircuitBuilder { | |
| std::vector<std::pair<size_t, size_t>> msm_mul_index; | ||
| std::vector<size_t> msm_sizes; | ||
|
|
||
| // std::vector<std::vector<size_t>> msm_indices; | ||
| // std::vector<size_t> active_msm_indices; | ||
| for (size_t i = 0; i < op_queue->raw_ops.size(); ++i) { | ||
| const auto& op = op_queue->raw_ops[i]; | ||
| const auto& raw_ops = op_queue->get_raw_ops(); | ||
| size_t op_idx = 0; | ||
| for (const auto& op : raw_ops) { | ||
| if (op.mul) { | ||
| if (op.z1 != 0 || op.z2 != 0) { | ||
| msm_opqueue_index.push_back(i); | ||
| msm_opqueue_index.push_back(op_idx); | ||
| msm_mul_index.emplace_back(msm_count, active_mul_count); | ||
| } | ||
| if (op.z1 != 0) { | ||
|
|
@@ -136,9 +135,10 @@ class ECCVMCircuitBuilder { | |
| msm_count++; | ||
| active_mul_count = 0; | ||
| } | ||
| op_idx++; | ||
| } | ||
| // if last op is a mul we have not correctly computed the total number of msms | ||
| if (op_queue->raw_ops.back().mul) { | ||
| if (raw_ops.back().mul) { | ||
| msm_sizes.push_back(active_mul_count); | ||
| msm_count++; | ||
| } | ||
|
|
@@ -152,7 +152,7 @@ class ECCVMCircuitBuilder { | |
| for (size_t i = start; i < end; i++) { | ||
| // for (size_t i = 0; i < msm_opqueue_index.size(); ++i) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
| const size_t opqueue_index = msm_opqueue_index[i]; | ||
| const auto& op = op_queue->raw_ops[opqueue_index]; | ||
| const auto& op = raw_ops[opqueue_index]; | ||
| auto [msm_index, mul_index] = msm_mul_index[i]; | ||
| if (op.z1 != 0) { | ||
| ASSERT(msms_test.size() > msm_index); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,11 +29,11 @@ TEST(ECCVMCircuitBuilderTests, BaseCase) | |
| op_queue->mul_accumulate(b, y); | ||
| op_queue->add_accumulate(a); | ||
| op_queue->mul_accumulate(b, x); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| op_queue->add_accumulate(c); | ||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->mul_accumulate(b, x); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->mul_accumulate(b, x); | ||
| op_queue->mul_accumulate(c, x); | ||
|
|
@@ -86,7 +86,7 @@ TEST(ECCVMCircuitBuilderTests, ShortMul) | |
| Fr x = small_x; | ||
|
|
||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
|
|
@@ -95,7 +95,6 @@ TEST(ECCVMCircuitBuilderTests, ShortMul) | |
|
|
||
| TEST(ECCVMCircuitBuilderTests, EqFails) | ||
| { | ||
| using ECCVMOperation = eccvm::VMOperation<G1>; | ||
| std::shared_ptr<ECCOpQueue> op_queue = std::make_shared<ECCOpQueue>(); | ||
|
|
||
| auto generators = G1::derive_generators("test generators", 3); | ||
|
|
@@ -104,14 +103,8 @@ TEST(ECCVMCircuitBuilderTests, EqFails) | |
|
|
||
| op_queue->mul_accumulate(a, x); | ||
| // Tamper with the eq op such that the expected value is incorect | ||
| op_queue->raw_ops.emplace_back(ECCVMOperation{ .add = false, | ||
| .mul = false, | ||
| .eq = true, | ||
| .reset = true, | ||
| .base_point = a, | ||
| .z1 = 0, | ||
| .z2 = 0, | ||
| .mul_scalar_full = 0 }); | ||
| op_queue->add_erroneous_equality_op_for_testing(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. niiice |
||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
| EXPECT_EQ(result, false); | ||
|
|
@@ -121,7 +114,7 @@ TEST(ECCVMCircuitBuilderTests, EmptyRow) | |
| { | ||
| std::shared_ptr<ECCOpQueue> op_queue = std::make_shared<ECCOpQueue>(); | ||
|
|
||
| op_queue->empty_row(); | ||
| op_queue->empty_row_for_testing(); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
|
|
@@ -137,8 +130,8 @@ TEST(ECCVMCircuitBuilderTests, EmptyRowBetweenOps) | |
| Fr x = Fr::random_element(&engine); | ||
|
|
||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->empty_row(); | ||
| op_queue->eq(); | ||
| op_queue->empty_row_for_testing(); | ||
| op_queue->eq_and_reset(); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
|
|
@@ -154,7 +147,7 @@ TEST(ECCVMCircuitBuilderTests, EndWithEq) | |
| Fr x = Fr::random_element(&engine); | ||
|
|
||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
|
|
@@ -170,7 +163,7 @@ TEST(ECCVMCircuitBuilderTests, EndWithAdd) | |
| Fr x = Fr::random_element(&engine); | ||
|
|
||
| op_queue->mul_accumulate(a, x); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| op_queue->add_accumulate(a); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
|
|
@@ -187,7 +180,7 @@ TEST(ECCVMCircuitBuilderTests, EndWithMul) | |
| Fr x = Fr::random_element(&engine); | ||
|
|
||
| op_queue->add_accumulate(a); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| op_queue->mul_accumulate(a, x); | ||
|
|
||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
|
|
@@ -204,10 +197,10 @@ TEST(ECCVMCircuitBuilderTests, EndWithNoop) | |
| Fr x = Fr::random_element(&engine); | ||
|
|
||
| op_queue->add_accumulate(a); | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| op_queue->mul_accumulate(a, x); | ||
|
|
||
| op_queue->empty_row(); | ||
| op_queue->empty_row_for_testing(); | ||
| ECCVMCircuitBuilder circuit{ op_queue }; | ||
| bool result = ECCVMTraceChecker::check(circuit); | ||
| EXPECT_EQ(result, true); | ||
|
|
@@ -228,7 +221,7 @@ TEST(ECCVMCircuitBuilderTests, MSM) | |
| expected += (points[i] * scalars[i]); | ||
| op_queue->mul_accumulate(points[i], scalars[i]); | ||
| } | ||
| op_queue->eq(); | ||
| op_queue->eq_and_reset(); | ||
| }; | ||
|
|
||
| // single msms | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know this is not on you but we really need eccvm documentation, this code is involved to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hah yes, agreed