Skip to content

Commit

Permalink
fmt clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaZ030 committed May 21, 2024
1 parent fac4b14 commit f3b9999
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 49 deletions.
1 change: 0 additions & 1 deletion host/src/interfaces/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use alloy_primitives::{Address, B256};
use clap::{Args, ValueEnum};
use raiko_lib::{
input::{GuestInput, GuestOutput},
protocol_instance::ProtocolInstance,
prover::{Proof, Prover},
};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion host/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async fn prepare_taiko_chain_input(

// Create the transactions from the proposed tx list
let transactions = generate_transactions(
&taiko_chain_spec,
taiko_chain_spec,
proposal_event.meta.blobUsed,
&tx_data,
Some(anchor_tx.clone()),
Expand Down
11 changes: 3 additions & 8 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{FixedBytes, B256};
use alloy_primitives::{FixedBytes};
use raiko_lib::builder::{BlockBuilderStrategy, TaikoStrategy};
use raiko_lib::consts::{ChainSpec, VerifierType};
use raiko_lib::input::{GuestInput, GuestOutput, TaikoProverData};
Expand Down Expand Up @@ -60,12 +60,7 @@ impl Raiko {
info!("Verifying final state using provider data ...");
info!("Final block hash derived successfully. {}", header.hash());
info!("Final block header derived successfully. {header:?}");
let pi = ProtocolInstance::new(
input,
&header,
VerifierType::None,
)?
.instance_hash();
let pi = ProtocolInstance::new(input, &header, VerifierType::None)?.instance_hash();

// Check against the expected value of all fields for easy debugability
let exp = &input.block_header_reference;
Expand Down Expand Up @@ -169,7 +164,7 @@ impl Prover for NativeProver {
return Err(ProverError::GuestError("Unexpected output".to_owned()));
};

ProtocolInstance::new( &input, &header, VerifierType::None)
ProtocolInstance::new(&input, &header, VerifierType::None)
.map_err(|e| ProverError::GuestError(e.to_string()))?;

to_proof(Ok(NativeResponse {
Expand Down
8 changes: 3 additions & 5 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct SupportedChainSpecs(HashMap<String, ChainSpec>);

impl SupportedChainSpecs {
pub fn default() -> Self {
let deserialized: Vec<ChainSpec> = serde_json::from_str(&DEFAULT_CHAIN_SPECS).unwrap();
let deserialized: Vec<ChainSpec> = serde_json::from_str(DEFAULT_CHAIN_SPECS).unwrap();
let chain_spec_list = deserialized
.iter()
.map(|cs| (cs.name.clone(), cs.clone()))
Expand All @@ -62,7 +62,7 @@ impl SupportedChainSpecs {
#[cfg(feature = "std")]
pub fn merge_from_file(file_path: PathBuf) -> Result<SupportedChainSpecs> {
let mut known_chain_specs = SupportedChainSpecs::default();
let file = std::fs::File::open(&file_path)?;
let file = std::fs::File::open(file_path)?;
let reader = std::io::BufReader::new(file);
let config: Value = serde_json::from_reader(reader)?;
let chain_spec_list: Vec<ChainSpec> = serde_json::from_value(config)?;
Expand All @@ -87,8 +87,7 @@ impl SupportedChainSpecs {
pub fn get_chain_spec_with_chain_id(&self, chain_id: u64) -> Option<ChainSpec> {
self.0
.values()
.find(|spec| spec.chain_id == chain_id)
.map(|spec| spec.clone())
.find(|spec| spec.chain_id == chain_id).cloned()
}
}

Expand Down Expand Up @@ -135,7 +134,6 @@ impl Default for Eip1559Constants {
}
}


#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum VerifierType {
Expand Down
35 changes: 16 additions & 19 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_consensus::Header as AlloyConsensusHeader;
use alloy_primitives::{Address, TxHash, B256};
use alloy_sol_types::{sol, SolValue};
use alloy_sol_types::{SolValue};
use anyhow::{ensure, Result};
use c_kzg::{Blob, KzgCommitment, KzgSettings};
use raiko_primitives::keccak::keccak;
Expand All @@ -10,7 +10,7 @@ use super::utils::ANCHOR_GAS_LIMIT;
#[cfg(not(feature = "std"))]
use crate::no_std::*;
use crate::{
consts::{VerifierType, SupportedChainSpecs},
consts::{SupportedChainSpecs, VerifierType},
input::{BlockMetadata, EthDeposit, GuestInput, Transition},
utils::HeaderHasher,
};
Expand All @@ -28,7 +28,6 @@ pub struct ProtocolInstance {
}

impl ProtocolInstance {

pub fn new(
input: &GuestInput,
header: &AlloyConsensusHeader,
Expand All @@ -55,7 +54,7 @@ impl ProtocolInstance {
} else {
TxHash::from(keccak(input.taiko.tx_data.as_slice()))
};

// If the passed in chain spec contains a known chain id, the chain spec NEEDS to match the
// one we expect, because the prover could otherwise just fill in any values.
// The chain id is used because that is the value that is put onchain,
Expand Down Expand Up @@ -91,7 +90,7 @@ impl ProtocolInstance {
"unexpected eip_1559_constants"
);
}

let deposits = input
.withdrawals
.iter()
Expand All @@ -101,13 +100,13 @@ impl ProtocolInstance {
id: w.index,
})
.collect::<Vec<_>>();

let gas_limit: u64 = header.gas_limit.try_into().unwrap();
let verifier_address = input
.chain_spec
.verifier_address
.get(&proof_type)
.expect(&format!("verifier_address not set for {:?}", proof_type))
.unwrap_or_else(|| panic!("verifier_address not set for {:?}", proof_type))
.unwrap();
let pi = ProtocolInstance {
transition: Transition {
Expand Down Expand Up @@ -142,7 +141,7 @@ impl ProtocolInstance {
chain_id: input.chain_spec.chain_id,
verifier_address,
};

// Sanity check
if input.chain_spec.is_taiko() {
ensure!(
Expand All @@ -153,7 +152,7 @@ impl ProtocolInstance {
)
);
}

Ok(pi)
}

Expand All @@ -162,7 +161,6 @@ impl ProtocolInstance {
self
}


pub fn meta_hash(&self) -> B256 {
keccak(self.block_metadata.abi_encode()).into()
}
Expand All @@ -171,19 +169,19 @@ impl ProtocolInstance {
pub fn instance_hash(&self) -> B256 {
/// packages/protocol/contracts/verifiers/libs/LibPublicInput.sol
/// "VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash
keccak(
(
keccak(
(
"VERIFY_PROOF",
self.chain_id,
self.verifier_address,
self.transition.clone(),
self.transition.clone(),
self.sgx_instance,
self.prover,
self.meta_hash(),
)
.abi_encode()
).into()
self.meta_hash(),
)
.abi_encode(),
)
.into()
}
}

Expand All @@ -194,7 +192,6 @@ pub fn kzg_to_versioned_hash(commitment: &KzgCommitment) -> B256 {
B256::new(res.into())
}


fn bytes_to_bytes32(input: &[u8]) -> [u8; 32] {
let mut bytes = [0u8; 32];
let len = core::cmp::min(input.len(), 32);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::fmt;

use alloy_primitives::B256;
use serde::Serialize;
use thiserror::Error as ThisError;

use crate::{
input::{GuestInput, GuestOutput},
protocol_instance::ProtocolInstance,
};

#[derive(ThisError, Debug)]
Expand Down
8 changes: 5 additions & 3 deletions provers/sgx/guest/src/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::{
use anyhow::{anyhow, bail, Context, Error, Result};
use base64_serde::base64_serde_type;
use raiko_lib::{
builder::{BlockBuilderStrategy, TaikoStrategy}, consts::VerifierType, input::GuestInput, protocol_instance::ProtocolInstance
builder::{BlockBuilderStrategy, TaikoStrategy},
consts::VerifierType,
input::GuestInput,
protocol_instance::ProtocolInstance,
};
use raiko_primitives::Address;
use secp256k1::{KeyPair, SecretKey};
Expand Down Expand Up @@ -134,8 +137,7 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
TaikoStrategy::build_from(&input).expect("Failed to build the resulting block");

// Calculate the public input hash
let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)?
.sgx_instance(new_instance);
let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)?.sgx_instance(new_instance);
let pi_hash = pi.instance_hash();

println!(
Expand Down
3 changes: 0 additions & 3 deletions provers/sgx/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ use std::{
str,
};

use alloy_sol_types::SolValue;
use once_cell::sync::Lazy;
use raiko_lib::{
input::{GuestInput, GuestOutput},
protocol_instance::ProtocolInstance,
prover::{to_proof, Proof, Prover, ProverConfig, ProverError, ProverResult},
};
use raiko_primitives::{keccak::keccak, B256};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::serde_as;
Expand Down
11 changes: 4 additions & 7 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#![cfg(feature = "enable")]
use std::env;

use alloy_primitives::B256;
use alloy_sol_types::SolValue;
use raiko_lib::{
input::{GuestInput, GuestOutput},
protocol_instance::ProtocolInstance,
prover::{to_proof, Proof, Prover, ProverConfig, ProverResult},
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -37,8 +34,6 @@ impl Prover for Sp1Prover {
let (pk, vk) = client.setup(ELF);
let mut proof = client.prove(&pk, stdin).expect("Sp1: proving failed");



// Read the output.
let output = proof.public_values.read::<GuestOutput>();
// Verify proof.
Expand Down Expand Up @@ -76,11 +71,13 @@ mod test {
let client = ProverClient::new();
let stdin = SP1Stdin::new();
let (pk, vk) = client.setup(TEST_ELF);
let proof = client.prove_groth16(&pk, stdin).expect("Sp1: proving failed");
let proof = client
.prove_groth16(&pk, stdin)
.expect("Sp1: proving failed");
// client
// .verify(&proof, &vk)
// .expect("Sp1: verification failed");

let contract_dir = "../contract";
sp1_sdk::artifacts::export_solidity_groth16_verifier(contract_dir)
.expect("failed to export verifier");
Expand Down

0 comments on commit f3b9999

Please sign in to comment.