|
1 | 1 | use std::{fs::read, marker::PhantomData, path::Path, sync::Arc}; |
2 | 2 |
|
3 | 3 | #[cfg(feature = "evm-verify")] |
4 | | -use alloy_primitives::{Bytes, FixedBytes}; |
5 | | -#[cfg(feature = "evm-verify")] |
6 | | -use alloy_sol_types::{sol, SolCall, SolValue}; |
| 4 | +use alloy_sol_types::sol; |
| 5 | +use commit::commit_app_exe; |
| 6 | +use config::{AggregationTreeConfig, AppConfig}; |
7 | 7 | use eyre::Result; |
| 8 | +use keygen::{AppProvingKey, AppVerifyingKey}; |
8 | 9 | use openvm_build::{ |
9 | 10 | build_guest_package, find_unique_executable, get_package, GuestOptions, TargetFilter, |
10 | 11 | }; |
@@ -41,9 +42,8 @@ use openvm_transpiler::{ |
41 | 42 | use snark_verifier_sdk::{evm::gen_evm_verifier_sol_code, halo2::aggregation::AggregationCircuit}; |
42 | 43 |
|
43 | 44 | use crate::{ |
44 | | - commit::commit_app_exe, |
45 | | - config::{AggConfig, AggregationTreeConfig, AppConfig}, |
46 | | - keygen::{AggProvingKey, AggStarkProvingKey, AppProvingKey, AppVerifyingKey}, |
| 45 | + config::AggConfig, |
| 46 | + keygen::{AggProvingKey, AggStarkProvingKey}, |
47 | 47 | prover::{AppProver, StarkProver}, |
48 | 48 | }; |
49 | 49 | #[cfg(feature = "evm-prove")] |
@@ -327,7 +327,7 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> { |
327 | 327 |
|
328 | 328 | let wrapper_pvs = agg_pk.halo2_pk.wrapper.pinning.metadata.num_pvs.clone(); |
329 | 329 | let pvs_length = match wrapper_pvs.first() { |
330 | | - // We subtract 14 to exclude the KZG accumulators and the app exe |
| 330 | + // We subtract 14 to exclude the KZG accumulator and the app exe |
331 | 331 | // and vm commits. |
332 | 332 | Some(v) => v |
333 | 333 | .checked_sub(14) |
@@ -411,55 +411,9 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> { |
411 | 411 | pub fn verify_evm_halo2_proof( |
412 | 412 | &self, |
413 | 413 | openvm_verifier: &types::EvmHalo2Verifier, |
414 | | - evm_proof: &EvmProof, |
| 414 | + evm_proof: EvmProof, |
415 | 415 | ) -> Result<u64> { |
416 | | - use crate::types::NUM_BN254_ACCUMULATORS; |
417 | | - |
418 | | - let EvmProof { |
419 | | - accumulators, |
420 | | - proof, |
421 | | - user_public_values, |
422 | | - exe_commit, |
423 | | - leaf_commit, |
424 | | - } = evm_proof; |
425 | | - let mut exe_commit = *exe_commit; |
426 | | - let mut leaf_commit = *leaf_commit; |
427 | | - exe_commit.reverse(); |
428 | | - leaf_commit.reverse(); |
429 | | - |
430 | | - assert_eq!(accumulators.len(), NUM_BN254_ACCUMULATORS * 32); |
431 | | - let mut evm_accumulators: Vec<u8> = Vec::with_capacity(accumulators.len()); |
432 | | - accumulators |
433 | | - .chunks(32) |
434 | | - .for_each(|chunk| evm_accumulators.extend(chunk.iter().rev().cloned())); |
435 | | - |
436 | | - let mut proof_data = evm_accumulators; |
437 | | - proof_data.extend(proof); |
438 | | - |
439 | | - assert!( |
440 | | - user_public_values.len() % 32 == 0, |
441 | | - "User public values length must be a multiple of 32" |
442 | | - ); |
443 | | - |
444 | | - // Take the first byte of each 32 byte chunk, and pack them together |
445 | | - // into one payload. |
446 | | - let user_public_values: Bytes = |
447 | | - user_public_values |
448 | | - .chunks(32) |
449 | | - .fold(Vec::<u8>::new().into(), |acc: Bytes, chunk| { |
450 | | - // We only care about the first byte, everything else should be 0-bytes |
451 | | - (acc, FixedBytes::<1>::from(*chunk.first().unwrap())) |
452 | | - .abi_encode_packed() |
453 | | - .into() |
454 | | - }); |
455 | | - |
456 | | - let calldata = IOpenVmHalo2Verifier::verifyCall { |
457 | | - publicValues: user_public_values.clone(), |
458 | | - proofData: proof_data.into(), |
459 | | - appExeCommit: exe_commit.into(), |
460 | | - appVmCommit: leaf_commit.into(), |
461 | | - } |
462 | | - .abi_encode(); |
| 416 | + let calldata = evm_proof.verifier_calldata(); |
463 | 417 | let deployment_code = openvm_verifier.artifact.bytecode.clone(); |
464 | 418 |
|
465 | 419 | let gas_cost = snark_verifier::loader::evm::deploy_and_call(deployment_code, calldata) |
|
0 commit comments