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: implementation for bigint opcodes #4288

Merged
merged 18 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
14 changes: 11 additions & 3 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "acir_format.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/dsl/acir_format/bigint_constraint.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include <cstddef>

namespace acir_format {

template class DSLBigInts<UltraCircuitBuilder>;
template class DSLBigInts<GoblinUltraCircuitBuilder>;

template <typename Builder>
void build_constraints(Builder& builder, AcirFormat const& constraint_system, bool has_valid_witness_assignments)
{
Expand Down Expand Up @@ -90,11 +94,15 @@ void build_constraints(Builder& builder, AcirFormat const& constraint_system, bo
}

// Add big_int constraints
DSLBigInts<Builder> dsl_bigints;
for (const auto& constraint : constraint_system.bigint_from_le_bytes_constraints) {
create_bigint_from_le_bytes_constraint(builder, constraint, dsl_bigints);
}
for (const auto& constraint : constraint_system.bigint_operations) {
create_bigint_operations_constraint(builder, constraint);
create_bigint_operations_constraint<Builder>(constraint, dsl_bigints);
}
for (const auto& constraint : constraint_system.bigint_from_le_bytes_constraints) {
create_bigint_from_le_bytes_constraint(builder, constraint);
for (const auto& constraint : constraint_system.bigint_to_le_bytes_constraints) {
create_bigint_to_le_bytes_constraint(builder, constraint, dsl_bigints);
}

// TODO(https://github.com/AztecProtocol/barretenberg/issues/817): disable these for UGH for now since we're not yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct AcirFormat {
std::vector<EcAdd> ec_add_constraints;
std::vector<RecursionConstraint> recursion_constraints;
std::vector<BigIntFromLeBytes> bigint_from_le_bytes_constraints;
std::vector<BigIntToLeBytes> bigint_to_le_bytes_constraints;
std::vector<BigIntOperation> bigint_operations;

// A standard plonk arithmetic constraint, as defined in the poly_triple struct, consists of selector values
Expand Down Expand Up @@ -80,6 +81,7 @@ struct AcirFormat {
constraints,
block_constraints,
bigint_from_le_bytes_constraints,
bigint_to_le_bytes_constraints,
bigint_operations);

friend bool operator==(AcirFormat const& lhs, AcirFormat const& rhs) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = { constraint },
.block_constraints = {},
Expand Down Expand Up @@ -161,6 +162,7 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = { expr_a, expr_b, expr_c, expr_d },
.block_constraints = {} };
Expand Down Expand Up @@ -226,6 +228,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = { poly_triple{
.a = schnorr_constraint.result,
Expand Down Expand Up @@ -319,6 +322,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = { poly_triple{
.a = schnorr_constraint.result,
Expand Down Expand Up @@ -431,6 +435,7 @@ TEST_F(AcirFormatTests, TestVarKeccak)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = { dummy },
.block_constraints = {},
Expand Down Expand Up @@ -475,6 +480,7 @@ TEST_F(AcirFormatTests, TestKeccakPermutation)
.ec_add_constraints = {},
.recursion_constraints = {},
.bigint_from_le_bytes_constraints = {},
.bigint_to_le_bytes_constraints = {},
.bigint_operations = {},
.constraints = {},
.block_constraints = {} };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, Aci
.modulus = map(arg.modulus, [](auto& e) -> uint32_t { return e; }),
.result = arg.output,
});
} else if constexpr (std::is_same_v<T, Circuit::BlackBoxFuncCall::BigIntToLeBytes>) {
af.bigint_to_le_bytes_constraints.push_back(BigIntToLeBytes{
.input = arg.input,
.result = map(arg.outputs, [](auto& e) { return e.value; }),
});
} else if constexpr (std::is_same_v<T, Circuit::BlackBoxFuncCall::BigIntAdd>) {
af.bigint_operations.push_back(BigIntOperation{
.lhs = arg.lhs,
Expand Down
Loading
Loading