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

fix(raiko): removed panic stabilization #232

Merged
merged 31 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5542dff
chore(install): source env if sp1 bin not in path
35359595 May 17, 2024
b8a726b
chore: actual new line instead of `\n` symbols
35359595 May 17, 2024
cd05248
chore(log): tracing logs instead println; levels;
35359595 May 17, 2024
5ab3275
Merge branch 'main' of github.com:taikoxyz/raiko
35359595 May 17, 2024
a1ee3ae
Merge branch 'main'
35359595 May 17, 2024
902c56b
chore: debug assertinos print inline
35359595 May 17, 2024
48bc58f
chore: removed unnecesary re-init; prints in db;
35359595 May 17, 2024
65a6a8c
Merge branch 'main' of github.com:taikoxyz/raiko
35359595 May 17, 2024
91ca30d
Merge branch 'main'
35359595 May 17, 2024
d1a7929
chore: warnings and cfg fixes
35359595 May 17, 2024
ad5df3a
Merge branch 'main' of github.com:taikoxyz/raiko
35359595 May 21, 2024
b733aca
Merge branch 'main'
35359595 May 21, 2024
635e619
fix: check_eq instead of assert_eq
35359595 May 22, 2024
ecb1318
Merge branch 'chore/auto_logging' into fix/removed_panic_stabilization
35359595 May 22, 2024
549ddc3
console only progress tracking
Brechtpd May 24, 2024
6b3b701
fix
Brechtpd May 24, 2024
e24d7fc
feat: disable inplace print in container env
johntaiko May 24, 2024
eeb22e9
chore: error propagation; warning cleanups
35359595 May 27, 2024
7678116
Merge branch 'fix/removed_panic_stabilization' of github.com:taikoxyz…
35359595 May 27, 2024
57f556a
chore: error formatting
35359595 May 27, 2024
6847dc3
Merge branch 'main'
35359595 May 28, 2024
891f6fe
fix; merge conflict fixes
35359595 May 28, 2024
feeb210
chore: B256 instead of trait init; cleanup
35359595 May 28, 2024
1e9987c
Merge branch 'main' into chore/auto_logging
35359595 May 28, 2024
1716891
Merge branch 'chore/auto_logging' into fix/removed_panic_stabilization
35359595 May 28, 2024
44d60f5
chore: psto-merge fixes
35359595 May 28, 2024
cf5e32f
chore: error debug formatting added
35359595 May 28, 2024
cdc3d5c
fix: require_eq error printing; reduced clonning;
35359595 May 30, 2024
3b01ad1
fix: removed extra empty line; reverted home path;
35359595 May 30, 2024
84a86f3
chore: error propagation; warning cleanups
35359595 Jun 3, 2024
6d6e01d
chore: imports fixes
35359595 Jun 3, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{collections::HashMap, path::Path, str::FromStr};

