Skip to content

Commit

Permalink
Merge branch 'master' into mm/pg-verifier-circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Jan 19, 2024
2 parents a86f207 + cd2f67f commit 661b2d0
Show file tree
Hide file tree
Showing 215 changed files with 582 additions and 837 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Composer = bb::plonk::StandardComposer;

void generate_test_plonk_circuit(Builder& builder, size_t num_gates)
{
plonk::stdlib::field_t a(plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
plonk::stdlib::field_t b(plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
plonk::stdlib::field_t c(&builder);
stdlib::field_t a(stdlib::witness_t(&builder, bb::fr::random_element()));
stdlib::field_t b(stdlib::witness_t(&builder, bb::fr::random_element()));
stdlib::field_t c(&builder);
for (size_t i = 0; i < (num_gates / 4) - 4; ++i) {
c = a + b;
c = a * c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace bench_utils {
*/
template <typename Builder> void generate_basic_arithmetic_circuit(Builder& builder, size_t log2_num_gates)
{
bb::plonk::stdlib::field_t a(bb::plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
bb::plonk::stdlib::field_t b(bb::plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
bb::plonk::stdlib::field_t c(&builder);
bb::stdlib::field_t a(bb::stdlib::witness_t(&builder, bb::fr::random_element()));
bb::stdlib::field_t b(bb::stdlib::witness_t(&builder, bb::fr::random_element()));
bb::stdlib::field_t c(&builder);
size_t passes = (1UL << log2_num_gates) / 4 - 4;
if (static_cast<int>(passes) <= 0) {
throw std::runtime_error("too few gates");
Expand All @@ -58,9 +58,9 @@ template <typename Builder> void generate_sha256_test_circuit(Builder& builder,
{
std::string in;
in.resize(32);
bb::plonk::stdlib::packed_byte_array<Builder> input(&builder, in);
bb::stdlib::packed_byte_array<Builder> input(&builder, in);
for (size_t i = 0; i < num_iterations; i++) {
input = bb::plonk::stdlib::sha256<Builder>(input);
input = bb::stdlib::sha256<Builder>(input);
}
}

Expand All @@ -74,9 +74,9 @@ template <typename Builder> void generate_keccak_test_circuit(Builder& builder,
{
std::string in = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01";

bb::plonk::stdlib::byte_array<Builder> input(&builder, in);
bb::stdlib::byte_array<Builder> input(&builder, in);
for (size_t i = 0; i < num_iterations; i++) {
input = bb::plonk::stdlib::keccak<Builder>::hash(input);
input = bb::stdlib::keccak<Builder>::hash(input);
}
}

Expand All @@ -88,7 +88,7 @@ template <typename Builder> void generate_keccak_test_circuit(Builder& builder,
*/
template <typename Builder> void generate_ecdsa_verification_test_circuit(Builder& builder, size_t num_iterations)
{
using curve = bb::plonk::stdlib::secp256k1<Builder>;
using curve = bb::stdlib::secp256k1<Builder>;
using fr = typename curve::fr;
using fq = typename curve::fq;
using g1 = typename curve::g1;
Expand All @@ -114,18 +114,18 @@ template <typename Builder> void generate_ecdsa_verification_test_circuit(Builde

typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key);

bb::plonk::stdlib::ecdsa::signature<Builder> sig{ typename curve::byte_array_ct(&builder, rr),
typename curve::byte_array_ct(&builder, ss),
bb::plonk::stdlib::uint8<Builder>(&builder, vv) };
bb::stdlib::ecdsa::signature<Builder> sig{ typename curve::byte_array_ct(&builder, rr),
typename curve::byte_array_ct(&builder, ss),
bb::stdlib::uint8<Builder>(&builder, vv) };

typename curve::byte_array_ct message(&builder, message_string);

// Verify ecdsa signature
bb::plonk::stdlib::ecdsa::verify_signature<Builder,
curve,
typename curve::fq_ct,
typename curve::bigfr_ct,
typename curve::g1_bigfr_ct>(message, public_key, sig);
bb::stdlib::ecdsa::verify_signature<Builder,
curve,
typename curve::fq_ct,
typename curve::bigfr_ct,
typename curve::g1_bigfr_ct>(message, public_key, sig);
}
}

Expand All @@ -137,7 +137,7 @@ template <typename Builder> void generate_ecdsa_verification_test_circuit(Builde
*/
template <typename Builder> void generate_merkle_membership_test_circuit(Builder& builder, size_t num_iterations)
{
using namespace bb::plonk::stdlib;
using namespace bb::stdlib;
using field_ct = field_t<Builder>;
using witness_ct = witness_t<Builder>;
using witness_ct = witness_t<Builder>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace acir_format {

template <typename Builder> void create_blake2s_constraints(Builder& builder, const Blake2sConstraint& constraint)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

// Create byte array struct
byte_array_ct arr(&builder);
Expand All @@ -26,7 +26,7 @@ template <typename Builder> void create_blake2s_constraints(Builder& builder, co
arr.write(element_bytes);
}

byte_array_ct output_bytes = bb::plonk::stdlib::blake2s<Builder>(arr);
byte_array_ct output_bytes = bb::stdlib::blake2s<Builder>(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace acir_format {

template <typename Builder> void create_blake3_constraints(Builder& builder, const Blake3Constraint& constraint)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

// Create byte array struct
byte_array_ct arr(&builder);
Expand All @@ -26,7 +26,7 @@ template <typename Builder> void create_blake3_constraints(Builder& builder, con
arr.write(element_bytes);
}

byte_array_ct output_bytes = bb::plonk::stdlib::blake3s<Builder>(arr);
byte_array_ct output_bytes = bb::stdlib::blake3s<Builder>(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ using namespace bb::plonk;

namespace acir_format {

template <typename Builder>
bb::plonk::stdlib::field_t<Builder> poly_to_field_ct(const poly_triple poly, Builder& builder)
template <typename Builder> bb::stdlib::field_t<Builder> poly_to_field_ct(const poly_triple poly, Builder& builder)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

ASSERT(poly.q_m == 0);
ASSERT(poly.q_r == 0);
Expand All @@ -26,9 +25,9 @@ bb::plonk::stdlib::field_t<Builder> poly_to_field_ct(const poly_triple poly, Bui
template <typename Builder>
void create_block_constraints(Builder& builder, const BlockConstraint constraint, bool has_valid_witness_assignments)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using rom_table_ct = bb::plonk::stdlib::rom_table<Builder>;
using ram_table_ct = bb::plonk::stdlib::ram_table<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;
using rom_table_ct = bb::stdlib::rom_table<Builder>;
using ram_table_ct = bb::stdlib::ram_table<Builder>;

std::vector<field_ct> init;
for (auto i : constraint.init) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ secp256k1_ct::g1_ct ecdsa_convert_inputs(Builder* ctx, const secp256k1::g1::affi
// with just a byte.
// notice that this function truncates each field_element to a byte
template <typename Builder>
bb::plonk::stdlib::byte_array<Builder> ecdsa_vector_of_bytes_to_byte_array(Builder& builder,
std::vector<uint32_t> vector_of_bytes)
bb::stdlib::byte_array<Builder> ecdsa_vector_of_bytes_to_byte_array(Builder& builder,
std::vector<uint32_t> vector_of_bytes)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

byte_array_ct arr(&builder);

Expand All @@ -95,10 +95,10 @@ void create_ecdsa_k1_verify_constraints(Builder& builder,
const EcdsaSecp256k1Constraint& input,
bool has_valid_witness_assignments)
{
using secp256k1_ct = bb::plonk::stdlib::secp256k1<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using bool_ct = bb::plonk::stdlib::bool_t<Builder>;
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using secp256k1_ct = bb::stdlib::secp256k1<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;
using bool_ct = bb::stdlib::bool_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;

if (has_valid_witness_assignments == false) {
dummy_ecdsa_constraint(builder, input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ template <typename Builder>
crypto::ecdsa::signature ecdsa_convert_signature(Builder& builder, std::vector<uint32_t> signature);
witness_ct ecdsa_index_to_witness(Builder& builder, uint32_t index);
template <typename Builder>
bb::plonk::stdlib::byte_array<Builder> ecdsa_vector_of_bytes_to_byte_array(Builder& builder,
std::vector<uint32_t> vector_of_bytes);
bb::stdlib::byte_array<Builder> ecdsa_vector_of_bytes_to_byte_array(Builder& builder,
std::vector<uint32_t> vector_of_bytes);

} // namespace acir_format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>

namespace acir_format::tests {
using curve_ct = bb::plonk::stdlib::secp256k1<Builder>;
using curve_ct = bb::stdlib::secp256k1<Builder>;

class ECDSASecp256k1 : public ::testing::Test {
protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void create_ecdsa_r1_verify_constraints(Builder& builder,
const EcdsaSecp256r1Constraint& input,
bool has_valid_witness_assignments)
{
using secp256r1_ct = bb::plonk::stdlib::secp256r1<Builder>;
using bool_ct = bb::plonk::stdlib::bool_t<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using secp256r1_ct = bb::stdlib::secp256r1<Builder>;
using bool_ct = bb::stdlib::bool_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

if (has_valid_witness_assignments == false) {
dummy_ecdsa_constraint(builder, input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>

namespace acir_format::tests {
using curve_ct = bb::plonk::stdlib::secp256r1<Builder>;
using curve_ct = bb::stdlib::secp256r1<Builder>;

// Generate r1 constraints given pre generated pubkey, sig and message values
size_t generate_r1_constraints(EcdsaSecp256r1Constraint& ecdsa_r1_constraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace acir_format {

template <typename Builder> void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input)
{
using cycle_group_ct = bb::plonk::stdlib::cycle_group<Builder>;
using cycle_scalar_ct = typename bb::plonk::stdlib::cycle_group<Builder>::cycle_scalar;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using cycle_group_ct = bb::stdlib::cycle_group<Builder>;
using cycle_scalar_ct = typename bb::stdlib::cycle_group<Builder>::cycle_scalar;
using field_ct = bb::stdlib::field_t<Builder>;

// Computes low * G + high * 2^128 * G
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace acir_format {

template <typename Builder> void create_keccak_constraints(Builder& builder, const KeccakConstraint& constraint)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

// Create byte array struct
byte_array_ct arr(&builder);
Expand All @@ -28,7 +28,7 @@ template <typename Builder> void create_keccak_constraints(Builder& builder, con
arr.write(element_bytes);
}

byte_array_ct output_bytes = bb::plonk::stdlib::keccak<Builder>::hash(arr);
byte_array_ct output_bytes = bb::stdlib::keccak<Builder>::hash(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand All @@ -40,9 +40,9 @@ template <typename Builder> void create_keccak_constraints(Builder& builder, con

template <typename Builder> void create_keccak_var_constraints(Builder& builder, const KeccakVarConstraint& constraint)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using uint32_ct = bb::plonk::stdlib::uint32<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;
using uint32_ct = bb::stdlib::uint32<Builder>;

// Create byte array struct
byte_array_ct arr(&builder);
Expand All @@ -64,7 +64,7 @@ template <typename Builder> void create_keccak_var_constraints(Builder& builder,

uint32_ct length = field_ct::from_witness_index(&builder, constraint.var_message_size);

byte_array_ct output_bytes = bb::plonk::stdlib::keccak<Builder>::hash(arr, length);
byte_array_ct output_bytes = bb::stdlib::keccak<Builder>::hash(arr, length);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand All @@ -76,10 +76,10 @@ template <typename Builder> void create_keccak_var_constraints(Builder& builder,

template <typename Builder> void create_keccak_permutations(Builder& builder, const Keccakf1600& constraint)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

// Create the array containing the permuted state
std::array<field_ct, bb::plonk::stdlib::keccak<Builder>::NUM_KECCAK_LANES> state;
std::array<field_ct, bb::stdlib::keccak<Builder>::NUM_KECCAK_LANES> state;

// Get the witness assignment for each witness index
// Write the witness assignment to the byte_array
Expand All @@ -88,7 +88,7 @@ template <typename Builder> void create_keccak_permutations(Builder& builder, co
state[i] = field_ct::from_witness_index(&builder, constraint.state[i]);
}

std::array<field_ct, 25> output_state = bb::plonk::stdlib::keccak<Builder>::permutation_opcode(state, &builder);
std::array<field_ct, 25> output_state = bb::stdlib::keccak<Builder>::permutation_opcode(state, &builder);

for (size_t i = 0; i < output_state.size(); ++i) {
builder.assert_equal(output_state[i].normalize().witness_index, constraint.result[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void create_logic_gate(Builder& builder,
const size_t num_bits,
const bool is_xor_gate)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

field_ct left = field_ct::from_witness_index(&builder, a);
field_ct right = field_ct::from_witness_index(&builder, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace bb::plonk;

template <typename Builder> void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

std::vector<field_ct> scalars;

Expand All @@ -24,7 +24,7 @@ template <typename Builder> void create_pedersen_constraint(Builder& builder, co

template <typename Builder> void create_pedersen_hash_constraint(Builder& builder, const PedersenHashConstraint& input)
{
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

std::vector<field_ct> scalars;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ std::array<uint32_t, RecursionConstraint::AGGREGATION_OBJECT_SIZE> create_recurs
vkey->program_width = noir_recursive_settings::program_width;

Transcript_ct transcript(&builder, manifest, proof_fields, input.public_inputs.size());
aggregation_state_ct result = bb::plonk::stdlib::recursion::verify_proof_<bn254, noir_recursive_settings>(
aggregation_state_ct result = bb::stdlib::recursion::verify_proof_<bn254, noir_recursive_settings>(
&builder, vkey, transcript, previous_aggregation);

// Assign correct witness value to the verification key hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace acir_format {

using namespace bb::plonk::stdlib;
using namespace bb::stdlib;

template <typename Builder>
crypto::schnorr::signature convert_signature(Builder& builder, std::vector<uint32_t> signature)
Expand Down Expand Up @@ -45,11 +45,10 @@ crypto::schnorr::signature convert_signature(Builder& builder, std::vector<uint3
// with just a byte.
// notice that this function truncates each field_element to a byte
template <typename Builder>
bb::plonk::stdlib::byte_array<Builder> vector_of_bytes_to_byte_array(Builder& builder,
std::vector<uint32_t> vector_of_bytes)
bb::stdlib::byte_array<Builder> vector_of_bytes_to_byte_array(Builder& builder, std::vector<uint32_t> vector_of_bytes)
{
using byte_array_ct = bb::plonk::stdlib::byte_array<Builder>;
using field_ct = bb::plonk::stdlib::field_t<Builder>;
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

byte_array_ct arr(&builder);

Expand All @@ -66,18 +65,18 @@ bb::plonk::stdlib::byte_array<Builder> vector_of_bytes_to_byte_array(Builder& bu
return arr;
}

template <typename Builder> bb::plonk::stdlib::witness_t<Builder> index_to_witness(Builder& builder, uint32_t index)
template <typename Builder> bb::stdlib::witness_t<Builder> index_to_witness(Builder& builder, uint32_t index)
{
fr value = builder.get_variable(index);
return { &builder, value };
}

template <typename Builder> void create_schnorr_verify_constraints(Builder& builder, const SchnorrConstraint& input)
{
using witness_ct = bb::plonk::stdlib::witness_t<Builder>;
using cycle_group_ct = bb::plonk::stdlib::cycle_group<Builder>;
using schnorr_signature_bits_ct = bb::plonk::stdlib::schnorr::signature_bits<Builder>;
using bool_ct = bb::plonk::stdlib::bool_t<Builder>;
using witness_ct = bb::stdlib::witness_t<Builder>;
using cycle_group_ct = bb::stdlib::cycle_group<Builder>;
using schnorr_signature_bits_ct = bb::stdlib::schnorr::signature_bits<Builder>;
using bool_ct = bb::stdlib::bool_t<Builder>;

auto new_sig = convert_signature(builder, input.signature);
// From ignorance, you will see me convert a bunch of witnesses from ByteArray -> BitArray
Expand Down
Loading

0 comments on commit 661b2d0

Please sign in to comment.