Skip to content

Commit

Permalink
9349: adapt proof length
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Oct 24, 2024
1 parent 74830c4 commit 248a196
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ void create_dummy_vkey_and_proof(Builder& builder,

// Relevant source for proof layout: AvmFlavor::Transcript::serialize_full_transcript()
assert((proof_size - Flavor::NUM_WITNESS_ENTITIES * Flavor::NUM_FRS_COM -
Flavor::NUM_ALL_ENTITIES * Flavor::NUM_FRS_FR - 2 * Flavor::NUM_FRS_COM - Flavor::NUM_FRS_FR) %
(Flavor::NUM_FRS_COM + Flavor::NUM_FRS_FR * Flavor::BATCHED_RELATION_PARTIAL_LENGTH) ==
(Flavor::NUM_ALL_ENTITIES + 1) * Flavor::NUM_FRS_FR - Flavor::NUM_FRS_COM) %
(Flavor::NUM_FRS_COM + Flavor::NUM_FRS_FR * (Flavor::BATCHED_RELATION_PARTIAL_LENGTH + 1)) ==
0);

// Derivation of circuit size based on the proof
// Here, we should always get CONST_PROOF_SIZE_LOG_N which is not what is
// usually set for the AVM proof. As it is a dummy key/proof, it should not matter.
auto log_circuit_size =
(proof_size - Flavor::NUM_WITNESS_ENTITIES * Flavor::NUM_FRS_COM -
Flavor::NUM_ALL_ENTITIES * Flavor::NUM_FRS_FR - 2 * Flavor::NUM_FRS_COM - Flavor::NUM_FRS_FR) /
(Flavor::NUM_FRS_COM + Flavor::NUM_FRS_FR * Flavor::BATCHED_RELATION_PARTIAL_LENGTH);
// Here, we should always get CONST_PROOF_SIZE_LOG_N.
auto log_circuit_size = (proof_size - Flavor::NUM_WITNESS_ENTITIES * Flavor::NUM_FRS_COM -
(Flavor::NUM_ALL_ENTITIES + 1) * Flavor::NUM_FRS_FR - Flavor::NUM_FRS_COM) /
(Flavor::NUM_FRS_COM + Flavor::NUM_FRS_FR * (Flavor::BATCHED_RELATION_PARTIAL_LENGTH + 1));

/***************************************************************************
* Construct Dummy Verification Key
Expand Down Expand Up @@ -109,8 +107,8 @@ void create_dummy_vkey_and_proof(Builder& builder,
offset++;
}

// now the shplemini commitments
for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; i++) {
// now the gemini fold commitments which are CONST_PROOF_SIZE_LOG_N - 1
for (size_t i = 1; i < CONST_PROOF_SIZE_LOG_N; i++) {
auto comm = curve::BN254::AffineElement::one() * fr::random_element();
auto frs = field_conversion::convert_to_bn254_frs(comm);
builder.assert_equal(builder.add_variable(frs[0]), proof_fields[offset].witness_index);
Expand All @@ -120,7 +118,13 @@ void create_dummy_vkey_and_proof(Builder& builder,
offset += 4;
}

// lastly the 2 commitments
// the gemini fold evaluations which are CONST_PROOF_SIZE_LOG_N
for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; i++) {
builder.assert_equal(builder.add_variable(fr::random_element()), proof_fields[offset].witness_index);
offset++;
}

// lastly the shplonk batched quotient commitment and kzg quotient commitment
for (size_t i = 0; i < 2; i++) {
auto comm = curve::BN254::AffineElement::one() * fr::random_element();
auto frs = field_conversion::convert_to_bn254_frs(comm);
Expand Down Expand Up @@ -163,14 +167,6 @@ AggregationObjectIndices create_avm_recursion_constraints(Builder& builder,
key_fields.emplace_back(field);
}

// TODO(JEANMON): Once we integrate with public inputs, we will have to decide whether we inject (see
// ProofSurgeon::create_indices_for_reconstructed_proof) them as part of proof_fields or through some separate
// argument like in the native verifier. The latter will be favored because the public inputs are not part of the
// transcript and the verifier code passes the proof to initialize the transcript.
// Create witness indices for the
// proof with public inputs reinserted std::vector<uint32_t> proof_indices =
// ProofSurgeon::create_indices_for_reconstructed_proof(input.proof, input.public_inputs);

auto fields_from_witnesses = [&](std::vector<uint32_t> const& input) {
std::vector<field_ct> result;
result.reserve(input.size());
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class AvmFlavor {
// After any circuit changes, hover `COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS` in your IDE
// to see its value and then update `AVM_PROOF_LENGTH_IN_FIELDS` in constants.nr.
static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS =
(NUM_WITNESS_ENTITIES + 2) * NUM_FRS_COM + (NUM_ALL_ENTITIES + 1) * NUM_FRS_FR +
CONST_PROOF_SIZE_LOG_N * (NUM_FRS_COM + NUM_FRS_FR * BATCHED_RELATION_PARTIAL_LENGTH);
1 + (NUM_WITNESS_ENTITIES + 1) * NUM_FRS_COM + NUM_ALL_ENTITIES * NUM_FRS_FR +
CONST_PROOF_SIZE_LOG_N * (NUM_FRS_COM + NUM_FRS_FR * (BATCHED_RELATION_PARTIAL_LENGTH + 1));

static_assert(AVM_PROOF_LENGTH_IN_FIELDS == COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS,
"\nUnexpected AVM proof length. This might be due to some changes in the\n"
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 674
#define PUBLIC_CONTEXT_INPUTS_LENGTH 41
#define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86
#define AVM_PROOF_LENGTH_IN_FIELDS 3818
#define AVM_PROOF_LENGTH_IN_FIELDS 3842
#define AVM_PUBLIC_COLUMN_MAX_SIZE 1024
#define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2722
#define MEM_TAG_FF 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ global AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 2 + 21 * 4;
// `AVM_PROOF_LENGTH_IN_FIELDS` must be updated when AVM circuit changes.
// To determine latest value, hover `COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS`
// in barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp
global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 3818;
global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 3842;
global AVM_PUBLIC_COLUMN_MAX_SIZE : u32 = 1024;
global AVM_PUBLIC_INPUTS_FLATTENED_SIZE : u32 = 2 * AVM_PUBLIC_COLUMN_MAX_SIZE + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH;
/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const TUBE_PROOF_LENGTH = 463;
export const HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS = 128;
export const CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS = 145;
export const AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS = 86;
export const AVM_PROOF_LENGTH_IN_FIELDS = 3818;
export const AVM_PROOF_LENGTH_IN_FIELDS = 3842;
export const AVM_PUBLIC_COLUMN_MAX_SIZE = 1024;
export const AVM_PUBLIC_INPUTS_FLATTENED_SIZE = 2722;
export const MEM_TAG_FF = 0;
Expand Down

0 comments on commit 248a196

Please sign in to comment.