Skip to content

Commit

Permalink
fix(core,host,sgx): fix compiler and clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Sep 17, 2024
1 parent 83d538b commit df758fa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
3 changes: 2 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ mod tests {
l1_network,
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(),
prover_args: test_proof_params(false),
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
Expand Down Expand Up @@ -456,6 +456,7 @@ mod tests {

let proof_request = ProofRequest {
block_number,
l1_inclusion_block_number: 0,
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
Expand Down
9 changes: 5 additions & 4 deletions core/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Prover for NativeProver {
}

Ok(Proof {
input: None,
proof: None,
quote: None,
})
Expand All @@ -68,10 +69,10 @@ impl Prover for NativeProver {
}

async fn aggregate(
input: raiko_lib::input::AggregationGuestInput,
output: &raiko_lib::input::AggregationGuestOutput,
config: &ProverConfig,
store: Option<&mut dyn IdWrite>,
_input: raiko_lib::input::AggregationGuestInput,
_output: &raiko_lib::input::AggregationGuestOutput,
_config: &ProverConfig,
_store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof> {
Ok(Proof {
..Default::default()
Expand Down
5 changes: 2 additions & 3 deletions host/src/server/api/v3/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use raiko_core::{
provider::get_task_data,
};
use raiko_tasks::{TaskDescriptor, TaskManager, TaskStatus};
use serde_json::Value;
use utoipa::OpenApi;

use crate::{interfaces::HostResult, server::api::v2::CancelStatus, Message, ProverState};
Expand All @@ -27,11 +26,11 @@ use crate::{interfaces::HostResult, server::api::v2::CancelStatus, Message, Prov
/// - risc0 - uses the risc0 prover
async fn cancel_handler(
State(prover_state): State<ProverState>,
Json(aggregation_request): Json<AggregationRequest>,
Json(mut aggregation_request): Json<AggregationRequest>,
) -> HostResult<CancelStatus> {
// Override the existing proof request config from the config file and command line
// options with the request from the client.
aggregation_request.merge(&prover_state.request_config());
aggregation_request.merge(&prover_state.request_config())?;

let proof_request_opts: Vec<ProofRequestOpt> = aggregation_request.into();

Expand Down
45 changes: 22 additions & 23 deletions host/src/server/api/v3/proof/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::str::FromStr;

use anyhow::anyhow;
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_core::{
interfaces::{AggregationRequest, ProofRequest, ProofRequestOpt, ProofType},
Expand All @@ -8,13 +9,12 @@ use raiko_core::{
use raiko_lib::input::{AggregationGuestInput, AggregationGuestOutput};
use raiko_tasks::{TaskDescriptor, TaskManager, TaskStatus};
use reth_primitives::B256;
use serde_json::Value;
use utoipa::OpenApi;

use crate::{
interfaces::HostResult,
metrics::{inc_current_req, inc_guest_req_count, inc_host_req_count},
server::api::v2::{self, Status},
server::api::{v2, v3::Status},
Message, ProverState,
};

Expand All @@ -38,16 +38,16 @@ mod cancel;
/// - risc0 - uses the risc0 prover
async fn proof_handler(
State(prover_state): State<ProverState>,
Json(aggregation_request): Json<AggregationRequest>,
Json(mut aggregation_request): Json<AggregationRequest>,
) -> HostResult<Status> {
inc_current_req();
// Override the existing proof request config from the config file and command line
// options with the request from the client.
aggregation_request.merge(&prover_state.request_config());
aggregation_request.merge(&prover_state.request_config())?;

let mut tasks = Vec::with_capacity(aggregation_request.block_numbers.len());

let proof_request_opts: Vec<ProofRequestOpt> = aggregation_request.into();
let proof_request_opts: Vec<ProofRequestOpt> = aggregation_request.clone().into();

// Construct the actual proof request from the available configs.
for proof_request_opt in proof_request_opts {
Expand Down Expand Up @@ -78,19 +78,16 @@ async fn proof_handler(
let mut is_registered = false;
let mut is_success = true;

let mut statuses = Vec::with_capacity(tasks.len());

for task in tasks {
let status = manager.get_task_proving_status(&task).await?;
for task in tasks.iter() {
let status = manager.get_task_proving_status(task).await?;

let Some((latest_status, ..)) = status.last() else {
// If there are no tasks with provided config, create a new one.
manager.enqueue_task(&task).await?;
manager.enqueue_task(task).await?;

prover_state
.task_channel
.try_send(Message::from(&aggregation_request))?;
prover_state.task_channel.try_send(Message::from(task))?;
is_registered = true;
continue;
};

match latest_status {
Expand All @@ -100,21 +97,18 @@ async fn proof_handler(
| TaskStatus::Cancelled_NeverStarted
| TaskStatus::CancellationInProgress => {
manager
.update_task_progress(task, TaskStatus::Registered, None)
.update_task_progress(task.clone(), TaskStatus::Registered, None)
.await?;

prover_state
.task_channel
.try_send(Message::from(&aggregation_request))?;
prover_state.task_channel.try_send(Message::from(task))?;

is_registered = true;
is_success = false;
}
// If the task has succeeded, return the proof.
TaskStatus::Success => {
is_success = is_success && true;
}
TaskStatus::Success => {}
// For all other statuses just return the status.
status => Ok((*status).into()),
_status => {}
}
}

Expand All @@ -129,13 +123,18 @@ async fn proof_handler(
proofs.push(proof);
}

let proof_type = ProofType::from_str(aggregation_request.proof_type)?;
let proof_type = ProofType::from_str(
aggregation_request
.proof_type
.as_ref()
.ok_or_else(|| anyhow!("No proof type"))?,
)?;
let input = AggregationGuestInput { proofs };
let output = AggregationGuestOutput { hash: B256::ZERO };
let config = serde_json::to_value(aggregation_request)?;

let proof = proof_type
.aggregate_proofs(input, &output, &config, manager)
.aggregate_proofs(input, &output, &config, Some(&mut manager))
.await?;

Ok(proof.into())
Expand Down
8 changes: 4 additions & 4 deletions provers/sgx/guest/src/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use base64_serde::base64_serde_type;
use raiko_lib::{
builder::calculate_block_header,
consts::VerifierType,
input::{AggregationGuestInput, GuestInput, RawAggregationGuestInput},
input::{GuestInput, RawAggregationGuestInput},
primitives::{keccak, Address, B256},
protocol_instance::{aggregation_output, aggregation_output_combine, ProtocolInstance},
protocol_instance::{aggregation_output_combine, ProtocolInstance},
};
use secp256k1::{Keypair, SecretKey};
use serde::Serialize;
Expand Down Expand Up @@ -208,8 +208,8 @@ pub async fn aggregate(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
let aggregation_hash = keccak::keccak(aggregation_output_combine(
[
vec![
B256::left_padding_from(&old_instance.to_vec()),
B256::left_padding_from(&new_instance.to_vec()),
B256::left_padding_from(old_instance.as_ref()),
B256::left_padding_from(new_instance.as_ref()),
],
input
.proofs
Expand Down
4 changes: 2 additions & 2 deletions provers/sgx/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ impl Prover for SgxProver {

async fn aggregate(
input: AggregationGuestInput,
output: &AggregationGuestOutput,
_output: &AggregationGuestOutput,
config: &ProverConfig,
id_store: Option<&mut dyn IdWrite>,
_id_store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof> {
let sgx_param = SgxParam::deserialize(config.get("sgx").unwrap()).unwrap();

Expand Down

0 comments on commit df758fa

Please sign in to comment.