Skip to content

Commit

Permalink
extend ExecutionArg
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Aug 1, 2024
1 parent 0860174 commit 23ef3bc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
7 changes: 7 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![deny(warnings)]
#![allow(clippy::too_many_arguments, clippy::while_let_on_iterator)]

use std::cell::RefCell;
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use std::rc::Rc;

use anyhow::Result;
use app_builder::app;
Expand Down Expand Up @@ -82,6 +85,8 @@ fn main() -> Result<()> {
public_inputs,
private_inputs,
context_inputs,
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
arg.running_arg.context_output,
arg.instruction_limit,
Expand Down Expand Up @@ -152,6 +157,8 @@ fn main() -> Result<()> {
public_inputs,
private_inputs,
context_inputs,
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
arg.running_arg.context_output,
arg.mock_test,
Expand Down
21 changes: 0 additions & 21 deletions crates/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,8 @@ use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use zkwasm_host_circuits::host::db::TreeDB;
use zkwasm_host_circuits::proof::OpType;

pub struct StandardExecutionArg {
/// Public inputs for `wasm_input(1)`
pub public_inputs: Vec<u64>,
/// Private inputs for `wasm_input(0)`
pub private_inputs: Vec<u64>,
/// Context inputs for `wasm_read_context()`
pub context_inputs: Vec<u64>,
/// indexed witness context
pub indexed_witness: Rc<RefCell<HashMap<u64, Vec<u64>>>>,
/// db src
pub tree_db: Option<Rc<RefCell<dyn TreeDB>>>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct HostEnvConfig {
pub ops: Vec<OpType>,
Expand Down Expand Up @@ -104,13 +90,6 @@ impl HostEnvBuilder for StandardHostEnvBuilder {
let host_env_config = HostEnvConfig {
ops: self.ops.clone(),
};
let arg = StandardExecutionArg {
public_inputs: arg.public_inputs,
private_inputs: arg.private_inputs,
context_inputs: arg.context_inputs,
indexed_witness: Rc::new(RefCell::new(HashMap::new())),
tree_db: None,
};

register_wasm_input_foreign(&mut env, arg.public_inputs, arg.private_inputs);
register_require_foreign(&mut env);
Expand Down
5 changes: 5 additions & 0 deletions crates/playground/examples/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use delphinus_zkwasm::runtime::host::default_env::ExecutionArg;
use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use delphinus_zkwasm::runtime::monitor::table_monitor::TableMonitor;
use pairing_bn256::bn256::Fr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

const K: u32 = MIN_K;

Expand All @@ -21,6 +24,8 @@ fn main() -> Result<()> {
public_inputs: vec![0],
private_inputs: vec![],
context_inputs: vec![],
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
);
let mut monitor = TableMonitor::new(K, &vec![], TraceBackend::Memory, &env);
Expand Down
7 changes: 7 additions & 0 deletions crates/playground/examples/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use delphinus_zkwasm::runtime::host::default_env::ExecutionArg;
use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use delphinus_zkwasm::runtime::monitor::table_monitor::TableMonitor;
use pairing_bn256::bn256::Fr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

const K: u32 = MIN_K;

Expand All @@ -22,6 +25,8 @@ fn main() -> Result<()> {
public_inputs: vec![],
private_inputs: vec![],
context_inputs: vec![2, 1],
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
);

Expand All @@ -44,6 +49,8 @@ fn main() -> Result<()> {
public_inputs: vec![],
private_inputs: vec![],
context_inputs: context_output.0,
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
);

Expand Down
5 changes: 5 additions & 0 deletions crates/playground/examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use delphinus_zkwasm::runtime::host::default_env::ExecutionArg;
use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use delphinus_zkwasm::runtime::monitor::table_monitor::TableMonitor;
use pairing_bn256::bn256::Fr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

const K: u32 = MIN_K;

Expand All @@ -21,6 +24,8 @@ fn main() -> Result<()> {
public_inputs: vec![5],
private_inputs: vec![],
context_inputs: vec![],
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
);
let mut monitor = TableMonitor::new(K, &vec![], TraceBackend::Memory, &env);
Expand Down
5 changes: 5 additions & 0 deletions crates/playground/examples/phantom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use delphinus_zkwasm::runtime::host::default_env::ExecutionArg;
use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use delphinus_zkwasm::runtime::monitor::table_monitor::TableMonitor;
use pairing_bn256::bn256::Fr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

const K: u32 = MIN_K;

Expand All @@ -21,6 +24,8 @@ fn main() -> Result<()> {
public_inputs: vec![2],
private_inputs: vec![],
context_inputs: vec![],
indexed_witness: Rc::new(RefCell::new(HashMap::default())),
tree_db: None,
},
);
let mut monitor = TableMonitor::new(K, &vec!["search".to_string()], TraceBackend::Memory, &env);
Expand Down
12 changes: 10 additions & 2 deletions crates/zkwasm/src/runtime/host/default_env.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

use zkwasm_host_circuits::host::db::TreeDB;

use crate::foreign::context::runtime::register_context_foreign;
use crate::foreign::log_helper::register_log_foreign;
use crate::foreign::require_helper::register_require_foreign;
Expand All @@ -6,15 +12,17 @@ use crate::foreign::wasm_input_helper::runtime::register_wasm_input_foreign;
use super::host_env::HostEnv;
use super::HostEnvBuilder;

// TODO: remove me after refine tracer
#[derive(Clone)]
pub struct ExecutionArg {
/// Public inputs for `wasm_input(1)`
pub public_inputs: Vec<u64>,
/// Private inputs for `wasm_input(0)`
pub private_inputs: Vec<u64>,
/// Context inputs for `wasm_read_context()`
pub context_inputs: Vec<u64>,
/// indexed witness context
pub indexed_witness: Rc<RefCell<HashMap<u64, Vec<u64>>>>,
/// db src
pub tree_db: Option<Rc<RefCell<dyn TreeDB>>>,
}

pub struct DefaultHostEnvBuilder;
Expand Down

0 comments on commit 23ef3bc

Please sign in to comment.