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 14 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.

8 changes: 3 additions & 5 deletions host/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(incomplete_features)]
use std::path::PathBuf;

use raiko_host::{interfaces::error::HostResult, server::serve, ProverState};
use std::path::PathBuf;
use tracing::debug;
use tracing_appender::{
non_blocking::WorkerGuard,
Expand All @@ -13,14 +12,13 @@ use tracing_subscriber::FmtSubscriber;
async fn main() -> HostResult<()> {
env_logger::init();
let state = ProverState::init()?;
debug!("Start config:\n{:#?}", state.opts.proof_request_opt);
debug!("Args:\n{:#?}", state.opts);

let _guard = subscribe_log(
&state.opts.log_path,
&state.opts.log_level,
state.opts.max_log,
);
debug!("Start config:\n{:#?}", state.opts.proof_request_opt);
debug!("Args:\n{:#?}", state.opts);

serve(state).await?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions host/src/interfaces/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ impl ProofType {
return sp1_driver::Sp1Prover::run(input, output, config)
.await
.map_err(|e| e.into());

#[cfg(not(feature = "sp1"))]
Err(HostError::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(HostError::FeatureNotSupportedError(self.clone()))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return sgx_prover::SgxProver::run(input, output, config)
.await
.map_err(|e| e.into());

#[cfg(not(feature = "sgx"))]
Err(HostError::FeatureNotSupportedError(self.clone()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ProverState {
}

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

use crate::ALLOCATOR;

Expand All @@ -184,7 +184,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
34 changes: 19 additions & 15 deletions host/src/preflight.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::{
interfaces::error::{HostError, HostResult},
provider::{db::ProviderDb, rpc::RpcBlockDataProvider, BlockDataProvider},
};
use alloy_consensus::{
SignableTransaction, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy,
};
Expand Down Expand Up @@ -25,12 +29,7 @@ use raiko_primitives::{
};
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, sync::Arc};
use tracing::{info, warn};

use crate::{
interfaces::error::{HostError, HostResult},
provider::{db::ProviderDb, rpc::RpcBlockDataProvider, BlockDataProvider},
};
use tracing::{debug, info, warn};

pub async fn preflight<BDP: BlockDataProvider>(
provider: BDP,
Expand Down Expand Up @@ -59,10 +58,13 @@ pub async fn preflight<BDP: BlockDataProvider>(
.hash
.ok_or_else(|| HostError::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 @@ -165,7 +167,7 @@ pub async fn preflight<BDP: BlockDataProvider>(
let mut done = false;
let mut num_iterations = 0;
while !done {
info!("Execution iteration {num_iterations}...");
debug!("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 {
Expand Down Expand Up @@ -236,8 +238,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 @@ -253,7 +257,7 @@ async fn prepare_taiko_chain_input(
HostError::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(|| {
HostError::Preflight("No L1 inclusion block hash for the requested block".to_owned())
Expand All @@ -270,7 +274,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
13 changes: 9 additions & 4 deletions host/src/provider/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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::error::{HostError, HostResult},
Expand Down Expand Up @@ -227,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
13 changes: 6 additions & 7 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use raiko_lib::protocol_instance::{assemble_protocol_instance, ProtocolInstance}
use raiko_lib::prover::{to_proof, Proof, Prover, ProverError, ProverResult};
use raiko_lib::utils::HeaderHasher;
use serde::{Deserialize, Serialize};
use tracing::{error, info, trace, warn};
use tracing::{debug, error, info, trace, warn};

use crate::preflight::preflight;
use crate::{
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Raiko {
Ok((header, _mpt_node)) => {
info!("Verifying final state using provider data ...");
info!("Final block hash derived successfully. {}", header.hash());
info!("Final block header derived successfully. {header:?}");
debug!("Final block header derived successfully. {header:?}");
let pi = self
.request
.proof_type
Expand Down Expand Up @@ -113,11 +113,10 @@ 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,
check_eq(
&Into::<FixedBytes<32>>::into(header.hash().0),
&input.block_hash_reference,
"block hash unexpected",
);
35359595 marked this conversation as resolved.
Show resolved Hide resolved
let output = GuestOutput::Success { header, hash: pi };

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::error::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::error::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).with_state(state);
axum::serve(listener, router)
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
16 changes: 10 additions & 6 deletions lib/src/builder/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use core::{fmt::Debug, mem::take, str::from_utf8};
use std::collections::HashSet;

use alloy_consensus::{constants::BEACON_ROOTS_ADDRESS, TxEnvelope};
use alloy_primitives::{TxKind, U256};
use anyhow::{anyhow, bail, ensure, Context, Error, Result};
use core::{fmt::Debug, mem::take, str::from_utf8};
#[cfg(feature = "std")]
use log::debug;
use raiko_primitives::{
Expand All @@ -32,6 +30,8 @@ use revm::{
},
taiko, Database, DatabaseCommit, Evm, JournaledState,
};
use std::collections::HashSet;
use tracing::trace;
cfg_if::cfg_if! {
if #[cfg(feature = "tracer")] {
use std::{fs::{OpenOptions, File}, io::{BufWriter, Write}, sync::{Arc, Mutex}};
Expand Down Expand Up @@ -82,7 +82,7 @@ impl TxExecStrategy for TkoTxExecStrategy {
let chain_spec = &block_builder.input.chain_spec;
let chain_id = chain_spec.chain_id();
let is_taiko = chain_spec.is_taiko();
println!("spec_id: {spec_id:?}");
trace!("spec_id: {spec_id:?}");

// generate the transactions from the tx list
// For taiko blocks, insert the anchor tx as the first transaction
Expand Down Expand Up @@ -175,7 +175,11 @@ impl TxExecStrategy for TkoTxExecStrategy {
let mut actual_tx_no = 0usize;
let num_transactions = transactions.len();
for (tx_no, tx) in take(&mut transactions).into_iter().enumerate() {
inplace_print(&format!("\rprocessing tx {tx_no}/{num_transactions}..."));
if cfg!(debug_assertions) {
inplace_print(&format!("\rprocessing tx {tx_no}/{num_transactions}..."));
} else {
trace!("\rprocessing tx {tx_no}/{num_transactions}...");
}

#[cfg(feature = "tracer")]
let trace = set_trace_writer(
Expand Down Expand Up @@ -283,7 +287,7 @@ impl TxExecStrategy for TkoTxExecStrategy {
}
};
#[cfg(feature = "std")]
debug!(" Ok: {result:?}");
trace!(" Ok: {result:?}");

#[cfg(feature = "tracer")]
// Flush the trace writer
Expand Down
10 changes: 6 additions & 4 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod no_std {
};
}

use tracing::debug;

pub mod builder;
pub mod consts;
pub mod input;
Expand Down Expand Up @@ -91,11 +93,11 @@ pub struct Measurement {
impl Measurement {
pub fn start(title: &str, inplace: bool) -> Measurement {
if inplace {
print!("{title}");
debug!("{title}");
#[cfg(feature = "std")]
io::stdout().flush().unwrap();
} else if !title.is_empty() {
println!("{title}");
debug!("{title}");
}

Self {
Expand Down Expand Up @@ -124,7 +126,7 @@ impl Measurement {
}

pub fn print_duration(title: &str, duration: time::Duration) {
println!(
debug!(
"{title}{}.{:03} seconds",
duration.as_secs(),
duration.subsec_millis()
Expand All @@ -133,7 +135,7 @@ pub fn print_duration(title: &str, duration: time::Duration) {

pub fn inplace_print(title: &str) {
print!("\r{title}");
#[cfg(feature = "std")]
#[cfg(all(feature = "std", debug_assertions))]
io::stdout().flush().unwrap();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::{ensure, Result};
use c_kzg::{Blob, KzgCommitment, KzgSettings};
use raiko_primitives::keccak::keccak;
use sha2::{Digest as _, Sha256};
use tracing::debug;

use super::utils::ANCHOR_GAS_LIMIT;
#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -96,10 +97,10 @@ pub fn assemble_protocol_instance(
let blob_used = input.taiko.block_proposed.meta.blobUsed;
let tx_list_hash = if blob_used {
if input.taiko.skip_verify_blob {
println!("kzg check disabled!");
debug!("kzg check disabled!");
input.taiko.tx_blob_hash.unwrap()
} else {
println!("kzg check enabled!");
debug!("kzg check enabled!");
let mut data = Vec::from(KZG_TRUST_SETUP_DATA);
let kzg_settings = KzgSettings::from_u8_slice(&mut data);
let kzg_commit = KzgCommitment::blob_to_kzg_commitment(
Expand Down Expand Up @@ -263,7 +264,6 @@ mod tests {
.skip(32)
.collect::<Vec<u8>>(),
);
// println!("pi_hash: {:?}", hex::encode(pi_hash));
assert_eq!(
hex::encode(pi_hash),
"4a7ba84010036277836eaf99acbbc10dc5d8ee9063e2e3c5be5e8be39ceba8ae"
Expand Down
2 changes: 1 addition & 1 deletion script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fi
if [ -z "$1" ] || [ "$1" == "sp1" ]; then
curl -L https://sp1.succinct.xyz | bash

if [ -z "${CI}" ]; then
if [ -z "${CI}" ] || [ ! command -v sp1up &> /dev/null ]; then
# Need to add sp1up to the path here
PROFILE=$HOME/.bashrc
echo ${PROFILE}
Expand Down
2 changes: 1 addition & 1 deletion script/prove-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ for block in $(eval echo {$rangeStart..$rangeEnd}); do
\"graffiti\": \"$graffiti\",
$proofParam
}"
echo "\\n"
echo ""
done
Loading