Skip to content

Commit

Permalink
fix: add missing ecc doubling gate into ultra plonk and ultra honk (#…
Browse files Browse the repository at this point in the history
…2610)

PR #1945 added a new selector into the Ultra arithmetisation (elliptic
curve point doubling). However this change was not propagated to the
polynomial relations evaluated by the UltraPlonk and UltraHonk
Prover/Verifier algorithms.

This PR fixes this, as well as upgrades the BaseUltraVerifier.sol
contract to use the new gate.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [x] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: vezenovm <[email protected]>
Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
3 people authored Oct 3, 2023
1 parent 0a161a4 commit 7cb7c58
Show file tree
Hide file tree
Showing 30 changed files with 642 additions and 611 deletions.
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -eu
BIN=${BIN:-../cpp/build/bin/bb}
FLOW=${FLOW:-prove_and_verify}
CRS_PATH=~/.bb-crs
BRANCH=master
BRANCH=mv/recursion-script
VERBOSE=${VERBOSE:-}
NAMED_TEST=${1:-}

Expand Down
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("2e1b6e64cd16912f2740d84a0e6c9e01784b35e09b303a026cc58ff5d6a5934d");

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 @@ -10,7 +10,13 @@ using namespace barretenberg;
using namespace proof_system::plonk::stdlib;
using namespace join_split_example::proofs::notes;
using namespace join_split_example::proofs::notes::circuit::value;
TEST(value_note, commits)

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

TEST_F(ValueNote, Commits)
{
auto user = join_split_example::fixtures::create_user_context();
auto builder = Builder();
Expand All @@ -35,7 +41,7 @@ TEST(value_note, commits)
auto prover = composer.create_prover(builder);

EXPECT_FALSE(builder.failed());
printf("composer gates = %zu\n", builder.get_num_gates());
info("composer gates = %zu\n", builder.get_num_gates());
auto verifier = composer.create_verifier(builder);

plonk::proof proof = prover.construct_proof();
Expand All @@ -44,7 +50,7 @@ TEST(value_note, commits)
EXPECT_EQ(proof_result, true);
}

TEST(value_note, commits_with_0_value)
TEST_F(ValueNote, CommitsWith0Value)
{
auto builder = Builder();

Expand Down Expand Up @@ -72,7 +78,7 @@ TEST(value_note, commits_with_0_value)
auto prover = composer.create_prover(builder);

EXPECT_FALSE(builder.failed());
printf("composer gates = %zu\n", builder.get_num_gates());
info("composer gates = %zu\n", builder.get_num_gates());
auto verifier = composer.create_verifier(builder);

plonk::proof proof = prover.construct_proof();
Expand All @@ -81,7 +87,7 @@ TEST(value_note, commits_with_0_value)
EXPECT_EQ(proof_result, true);
}

TEST(value_note, commit_with_oversized_asset_id_fails)
TEST_F(ValueNote, CommitWithOversizedAssetIdFails)
{
auto builder = Builder();

Expand All @@ -106,7 +112,7 @@ TEST(value_note, commit_with_oversized_asset_id_fails)
auto prover = composer.create_prover(builder);

EXPECT_TRUE(builder.failed());
printf("composer gates = %zu\n", builder.get_num_gates());
info("composer gates = %zu\n", builder.get_num_gates());
auto verifier = composer.create_verifier(builder);

plonk::proof proof = prover.construct_proof();
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
Loading

0 comments on commit 7cb7c58

Please sign in to comment.