Skip to content

Commit

Permalink
resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Jun 23, 2023
1 parent 43a9103 commit a89b90c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 85 deletions.
12 changes: 6 additions & 6 deletions cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
witness_len++;

fr two = fr::one() + fr::one();
poly_triple a0 = poly_triple{
poly_triple a0 = {
.a = 1,
.b = 0,
.c = 0,
Expand All @@ -24,7 +24,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
.q_c = 0,
};
fr three = fr::one() + two;
poly_triple a1 = poly_triple{
poly_triple a1 = {
.a = 0,
.b = 0,
.c = 0,
Expand All @@ -34,7 +34,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
.q_o = 0,
.q_c = three,
};
poly_triple r1 = poly_triple{
poly_triple r1 = {
.a = 1,
.b = 0,
.c = 0,
Expand All @@ -44,7 +44,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
.q_o = 0,
.q_c = fr::neg_one(),
};
poly_triple r2 = poly_triple{
poly_triple r2 = {
.a = 1,
.b = 0,
.c = 0,
Expand All @@ -54,7 +54,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
.q_o = 0,
.q_c = fr::neg_one(),
};
poly_triple y = poly_triple{
poly_triple y = {
.a = 2,
.b = 0,
.c = 0,
Expand All @@ -66,7 +66,7 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_
};
witness_values.emplace_back(2);
witness_len++;
poly_triple z = poly_triple{
poly_triple z = {
.a = 3,
.b = 0,
.c = 0,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/ecc/curves/bn254/bn254.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class BN254 {
using AffineElement = typename Group::affine_element;
using G2AffineElement = typename barretenberg::g2::affine_element;
using G2BaseField = typename barretenberg::fq2;
using Fq12 = barretenberg::fq12;
using TargetField = barretenberg::fq12;
};
} // namespace curve
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/common/serialize.hpp"

// TODO(#557): The field-specific aliases for dates should be removed and the type could be made explicit when this
// structures are used to avoid having foo_gate and foo_gate_grumpkin. Moreover, we need to ensure the read/write
// functions handle grumpkin gates as well.
namespace proof_system {
template <typename FF> struct add_triple_ {
uint32_t a;
Expand Down Expand Up @@ -67,7 +70,6 @@ template <typename FF> struct poly_triple_ {

using poly_triple = poly_triple_<barretenberg::fr>;

// TODO: figure out what to do with this...
template <typename B> inline void read(B& buf, poly_triple& constraint)
{
using serialize::read;
Expand All @@ -80,7 +82,6 @@ template <typename B> inline void read(B& buf, poly_triple& constraint)
read(buf, constraint.q_o);
read(buf, constraint.q_c);
}
// TODO: and this..
template <typename B> inline void write(B& buf, poly_triple const& constraint)
{
using serialize::write;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ template <typename FF> void StandardCircuitConstructor_<FF>::create_big_add_gate
FF temp = t0 + t1;
uint32_t temp_idx = this->add_variable(temp);

create_add_gate(add_triple_<FF>{ in.a, in.b, temp_idx, in.a_scaling, in.b_scaling, FF::neg_one(), FF::zero() });
create_add_gate({ in.a, in.b, temp_idx, in.a_scaling, in.b_scaling, FF::neg_one(), FF::zero() });

create_add_gate(add_triple_<FF>{ in.c, in.d, temp_idx, in.c_scaling, in.d_scaling, FF::one(), in.const_scaling });
create_add_gate({ in.c, in.d, temp_idx, in.c_scaling, in.d_scaling, FF::one(), in.const_scaling });
}

/**
Expand Down Expand Up @@ -135,14 +135,14 @@ void StandardCircuitConstructor_<FF>::create_big_add_gate_with_bit_extraction(co

uint32_t delta_idx = this->add_variable(delta);
constexpr FF neg_four = -(FF(4));
create_add_gate(add_triple_<FF>{ in.c, in.d, delta_idx, FF::one(), neg_four, FF::neg_one(), FF::zero() });
create_add_gate({ in.c, in.d, delta_idx, FF::one(), neg_four, FF::neg_one(), FF::zero() });

constexpr FF two = FF(2);
constexpr FF seven = FF(7);
constexpr FF nine = FF(9);
const FF r_0 = (delta * nine) - ((delta.sqr() * two) + seven);
uint32_t r_0_idx = this->add_variable(r_0);
create_poly_gate(poly_triple_<FF>{ delta_idx, delta_idx, r_0_idx, -two, nine, FF::zero(), FF::neg_one(), -seven });
create_poly_gate({ delta_idx, delta_idx, r_0_idx, -two, nine, FF::zero(), FF::neg_one(), -seven });

FF r_1 = r_0 * delta;
uint32_t r_1_idx = this->add_variable(r_1);
Expand All @@ -159,7 +159,7 @@ void StandardCircuitConstructor_<FF>::create_big_add_gate_with_bit_extraction(co

FF r_2 = (r_1 + (this->get_variable(in.d) * in.d_scaling));
uint32_t r_2_idx = this->add_variable(r_2);
create_add_gate(add_triple_<FF>{ in.d, r_1_idx, r_2_idx, in.d_scaling, FF::one(), FF::neg_one(), FF::zero() });
create_add_gate({ in.d, r_1_idx, r_2_idx, in.d_scaling, FF::one(), FF::neg_one(), FF::zero() });

create_big_add_gate(add_quad_<FF>{
in.a, in.b, in.c, r_2_idx, in.a_scaling, in.b_scaling, in.c_scaling, FF::one(), in.const_scaling });
Expand All @@ -169,10 +169,9 @@ template <typename FF> void StandardCircuitConstructor_<FF>::create_big_mul_gate
{
FF temp = ((this->get_variable(in.c) * in.c_scaling) + (this->get_variable(in.d) * in.d_scaling));
uint32_t temp_idx = this->add_variable(temp);
create_add_gate(add_triple_<FF>{ in.c, in.d, temp_idx, in.c_scaling, in.d_scaling, FF::neg_one(), FF::zero() });
create_add_gate({ in.c, in.d, temp_idx, in.c_scaling, in.d_scaling, FF::neg_one(), FF::zero() });

create_poly_gate(poly_triple_<FF>{
in.a, in.b, temp_idx, in.mul_scaling, in.a_scaling, in.b_scaling, FF::one(), in.const_scaling });
create_poly_gate({ in.a, in.b, temp_idx, in.mul_scaling, in.a_scaling, in.b_scaling, FF::one(), in.const_scaling });
}

/**
Expand Down Expand Up @@ -277,8 +276,7 @@ std::vector<uint32_t> StandardCircuitConstructor_<FF>::decompose_into_base4_accu
uint64_t quad = (lo ? 1U : 0U) + (hi ? 2U : 0U);
quad_idx = this->add_variable(FF{ quad, 0, 0, 0 }.to_montgomery_form());

create_add_gate(add_triple_<FF>{
lo_idx, hi_idx, quad_idx, FF::one(), FF::one() + FF::one(), FF::neg_one(), FF::zero() });
create_add_gate({ lo_idx, hi_idx, quad_idx, FF::one(), FF::one() + FF::one(), FF::neg_one(), FF::zero() });
}

if (i == num_quads - 1) {
Expand All @@ -290,8 +288,8 @@ std::vector<uint32_t> StandardCircuitConstructor_<FF>::decompose_into_base4_accu
new_accumulator = new_accumulator + new_accumulator;
new_accumulator = new_accumulator + this->get_variable(quad_idx);
uint32_t new_accumulator_idx = this->add_variable(new_accumulator);
create_add_gate(add_triple_<FF>{
accumulator_idx, quad_idx, new_accumulator_idx, four, FF::one(), FF::neg_one(), FF::zero() });
create_add_gate(
{ accumulator_idx, quad_idx, new_accumulator_idx, four, FF::one(), FF::neg_one(), FF::zero() });
accumulators.push_back(new_accumulator_idx);
accumulator = new_accumulator;
accumulator_idx = new_accumulator_idx;
Expand Down Expand Up @@ -351,23 +349,23 @@ accumulator_triple StandardCircuitConstructor_<FF>::create_logic_constraint(cons

// a & b = ab
// a ^ b = a + b - 2ab
create_poly_gate(poly_triple_<FF>{ left_hi_idx,
right_hi_idx,
out_hi_idx,
is_xor_gate ? neg_two : FF::one(),
is_xor_gate ? FF::one() : FF::zero(),
is_xor_gate ? FF::one() : FF::zero(),
FF::neg_one(),
FF::zero() });

create_poly_gate(poly_triple_<FF>{ left_lo_idx,
right_lo_idx,
out_lo_idx,
is_xor_gate ? neg_two : FF::one(),
is_xor_gate ? FF::one() : FF::zero(),
is_xor_gate ? FF::one() : FF::zero(),
FF::neg_one(),
FF::zero() });
create_poly_gate({ left_hi_idx,
right_hi_idx,
out_hi_idx,
is_xor_gate ? neg_two : FF::one(),
is_xor_gate ? FF::one() : FF::zero(),
is_xor_gate ? FF::one() : FF::zero(),
FF::neg_one(),
FF::zero() });

create_poly_gate({ left_lo_idx,
right_lo_idx,
out_lo_idx,
is_xor_gate ? neg_two : FF::one(),
is_xor_gate ? FF::one() : FF::zero(),
is_xor_gate ? FF::one() : FF::zero(),
FF::neg_one(),
FF::zero() });

FF left_quad =
this->get_variable(left_lo_idx) + this->get_variable(left_hi_idx) + this->get_variable(left_hi_idx);
Expand All @@ -384,34 +382,34 @@ accumulator_triple StandardCircuitConstructor_<FF>::create_logic_constraint(cons
new_left_accumulator = new_left_accumulator + left_quad;
uint32_t new_left_accumulator_idx = this->add_variable(new_left_accumulator);

create_add_gate(add_triple_<FF>{ left_accumulator_idx,
left_quad_idx,
new_left_accumulator_idx,
four,
FF::one(),
FF::neg_one(),
FF::zero() });
create_add_gate({ left_accumulator_idx,
left_quad_idx,
new_left_accumulator_idx,
four,
FF::one(),
FF::neg_one(),
FF::zero() });

FF new_right_accumulator = right_accumulator + right_accumulator;
new_right_accumulator = new_right_accumulator + new_right_accumulator;
new_right_accumulator = new_right_accumulator + right_quad;
uint32_t new_right_accumulator_idx = this->add_variable(new_right_accumulator);

create_add_gate(add_triple_<FF>{ right_accumulator_idx,
right_quad_idx,
new_right_accumulator_idx,
four,
FF::one(),
FF::neg_one(),
FF::zero() });
create_add_gate({ right_accumulator_idx,
right_quad_idx,
new_right_accumulator_idx,
four,
FF::one(),
FF::neg_one(),
FF::zero() });

FF new_out_accumulator = out_accumulator + out_accumulator;
new_out_accumulator = new_out_accumulator + new_out_accumulator;
new_out_accumulator = new_out_accumulator + out_quad;
uint32_t new_out_accumulator_idx = this->add_variable(new_out_accumulator);

create_add_gate(add_triple_<FF>{
out_accumulator_idx, out_quad_idx, new_out_accumulator_idx, four, FF::one(), FF::neg_one(), FF::zero() });
create_add_gate(
{ out_accumulator_idx, out_quad_idx, new_out_accumulator_idx, four, FF::one(), FF::neg_one(), FF::zero() });

accumulators.left.emplace_back(new_left_accumulator_idx);
accumulators.right.emplace_back(new_right_accumulator_idx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ TEST(turbo_circuit_constructor, small_scalar_multipliers)
bool skew = false;
barretenberg::wnaf::fixed_wnaf<num_wnaf_bits, 1, 2>(&scalar_multiplier_base.data[0], &wnaf_entries[0], skew, 0);

fr accumulator_ofrset = (fr::one() + fr::one()).pow(static_cast<uint64_t>(initial_exponent)).invert();
fr origin_accumulators[2]{ fr::one(), accumulator_ofrset + fr::one() };
fr accumulator_offset = (fr::one() + fr::one()).pow(static_cast<uint64_t>(initial_exponent)).invert();
fr origin_accumulators[2]{ fr::one(), accumulator_offset + fr::one() };

grumpkin::g1::element* multiplication_transcript =
static_cast<grumpkin::g1::element*>(aligned_alloc(64, sizeof(grumpkin::g1::element) * (num_quads + 1)));
Expand Down Expand Up @@ -228,7 +228,7 @@ TEST(turbo_circuit_constructor, small_scalar_multipliers)

TurboCircuitConstructor circuit_constructor = TurboCircuitConstructor();

fr x_alpha = accumulator_ofrset;
fr x_alpha = accumulator_offset;
for (size_t i = 0; i < num_quads; ++i) {
fixed_group_add_quad round_quad;
round_quad.d = circuit_constructor.add_variable(accumulator_transcript[i]);
Expand Down Expand Up @@ -311,8 +311,8 @@ TEST(turbo_circuit_constructor, large_scalar_multipliers)
bool skew = false;
barretenberg::wnaf::fixed_wnaf<num_wnaf_bits, 1, 2>(&scalar_multiplier_base.data[0], &wnaf_entries[0], skew, 0);

fr accumulator_ofrset = (fr::one() + fr::one()).pow(static_cast<uint64_t>(initial_exponent)).invert();
fr origin_accumulators[2]{ fr::one(), accumulator_ofrset + fr::one() };
fr accumulator_offset = (fr::one() + fr::one()).pow(static_cast<uint64_t>(initial_exponent)).invert();
fr origin_accumulators[2]{ fr::one(), accumulator_offset + fr::one() };

grumpkin::g1::element* multiplication_transcript =
static_cast<grumpkin::g1::element*>(aligned_alloc(64, sizeof(grumpkin::g1::element) * (num_quads + 1)));
Expand Down Expand Up @@ -352,7 +352,7 @@ TEST(turbo_circuit_constructor, large_scalar_multipliers)

TurboCircuitConstructor circuit_constructor = TurboCircuitConstructor();

fr x_alpha = accumulator_ofrset;
fr x_alpha = accumulator_offset;
for (size_t i = 0; i < num_quads; ++i) {
fixed_group_add_quad round_quad;
round_quad.d = circuit_constructor.add_variable(accumulator_transcript[i]);
Expand Down
Loading

0 comments on commit a89b90c

Please sign in to comment.