-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unit test for BB big integer opcode implementation (#4177)
The unit test is just creating big int constraints and should be updated when the constraints are implemented.
- Loading branch information
Showing
11 changed files
with
237 additions
and
1 deletion.
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
33 changes: 33 additions & 0 deletions
33
barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.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,33 @@ | ||
#include "bigint_constraint.hpp" | ||
#include "barretenberg/dsl/types.hpp" | ||
#include "barretenberg/numeric/uint256/uint256.hpp" | ||
#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" | ||
|
||
namespace acir_format { | ||
|
||
template <typename Builder> void create_bigint_operations_constraint(Builder& builder, const BigIntOperation& input) | ||
{ | ||
// TODO | ||
(void)builder; | ||
info(input); | ||
} | ||
|
||
template void create_bigint_operations_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder, | ||
const BigIntOperation& input); | ||
template void create_bigint_operations_constraint<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder, | ||
const BigIntOperation& input); | ||
|
||
template <typename Builder> | ||
void create_bigint_from_le_bytes_constraint(Builder& builder, const BigIntFromLeBytes& input) | ||
{ | ||
// TODO | ||
(void)builder; | ||
info(input); | ||
} | ||
|
||
template void create_bigint_from_le_bytes_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder, | ||
const BigIntFromLeBytes& input); | ||
template void create_bigint_from_le_bytes_constraint<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder, | ||
const BigIntFromLeBytes& input); | ||
|
||
} // namespace acir_format |
35 changes: 35 additions & 0 deletions
35
barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.hpp
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,35 @@ | ||
#pragma once | ||
#include "barretenberg/dsl/types.hpp" | ||
#include "barretenberg/serialize/msgpack.hpp" | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace acir_format { | ||
|
||
struct BigIntFromLeBytes { | ||
std::vector<uint32_t> inputs; | ||
std::vector<uint32_t> modulus; | ||
uint32_t result; | ||
|
||
// For serialization, update with any new fields | ||
MSGPACK_FIELDS(inputs, result); | ||
friend bool operator==(BigIntFromLeBytes const& lhs, BigIntFromLeBytes const& rhs) = default; | ||
}; | ||
|
||
enum BigIntOperationType { Add, Neg, Mul, Div }; | ||
|
||
struct BigIntOperation { | ||
uint32_t lhs; | ||
uint32_t rhs; | ||
uint32_t result; | ||
BigIntOperationType opcode; | ||
|
||
// For serialization, update with any new fields | ||
MSGPACK_FIELDS(lhs, rhs, opcode, result); | ||
friend bool operator==(BigIntOperation const& lhs, BigIntOperation const& rhs) = default; | ||
}; | ||
|
||
template <typename Builder> void create_bigint_operations_constraint(Builder& builder, const BigIntOperation& input); | ||
template <typename Builder> | ||
void create_bigint_from_le_bytes_constraint(Builder& builder, const BigIntFromLeBytes& input); | ||
} // namespace acir_format |
88 changes: 88 additions & 0 deletions
88
barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.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,88 @@ | ||
#include "bigint_constraint.hpp" | ||
#include "acir_format.hpp" | ||
#include "barretenberg/plonk/proof_system/types/proof.hpp" | ||
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
#include <vector> | ||
|
||
namespace acir_format::tests { | ||
|
||
class BigIntTests : public ::testing::Test { | ||
protected: | ||
static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } | ||
}; | ||
|
||
TEST_F(BigIntTests, TestBigIntConstraintDummy) | ||
{ | ||
// Dummy Test: to be updated when big ints opcodes are implemented | ||
BigIntOperation add_constraint{ | ||
.lhs = 1, | ||
.rhs = 2, | ||
.result = 3, | ||
.opcode = BigIntOperationType::Add, | ||
}; | ||
BigIntOperation neg_constraint{ | ||
.lhs = 1, | ||
.rhs = 2, | ||
.result = 3, | ||
.opcode = BigIntOperationType::Neg, | ||
}; | ||
BigIntOperation mul_constraint{ | ||
.lhs = 1, | ||
.rhs = 2, | ||
.result = 3, | ||
.opcode = BigIntOperationType::Mul, | ||
}; | ||
BigIntOperation div_constraint{ | ||
.lhs = 1, | ||
.rhs = 2, | ||
.result = 3, | ||
.opcode = BigIntOperationType::Div, | ||
}; | ||
BigIntFromLeBytes from_le_bytes_constraint{ | ||
.inputs = { 0 }, | ||
.modulus = { 23 }, | ||
.result = 1, | ||
}; | ||
|
||
acir_format constraint_system{ | ||
.varnum = 4, | ||
.public_inputs = {}, | ||
.logic_constraints = {}, | ||
.range_constraints = {}, | ||
.sha256_constraints = {}, | ||
.schnorr_constraints = {}, | ||
.ecdsa_k1_constraints = {}, | ||
.ecdsa_r1_constraints = {}, | ||
.blake2s_constraints = {}, | ||
.blake3_constraints = {}, | ||
.keccak_constraints = {}, | ||
.keccak_var_constraints = {}, | ||
.keccak_permutations = {}, | ||
.pedersen_constraints = {}, | ||
.pedersen_hash_constraints = {}, | ||
.fixed_base_scalar_mul_constraints = {}, | ||
.ec_add_constraints = {}, | ||
.ec_double_constraints = {}, | ||
.recursion_constraints = {}, | ||
.bigint_from_le_bytes_constraints = { from_le_bytes_constraint }, | ||
.bigint_operations = { add_constraint, neg_constraint, mul_constraint, div_constraint }, | ||
.constraints = {}, | ||
.block_constraints = {}, | ||
|
||
}; | ||
|
||
WitnessVector witness{ 0, 0, 1 }; | ||
auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); | ||
|
||
auto composer = Composer(); | ||
auto prover = composer.create_ultra_with_keccak_prover(builder); | ||
auto proof = prover.construct_proof(); | ||
|
||
auto verifier = composer.create_ultra_with_keccak_verifier(builder); | ||
|
||
EXPECT_EQ(verifier.verify_proof(proof), true); | ||
} | ||
|
||
} // namespace acir_format::tests |
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