Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft committed Jan 12, 2025
1 parent 369a7ce commit a33c801
Show file tree
Hide file tree
Showing 9 changed files with 983 additions and 1,049 deletions.
1,588 changes: 720 additions & 868 deletions Cargo.lock

Large diffs are not rendered by default.

42 changes: 8 additions & 34 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,20 @@ mod tests {
.parse()
.unwrap();
let provider = if v2_preflight {
let provider: RethPreflightBlockDataProvider = RethPreflightBlockDataProvider::new(
let mut provider: RethPreflightBlockDataProvider = RethPreflightBlockDataProvider::new(
&taiko_chain_spec.rpc.clone(),
proof_request.block_number - 1,
)
.await
.expect("new RethPreflightBlockDataProvider should be ok");
provider.fetch_preflight_data().await.unwrap();
BlockDataProviderType::PreflightRpc(provider)
} else {
let provider = RpcBlockDataProvider::new(
&taiko_chain_spec.rpc.clone(),
taiko_chain_spec.preflight_rpc.clone(),
proof_request.block_number - 1,
)
.await
.expect("new RpcBlockDataProvider should be ok");
BlockDataProviderType::CommonRpc(provider)
};
Expand All @@ -366,36 +368,6 @@ mod tests {
.expect("proof generation failed")
}

#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_taiko_dev() {
let proof_type = get_proof_type_from_env();
let l1_network = "taiko_dev_l1".to_owned();
let network = "taiko_dev".to_owned();
// Give the CI an simpler block to test because it doesn't have enough memory.
// Unfortunately that also means that kzg is not getting fully verified by CI.
let block_number = 20;
let chain_specs = SupportedChainSpecs::merge_from_file(
"../host/config/chain_spec_list_devnet.json".into(),
)
.unwrap();
let taiko_chain_spec = chain_specs.get_chain_spec(&network).unwrap();
let l1_chain_spec = chain_specs.get_chain_spec(&l1_network).unwrap();

let proof_request = ProofRequest {
block_number,
l1_inclusion_block_number: 80,
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
l1_network,
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(false),
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_taiko_a7() {
let _ = env_logger::builder().is_test(true).try_init();
Expand All @@ -405,7 +377,7 @@ mod tests {
let network = Network::TaikoA7.to_string();
// Give the CI an simpler block to test because it doesn't have enough memory.
// Unfortunately that also means that kzg is not getting fully verified by CI.
let block_number = if is_ci() { 105987 } else { 101368 };
let block_number = if is_ci() { 105987 } else { 0x110e68 };
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&network)
.unwrap();
Expand All @@ -428,7 +400,9 @@ mod tests {
}

async fn get_recent_block_num(chain_spec: &ChainSpec) -> u64 {
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, 0).unwrap();
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, None, 0)
.await
.unwrap();
let height = provider.provider.get_block_number().await.unwrap();
height - 100
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/preflight/reth_preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use alloy_rpc_types::eth::{
Block as AlloyEthBlock, EIP1186AccountProofResponse, Header as AlloyEthHeader,
};
use raiko_lib::{
builder::RethBlockBuilder,
input::{GuestInput},
primitives::mpt::proofs_to_tries,
Measurement,
builder::RethBlockBuilder, input::GuestInput, primitives::mpt::proofs_to_tries, Measurement,
};
use serde::{Deserialize, Serialize};
use tracing::error;
Expand All @@ -23,6 +20,7 @@ use crate::preflight::util::{

/// `PreFlightRpcData` is the pre-flight data for the proving process.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PreFlightRpcData {
/// The block to be proven.
// pub block: alloy_rpc_types_eth::Block,
Expand Down
2 changes: 1 addition & 1 deletion core/src/preflight/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub async fn prepare_taiko_chain_input(

// // 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.
let provider_l1 = RpcBlockDataProvider::new(&l1_chain_spec.rpc, block_number)?;
let provider_l1 = RpcBlockDataProvider::new(&l1_chain_spec.rpc, None, block_number).await?;

info!("current taiko chain fork: {fork:?}");

Expand Down
3 changes: 2 additions & 1 deletion core/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub async fn get_task_data(
let taiko_chain_spec = chain_specs
.get_chain_spec(network)
.ok_or_else(|| RaikoError::InvalidRequestConfig("Unsupported raiko network".to_string()))?;
let provider = RpcBlockDataProvider::new(&taiko_chain_spec.rpc.clone(), block_number - 1)?;
let provider =
RpcBlockDataProvider::new(&taiko_chain_spec.rpc.clone(), None, block_number - 1).await?;
let blocks = provider.get_blocks(&[(block_number, false)]).await?;
let block = blocks
.first()
Expand Down
98 changes: 60 additions & 38 deletions core/src/provider/preflight_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_primitives::{Address, FixedBytes, U256};
use alloy_provider::{ProviderBuilder, ReqwestProvider, RootProvider};
use alloy_rpc_client::{ClientBuilder, RpcClient};
use alloy_rpc_types::{Block, BlockId, BlockNumberOrTag};
use alloy_rpc_types::{Block, BlockNumberOrTag};
use alloy_transport_http::Http;
use reqwest_alloy::Client;
use reth_primitives::revm_primitives::{AccountInfo, Bytecode};
Expand All @@ -25,24 +25,17 @@ pub struct RethPreflightBlockDataProvider {
}

impl RethPreflightBlockDataProvider {
pub async fn new(url: &str, parent_block_num: u64) -> RaikoResult<Self> {
pub fn new(url: &str, parent_block_num: u64) -> RaikoResult<Self> {
let url =
reqwest::Url::parse(url).map_err(|_| RaikoError::RPC("Invalid RPC URL".to_owned()))?;

let client = ClientBuilder::default().http(url.clone());
let preflight_data = client
.request(
"taiko_provingPreflight",
&(BlockId::from(parent_block_num + 1)),
)
.await
.map_err(|e| RaikoError::RPC(format!("Error getting preflight data: {e}")))?;

Ok(Self {
provider: ProviderBuilder::new().on_provider(RootProvider::new_http(url.clone())),
client,
parent_block_num,
preflight_data,
preflight_data: None,
})
}

Expand All @@ -57,6 +50,17 @@ impl RethPreflightBlockDataProvider {
pub fn provider(&self) -> &ReqwestProvider {
&self.provider
}

pub async fn fetch_preflight_data(&mut self) -> RaikoResult<()> {
let curr_block_num_hex = format!("0x{:x}", self.parent_block_num + 1);
let preflight_data = self
.client
.request("taiko_provingPreflight", vec![curr_block_num_hex])
.await
.map_err(|e| RaikoError::RPC(format!("Error getting preflight data: {e}")))?;
self.preflight_data = Some(preflight_data);
Ok(())
}
}

impl BlockDataProvider for RethPreflightBlockDataProvider {
Expand Down Expand Up @@ -110,26 +114,44 @@ impl BlockDataProvider for RethPreflightBlockDataProvider {

let preflight_data = self.preflight_data.as_ref().unwrap();
let mut all_accounts: Vec<AccountInfo> = Vec::with_capacity(accounts.len());
preflight_data
.parent_account_proofs
.iter()
.for_each(|account_proof| {
let balance = account_proof.balance;
let nonce = account_proof.nonce;
let code_hash = account_proof.code_hash;
let code = preflight_data
.contracts
.get(&account_proof.code_hash)
.map(|code| Bytecode::new_raw(code.clone()))
.unwrap();
assert_eq!(code_hash, code.hash_slow());
all_accounts.push(AccountInfo::new(
balance,
nonce.as_limbs()[0],
code_hash,
code,
))
});
let none_place_holder = alloy_rpc_types::EIP1186AccountProofResponse::default();
let none_byte_holder = reth_primitives::Bytes::default();
accounts.iter().for_each(|address| {
let account_proof: &alloy_rpc_types::EIP1186AccountProofResponse = match preflight_data
.parent_account_proofs
.iter()
.find(|account_proof| {
account_proof.address.to_checksum(None) == address.to_checksum(None)
}) {
Some(account_proof) => account_proof,
None => {
println!(
"Unable to find account proof for address {} in {:?} parent account proofs",
address.to_checksum(None),
&preflight_data
.parent_account_proofs
.iter()
.map(|a| a.address.to_checksum(None))
.collect::<Vec<_>>()
);
&none_place_holder
}
};

all_accounts.push(AccountInfo::new(
account_proof.balance,
account_proof.nonce.as_limbs()[0],
account_proof.code_hash,
Bytecode::new_raw(
preflight_data
.contracts
.get(&account_proof.code_hash)
.or(Some(&none_byte_holder))
.unwrap()
.clone(),
),
));
});
Ok(all_accounts)
}

Expand All @@ -143,7 +165,9 @@ impl BlockDataProvider for RethPreflightBlockDataProvider {
let storage_proof = preflight_data
.parent_account_proofs
.iter()
.find(|account_proof| account_proof.address == *address)
.find(|account_proof| {
account_proof.address.to_checksum(None) == address.to_checksum(None)
})
.and_then(|account_proof| {
account_proof
.storage_proof
Expand All @@ -155,9 +179,9 @@ impl BlockDataProvider for RethPreflightBlockDataProvider {
all_values.push(storage_proof.value);
} else {
error!("Unable to find storage proof for address {address} and key {key}");
return Err(RaikoError::RPC(format!(
"Unable to find storage proof for address {address} and key {key}"
)));
// return Err(RaikoError::RPC(format!(
// "Unable to find storage proof for address {address} and key {key}"
// )));
}
}
Ok(all_values)
Expand All @@ -170,7 +194,7 @@ impl BlockDataProvider for RethPreflightBlockDataProvider {
_offset: usize,
num_storage_proofs: usize,
) -> RaikoResult<MerkleProof> {
if block_number != self.parent_block_num || block_number != self.parent_block_num + 1 {
if block_number != self.parent_block_num && block_number != self.parent_block_num + 1 {
return Err(RaikoError::RPC(format!(
"Block number {block_number} does not match preflight block number {:?} or its parent", self.parent_block_num
)));
Expand Down Expand Up @@ -219,9 +243,7 @@ mod test {
#[tokio::test]
async fn test_preflight_rpc() {
let preflight_rpc_provider =
RethPreflightBlockDataProvider::new("http://localhost:8545", 0)
.await
.unwrap();
RethPreflightBlockDataProvider::new("http://localhost:8545", 0).unwrap();

let blocks: Vec<alloy_rpc_types::Block> = preflight_rpc_provider
.get_blocks(&[(0, true)])
Expand Down
Loading

0 comments on commit a33c801

Please sign in to comment.