Skip to content

Commit

Permalink
Create ZkApp
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Oct 8, 2023
1 parent b1ffb33 commit 85cd564
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
5 changes: 2 additions & 3 deletions examples/demo-prover/methods/guest-celestia/src/bin/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#![no_main]

use const_rollup_config::ROLLUP_NAMESPACE_RAW;
use demo_stf::create_zk_app_template;
use demo_stf::AppVerifier;
use demo_stf::{AppVerifier, ZkApp};
use sov_celestia_adapter::types::NamespaceId;
use sov_celestia_adapter::verifier::CelestiaVerifier;
use sov_risc0_adapter::guest::Risc0Guest;
Expand All @@ -17,7 +16,7 @@ risc0_zkvm::guest::entry!(main);
pub fn main() {
let guest = Risc0Guest::new();
let mut stf_verifier = AppVerifier::new(
create_zk_app_template::<Risc0Guest, _>(),
ZkApp::<Risc0Guest, _>::default().stf,
CelestiaVerifier {
rollup_namespace: ROLLUP_NAMESPACE,
},
Expand Down
5 changes: 2 additions & 3 deletions examples/demo-prover/methods/guest-mock/src/bin/mock_da.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![no_main]

use demo_stf::create_zk_app_template;
use demo_stf::AppVerifier;
use demo_stf::{AppVerifier, ZkApp};
use sov_risc0_adapter::guest::Risc0Guest;

use sov_rollup_interface::mocks::MockDaVerifier;
Expand All @@ -12,7 +11,7 @@ pub fn main() {
let guest = Risc0Guest::new();

let mut stf_verifier =
AppVerifier::new(create_zk_app_template::<Risc0Guest, _>(), MockDaVerifier {});
AppVerifier::new(ZkApp::<Risc0Guest, _>::default().stf, MockDaVerifier {});

stf_verifier
.run_block(guest)
Expand Down
11 changes: 6 additions & 5 deletions examples/demo-rollup/src/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use anyhow::Context;
use const_rollup_config::SEQUENCER_DA_ADDRESS;
use demo_stf::genesis_config::{get_genesis_config, GenesisPaths, StorageConfig};
use demo_stf::runtime::{get_rpc_methods, GenesisConfig, Runtime};
use demo_stf::{create_zk_app_template, App, AppVerifier, DefaultContext};

use demo_stf::{App, AppVerifier, DefaultContext, ZkApp};
#[cfg(feature = "experimental")]
use secp256k1::SecretKey;
use sov_celestia_adapter::verifier::address::CelestiaAddress;
Expand All @@ -22,6 +21,7 @@ use sov_modules_api::default_context::ZkDefaultContext;
#[cfg(feature = "experimental")]
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_stf_template::AppTemplate;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_rollup_interface::mocks::{
MockAddress, MockDaConfig, MockDaService, MOCK_SEQUENCER_DA_ADDRESS,
};
Expand Down Expand Up @@ -69,9 +69,10 @@ pub fn configure_prover<Vm: ZkvmHost, Da: DaService>(
da_verifier: Da::Verifier,
) -> Prover<ZkStf<Da::Spec, Vm::Guest>, Da, Vm> {
let config = match cfg {
DemoProverConfig::Simulate => {
ProofGenConfig::Simulate(AppVerifier::new(create_zk_app_template(), da_verifier))
}
DemoProverConfig::Simulate => ProofGenConfig::Simulate(AppVerifier::new(
ZkApp::<Risc0Guest, _>::default().stf,
da_verifier,
)),
DemoProverConfig::Execute => ProofGenConfig::Execute,
DemoProverConfig::Prove => ProofGenConfig::Prover,
};
Expand Down
20 changes: 16 additions & 4 deletions examples/demo-stf/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ use sov_state::{ProverStorage, Storage};

use crate::runtime::Runtime;

/// Contains StateTransitionFunction and other necessary dependencies needed for implementing a full node.
#[cfg(feature = "native")]
pub struct App<Vm: Zkvm, Da: DaSpec> {
/// Concrete state transition function.
pub stf: AppTemplate<DefaultContext, Da, Vm, Runtime<DefaultContext, Da>>,
/// Batch builder.
pub batch_builder: Option<FiFoStrictBatchBuilder<Runtime<DefaultContext, Da>, DefaultContext>>,
}

#[cfg(feature = "native")]
impl<Vm: Zkvm, Da: DaSpec> App<Vm, Da> {
/// Creates a new `App`.
pub fn new(storage_config: StorageConfig) -> Self {
let storage =
ProverStorage::with_config(storage_config).expect("Failed to open prover storage");
Expand All @@ -49,8 +53,16 @@ impl<Vm: Zkvm, Da: DaSpec> App<Vm, Da> {
}
}

pub fn create_zk_app_template<Vm: Zkvm, Da: DaSpec>(
) -> AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultContext, Da>> {
let storage = ZkStorage::new();
AppTemplate::new(storage, Runtime::default())
/// Contains StateTransitionFunction for the `zk` context.
pub struct ZkApp<Vm: Zkvm, Da: DaSpec> {
pub stf: AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultContext, Da>>,
}

impl<Vm: Zkvm, Da: DaSpec> Default for ZkApp<Vm, Da> {
fn default() -> Self {
let storage = ZkStorage::new();
Self {
stf: AppTemplate::new(storage, Runtime::default()),
}
}
}

0 comments on commit 85cd564

Please sign in to comment.