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): Fake verification routine for avm recursion in public base rollup #10382

Merged
merged 2 commits into from
Dec 4, 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
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
Loading