use crate::{merge, prover::NativeProver};
use alloy_primitives::{Address, B256};
use clap::{Args, ValueEnum};
use raiko_lib::{
Expand All @@ -9,10 +8,9 @@ use raiko_lib::{
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::{serde_as, DisplayFromStr};
use std::{collections::HashMap, path::Path, str::FromStr};
use utoipa::ToSchema;

use crate::{merge, prover::NativeProver};

#[derive(Debug, thiserror::Error, ToSchema)]
pub enum RaikoError {
/// For invalid proof type generation request.
Expand Down Expand Up @@ -139,15 +137,15 @@ impl ProofType {
return sp1_driver::Sp1Prover::run(input, output, config)
.await
.map_err(|e| e.into());

#[cfg(not(feature = "sp1"))]
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return risc0_driver::Risc0Prover::run(input, output, config)
.await
.map_err(|e| e.into());

#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
ProofType::Sgx => {
Expand All @@ -156,6 +154,7 @@ impl ProofType {
.await
.map_err(|e| e.into());

#[cfg(not(feature = "sgx"))]
35359595 marked this conversation as resolved.
Show resolved Hide resolved
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
}
Expand Down
28 changes: 12 additions & 16 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use alloy_primitives::{Address, FixedBytes};
use crate::{
interfaces::{ProofRequest, RaikoError, RaikoResult},
preflight::preflight,
provider::BlockDataProvider,
};
use alloy_primitives::{Address, B256};
use alloy_rpc_types::EIP1186AccountProofResponse;
use raiko_lib::{
builder::{BlockBuilderStrategy, TaikoStrategy},
Expand All @@ -11,19 +14,14 @@ use raiko_lib::{
utils::HeaderHasher,
};
use serde_json::Value;
use tracing::{error, info, warn};
use std::collections::HashMap;
use tracing::{debug, error, info, warn};

pub mod interfaces;
pub mod preflight;
pub mod prover;
pub mod provider;

use crate::{
interfaces::{ProofRequest, RaikoError, RaikoResult},
preflight::preflight,
provider::BlockDataProvider,
};

pub type MerkleProof = HashMap<Address, EIP1186AccountProofResponse>;

pub struct Raiko {
Expand Down Expand Up @@ -68,6 +66,7 @@ impl Raiko {
Ok((header, _mpt_node)) => {
info!("Verifying final state using provider data ...");
info!("Final block hash derived successfully. {}", header.hash());
debug!("Final block header derived successfully. {header:?}");
info!("Final block header derived successfully. {header:?}");
let pi = ProtocolInstance::new(input, &header, VerifierType::None)?.instance_hash();

Expand Down Expand Up @@ -119,12 +118,9 @@ impl Raiko {
);

// Make sure the blockhash from the node matches the one from the builder
assert_eq!(
Into::<FixedBytes<32>>::into(header.hash().0),
input.block_hash_reference,
"block hash unexpected for block {}",
input.block_number,
);
if B256::from(header.hash().0) != input.block_hash_reference {
return Err(anyhow::Error::msg("block hash unexpected").into());
}
let output = GuestOutput::Success { header, hash: pi };

Ok(output)
Expand Down
39 changes: 24 additions & 15 deletions core/src/preflight.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::{
interfaces::{RaikoError, RaikoResult},
provider::{db::ProviderDb, rpc::RpcBlockDataProvider, BlockDataProvider},
};
use alloy_consensus::{
SignableTransaction, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy,
};
Expand All @@ -11,7 +15,9 @@ use raiko_lib::{
builder::{
prepare::TaikoHeaderPrepStrategy, BlockBuilder, OptimisticDatabase, TkoTxExecStrategy,
},
clear_line,
consts::ChainSpec,
inplace_print,
input::{
decode_anchor, proposeBlockCall, BlockProposed, GuestInput, TaikoGuestInput,
TaikoProverData,
Expand All @@ -25,12 +31,7 @@ use raiko_primitives::{
};
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, sync::Arc};
use tracing::{info, warn};

use crate::{
interfaces::{RaikoError, RaikoResult},
provider::{db::ProviderDb, rpc::RpcBlockDataProvider, BlockDataProvider},
};
use tracing::{debug, info, warn};

pub async fn preflight<BDP: BlockDataProvider>(
provider: BDP,
Expand Down Expand Up @@ -58,10 +59,13 @@ pub async fn preflight<BDP: BlockDataProvider>(
RaikoError::Preflight("No block hash for the requested block".to_string())
})?;

info!("\nblock.hash: {hash:?}");
info!("block.parent_hash: {:?}", block.header.parent_hash);
info!("block gas used: {:?}", block.header.gas_used);
info!("block transactions: {:?}", block.transactions.len());
info!(
"Processing block {:?} with block.hash: {:?}",
block.header.number, block.header.hash
);
debug!("block.parent_hash: {:?}", block.header.parent_hash);
debug!("block gas used: {:?}", block.header.gas_used);
debug!("block transactions: {:?}", block.transactions.len());

let taiko_guest_input = if taiko_chain_spec.is_taiko() {
prepare_taiko_chain_input(
Expand Down Expand Up @@ -162,14 +166,17 @@ pub async fn preflight<BDP: BlockDataProvider>(
let mut done = false;
let mut num_iterations = 0;
while !done {
info!("Execution iteration {num_iterations}...");
inplace_print(&format!("Execution iteration {num_iterations}..."));
builder.mut_db().unwrap().optimistic = num_iterations + 1 < max_iterations;
builder = builder.execute_transactions::<TkoTxExecStrategy>()?;
if builder.mut_db().unwrap().fetch_data().await {
done = true;
}
num_iterations += 1;
}
clear_line();
println!("State data fetched in {num_iterations} iterations");

let provider_db = builder.mut_db().unwrap();

// Gather inclusion proofs for the initial and final state
Expand Down Expand Up @@ -233,8 +240,10 @@ async fn prepare_taiko_chain_input(
let l1_state_block_number = anchor_call.l1BlockId;
let l1_inclusion_block_number = l1_state_block_number + 1;

info!("anchor L1 block id: {:?}", anchor_call.l1BlockId);
info!("anchor L1 state root: {:?}", anchor_call.l1StateRoot);
debug!(
"anchor L1 block id: {:?}\nanchor L1 state root: {:?}",
anchor_call.l1BlockId, anchor_call.l1StateRoot
);

// Get the L1 block in which the L2 block was included so we can fetch the DA data.
// Also get the L1 state block header so that we can prove the L1 state root.
Expand All @@ -250,7 +259,7 @@ async fn prepare_taiko_chain_input(
RaikoError::Preflight("No L1 state block hash for the requested block".to_owned())
})?;

info!("l1_state_root_block hash: {l1_state_block_hash:?}");
debug!("l1_state_root_block hash: {l1_state_block_hash:?}");

let l1_inclusion_block_hash = l1_inclusion_block.header.hash.ok_or_else(|| {
RaikoError::Preflight("No L1 inclusion block hash for the requested block".to_owned())
Expand All @@ -267,7 +276,7 @@ async fn prepare_taiko_chain_input(

// Fetch the tx data from either calldata or blobdata
let (tx_data, tx_blob_hash) = if proposal_event.meta.blobUsed {
info!("blob active");
debug!("blob active");
// Get the blob hashes attached to the propose tx
let blob_hashes = proposal_tx.blob_versioned_hashes.unwrap_or_default();
assert!(!blob_hashes.is_empty());
Expand Down
16 changes: 10 additions & 6 deletions core/src/provider/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::HashMap;

use alloy_primitives::{Address, Bytes, StorageKey, Uint, U256};
use alloy_provider::{ProviderBuilder, ReqwestProvider, RootProvider};
use alloy_rpc_client::{ClientBuilder, RpcClient};
use alloy_rpc_types::{Block, BlockId, BlockNumberOrTag, EIP1186AccountProofResponse};
use alloy_transport_http::Http;
use raiko_lib::{clear_line, inplace_print};
use raiko_lib::clear_line;
use reqwest_alloy::Client;
use revm::primitives::{AccountInfo, Bytecode};
use std::collections::HashMap;
use tracing::trace;

use crate::{
interfaces::{RaikoError, RaikoResult},
Expand Down Expand Up @@ -228,9 +228,13 @@ impl BlockDataProvider for RpcBlockDataProvider {

let batch_limit = 1000;
while !accounts.is_empty() {
inplace_print(&format!(
"fetching storage proof {idx}/{num_storage_proofs}..."
));
if cfg!(debug_assertions) {
raiko_lib::inplace_print(&format!(
"fetching storage proof {idx}/{num_storage_proofs}..."
));
} else {
trace!("Fetching storage proof {idx}/{num_storage_proofs}...");
}

// Create a batch for all storage proofs
let mut batch = self.client.new_batch();
Expand Down
2 changes: 2 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -xeo pipefail

export IN_CONTAINER=1

GRAMINE_PRIV_KEY="$HOME/.config/gramine/enclave-key.pem"
RAIKO_DOCKER_VOLUME_PATH="/root/.config/raiko"
RAIKO_DOCKER_VOLUME_CONFIG_PATH="$RAIKO_DOCKER_VOLUME_PATH/config"
Expand Down
7 changes: 4 additions & 3 deletions host/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![allow(incomplete_features)]
use std::path::PathBuf;

use raiko_host::{interfaces::HostResult, server::serve, ProverState};
use tracing::info;
use std::path::PathBuf;
use tracing::{debug, info};
use tracing_appender::{
non_blocking::WorkerGuard,
rolling::{Builder, Rotation},
Expand All @@ -18,6 +17,8 @@ async fn main() -> HostResult<()> {
&state.opts.log_level,
state.opts.max_log,
);
debug!("Start config:\n{:#?}", state.opts.proof_request_opt);
debug!("Args:\n{:#?}", state.opts);

info!("Supported chains: {:?}", state.chain_specs);
info!("Start config:\n{:#?}", state.opts.proof_request_opt);
Expand Down
4 changes: 2 additions & 2 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl ProverState {
}

mod memory {
use tracing::info;
use tracing::debug;

use crate::ALLOCATOR;

Expand All @@ -165,7 +165,7 @@ mod memory {

pub(crate) fn print_stats(title: &str) {
let max_memory = get_max_allocated();
info!(
debug!(
"{title}{}.{:06} MB",
max_memory / 1_000_000,
max_memory % 1_000_000
Expand Down
10 changes: 4 additions & 6 deletions host/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::{net::SocketAddr, str::FromStr};

use crate::{interfaces::HostError, server::api::create_router, ProverState};
use anyhow::Context;
use std::{net::SocketAddr, str::FromStr};
use tokio::net::TcpListener;
use tracing::debug;

use crate::{interfaces::HostError, server::api::create_router, ProverState};
use tracing::info;

pub mod api;

Expand All @@ -14,7 +12,7 @@ pub async fn serve(state: ProverState) -> anyhow::Result<()> {
.map_err(|_| HostError::InvalidAddress(state.opts.address.clone()))?;
let listener = TcpListener::bind(addr).await?;

debug!("Listening on: {}", listener.local_addr()?);
info!("Listening on: {}", listener.local_addr()?);

let router = create_router(
state.opts.concurrency_limit,
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ hex = { workspace = true }
c-kzg = { workspace = true }
sha2 = { workspace = true }
cfg-if = { workspace = true }
tracing = { workspace = true }

# [target.'cfg(feature = "std")'.dependencies]
thiserror = { workspace = true, optional = true }
Expand Down
Loading
Loading