Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prover-sever): enhance error checking #20

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bin/src/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::io::Write;
use std::path::PathBuf;
use utils::Measurer;
use zkevm::{
circuit::{EvmCircuit, StateCircuit, AGG_DEGREE, DEGREE},
circuit::{EvmCircuit, StateCircuit, AGG_DEGREE, DEGREE, MAX_TXS},
io::write_file,
prover::Prover,
utils::{get_block_trace_from_file, load_or_create_params, load_or_create_seed},
Expand Down Expand Up @@ -78,6 +78,16 @@ fn main() {
// Generating proofs for each trace
let mut outer_timer = Measurer::new();
for (trace_name, trace) in traces {
let tx_count = trace.transactions.len();
if tx_count > MAX_TXS {
panic!(
"{}",
format!(
"too many transactions. MAX_TXS: {}, given transactions: {}",
MAX_TXS, tx_count
)
);
}
let mut out_dir = PathBuf::from(&trace_name);
fs::create_dir_all(&out_dir).unwrap();

Expand Down
3 changes: 1 addition & 2 deletions prover-server/src/mock_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ async fn test_request_proof(cli: HttpClient, proof_type: ProofType) -> bool {
async fn test_request_spec(cli: HttpClient) -> bool {
kroma_info("Send 'spec' request to prover-server");
let params = rpc_params![];
let response: String = cli.request("spec", params).await.unwrap();
let zk_spec: ZkSpec = serde_json::from_str(&response).unwrap();
let zk_spec: ZkSpec = cli.request("spec", params).await.unwrap();

kroma_info(format!(
"Got: \
Expand Down
49 changes: 39 additions & 10 deletions prover-server/src/server_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use crate::spec::ProofType;
use crate::utils::{kroma_err, kroma_info};
use clap::Parser;
use jsonrpc_derive::rpc;
use jsonrpc_http_server::jsonrpc_core::{ErrorCode, Result};
use jsonrpc_http_server::jsonrpc_core::Result;
use jsonrpc_http_server::ServerBuilder;
use spec::ZkSpec;
use types::eth::BlockTrace;

const KROMA_CHAIN_ID: u32 = 901;
use zkevm::circuit::{CHAIN_ID, MAX_TXS};

#[rpc]
pub trait Rpc {
Expand All @@ -28,7 +27,7 @@ pub trait Rpc {
/// 4. pub max_txs: u32,
/// 5. pub max_call_data: u32,
fn spec(&self) -> Result<ZkSpec> {
let spec = ZkSpec::new(KROMA_CHAIN_ID);
let spec = ZkSpec::new(*CHAIN_ID as u32);
Ok(spec)
}

Expand All @@ -48,21 +47,50 @@ impl Rpc for RpcImpl {
///
/// # Returns
/// ProofResult instance which includes proof and final pair.
fn prove(&self, trace: String, proof_type: i32) -> Result<ProofResult> {
fn prove(&self, trace: String, proof_type_val: i32) -> Result<ProofResult> {
// initiate ProofType
let proof_type = ProofType::from_value(proof_type_val);
if let ProofType::None = proof_type {
let msg = format!(
"invalid prove param: expected param from 1 to 4, but {:?}",
proof_type_val
);
kroma_err(&msg);
let err = jsonrpc_core::Error::invalid_params(msg);
return Err(err);
}

// initiate BlockTrace
let block_trace: BlockTrace = match serde_json::from_slice(trace.as_bytes()) {
Ok(trace) => trace,
Err(_) => {
kroma_err("invalid block trace.");
let err = jsonrpc_core::Error::new(ErrorCode::InvalidParams);
let err = jsonrpc_core::Error::invalid_params("invalid format trace");
return Err(err);
}
};

// initiate ProofType
let proof_type = ProofType::from_value(proof_type);
if let ProofType::None = proof_type {
let err = jsonrpc_core::Error::new(ErrorCode::InvalidParams);
// check number of txs in the trace
let tx_count = block_trace.transactions.len();
if tx_count > MAX_TXS {
let msg = format!(
"too many transactions. MAX_TXS: {}, given transactions: {}",
MAX_TXS, tx_count
);
kroma_err(&msg);
let err = jsonrpc_core::Error::invalid_params(msg);
return Err(err);
}

// check chain id
let trace_chain_id = block_trace.chain_id;
if *CHAIN_ID != trace_chain_id.as_u64() {
let msg = format!(
"not matched chain ids: expected({:?}), requested({:?})",
*CHAIN_ID, trace_chain_id
);
kroma_err(&msg);
let err = jsonrpc_core::Error::invalid_params(msg);
return Err(err);
}

Expand Down Expand Up @@ -103,6 +131,7 @@ fn main() {
kroma_info(format!("Prover server starting on {endpoint}"));
let server = ServerBuilder::new(io)
.threads(3)
.max_request_body_size(32_000_000)
.start_http(&endpoint.parse().unwrap())
.unwrap();

Expand Down
12 changes: 6 additions & 6 deletions zkevm/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const MAX_EXP_STEPS: usize = 10_000;
*/

////// params for degree = 20 ////////////
pub static DEGREE: Lazy<usize> = Lazy::new(|| read_env_var("DEGREE", 20));
pub const MAX_TXS: usize = 25;
pub static DEGREE: Lazy<usize> = Lazy::new(|| read_env_var("DEGREE", 21));
pub const MAX_TXS: usize = 100;
const MAX_INNER_BLOCKS: usize = 1;
pub const MAX_CALLDATA: usize = 400_000;
const MAX_RWS: usize = 1_000_000;
const MAX_KECCAK_ROWS: usize = 524_000;
const MAX_EXP_STEPS: usize = 10_000;
pub const MAX_CALLDATA: usize = 2_000_000;
const MAX_RWS: usize = 2_000_000;
const MAX_KECCAK_ROWS: usize = 1_000_000;
const MAX_EXP_STEPS: usize = 100_000;

pub static CHAIN_ID: Lazy<u64> = Lazy::new(|| read_env_var("CHAIN_ID", 2357));
pub static AGG_DEGREE: Lazy<usize> = Lazy::new(|| read_env_var("AGG_DEGREE", 26));
Expand Down