-
Notifications
You must be signed in to change notification settings - Fork 614
feat: Implement Embedded EC add and double opcodes #3982
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
87acf20
Implement Embedded EC add and double opcodes
guipublic 50db51f
assign dummy witness values properly for verification
guipublic 8c0fa44
Merge branch 'master' into gd/ec_operations
guipublic 48fec2a
Merge branch 'master' into gd/ec_operations
guipublic 19f8119
code review
guipublic ebac236
clippy
guipublic c877c23
code review
guipublic 4674646
Merge branch 'master' into gd/ec_operations
guipublic c5aac9f
Merge branch 'master' into gd/ec_operations
guipublic 0b8dc4b
Merge branch 'master' into gd/ec_operations
guipublic 73d6a1c
Merge branch 'master' into gd/ec_operations
guipublic e4a82c6
Merge branch 'master' into gd/ec_operations
guipublic 7ca7f41
Merge branch 'master' into gd/ec_operations
guipublic 4b271db
Merge branch 'master' into gd/ec_operations
guipublic 6355f7d
fix the build
guipublic 4b41f37
fix the build(2)
guipublic 217a159
Merge branch 'master' into gd/ec_operations
guipublic 348364e
fix ec_operations test
guipublic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #include "ec_operations.hpp" | ||
| #include "acir_format.hpp" | ||
| #include "barretenberg/plonk/proof_system/types/proof.hpp" | ||
| #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <vector> | ||
|
|
||
| namespace acir_format::tests { | ||
| using curve_ct = proof_system::plonk::stdlib::secp256k1<Builder>; | ||
|
|
||
| class EcOperations : public ::testing::Test { | ||
| protected: | ||
| static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); } | ||
| }; | ||
|
|
||
| size_t generate_ec_add_constraint(EcAdd& ec_add_constraint, WitnessVector& witness_values) | ||
| { | ||
| using cycle_group_ct = proof_system::plonk::stdlib::cycle_group<Builder>; | ||
| auto g1 = grumpkin::g1::affine_one; | ||
| cycle_group_ct input_point(g1); | ||
| // Doubling | ||
| cycle_group_ct result = input_point.dbl(); | ||
| // add: x,y,x2,y2 | ||
| witness_values.push_back(g1.x); | ||
| witness_values.push_back(g1.y); | ||
| witness_values.push_back(g1.x); | ||
| witness_values.push_back(g1.y); | ||
| witness_values.push_back(result.x.get_value()); | ||
| witness_values.push_back(result.y.get_value()); | ||
| ec_add_constraint = EcAdd{ | ||
| .input1_x = 1, | ||
| .input1_y = 2, | ||
| .input2_x = 3, | ||
| .input2_y = 4, | ||
| .result_x = 5, | ||
| .result_y = 6, | ||
| }; | ||
| return witness_values.size(); | ||
| } | ||
|
|
||
| size_t generate_ec_double_constraint(EcDouble& ec_double_constraint, WitnessVector& witness_values) | ||
| { | ||
|
|
||
| using cycle_group_ct = proof_system::plonk::stdlib::cycle_group<Builder>; | ||
| auto g1 = grumpkin::g1::affine_one; | ||
| cycle_group_ct input_point(g1); | ||
| // Doubling | ||
| cycle_group_ct result = input_point.dbl(); | ||
| // add: x,y,x2,y2 | ||
| uint32_t result_x_witness_index = (uint32_t)witness_values.size() + 1; | ||
| witness_values.push_back(result.x.get_value()); | ||
| uint32_t result_y_witness_index = (uint32_t)witness_values.size() + 1; | ||
| witness_values.push_back(result.y.get_value()); | ||
| info("DOUBLE"); | ||
| info(result.x.get_value()); | ||
| ec_double_constraint = EcDouble{ | ||
| .input_x = 1, | ||
| .input_y = 2, | ||
| .result_x = result_x_witness_index, | ||
| .result_y = result_y_witness_index, | ||
| }; | ||
| return witness_values.size(); | ||
| } | ||
|
|
||
| TEST_F(EcOperations, TestECOperations) | ||
| { | ||
| EcAdd ec_add_constraint; | ||
| EcDouble ec_double_constraint; | ||
|
|
||
| WitnessVector witness_values; | ||
| generate_ec_add_constraint(ec_add_constraint, witness_values); | ||
| size_t num_variables = generate_ec_double_constraint(ec_double_constraint, witness_values); | ||
|
|
||
| poly_triple constrain_5_is_7{ | ||
| .a = 5, | ||
| .b = 7, | ||
| .c = 0, | ||
| .q_m = 0, | ||
| .q_l = 1, | ||
| .q_r = -1, | ||
| .q_o = 0, | ||
| .q_c = 0, | ||
| }; | ||
| poly_triple constrain_6_is_8{ | ||
| .a = 6, | ||
| .b = 8, | ||
| .c = 0, | ||
| .q_m = 0, | ||
| .q_l = 1, | ||
| .q_r = -1, | ||
| .q_o = 0, | ||
| .q_c = 0, | ||
| }; | ||
|
|
||
| acir_format constraint_system{ | ||
| .varnum = static_cast<uint32_t>(num_variables + 1), | ||
| .public_inputs = {}, | ||
| .logic_constraints = {}, | ||
| .range_constraints = {}, | ||
| .sha256_constraints = {}, | ||
| .schnorr_constraints = {}, | ||
| .ecdsa_k1_constraints = {}, | ||
| .ecdsa_r1_constraints = {}, | ||
| .blake2s_constraints = {}, | ||
| .blake3_constraints = {}, | ||
| .keccak_constraints = {}, | ||
| .keccak_var_constraints = {}, | ||
| .keccak_permutations = {}, | ||
| .pedersen_constraints = {}, | ||
| .pedersen_hash_constraints = {}, | ||
| .fixed_base_scalar_mul_constraints = {}, | ||
| .ec_add_constraints = { ec_add_constraint }, | ||
| .ec_double_constraints = { ec_double_constraint }, | ||
| .recursion_constraints = {}, | ||
| .constraints = { constrain_5_is_7, constrain_6_is_8 }, | ||
| .block_constraints = {}, | ||
| }; | ||
|
|
||
| auto builder = create_circuit_with_witness(constraint_system, witness_values); | ||
| auto composer = Composer(); | ||
| auto prover = composer.create_prover(builder); | ||
|
|
||
| auto proof = prover.construct_proof(); | ||
| EXPECT_TRUE(builder.check_circuit()); | ||
| // We create another builder | ||
| auto builder2 = create_circuit(constraint_system); | ||
| auto composer2 = Composer(); | ||
| auto verifier = composer2.create_verifier(builder2); | ||
| EXPECT_EQ(verifier.verify_proof(proof), true); | ||
| } | ||
|
|
||
| } // namespace acir_format::tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.