-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
multi_scalar_mul
blackbox func (#6097)
Fixes noir-lang/noir#4928 Fixes noir-lang/noir#4932 **Note**: Noticed that we have [lookup table](https://github.com/AztecProtocol/aztec-packages/blob/46749ac9f32d4720efb380fb3a0e10a8ab1c345d/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp#L15) for fixed base in BB. Not sure if it's still needed after nuking the fixed based scalar mul.
- Loading branch information
Showing
68 changed files
with
627 additions
and
1,256 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
33 changes: 0 additions & 33 deletions
33
barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.cpp
This file contains 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,48 @@ | ||
#include "multi_scalar_mul.hpp" | ||
#include "barretenberg/dsl/types.hpp" | ||
#include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" | ||
#include "barretenberg/plonk_honk_shared/arithmetization/gate_data.hpp" | ||
#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" | ||
|
||
namespace acir_format { | ||
|
||
template <typename Builder> void create_multi_scalar_mul_constraint(Builder& builder, const MultiScalarMul& input) | ||
{ | ||
using cycle_group_ct = bb::stdlib::cycle_group<Builder>; | ||
using cycle_scalar_ct = typename bb::stdlib::cycle_group<Builder>::cycle_scalar; | ||
using field_ct = bb::stdlib::field_t<Builder>; | ||
|
||
std::vector<cycle_group_ct> points; | ||
std::vector<cycle_scalar_ct> scalars; | ||
|
||
for (size_t i = 0; i < input.points.size(); i += 2) { | ||
// Instantiate the input point/variable base as `cycle_group_ct` | ||
auto point_x = field_ct::from_witness_index(&builder, input.points[i]); | ||
auto point_y = field_ct::from_witness_index(&builder, input.points[i + 1]); | ||
cycle_group_ct input_point(point_x, point_y, false); | ||
|
||
// Reconstruct the scalar from the low and high limbs | ||
field_ct scalar_low_as_field = field_ct::from_witness_index(&builder, input.scalars[i]); | ||
field_ct scalar_high_as_field = field_ct::from_witness_index(&builder, input.scalars[i + 1]); | ||
cycle_scalar_ct scalar(scalar_low_as_field, scalar_high_as_field); | ||
|
||
// Add the point and scalar to the vectors | ||
points.push_back(input_point); | ||
scalars.push_back(scalar); | ||
} | ||
|
||
// Call batch_mul to multiply the points and scalars and sum the results | ||
auto output_point = cycle_group_ct::batch_mul(scalars, points); | ||
|
||
// Add the constraints | ||
builder.assert_equal(output_point.x.get_witness_index(), input.out_point_x); | ||
builder.assert_equal(output_point.y.get_witness_index(), input.out_point_y); | ||
} | ||
|
||
template void create_multi_scalar_mul_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder, | ||
const MultiScalarMul& input); | ||
template void create_multi_scalar_mul_constraint<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder, | ||
const MultiScalarMul& input); | ||
|
||
} // namespace acir_format |
Oops, something went wrong.