|
1 |
| -use std::{fs::read, marker::PhantomData, path::Path, sync::Arc}; |
| 1 | +use std::{ |
| 2 | + env, |
| 3 | + fs::{create_dir_all, read, write}, |
| 4 | + marker::PhantomData, |
| 5 | + path::Path, |
| 6 | + process::Command, |
| 7 | + sync::Arc, |
| 8 | +}; |
2 | 9 |
|
3 | 10 | #[cfg(feature = "evm-verify")]
|
4 | 11 | use alloy_sol_types::sol;
|
@@ -43,6 +50,10 @@ use snark_verifier_sdk::{evm::gen_evm_verifier_sol_code, halo2::aggregation::Agg
|
43 | 50 |
|
44 | 51 | use crate::{
|
45 | 52 | config::AggConfig,
|
| 53 | + fs::{ |
| 54 | + EVM_HALO2_VERIFIER_BASE_NAME, EVM_HALO2_VERIFIER_INTERFACE_NAME, |
| 55 | + EVM_HALO2_VERIFIER_PARENT_NAME, |
| 56 | + }, |
46 | 57 | keygen::{AggProvingKey, AggStarkProvingKey},
|
47 | 58 | prover::{AppProver, StarkProver},
|
48 | 59 | };
|
@@ -540,3 +551,48 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> {
|
540 | 551 | Ok(gas_cost)
|
541 | 552 | }
|
542 | 553 | }
|
| 554 | + |
| 555 | +/// We will split the output by whitespace and look for the following |
| 556 | +/// sequence: |
| 557 | +/// [ |
| 558 | +/// ... |
| 559 | +/// "=======", |
| 560 | +/// "OpenVmHalo2Verifier.sol:OpenVmHalo2Verifier", |
| 561 | +/// "=======", |
| 562 | +/// "Binary:" |
| 563 | +/// "[compiled bytecode]" |
| 564 | +/// ... |
| 565 | +/// ] |
| 566 | +/// |
| 567 | +/// Once we find "OpenVmHalo2Verifier.sol:OpenVmHalo2Verifier," we can skip |
| 568 | +/// to the appropriate offset to get the compiled bytecode. |
| 569 | +fn extract_binary(output: &[u8], contract_name: &str) -> Vec<u8> { |
| 570 | + let split = split_by_ascii_whitespace(output); |
| 571 | + let contract_name_bytes = contract_name.as_bytes(); |
| 572 | + |
| 573 | + for i in 0..split.len().saturating_sub(3) { |
| 574 | + if split[i] == contract_name_bytes { |
| 575 | + return hex::decode(split[i + 3]).expect("Invalid hex in Binary"); |
| 576 | + } |
| 577 | + } |
| 578 | + |
| 579 | + panic!("Contract '{}' not found", contract_name); |
| 580 | +} |
| 581 | + |
| 582 | +fn split_by_ascii_whitespace(bytes: &[u8]) -> Vec<&[u8]> { |
| 583 | + let mut split = Vec::new(); |
| 584 | + let mut start = None; |
| 585 | + for (idx, byte) in bytes.iter().enumerate() { |
| 586 | + if byte.is_ascii_whitespace() { |
| 587 | + if let Some(start) = start.take() { |
| 588 | + split.push(&bytes[start..idx]); |
| 589 | + } |
| 590 | + } else if start.is_none() { |
| 591 | + start = Some(idx); |
| 592 | + } |
| 593 | + } |
| 594 | + if let Some(last) = start { |
| 595 | + split.push(&bytes[last..]); |
| 596 | + } |
| 597 | + split |
| 598 | +} |
0 commit comments