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

feat(raiko-lib): unify protocol instance for on chain verification #230

Merged
merged 38 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
724e6d0
instance_hash
CeciliaZ030 May 21, 2024
4e8b59a
change pi + copied sp1 templete
CeciliaZ030 May 21, 2024
81c2007
get rid of host-side matches
CeciliaZ030 May 21, 2024
70c2673
get rid of sol
CeciliaZ030 May 21, 2024
112d90d
fix
CeciliaZ030 May 21, 2024
fac4b14
delete contracts
CeciliaZ030 May 21, 2024
f3b9999
fmt clippy
CeciliaZ030 May 21, 2024
896c6df
fix ci
CeciliaZ030 May 21, 2024
bdd07b0
Merge branch 'main' into unify-pi
CeciliaZ030 May 21, 2024
d7fa70c
fix
CeciliaZ030 May 21, 2024
04fa124
delet test generated json
CeciliaZ030 May 21, 2024
a4b5af8
fmt
CeciliaZ030 May 21, 2024
df45421
fix
CeciliaZ030 May 21, 2024
6815a24
Update lib.rs
CeciliaZ030 May 21, 2024
c7a3069
Update lib/src/consts.rs
CeciliaZ030 May 21, 2024
d46f5b5
fix
CeciliaZ030 May 22, 2024
756a2a8
apply comments
CeciliaZ030 May 22, 2024
5a5fd70
fmt
CeciliaZ030 May 22, 2024
401baab
Merge branch 'main' into unify-pi
CeciliaZ030 May 22, 2024
bfb2ece
debug sp1
CeciliaZ030 May 22, 2024
4578bb0
unwrap_or_default
CeciliaZ030 May 22, 2024
c2e5554
fix: let config_path in config_dir (#233)
johntaiko May 22, 2024
eef94ac
chore(docker): use same image when pulling to avoid different binary …
smtmfft May 22, 2024
8ec2892
feat(raiko): update chain spec (#235)
smtmfft May 22, 2024
909e7c8
feat: use spec in setup (#236)
johntaiko May 22, 2024
5ba5809
chore(docker): fix docker build (#237)
smtmfft May 22, 2024
70e8305
chore(raiko): revert docker build changes (#240)
smtmfft May 22, 2024
496a7ed
fix: docker stuff (#241)
johntaiko May 22, 2024
892326a
fmt
CeciliaZ030 May 22, 2024
252ee85
sgx_verifier_addr
CeciliaZ030 May 22, 2024
fb6661f
Merge branch 'main' into unify-pi
CeciliaZ030 May 22, 2024
aecff60
fix
CeciliaZ030 May 22, 2024
b1ebad8
fmt
CeciliaZ030 May 22, 2024
9e19230
skip_verify_blob false
CeciliaZ030 May 22, 2024
06a80c1
Merge branch 'main' into unify-pi
CeciliaZ030 May 24, 2024
a8d5744
fmt
CeciliaZ030 May 24, 2024
e53b8a9
Merge branch 'main' into unify-pi
CeciliaZ030 May 24, 2024
b3dd623
Merge branch 'main' into unify-pi
Brechtpd May 25, 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
18 changes: 15 additions & 3 deletions host/config/chain_spec_list_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
"l2_contract": null,
"rpc": "https://rpc.ankr.com/eth",
"beacon_rpc": "https://ethereum-beacon-api.publicnode.com",
"sgx_verifier_address": null,
"verifier_address": {
"SGX":"0x0000000000000000000000000000000000000000",
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 1606824023,
"seconds_per_slot": 12,
"is_taiko": false
Expand Down Expand Up @@ -57,7 +61,11 @@
"l2_contract": null,
"rpc": "https://ethereum-holesky-rpc.publicnode.com",
"beacon_rpc": "https://fabled-weathered-cherry.ethereum-holesky.quiknode.pro/8f1c66935fa5f9afbda0db43318fe3c9e7b061e1/",
"sgx_verifier_address": null,
"verifier_address": {
"SGX":"0x0000000000000000000000000000000000000000",
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 1695902400,
"seconds_per_slot": 12,
"is_taiko": false
Expand All @@ -82,7 +90,11 @@
"l2_contract": "0x1670090000000000000000000000000000010001",
"rpc": "https://rpc.hekla.taiko.xyz",
"beacon_rpc": null,
"sgx_verifier_address": "0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"verifier_address":{
"SGX":"0x0000000000000000000000000000000000000000",
smtmfft marked this conversation as resolved.
Show resolved Hide resolved
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
Expand Down
26 changes: 0 additions & 26 deletions 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 Expand Up @@ -69,31 +68,6 @@ impl FromStr for ProofType {
}

impl ProofType {
/// Get the instance hash for the protocol instance depending on the proof type.
pub fn instance_hash(&self, pi: ProtocolInstance) -> HostResult<B256> {
match self {
ProofType::Native => Ok(NativeProver::instance_hash(pi)),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return Ok(sp1_driver::Sp1Prover::instance_hash(pi));

Err(HostError::FeatureNotSupportedError(self.clone()))
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return Ok(risc0_driver::Risc0Prover::instance_hash(pi));

Err(HostError::FeatureNotSupportedError(self.clone()))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return Ok(sgx_prover::SgxProver::instance_hash(pi));

Err(HostError::FeatureNotSupportedError(self.clone()))
}
}
}

/// Run the prover driver depending on the proof type.
pub async fn run_prover(
&self,
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
17 changes: 5 additions & 12 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloy_primitives::{FixedBytes, B256};
use alloy_primitives::FixedBytes;
use raiko_lib::builder::{BlockBuilderStrategy, TaikoStrategy};
use raiko_lib::consts::ChainSpec;
use raiko_lib::consts::{ChainSpec, VerifierType};
use raiko_lib::input::{GuestInput, GuestOutput, TaikoProverData};
use raiko_lib::protocol_instance::{assemble_protocol_instance, ProtocolInstance};
use raiko_lib::protocol_instance::ProtocolInstance;
use raiko_lib::prover::{to_proof, Proof, Prover, ProverError, ProverResult};
use raiko_lib::utils::HeaderHasher;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -60,10 +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 = self
.request
.proof_type
.instance_hash(assemble_protocol_instance(input, &header)?)?;
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 @@ -163,17 +160,13 @@ impl Prover for NativeProver {
return Err(ProverError::GuestError("Unexpected output".to_owned()));
};

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

to_proof(Ok(NativeResponse {
output: output.clone(),
}))
}

fn instance_hash(_pi: ProtocolInstance) -> B256 {
B256::default()
}
}

fn check_eq<T: std::cmp::PartialEq + std::fmt::Debug>(expected: &T, actual: &T, message: &str) {
Expand Down
27 changes: 20 additions & 7 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 @@ -88,7 +88,7 @@ impl SupportedChainSpecs {
self.0
.values()
.find(|spec| spec.chain_id == chain_id)
.map(|spec| spec.clone())
.cloned()
}
}

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

#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum VerifierType {
Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
None,
SGX,
SP1,
RISC0,
}

/// Specification of a specific chain.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct ChainSpec {
Expand All @@ -147,8 +156,7 @@ pub struct ChainSpec {
pub l2_contract: Option<Address>,
pub rpc: String,
pub beacon_rpc: Option<String>,
// TRICKY: the sgx_verifier_addr is in l1, not in itself
pub sgx_verifier_address: Option<Address>,
pub verifier_address: BTreeMap<VerifierType, Option<Address>>,
pub genesis_time: u64,
pub seconds_per_slot: u64,
pub is_taiko: bool,
Expand All @@ -173,7 +181,7 @@ impl ChainSpec {
l2_contract: None,
rpc: "".to_string(),
beacon_rpc: None,
sgx_verifier_address: None,
verifier_address: BTreeMap::new(),
genesis_time: 0u64,
seconds_per_slot: 1u64,
is_taiko,
Expand Down Expand Up @@ -282,14 +290,19 @@ mod tests {
l2_contract: None,
rpc: "".to_string(),
beacon_rpc: None,
sgx_verifier_address: None,
verifier_address: BTreeMap::from([
(VerifierType::SGX, Some(Address::default())),
(VerifierType::SP1, None),
(VerifierType::RISC0, Some(Address::default())),
]),
genesis_time: 0u64,
seconds_per_slot: 1u64,
is_taiko: false,
};

let json = serde_json::to_string(&spec).unwrap();
// write to a file called chain_specs.json

Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
std::fs::write("chain_spec.json", json).unwrap();

// read back from the file
Expand Down
Loading
Loading