Skip to content

Commit

Permalink
chore(avm): Fake verification routine for avm recursion in public bas…
Browse files Browse the repository at this point in the history
…e rollup (#10382)

Resolves #10243
  • Loading branch information
jeanmon authored Dec 4, 2024
1 parent 5cef628 commit a1e5966
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ TEST_F(AvmRecursiveTests, recursion)
verification_key->pcs_verification_key->pairing_check(agg_output.P0.get_value(), agg_output.P1.get_value());

ASSERT_TRUE(agg_output_valid) << "Pairing points (aggregation state) are not valid.";

vinfo("Recursive verifier: num gates = ", outer_circuit.num_gates);
ASSERT_FALSE(outer_circuit.failed()) << "Outer circuit has failed.";

bool outer_circuit_checked = CircuitChecker::check(outer_circuit);
Expand Down Expand Up @@ -139,6 +137,8 @@ TEST_F(AvmRecursiveTests, recursion)
auto ultra_verification_key = std::make_shared<UltraFlavor::VerificationKey>(ultra_instance->proving_key);
OuterVerifier ultra_verifier(ultra_verification_key);

vinfo("Recursive verifier: finalized num gates = ", outer_circuit.num_gates);

auto recursion_proof = ultra_prover.construct_proof();
bool recursion_verified = ultra_verifier.verify_proof(recursion_proof);
EXPECT_TRUE(recursion_verified) << "recursion proof verification failed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ impl PublicBaseRollupInputs {
// self.tube_data.vk_data.validate_in_vk_tree([TUBE_VK_INDEX]);
}

// Warning: Fake verification! TODO(#8470)
if !dep::std::runtime::is_unconstrained() {
self.avm_proof_data.fake_verify();
}

// TODO(#8470)
// if !dep::std::runtime::is_unconstrained() {
// self.avm_proof_data.verify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::{
utils::reader::Reader,
};

use std::hash::{poseidon2, poseidon2_permutation};

pub struct AvmCircuitPublicInputs {
///////////////////////////////////
// Inputs.
Expand Down Expand Up @@ -180,6 +182,37 @@ pub struct AvmProofData {
pub vk_data: VkData<AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS>,
}

// The number of columns for the AVM recursive verifier we want to fake, i.e., the resulting
// verify() routine below will create a similar number of gates as a real AVM recursive verifier
// with the number of columns set by this constant.
pub global DUMMY_AVM_VERIFIER_NUM_COLUMNS: u32 = 2200;

// Current AVM recursive verifier has 9500 gates per column.
// Note that the addition of a single column in AVM recursive verifier incurs 8500 gates.
// (some additional costs are due to lookups, relations, ...).
// 78 gates per Poseidon permutation
// 9500/78 = 121.8
pub global DUMMY_AVM_VERIFIER_NUM_ITERATIONS: u32 = DUMMY_AVM_VERIFIER_NUM_COLUMNS * 122;

// Warning: This is a fake avm recursive verification whose sole goal is to reproduce a similar
// computational effort (number of gates) as the real recursive verifier.
// TODO(#8470): Replace with the real AVM recursive verifier
impl AvmProofData {
pub fn fake_verify(self) {
let mut input_hash = poseidon2::Poseidon2::hash(
[self.public_inputs.transaction_fee, self.proof.fields[0], self.vk_data.vk.key[0]],
3,
);

let mut result: [Field; 4] = [input_hash, 0, 0, 0];
for i in 0..DUMMY_AVM_VERIFIER_NUM_ITERATIONS {
result = poseidon2_permutation(result, 4);
}

assert(!result[0].lt(1));
}
}

impl Verifiable for AvmProofData {
fn verify(self) {
// TODO(#8470)
Expand Down

0 comments on commit a1e5966

Please sign in to comment.