Skip to content
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

feat: add ACIR opcodes for ECADD and ECDOUBLE #3878

Merged
merged 9 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ void build_constraints(Builder& builder, acir_format const& constraint_system, b
create_fixed_base_constraint(builder, constraint);
}

// Add ec add constraints
for (const auto& constraint : constraint_system.ec_add_constraints) {
create_ec_add_constraint(builder, constraint);
}

// Add ec double
for (const auto& constraint : constraint_system.ec_double_constraints) {
create_ec_double_constraint(builder, constraint);
}

// Add block constraints
for (const auto& constraint : constraint_system.block_constraints) {
create_block_constraints(builder, constraint, has_valid_witness_assignments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "blake2s_constraint.hpp"
#include "blake3_constraint.hpp"
#include "block_constraint.hpp"
#include "ec_operations.hpp"
#include "ecdsa_secp256k1.hpp"
#include "ecdsa_secp256r1.hpp"
#include "fixed_base_scalar_mul.hpp"
Expand Down Expand Up @@ -38,6 +39,8 @@ struct acir_format {
std::vector<PedersenConstraint> pedersen_constraints;
std::vector<PedersenHashConstraint> pedersen_hash_constraints;
std::vector<FixedBaseScalarMul> fixed_base_scalar_mul_constraints;
std::vector<EcAdd> ec_add_constraints;
std::vector<EcDouble> ec_double_constraints;
std::vector<RecursionConstraint> recursion_constraints;

// A standard plonk arithmetic constraint, as defined in the poly_triple struct, consists of selector values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { constraint },
.block_constraints = {},
Expand Down Expand Up @@ -152,6 +154,8 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { expr_a, expr_b, expr_c, expr_d },
.block_constraints = {} };
Expand Down Expand Up @@ -218,6 +222,8 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { poly_triple{
.a = schnorr_constraint.result,
Expand Down Expand Up @@ -307,6 +313,8 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { poly_triple{
.a = schnorr_constraint.result,
Expand Down Expand Up @@ -415,6 +423,8 @@ TEST_F(AcirFormatTests, TestVarKeccak)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { dummy },
.block_constraints = {},
Expand Down Expand Up @@ -454,6 +464,8 @@ TEST_F(AcirFormatTests, TestKeccakPermutation)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {} };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = { block },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "ec_operations.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/proof_system/arithmetization/gate_data.hpp"

namespace acir_format {

template <typename Builder> void create_ec_add_constraint(Builder& builder, const EcAdd& input)
{
// TODO
builder.assert_equal(input.input1_x, input.input1_x);
ASSERT(false);
}

template void create_ec_add_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder, const EcAdd& input);
template void create_ec_add_constraint<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder,
const EcAdd& input);

template <typename Builder> void create_ec_double_constraint(Builder& builder, const EcDouble& input)
{
// TODO
builder.assert_equal(input.input_x, input.input_x);
ASSERT(false);
}

template void create_ec_double_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder, const EcDouble& input);
template void create_ec_double_constraint<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder,
const EcDouble& input);

} // namespace acir_format
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/serialize/msgpack.hpp"
#include <cstdint>

namespace acir_format {

struct EcAdd {
uint32_t input1_x;
uint32_t input1_y;
uint32_t input2_x;
uint32_t input2_y;
uint32_t result_x;
uint32_t result_y;

// for serialization, update with any new fields
MSGPACK_FIELDS(input1_x, input1_y, input2_x, input2_y, result_x, result_y);
friend bool operator==(EcAdd const& lhs, EcAdd const& rhs) = default;
};

template <typename Builder> void create_ec_add_constraint(Builder& builder, const EcAdd& input);

struct EcDouble {
uint32_t input_x;
uint32_t input_y;
uint32_t result_x;
uint32_t result_y;

// for serialization, update with any new fields
MSGPACK_FIELDS(input_x, input_y, result_x, result_y);
friend bool operator==(EcDouble const& lhs, EcDouble const& rhs) = default;
};

template <typename Builder> void create_ec_double_constraint(Builder& builder, const EcDouble& input);
} // namespace acir_format
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down Expand Up @@ -146,6 +148,8 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down Expand Up @@ -183,6 +187,8 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ TEST(ECDSASecp256r1, test_hardcoded)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down Expand Up @@ -181,6 +183,8 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down Expand Up @@ -222,6 +226,8 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down Expand Up @@ -258,6 +264,8 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = {},
.block_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Builder create_inner_circuit()
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = {},
.constraints = { expr_a, expr_b, expr_c, expr_d },
.block_constraints = {} };
Expand Down Expand Up @@ -253,6 +255,8 @@ Builder create_outer_circuit(std::vector<Builder>& inner_circuits)
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.fixed_base_scalar_mul_constraints = {},
.ec_add_constraints = {},
.ec_double_constraints = {},
.recursion_constraints = recursion_constraints,
.constraints = {},
.block_constraints = {} };
Expand Down
Loading