Skip to content

Commit

Permalink
running standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
zobront committed Jun 27, 2024
1 parent 1174b3c commit eea0485
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 267 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/kona_compile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: compile zkvm_client for kona_host

on:
pull_request:
branches:
- main

jobs:
build_and_run:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Compile the client program
run: cargo build --profile release-client-lto
working-directory: zkvm-client
21 changes: 21 additions & 0 deletions .github/workflows/zkvm_compile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: compile zkvm_client for zkvm

on:
pull_request:
branches:
- main

jobs:
build_and_run:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download SP1
run: curl -L https://sp1.succinct.xyz | bash
- name: Install SP1
run: /home/runner/.config/.sp1/bin/sp1up
- name: Compile the client program
run: /home/runner/.config/.sp1/bin/cargo-prove prove build --ignore-rust-version
working-directory: zkvm-client
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
3 changes: 0 additions & 3 deletions zkvm-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
mod boot;
pub use boot::BootInfoWithoutRollupConfig;

mod precompile;
pub use precompile::Precompile;
5 changes: 0 additions & 5 deletions zkvm-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! A program to verify a Optimism L2 block STF in the zkVM.
#![cfg_attr(target_os = "zkvm", no_main)]

mod precompile;
pub use precompile::Precompile;

use kona_client::CachingOracle;
use kona_executor::StatelessL2BlockExecutor;
use kona_primitives::L2AttributesWithParent;
Expand Down Expand Up @@ -52,8 +49,6 @@ fn main() {
let kv_store_bytes: Vec<u8> = sp1_zkvm::io::read_vec();
let oracle = Arc::new(InMemoryOracle::from_raw_bytes(kv_store_bytes));

oracle.verify().expect("key value verification failed");

// If we are compiling for online mode, create a caching oracle that speaks to the
// fetcher via hints, and gather boot info from this oracle.
} else {
Expand Down
115 changes: 0 additions & 115 deletions zkvm-client/src/oracle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Contains the host <-> client communication utilities.
use super::Precompile;

use alloc::{boxed::Box, vec::Vec};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
Expand Down Expand Up @@ -49,116 +47,3 @@ impl HintWriterClient for InMemoryOracle {
Ok(())
}
}

// #[derive(Default)]
// struct Blob {
// // TODO: Advantage / disadvantage of using FixedBytes?
// commitment: FixedBytes<48>,
// // TODO: Import and use Blob type from kona-derive?
// data: FixedBytes<4096>,
// kzg_proof: FixedBytes<48>,
// }

impl InMemoryOracle {
pub fn verify(&self) -> Result<()> {
// let mut blobs: HashMap<FixedBytes<48>, Blob> = HashMap::new();

// for (key, value) in self.cache.iter() {
// match key.key_type() {
// PreimageKeyType::Local => {
// // no op - these are public values so verification happens in solidity
// },
// PreimageKeyType::Keccak256 => {
// let derived_key = PreimageKey::new(keccak256(value).into(), PreimageKeyType::Keccak256);
// assert_eq!(*key, derived_key, "zkvm keccak constraint failed!");
// },
// PreimageKeyType::GlobalGeneric => {
// unimplemented!();
// },
// PreimageKeyType::Sha256 => {
// let derived_key: [u8; 32] = Sha256::digest(value).into();
// // TODO: Confirm we don't need `derived_key[0] = 0x01; // VERSIONED_HASH_VERSION_KZG` because it's overwritten by PreimageKey
// let derived_key = PreimageKey::new(derived_key, PreimageKeyType::Sha256);
// assert_eq!(*key, derived_key, "zkvm sha256 constraint failed!");
// },
// PreimageKeyType::Blob => {
// let blob_data_key = PreimageKey::new(
// <PreimageKey as Into<[u8;32]>>::into(*key),
// PreimageKeyType::Keccak256
// );

// if let Some(blob_data) = self.cache.get(&blob_data_key) {
// let commitment: FixedBytes<48> = blob_data[..48].try_into().unwrap();
// let element: [u8; 8] = blob_data[72..].try_into().unwrap();
// let element: u64 = u64::from_be_bytes(element);

// if element == 4096 {
// // This is the proof for the blob
// blobs
// .entry(commitment)
// .or_insert(Blob::default())
// .kzg_proof[..32]
// .copy_from_slice(value);
// continue;
// } else if element == 4097 {
// // This is the commitment for the blob
// blobs
// .entry(commitment)
// .or_insert(Blob::default())
// .kzg_proof[32..]
// .copy_from_slice(&value[..16]);
// continue;
// }

// // value is 32 byte segment from blob, so insert it in the right place
// blobs
// .entry(commitment)
// .or_insert(Blob::default())
// .data
// .get_mut((element as usize) << 5..(element as usize + 1) << 5)
// .map(|slice| {
// if slice.iter().all(|&byte| byte == 0) {
// slice.copy_from_slice(value);
// Ok(())
// } else {
// return Err(anyhow!("trying to overwrite existing blob data"));
// }
// });
// } else {
// return Err(anyhow!("blob data not found"));
// }
// // Aggregate blobs and proofs in memory and verify after loop.
// // Check that range is empty then add it (should be guaranteed because can't add twice, can optimize out later)
// },
// PreimageKeyType::Precompile => {
// // Convert the Precompile type to a Keccak type. This is the key to get the hint data.
// let hint_data_key = PreimageKey::new(
// <PreimageKey as Into<[u8;32]>>::into(*key),
// PreimageKeyType::Keccak256
// );

// // Look up the hint data in the cache. It should always exist, because we only
// // set Precompile KV pairs along with Keccak KV pairs for the hint data.
// if let Some(hint_data) = self.cache.get(&hint_data_key) {
// let precompile = Precompile::from_bytes(hint_data).unwrap();
// let output = precompile.execute();
// assert_eq!(value, &output, "zkvm precompile constraint failed!")
// } else {
// return Err(anyhow!("precompile hint data not found"));
// }
// }
// }
// }

// // Blob verification of complete blobs goes here.
// for (commitment, blob) in blobs.iter() {
// // call out to kzg-rs to verify that the full blob is valid
// // kzg::verify_blob_kzg_proof(&blob.data, commitment, &blob.kzg_proof)
// // .map_err(|e| format!("blob verification failed for {:?}: {}", commitment, e))?;

// // TODO: I think allows us to leave empty segments in blobs that were not empty and prove that?
// }

Ok(())
}
}
143 changes: 0 additions & 143 deletions zkvm-client/src/precompile.rs

This file was deleted.

2 changes: 1 addition & 1 deletion zkvm-host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
stdin.write(&boot_info);

// Read KV store into raw bytes and pass to stdin.
let kv_store = load_kv_store(&format!("../../data/{}", l2_claim_block));
let kv_store = load_kv_store(&format!("../data/{}", l2_claim_block));

let mut serializer = CompositeSerializer::new(
AlignedSerializer::new(AlignedVec::new()),
Expand Down

0 comments on commit eea0485

Please sign in to comment.