Skip to content

Commit

Permalink
Merge branch 'main' into cancel-api
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jul 16, 2024
2 parents 5f35417 + 9568634 commit 91ac590
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
!/provers/sgx/setup
!/kzg_settings_raw.bin
!/core
!/task_manager
!/tasks
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
"provers/sgx/setup",
"pipeline",
"core",
"task_manager",
"tasks",
]

# Always optimize; building and running the guest takes much longer without optimization.
Expand All @@ -36,7 +36,7 @@ opt-level = 3
# raiko
raiko-lib = { path = "./lib", features = ["std"] }
raiko-core = { path = "./core" }
raiko-task-manager = { path = "./task_manager" }
raiko-tasks = { path = "./tasks" }

# reth
reth-primitives = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false, features = [
Expand Down
19 changes: 17 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod tests {
ChainSpec, Raiko,
};
use alloy_primitives::Address;
use alloy_provider::Provider;
use clap::ValueEnum;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
Expand Down Expand Up @@ -300,20 +301,30 @@ mod tests {
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}

async fn get_recent_block_num(chain_spec: &ChainSpec) -> u64 {
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, 0).unwrap();
let height = provider.provider.get_block_number().await.unwrap();
height - 100
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_ethereum() {
let proof_type = get_proof_type_from_env();
// Skip test on SP1 for now because it's too slow on CI
if !(is_ci() && proof_type == ProofType::Sp1) {
let network = Network::Ethereum.to_string();
let l1_network = Network::Ethereum.to_string();
let block_number = 19907175;
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&network)
.unwrap();
let l1_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&l1_network)
.unwrap();
let block_number = get_recent_block_num(&taiko_chain_spec).await;
println!(
"test_prove_block_ethereum in block_number: {}",
block_number
);
let proof_request = ProofRequest {
block_number,
network,
Expand All @@ -335,13 +346,17 @@ mod tests {
if !(is_ci() && proof_type == ProofType::Sp1) {
let network = Network::TaikoMainnet.to_string();
let l1_network = Network::Ethereum.to_string();
let block_number = 88970;
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&network)
.unwrap();
let l1_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&l1_network)
.unwrap();
let block_number = get_recent_block_num(&taiko_chain_spec).await;
println!(
"test_prove_block_taiko_mainnet in block_number: {}",
block_number
);
let proof_request = ProofRequest {
block_number,
network,
Expand Down
2 changes: 1 addition & 1 deletion host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sgx-prover = { path = "../provers/sgx/prover", optional = true }
# raiko
raiko-lib = { workspace = true }
raiko-core = { workspace = true }
raiko-task-manager = { workspace = true }
raiko-tasks = { workspace = true }

# alloy
alloy-rlp = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion host/src/interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::response::IntoResponse;
use raiko_core::interfaces::ProofType;
use raiko_lib::prover::ProverError;
use raiko_task_manager::{TaskManagerError, TaskStatus};
use raiko_tasks::{TaskManagerError, TaskStatus};
use tokio::sync::mpsc::error::TrySendError;
use utoipa::ToSchema;

Expand Down
2 changes: 1 addition & 1 deletion host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use raiko_core::{
merge,
};
use raiko_lib::consts::SupportedChainSpecs;
use raiko_task_manager::{get_task_manager, TaskDescriptor, TaskManagerOpts, TaskManagerWrapper};
use raiko_tasks::{get_task_manager, TaskDescriptor, TaskManagerOpts, TaskManagerWrapper};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::sync::mpsc;
Expand Down
2 changes: 1 addition & 1 deletion host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use raiko_core::{
Raiko,
};
use raiko_lib::{consts::SupportedChainSpecs, Measurement};
use raiko_task_manager::{get_task_manager, TaskDescriptor, TaskManager, TaskStatus};
use raiko_tasks::{get_task_manager, TaskDescriptor, TaskManager, TaskStatus};
use tokio::{
select,
sync::{mpsc::Receiver, Mutex, Semaphore},
Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{response::IntoResponse, Json, Router};
use raiko_task_manager::TaskStatus;
use raiko_tasks::TaskStatus;
use serde::{Serialize, Serializer};
use utoipa::{OpenApi, ToSchema};
use utoipa_scalar::{Scalar, Servable};
Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/cancel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_core::{interfaces::ProofRequest, provider::get_task_data};
use raiko_task_manager::{TaskDescriptor, TaskManager, TaskStatus};
use raiko_tasks::{TaskDescriptor, TaskManager, TaskStatus};
use serde_json::Value;
use utoipa::OpenApi;

Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_core::{interfaces::ProofRequest, provider::get_task_data};
use raiko_task_manager::{TaskDescriptor, TaskManager, TaskStatus};
use raiko_tasks::{TaskDescriptor, TaskManager, TaskStatus};
use serde_json::Value;
use utoipa::OpenApi;

Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/prune.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{debug_handler, extract::State, routing::post, Router};
use raiko_task_manager::TaskManager;
use raiko_tasks::TaskManager;
use utoipa::OpenApi;

use crate::{interfaces::HostResult, server::api::v2::PruneStatus, ProverState};
Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/report.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{debug_handler, extract::State, routing::get, Json, Router};
use raiko_task_manager::TaskManager;
use raiko_tasks::TaskManager;
use serde_json::Value;
use utoipa::OpenApi;

Expand Down
3 changes: 2 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ std = [
sgx = []
sp1 = []
risc0 = []
sp1-cycle-tracker = []
sp1-cycle-tracker = []
proof_of_equivalence = []
8 changes: 4 additions & 4 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ impl TryFrom<Vec<TransactionSigned>> for TaikoGuestInput {

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub enum BlobProofType {
/// Guest runs through the entire computation from blob to Kzg commitment
/// then to version hash
#[default]
ProofOfCommitment,
/// Simplified Proof of Equivalence with fiat input in non-aligned field
/// Referencing https://notes.ethereum.org/@dankrad/kzg_commitments_in_proofs
/// with impl details in https://github.com/taikoxyz/raiko/issues/292
/// Guest proves the KZG evaluation of the a fiat-shamir input x and output result y
/// x = sha256(sha256(blob), kzg_commit(blob))
/// y = f(x)
/// where f is the KZG polynomial
#[default]
ProofOfEquivalence,
/// Guest runs through the entire computation from blob to Kzg commitment
/// then to version hash
ProofOfCommitment,
}

impl FromStr for BlobProofType {
Expand Down
26 changes: 16 additions & 10 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,22 @@ impl ProtocolInstance {
pub fn instance_hash(&self) -> B256 {
// packages/protocol/contracts/verifiers/libs/LibPublicInput.sol
// "VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash
let mut data = (
let data = (
"VERIFY_PROOF",
self.chain_id,
self.verifier_address,
self.transition.clone(),
self.sgx_instance,
self.prover,
self.meta_hash(),
#[cfg(feature = "proof_of_equivalence")]
self.proof_of_equivalence,
)
.abi_encode();
if self.sgx_instance != Address::default() {
data = data.iter().copied().skip(32).collect::<Vec<u8>>();
}
.abi_encode()
.iter()
.skip(32)
.copied()
.collect::<Vec<u8>>();
keccak(data).into()
}
}
Expand All @@ -188,11 +190,15 @@ fn get_blob_proof_type(
proof_type: VerifierType,
blob_proof_type_hint: BlobProofType,
) -> BlobProofType {
match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::ProofOfCommitment,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
if cfg!(feature = "proof_of_equivalence") {
match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::ProofOfCommitment,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
}
} else {
BlobProofType::ProofOfCommitment
}
}

Expand Down
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_guest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_GUEST_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
pub const RISC0_GUEST_ID: [u32; 8] = [
3656027178, 4281856604, 2184891755, 3275826590, 1143313757, 1779451290, 3242125827, 14009949,
1914784930, 3634152083, 2963332796, 2630159414, 3104046433, 3092402903, 3447446567, 3034579556,
];
Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.
6 changes: 3 additions & 3 deletions task_manager/Cargo.toml → tasks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "raiko-task-manager"
name = "raiko-tasks"
version = "0.1.0"
authors = ["Mamy Ratsimbazafy <mamy $at$ taiko.xyz>"]
authors = ["Taiko Labs"]
edition = "2021" # { workspace = true }

[dependencies]
Expand Down Expand Up @@ -33,5 +33,5 @@ sqlite = []
in-memory = []

[[test]]
name = "task_manager_tests"
name = "tasks_tests"
path = "tests/main.rs"
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion task_manager/tests/main.rs → tasks/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
use rand_chacha::ChaCha8Rng;

use raiko_lib::{input::BlobProofType, primitives::B256};
use raiko_task_manager::{get_task_manager, TaskManager, TaskManagerOpts, TaskStatus};
use raiko_tasks::{get_task_manager, TaskManager, TaskManagerOpts, TaskStatus};

fn create_random_task(rng: &mut ChaCha8Rng) -> (u64, B256, ProofRequest) {
let chain_id = 100;
Expand Down

0 comments on commit 91ac590

Please sign in to comment.