Skip to content

Commit

Permalink
10243: Fake verification routine for avm recursion in public base rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Dec 3, 2024
1 parent 5a02480 commit 9de72e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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 @@ -16,11 +16,14 @@ use crate::{
AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH, AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS,
MAX_ENQUEUED_CALLS_PER_TX,
},
hash::poseidon2_hash,
proof::{avm_proof::AvmProof, traits::Verifiable, vk_data::VkData},
traits::{Deserialize, Empty, Serialize},
utils::reader::Reader,
};

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

pub struct AvmCircuitPublicInputs {
///////////////////////////////////
// Inputs.
Expand Down Expand Up @@ -180,6 +183,39 @@ 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 = 3000;

// Current AVM recursive verifier has 7000 gates per column.
// Note that the addition of a single column in AVM recursive verifier incurs 6600 gates.
// (some additional costs due to lookups/perms, etc...).
// 78 gates per Poseidon permutation
// 7000/78 = 89.7
pub global DUMMY_AVM_VERIFIER_NUM_ITERATIONS: u32 = DUMMY_AVM_VERIFIER_NUM_COLUMNS * 90;

// 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; 1] = [input_hash];
let mut result: [Field; 4] = [input_hash, 0, 0, 0];
for i in 0..DUMMY_AVM_VERIFIER_NUM_ITERATIONS {
result = poseidon2_permutation(result, 4);
//result = poseidon2_hash([result]);
}

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

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

0 comments on commit 9de72e4

Please sign in to comment.