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

fix: add missing ecc doubling gate into ultra plonk and ultra honk #2610

Merged
merged 16 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#include "ecdsa_secp256k1.hpp"

namespace acir_format::tests {
TEST(acir_format, test_a_single_constraint_no_pub_inputs)

class AcirFormatTests : public ::testing::Test {
protected:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};
TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs)
{

poly_triple constraint{
Expand Down Expand Up @@ -53,12 +58,12 @@ TEST(acir_format, test_a_single_constraint_no_pub_inputs)
EXPECT_EQ(verifier.verify_proof(proof), false);
}

TEST(acir_format, msgpack_logic_constraint)
TEST_F(AcirFormatTests, MsgpackLogicConstraint)
{
auto [actual, expected] = msgpack_roundtrip(LogicConstraint{});
EXPECT_EQ(actual, expected);
}
TEST(acir_format, test_logic_gate_from_noir_circuit)
TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit)
{
/**
* constraints produced by Noir program:
Expand Down Expand Up @@ -167,7 +172,7 @@ TEST(acir_format, test_logic_gate_from_noir_circuit)
EXPECT_EQ(verifier.verify_proof(proof), true);
}

TEST(acir_format, test_schnorr_verify_pass)
TEST_F(AcirFormatTests, TestSchnorrVerifyPass)
{
std::vector<RangeConstraint> range_constraints;
for (uint32_t i = 0; i < 10; i++) {
Expand Down Expand Up @@ -239,7 +244,7 @@ TEST(acir_format, test_schnorr_verify_pass)
EXPECT_EQ(verifier.verify_proof(proof), true);
}

TEST(acir_format, test_schnorr_verify_small_range)
TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange)
{
std::vector<RangeConstraint> range_constraints;
for (uint32_t i = 0; i < 10; i++) {
Expand Down Expand Up @@ -311,7 +316,7 @@ TEST(acir_format, test_schnorr_verify_small_range)
EXPECT_EQ(verifier.verify_proof(proof), true);
}

TEST(acir_format, test_var_keccak)
TEST_F(AcirFormatTests, TestVarKeccak)
{
HashInput input1;
input1.witness = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <vector>

namespace acir_format::tests {

class UltraPlonkRAM : public ::testing::Test {
protected:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};
size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& witness_values)
{
size_t witness_len = 1;
Expand Down Expand Up @@ -98,7 +103,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit
return witness_len;
}

TEST(up_ram, TestBlockConstraint)
TEST_F(UltraPlonkRAM, TestBlockConstraint)
{
BlockConstraint block;
WitnessVector witness_values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
namespace acir_format::tests {
using curve_ct = proof_system::plonk::stdlib::secp256k1<Builder>;

class ECDSASecp256k1 : public ::testing::Test {
protected:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};

size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, WitnessVector& witness_values)
{
std::string message_string = "Instructions unclear, ask again later.";
Expand Down Expand Up @@ -77,7 +82,7 @@ size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, Wit
return offset;
}

TEST(ECDSASecp256k1, TestECDSAConstraintSucceed)
TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed)
{
EcdsaSecp256k1Constraint ecdsa_k1_constraint;
WitnessVector witness_values;
Expand Down Expand Up @@ -117,7 +122,7 @@ TEST(ECDSASecp256k1, TestECDSAConstraintSucceed)
// Test that the verifier can create an ECDSA circuit.
// The ECDSA circuit requires that certain dummy data is valid
// even though we are just building the circuit.
TEST(ECDSASecp256k1, TestECDSACompilesForVerifier)
TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier)
{
EcdsaSecp256k1Constraint ecdsa_k1_constraint;
WitnessVector witness_values;
Expand Down Expand Up @@ -145,7 +150,7 @@ TEST(ECDSASecp256k1, TestECDSACompilesForVerifier)
auto builder = create_circuit(constraint_system);
}

TEST(ECDSASecp256k1, TestECDSAConstraintFail)
TEST_F(ECDSASecp256k1, TestECDSAConstraintFail)
{
EcdsaSecp256k1Constraint ecdsa_k1_constraint;
WitnessVector witness_values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

using namespace proof_system::plonk;

class AcirRecursionConstraint : public ::testing::Test {
protected:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};
namespace acir_format::test {
Builder create_inner_circuit()
{
Expand Down Expand Up @@ -226,7 +230,7 @@ Builder create_outer_circuit(std::vector<Builder>& inner_circuits)
return outer_circuit;
}

TEST(RecursionConstraint, TestBasicDoubleRecursionConstraints)
TEST_F(AcirRecursionConstraint, TestBasicDoubleRecursionConstraints)
{
std::vector<Builder> layer_1_circuits;
layer_1_circuits.push_back(create_inner_circuit());
Expand All @@ -245,7 +249,7 @@ TEST(RecursionConstraint, TestBasicDoubleRecursionConstraints)
EXPECT_EQ(verifier.verify_proof(proof), true);
}

TEST(RecursionConstraint, TestOneOuterRecursiveCircuit)
TEST_F(AcirRecursionConstraint, TestOneOuterRecursiveCircuit)
{
/**
* We want to test the following:
Expand Down Expand Up @@ -302,7 +306,7 @@ TEST(RecursionConstraint, TestOneOuterRecursiveCircuit)
EXPECT_EQ(verifier.verify_proof(proof), true);
}

TEST(RecursionConstraint, TestFullRecursiveComposition)
TEST_F(AcirRecursionConstraint, TestFullRecursiveComposition)
{
std::vector<Builder> layer_b_1_circuits;
layer_b_1_circuits.push_back(create_inner_circuit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class join_split_tests : public ::testing::Test {
static constexpr size_t ACCOUNT_INDEX = 14;
static void SetUpTestCase()
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
auto null_crs_factory = std::make_shared<barretenberg::srs::factories::CrsFactory<curve::BN254>>();
init_proving_key(null_crs_factory, false);
auto crs_factory =
Expand Down Expand Up @@ -709,7 +710,7 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change)

constexpr uint32_t CIRCUIT_GATE_COUNT = 184517;
constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 524288;
const uint256_t VK_HASH("787c464414a2c2e3332314ff528bd236b13133c269c5704505a0f3a3ad56ad57");
const uint256_t VK_HASH("1929939fd7efdfcb167f46891cec9427c3785c240890aca032462e69c79c8dc7");

auto number_of_gates_js = result.number_of_gates;
std::cout << get_verification_key()->sha256_hash() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ namespace rollup {
namespace proofs {
namespace mock {

TEST(mock_circuit_tests, test_simple_circuit)
class MockCircuitTests : public ::testing::Test {
protected:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};

TEST_F(MockCircuitTests, test_simple_circuit)
{
// Dummy public inputs
std::vector<fr> public_inputs;
for (size_t i = 0; i < 16; i++) {
public_inputs.push_back(fr::random_element());
}

Composer composer = Composer("../srs_db/ignition");
Composer composer = Composer();
mock_circuit(composer, public_inputs);

auto prover = composer.create_prover();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class StandardComposer {

bool computed_witness = false;

StandardComposer()
: StandardComposer(std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>>(
new barretenberg::srs::factories::FileCrsFactory<curve::BN254>("../srs_db/ignition")))
{}
StandardComposer() { crs_factory_ = barretenberg::srs::get_crs_factory(); }
StandardComposer(std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> crs_factory)
: crs_factory_(std::move(crs_factory))
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ namespace {
auto& engine = numeric::random::get_debug_engine();
}

TEST(standard_plonk_composer, base_case)
class StandardPlonkComposer : public ::testing::Test {
public:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }
};

TEST_F(StandardPlonkComposer, BaseCase)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -28,7 +33,7 @@ TEST(standard_plonk_composer, base_case)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, composer_from_serialized_keys)
TEST_F(StandardPlonkComposer, ComposerFromSerializedKeys)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand Down Expand Up @@ -58,7 +63,7 @@ TEST(standard_plonk_composer, composer_from_serialized_keys)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, test_add_gate_proofs)
TEST_F(StandardPlonkComposer, TestAddGateProofs)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand Down Expand Up @@ -118,13 +123,13 @@ TEST(standard_plonk_composer, test_add_gate_proofs)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, test_mul_gate_proofs)
TEST_F(StandardPlonkComposer, TestMulGateProofs)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
fr q[7]{ fr::random_element(), fr::random_element(), fr::random_element(), fr::random_element(),
fr::random_element(), fr::random_element(), fr::random_element() };
fr q_inv[7]{
std::array<fr, 7> q{ fr::random_element(), fr::random_element(), fr::random_element(), fr::random_element(),
fr::random_element(), fr::random_element(), fr::random_element() };
std::array<fr, 7> q_inv{
q[0].invert(), q[1].invert(), q[2].invert(), q[3].invert(), q[4].invert(), q[5].invert(), q[6].invert(),
};

Expand Down Expand Up @@ -198,7 +203,7 @@ TEST(standard_plonk_composer, test_mul_gate_proofs)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, range_constraint)
TEST_F(StandardPlonkComposer, RangeConstraint)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -216,7 +221,7 @@ TEST(standard_plonk_composer, range_constraint)
for (uint32_t j = 0; j < 16; ++j) {
uint32_t result = (value >> (30U - (2 * j)));
fr source = builder.get_variable(accumulators[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t expected = static_cast<uint32_t>(source.data[0]);
auto expected = static_cast<uint32_t>(source.data[0]);
EXPECT_EQ(result, expected);
}
for (uint32_t j = 1; j < 16; ++j) {
Expand All @@ -242,7 +247,7 @@ TEST(standard_plonk_composer, range_constraint)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, range_constraint_fail)
TEST_F(StandardPlonkComposer, RangeConstraintFail)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -263,7 +268,7 @@ TEST(standard_plonk_composer, range_constraint_fail)
EXPECT_EQ(result, false);
}

TEST(standard_plonk_composer, and_constraint)
TEST_F(StandardPlonkComposer, AndConstraint)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand Down Expand Up @@ -291,13 +296,13 @@ TEST(standard_plonk_composer, and_constraint)
uint32_t out_expected = left_expected & right_expected;

fr left_source = builder.get_variable(accumulators.left[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t left_result = static_cast<uint32_t>(left_source.data[0]);
auto left_result = static_cast<uint32_t>(left_source.data[0]);

fr right_source = builder.get_variable(accumulators.right[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t right_result = static_cast<uint32_t>(right_source.data[0]);
auto right_result = static_cast<uint32_t>(right_source.data[0]);

fr out_source = builder.get_variable(accumulators.out[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t out_result = static_cast<uint32_t>(out_source.data[0]);
auto out_result = static_cast<uint32_t>(out_source.data[0]);

EXPECT_EQ(left_result, left_expected);
EXPECT_EQ(right_result, right_expected);
Expand Down Expand Up @@ -334,7 +339,7 @@ TEST(standard_plonk_composer, and_constraint)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, xor_constraint)
TEST_F(StandardPlonkComposer, XorConstraint)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -361,13 +366,13 @@ TEST(standard_plonk_composer, xor_constraint)
uint32_t out_expected = left_expected ^ right_expected;

fr left_source = builder.get_variable(accumulators.left[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t left_result = static_cast<uint32_t>(left_source.data[0]);
auto left_result = static_cast<uint32_t>(left_source.data[0]);

fr right_source = builder.get_variable(accumulators.right[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t right_result = static_cast<uint32_t>(right_source.data[0]);
auto right_result = static_cast<uint32_t>(right_source.data[0]);

fr out_source = builder.get_variable(accumulators.out[j + (extra_bits >> 1)]).from_montgomery_form();
uint32_t out_result = static_cast<uint32_t>(out_source.data[0]);
auto out_result = static_cast<uint32_t>(out_source.data[0]);

EXPECT_EQ(left_result, left_expected);
EXPECT_EQ(right_result, right_expected);
Expand Down Expand Up @@ -404,7 +409,7 @@ TEST(standard_plonk_composer, xor_constraint)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, big_add_gate_with_bit_extract)
TEST_F(StandardPlonkComposer, BigAddGateWithBitExtract)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand Down Expand Up @@ -447,7 +452,7 @@ TEST(standard_plonk_composer, big_add_gate_with_bit_extract)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, test_range_constraint_fail)
TEST_F(StandardPlonkComposer, TestRangeConstraintFail)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -465,7 +470,7 @@ TEST(standard_plonk_composer, test_range_constraint_fail)
EXPECT_EQ(result, false);
}

TEST(standard_plonk_composer, test_check_circuit_correct)
TEST_F(StandardPlonkComposer, TestCheckCircuitCorrect)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand All @@ -486,7 +491,7 @@ TEST(standard_plonk_composer, test_check_circuit_correct)
EXPECT_EQ(result, true);
}

TEST(standard_plonk_composer, test_check_circuit_broken)
TEST_F(StandardPlonkComposer, TestCheckCircuitBroken)
{
auto builder = StandardCircuitBuilder();
auto composer = StandardComposer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class UltraComposer {
// vanishing_polynomial cannot be trivially fetched here, I am directly setting this to 4 - 1 = 3.
static constexpr size_t s_randomness = 3;

UltraComposer()
: UltraComposer("../srs_db/ignition"){};

UltraComposer(std::string const& crs_path)
: UltraComposer(std::make_unique<barretenberg::srs::factories::FileCrsFactory<Curve>>(crs_path)){};
UltraComposer() { crs_factory_ = barretenberg::srs::get_crs_factory(); }

explicit UltraComposer(std::shared_ptr<barretenberg::srs::factories::CrsFactory<Curve>> crs_factory)
: crs_factory_(std::move(crs_factory))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ std::vector<uint32_t> add_variables(UltraCircuitBuilder& builder, std::vector<fr

template <typename T> class ultra_plonk_composer : public ::testing::Test {
public:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }

void prove_and_verify(UltraCircuitBuilder& builder, UltraComposer& composer, bool expected_result)
{
if constexpr (T::use_keccak) {
Expand Down
Loading