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

chore(avm): more pilcom compat changes #10569

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void avm_prove(const std::filesystem::path& public_inputs_path,
*/
bool avm_verify(const std::filesystem::path& proof_path, const std::filesystem::path& vk_path)
{
using Commitment = AvmFlavorSettings::Commitment;
using Commitment = bb::avm::AvmFlavorSettings::Commitment;
std::vector<fr> const proof = many_from_buffer<fr>(read_file(proof_path));
std::vector<uint8_t> vk_bytes = read_file(vk_path);
std::vector<fr> vk_as_fields = many_from_buffer<fr>(vk_bytes);
Expand All @@ -683,14 +683,14 @@ bool avm_verify(const std::filesystem::path& proof_path, const std::filesystem::
return false;
}

std::array<Commitment, AvmFlavor::NUM_PRECOMPUTED_ENTITIES> precomputed_cmts;
for (size_t i = 0; i < AvmFlavor::NUM_PRECOMPUTED_ENTITIES; i++) {
std::array<Commitment, bb::avm::AvmFlavor::NUM_PRECOMPUTED_ENTITIES> precomputed_cmts;
for (size_t i = 0; i < bb::avm::AvmFlavor::NUM_PRECOMPUTED_ENTITIES; i++) {
// Start at offset 2 and adds 4 (NUM_FRS_COM) fr elements per commitment. Therefore, index = 4 * i + 2.
precomputed_cmts[i] = field_conversion::convert_from_bn254_frs<Commitment>(
vk_span.subspan(AvmFlavor::NUM_FRS_COM * i + 2, AvmFlavor::NUM_FRS_COM));
vk_span.subspan(bb::avm::AvmFlavor::NUM_FRS_COM * i + 2, bb::avm::AvmFlavor::NUM_FRS_COM));
}

auto vk = AvmFlavor::VerificationKey(circuit_size, num_public_inputs, precomputed_cmts);
auto vk = bb::avm::AvmFlavor::VerificationKey(circuit_size, num_public_inputs, precomputed_cmts);

const bool verified = AVM_TRACK_TIME_V("verify/all", avm_trace::Execution::verify(vk, proof));
vinfo("verified: ", verified);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void create_dummy_vkey_and_proof(Builder& builder,
const std::vector<field_ct>& key_fields,
const std::vector<field_ct>& proof_fields)
{
using Flavor = AvmFlavor;
using Flavor = bb::avm::AvmFlavor;

// Relevant source for proof layout: AvmFlavor::Transcript::serialize_full_transcript()
assert((proof_size - Flavor::NUM_WITNESS_ENTITIES * Flavor::NUM_FRS_COM -
Expand Down Expand Up @@ -157,7 +157,7 @@ PairingPointAccumulatorIndices create_avm_recursion_constraints(
{
using Flavor = AvmRecursiveFlavor_<Builder>;
using RecursiveVerificationKey = Flavor::VerificationKey;
using RecursiveVerifier = AvmRecursiveVerifier_<Flavor>;
using RecursiveVerifier = bb::avm::AvmRecursiveVerifier_<Flavor>;

ASSERT(input.proof_type == AVM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ using namespace bb::avm_trace;

class AcirAvmRecursionConstraint : public ::testing::Test {
public:
using InnerBuilder = AvmCircuitBuilder;
using InnerProver = AvmProver;
using InnerVerifier = AvmVerifier;
using InnerBuilder = bb::avm::AvmCircuitBuilder;
using InnerProver = bb::avm::AvmProver;
using InnerVerifier = bb::avm::AvmVerifier;
using InnerComposer = bb::avm::AvmComposer;

using OuterProver = UltraProver;
using OuterVerifier = UltraVerifier;
Expand Down Expand Up @@ -77,7 +78,7 @@ class AcirAvmRecursionConstraint : public ::testing::Test {
SlabVector<fr> witness;

for (auto& avm_circuit : inner_avm_circuits) {
AvmComposer composer = AvmComposer();
InnerComposer composer = InnerComposer();
InnerProver prover = composer.create_prover(avm_circuit);
InnerVerifier verifier = composer.create_verifier(avm_circuit);

Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ class UltraKeccakFlavor;
class MegaFlavor;
class MegaZKFlavor;
class TranslatorFlavor;
namespace avm {
class AvmFlavor;
}
template <typename BuilderType> class UltraRecursiveFlavor_;
template <typename BuilderType> class UltraRollupRecursiveFlavor_;
template <typename BuilderType> class MegaRecursiveFlavor_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp"
#include "barretenberg/vm/stats.hpp"

namespace bb {
namespace bb::avm {

AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() const
{
Expand Down Expand Up @@ -914,4 +914,4 @@ bool AvmCircuitBuilder::check_circuit() const
return errors.empty();
}

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#include "flavor.hpp"
#include "full_row.hpp"

namespace bb {
namespace bb::avm {

class AvmCircuitBuilder {
public:
// Do not use this constant directly, use get_circuit_subgroup_size() instead.
constexpr static size_t CIRCUIT_SUBGROUP_SIZE = 1 << 21;

using Flavor = bb::AvmFlavor;
using Flavor = bb::avm::AvmFlavor;
using FF = Flavor::FF;
using Row = AvmFullRow<FF>;
using Polynomial = Flavor::Polynomial;
Expand Down Expand Up @@ -44,4 +44,4 @@ class AvmCircuitBuilder {
std::vector<Row> rows;
};

} // namespace bb
} // namespace bb::avm
30 changes: 14 additions & 16 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/columns.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "composer.hpp"
#include "barretenberg/vm/stats.hpp"

namespace bb {
namespace bb::avm {

using Flavor = AvmFlavor;
void AvmComposer::compute_witness(CircuitConstructor& circuit)
Expand Down Expand Up @@ -64,4 +64,4 @@ std::shared_ptr<Flavor::VerificationKey> AvmComposer::compute_verification_key(C
return verification_key;
}

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "prover.hpp"
#include "verifier.hpp"

namespace bb {
namespace bb::avm {

class AvmComposer {
public:
Expand Down Expand Up @@ -63,4 +63,4 @@ class AvmComposer {
};
};

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// AUTOGENERATED FILE
#include "flavor.hpp"

namespace bb {
namespace bb::avm {

AvmFlavor::AllConstRefValues::AllConstRefValues(
const RefArray<AvmFlavor::AllConstRefValues::BaseDataType, AvmFlavor::NUM_ALL_ENTITIES>& il)
Expand Down Expand Up @@ -2518,4 +2518,4 @@ std::vector<AvmFlavor::VerificationKey::FF> AvmFlavor::VerificationKey::to_field
return elements;
}

} // namespace bb
} // namespace bb::avm
16 changes: 8 additions & 8 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
// Metaprogramming to concatenate tuple types.
template <typename... input_t> using tuple_cat_t = decltype(std::tuple_cat(std::declval<input_t>()...));

namespace bb {
namespace bb::avm {

class AvmFlavor {
public:
Expand Down Expand Up @@ -252,7 +252,7 @@ class AvmFlavor {
public:
using DataType = DataType_;

DEFINE_FLAVOR_MEMBERS(DataType, PRECOMPUTED_ENTITIES)
DEFINE_FLAVOR_MEMBERS(DataType, AVM_PRECOMPUTED_ENTITIES)

RefVector<DataType> get_selectors() { return get_all(); }
RefVector<DataType> get_sigma_polynomials() { return {}; }
Expand All @@ -263,23 +263,23 @@ class AvmFlavor {
private:
template <typename DataType> class WireEntities {
public:
DEFINE_FLAVOR_MEMBERS(DataType, WIRE_ENTITIES)
DEFINE_FLAVOR_MEMBERS(DataType, AVM_WIRE_ENTITIES)
};

template <typename DataType> class DerivedWitnessEntities {
public:
DEFINE_FLAVOR_MEMBERS(DataType, DERIVED_WITNESS_ENTITIES)
DEFINE_FLAVOR_MEMBERS(DataType, AVM_DERIVED_WITNESS_ENTITIES)
};

template <typename DataType> class ShiftedEntities {
public:
DEFINE_FLAVOR_MEMBERS(DataType, SHIFTED_ENTITIES)
DEFINE_FLAVOR_MEMBERS(DataType, AVM_SHIFTED_ENTITIES)
};

template <typename DataType, typename PrecomputedAndWitnessEntitiesSuperset>
static auto get_to_be_shifted([[maybe_unused]] PrecomputedAndWitnessEntitiesSuperset& entities)
{
return RefArray<DataType, NUM_SHIFTED_ENTITIES>{ TO_BE_SHIFTED(entities) };
return RefArray<DataType, NUM_SHIFTED_ENTITIES>{ AVM_TO_BE_SHIFTED(entities) };
}

public:
Expand Down Expand Up @@ -386,7 +386,7 @@ class AvmFlavor {
using BaseDataType = const FF;
using DataType = BaseDataType&;

DEFINE_FLAVOR_MEMBERS(DataType, ALL_ENTITIES)
DEFINE_FLAVOR_MEMBERS(DataType, AVM_ALL_ENTITIES)

AllConstRefValues(const RefArray<BaseDataType, NUM_ALL_ENTITIES>& il);
};
Expand Down Expand Up @@ -513,4 +513,4 @@ class AvmFlavor {
};
};

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/polynomials/univariate.hpp"

namespace bb {
namespace bb::avm {

class AvmFlavorSettings {
public:
Expand All @@ -26,4 +26,4 @@ class AvmFlavorSettings {
using RelationSeparator = FF;
};

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace bb::avm {
template <typename FF_> struct AvmFullRow {
using FF = FF_;

FF ALL_ENTITIES;
FF AVM_ALL_ENTITIES;

RefVector<const FF> as_vector() const;
static std::vector<std::string> names();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "barretenberg/sumcheck/sumcheck.hpp"
#include "barretenberg/vm/stats.hpp"

namespace bb {
namespace bb::avm {

using Flavor = AvmFlavor;
using FF = Flavor::FF;
Expand Down Expand Up @@ -154,4 +154,4 @@ HonkProof AvmProver::construct_proof()
return export_proof();
}

} // namespace bb
} // namespace bb::avm
26 changes: 15 additions & 11 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "barretenberg/transcript/transcript.hpp"
#include "flavor.hpp"

namespace bb {
namespace bb::avm {

class AvmProver {
using Flavor = AvmFlavor;
Expand All @@ -23,16 +23,20 @@ class AvmProver {

public:
explicit AvmProver(std::shared_ptr<ProvingKey> input_key, std::shared_ptr<PCSCommitmentKey> commitment_key);
AvmProver(AvmProver&& prover) = default;
virtual ~AvmProver() = default;

void execute_preamble_round();
void execute_wire_commitments_round();
void execute_log_derivative_inverse_round();
void execute_log_derivative_inverse_commitments_round();
void execute_relation_check_rounds();
void execute_pcs_rounds();
// Note: all the following methods are virtual to allow Avm2 to tweak the behaviour.
// We can remove this once the transition is done.
virtual void execute_preamble_round();
virtual void execute_wire_commitments_round();
virtual void execute_log_derivative_inverse_round();
virtual void execute_log_derivative_inverse_commitments_round();
virtual void execute_relation_check_rounds();
virtual void execute_pcs_rounds();

HonkProof export_proof();
HonkProof construct_proof();
virtual HonkProof export_proof();
virtual HonkProof construct_proof();

std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();

Expand All @@ -54,8 +58,8 @@ class AvmProver {

std::shared_ptr<PCSCommitmentKey> commitment_key;

private:
protected:
HonkProof proof;
};

} // namespace bb
} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cstddef>
#include <memory>

namespace bb {
namespace bb::avm {

template <typename Flavor>
AvmRecursiveVerifier_<Flavor>::AvmRecursiveVerifier_(
Expand Down Expand Up @@ -170,4 +170,5 @@ AvmRecursiveVerifier_<Flavor>::AggregationObject AvmRecursiveVerifier_<Flavor>::
}

template class AvmRecursiveVerifier_<AvmRecursiveFlavor_<UltraCircuitBuilder>>;
} // namespace bb

} // namespace bb::avm
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ template <typename FF> class alu : public Relation<aluImpl<FF>> {
return std::to_string(index);
}

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_ALU_MULTIPLICATION_FF = 20;
static constexpr size_t SR_ALU_PROD_MUL = 24;
static constexpr size_t SR_DIVISION_RELATION = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ template <typename FF> class binary : public Relation<binaryImpl<FF>> {
return std::to_string(index);
}

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_OP_ID_REL = 1;
static constexpr size_t SR_MEM_TAG_REL = 2;
static constexpr size_t SR_SEL_BIN_CTR_REL = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ template <typename FF> class cmp : public Relation<cmpImpl<FF>> {
return std::to_string(index);
}

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_CMP_RES_IS_BOOL = 3;
static constexpr size_t SR_CMP_OP_EQ = 4;
static constexpr size_t SR_INPUT_DECOMP_1 = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ template <typename FF> class gas : public Relation<gasImpl<FF>> {
return std::to_string(index);
}

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_IS_GAS_ACCOUNTED = 0;
static constexpr size_t SR_L2_GAS_NO_DECREMENT_FAKE_ROW = 4;
static constexpr size_t SR_DA_GAS_NO_DECREMENT_FAKE_ROW = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cstddef>
#include <tuple>

namespace bb {
namespace bb::avm {

class incl_main_tag_err_lookup_settings {
public:
Expand Down Expand Up @@ -61,4 +61,4 @@ class incl_main_tag_err_relation : public GenericLookupRelation<incl_main_tag_er
};
template <typename FF_> using incl_main_tag_err = GenericLookup<incl_main_tag_err_lookup_settings, FF_>;

} // namespace bb
} // namespace bb::avm
Loading
Loading