Skip to content

Commit

Permalink
refactor: create_fixed_base_constraint cleanup (#6047)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Apr 26, 2024
1 parent 3a3afb5 commit e1d6526
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ template <typename Builder> void create_fixed_base_constraint(Builder& builder,
using cycle_scalar_ct = typename bb::stdlib::cycle_group<Builder>::cycle_scalar;
using field_ct = bb::stdlib::field_t<Builder>;

// Computes low * G + high * 2^128 * G
//
// Low and high need to be less than 2^128
auto x = field_ct::from_witness_index(&builder, input.pub_key_x);
auto y = field_ct::from_witness_index(&builder, input.pub_key_y);
grumpkin::g1::affine_element base_point_var(x.get_value(), y.get_value());
cycle_group_ct base_point(base_point_var);

// We reconstruct the scalar from the low and high limbs
field_ct low_as_field = field_ct::from_witness_index(&builder, input.low);
field_ct high_as_field = field_ct::from_witness_index(&builder, input.high);
cycle_scalar_ct scalar(low_as_field, high_as_field);

// We multiply the scalar with G1 to get the result
auto result = cycle_group_ct(grumpkin::g1::affine_one) * scalar;

// Finally we add the constraints
builder.assert_equal(result.x.get_witness_index(), input.pub_key_x);
builder.assert_equal(result.y.get_witness_index(), input.pub_key_y);
}
Expand Down

0 comments on commit e1d6526

Please sign in to comment.