Skip to content

Commit

Permalink
chore: Remove composer keyword from stdlib (#2418)
Browse files Browse the repository at this point in the history
Replacing the keyword "Composer" with "Builder" (or variations as
appropriate) in the `stdlib`.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] 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).
  • Loading branch information
ledwards2225 authored Sep 25, 2023
1 parent 5813fb3 commit f3e7d91
Show file tree
Hide file tree
Showing 117 changed files with 4,498 additions and 4,568 deletions.
8 changes: 4 additions & 4 deletions barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,21 +680,21 @@ class ArithmeticFuzzHelper {
};

template <template <typename> class Fuzzer, typename Composer>
constexpr void RunWithComposer(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
constexpr void RunWithBuilder(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
{
VarianceRNG.reseed(0);
auto instructions = ArithmeticFuzzHelper<Fuzzer<Composer>>::parseDataIntoInstructions(Data, Size);
ArithmeticFuzzHelper<Fuzzer<Composer>>::template executeInstructions<Composer>(instructions);
}

template <template <typename> class Fuzzer, uint64_t Composers>
constexpr void RunWithComposers(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
constexpr void RunWithBuilders(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
{
if (Composers & 1) {
RunWithComposer<Fuzzer, proof_system::StandardCircuitBuilder>(Data, Size, VarianceRNG);
RunWithBuilder<Fuzzer, proof_system::StandardCircuitBuilder>(Data, Size, VarianceRNG);
}
if (Composers & 2) {
RunWithComposer<Fuzzer, proof_system::TurboCircuitBuilder>(Data, Size, VarianceRNG);
RunWithBuilder<Fuzzer, proof_system::TurboCircuitBuilder>(Data, Size, VarianceRNG);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace stdlib {

constexpr uint64_t WNAF_MASK = crypto::generators::WNAF_MASK;

template <typename ComposerContext> class pedersen_commitment {
template <typename CircuitBuilder> class pedersen_commitment {
private:
typedef stdlib::field_t<ComposerContext> field_t;
typedef stdlib::point<ComposerContext> point;
typedef stdlib::byte_array<ComposerContext> byte_array;
typedef stdlib::bool_t<ComposerContext> bool_t;
typedef stdlib::field_t<CircuitBuilder> field_t;
typedef stdlib::point<CircuitBuilder> point;
typedef stdlib::byte_array<CircuitBuilder> byte_array;
typedef stdlib::bool_t<CircuitBuilder> bool_t;

public:
static point commit(const std::vector<field_t>& inputs, const size_t hash_index = 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace {
auto& engine = numeric::random::get_debug_engine();
}

template <typename Composer> class stdlib_pedersen : public testing::Test {
typedef stdlib::bn254<Composer> curve;
template <typename Builder> class stdlib_pedersen : public testing::Test {
typedef stdlib::bn254<Builder> curve;

typedef typename curve::byte_array_ct byte_array_ct;
typedef typename curve::ScalarField fr_ct;
typedef typename curve::witness_ct witness_ct;
typedef typename curve::public_witness_ct public_witness_ct;
typedef typename stdlib::pedersen_commitment<Composer> pedersen_commitment;
typedef typename stdlib::pedersen_commitment<Builder> pedersen_commitment;

public:
static grumpkin::g1::element pedersen_recover(const fr& left_in, const fr& right_in)
Expand Down Expand Up @@ -135,7 +135,7 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {
static void test_pedersen()
{

Composer composer;
Builder builder;

fr left_in = fr::random_element();
fr right_in = fr::random_element();
Expand All @@ -148,17 +148,17 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {
right_in += fr::one();
}

fr_ct left = public_witness_ct(&composer, left_in);
fr_ct right = witness_ct(&composer, right_in);
fr_ct left = public_witness_ct(&builder, left_in);
fr_ct right = witness_ct(&builder, right_in);

composer.fix_witness(left.witness_index, left.get_value());
composer.fix_witness(right.witness_index, right.get_value());
builder.fix_witness(left.witness_index, left.get_value());
builder.fix_witness(right.witness_index, right.get_value());

fr_ct out = pedersen_commitment::compress(left, right);

info("composer gates = ", composer.get_num_gates());
info("num gates = ", builder.get_num_gates());

bool result = composer.check_circuit();
bool result = builder.check_circuit();
EXPECT_EQ(result, true);

auto hash_output = pedersen_recover(left_in, right_in);
Expand All @@ -176,29 +176,29 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {

static void test_pedersen_edge_cases()
{
Composer composer;
Builder builder;

fr zero_fr = fr::zero();
fr one_fr = fr::one();
fr r_minus_one_fr = fr::modulus - 1;
fr r_minus_two_fr = fr::modulus - 2;
fr r_fr = fr::modulus;

fr_ct zero = witness_ct(&composer, zero_fr);
fr_ct one = witness_ct(&composer, one_fr);
fr_ct r_minus_one = witness_ct(&composer, r_minus_one_fr);
fr_ct r_minus_two = witness_ct(&composer, r_minus_two_fr);
fr_ct r = witness_ct(&composer, r_fr);
fr_ct zero = witness_ct(&builder, zero_fr);
fr_ct one = witness_ct(&builder, one_fr);
fr_ct r_minus_one = witness_ct(&builder, r_minus_one_fr);
fr_ct r_minus_two = witness_ct(&builder, r_minus_two_fr);
fr_ct r = witness_ct(&builder, r_fr);

fr_ct out_1_with_zero = pedersen_commitment::compress(zero, one);
fr_ct out_1_with_r = pedersen_commitment::compress(r, one);
fr_ct out_2 = pedersen_commitment::compress(r_minus_one, r_minus_two);
fr_ct out_with_zero = pedersen_commitment::compress(out_1_with_zero, out_2);
fr_ct out_with_r = pedersen_commitment::compress(out_1_with_r, out_2);

info("composer gates = ", composer.get_num_gates());
info("num gates = ", builder.get_num_gates());

bool result = composer.check_circuit();
bool result = builder.check_circuit();
EXPECT_EQ(result, true);

auto hash_output_1_with_zero = pedersen_recover(zero_fr, one_fr);
Expand Down Expand Up @@ -242,7 +242,7 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {

static void test_pedersen_large()
{
Composer composer;
Builder builder;

fr left_in = fr::random_element();
fr right_in = fr::random_element();
Expand All @@ -253,26 +253,26 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {
if ((right_in.from_montgomery_form().data[0] & 1) == 0) {
right_in += fr::one();
}
fr_ct left = witness_ct(&composer, left_in);
fr_ct right = witness_ct(&composer, right_in);
fr_ct left = witness_ct(&builder, left_in);
fr_ct right = witness_ct(&builder, right_in);

for (size_t i = 0; i < 256; ++i) {
left = pedersen_commitment::compress(left, right);
}

composer.set_public_input(left.witness_index);
builder.set_public_input(left.witness_index);

info("composer gates = ", composer.get_num_gates());
info("num gates = ", builder.get_num_gates());

bool result = composer.check_circuit();
bool result = builder.check_circuit();
EXPECT_EQ(result, true);
}

static void test_compress_byte_array()
{
const size_t num_input_bytes = 351;

Composer composer;
Builder builder;

std::vector<uint8_t> input;
input.reserve(num_input_bytes);
Expand All @@ -282,20 +282,20 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {

fr expected = crypto::pedersen_commitment::compress_native(input);

byte_array_ct circuit_input(&composer, input);
byte_array_ct circuit_input(&builder, input);
auto result = pedersen_commitment::compress(circuit_input);

EXPECT_EQ(result.get_value(), expected);

info("composer gates = ", composer.get_num_gates());
info("num gates = ", builder.get_num_gates());

bool proof_result = composer.check_circuit();
bool proof_result = builder.check_circuit();
EXPECT_EQ(proof_result, true);
}

static void test_multi_compress()
{
Composer composer;
Builder builder;

for (size_t i = 0; i < 7; ++i) {
std::vector<barretenberg::fr> inputs;
Expand Down Expand Up @@ -329,7 +329,7 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {
}
std::vector<fr_ct> witnesses;
for (auto input : inputs) {
witnesses.push_back(witness_ct(&composer, input));
witnesses.push_back(witness_ct(&builder, input));
}

barretenberg::fr expected = crypto::pedersen_commitment::compress_native(inputs);
Expand All @@ -338,23 +338,23 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {
EXPECT_EQ(result.get_value(), expected);
}

info("composer gates = ", composer.get_num_gates());
info("num gates = ", builder.get_num_gates());

bool proof_result = composer.check_circuit();
bool proof_result = builder.check_circuit();
EXPECT_EQ(proof_result, true);
}

static void test_compress_eight()
{
Composer composer;
Builder builder;

std::vector<grumpkin::fq> inputs;
inputs.reserve(8);
std::vector<stdlib::field_t<Composer>> witness_inputs;
std::vector<stdlib::field_t<Builder>> witness_inputs;

for (size_t i = 0; i < 8; ++i) {
inputs.emplace_back(barretenberg::fr::random_element());
witness_inputs.emplace_back(witness_ct(&composer, inputs[i]));
witness_inputs.emplace_back(witness_ct(&builder, inputs[i]));
}

constexpr size_t hash_idx = 10;
Expand All @@ -366,17 +366,17 @@ template <typename Composer> class stdlib_pedersen : public testing::Test {

static void test_compress_constants()
{
Composer composer;
Builder builder;

std::vector<barretenberg::fr> inputs;
std::vector<stdlib::field_t<Composer>> witness_inputs;
std::vector<stdlib::field_t<Builder>> witness_inputs;

for (size_t i = 0; i < 8; ++i) {
inputs.push_back(barretenberg::fr::random_element());
if (i % 2 == 1) {
witness_inputs.push_back(witness_ct(&composer, inputs[i]));
witness_inputs.push_back(witness_ct(&builder, inputs[i]));
} else {
witness_inputs.push_back(fr_ct(&composer, inputs[i]));
witness_inputs.push_back(fr_ct(&builder, inputs[i]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace proof_system::plonk {
namespace stdlib {

template <typename ComposerContext> class pedersen_plookup_commitment {
template <typename CircuitBuilder> class pedersen_plookup_commitment {
private:
typedef stdlib::field_t<ComposerContext> field_t;
typedef stdlib::point<ComposerContext> point;
typedef stdlib::packed_byte_array<ComposerContext> packed_byte_array;
typedef stdlib::bool_t<ComposerContext> bool_t;
typedef stdlib::field_t<CircuitBuilder> field_t;
typedef stdlib::point<CircuitBuilder> point;
typedef stdlib::packed_byte_array<CircuitBuilder> packed_byte_array;
typedef stdlib::bool_t<CircuitBuilder> bool_t;

public:
static point commit(const std::vector<field_t>& inputs, const size_t hash_index = 0);
Expand Down
Loading

0 comments on commit f3e7d91

Please sign in to comment.