Skip to content

Commit

Permalink
feat(raiko-lib): unify protocol instance for on chain verification (#230
Browse files Browse the repository at this point in the history
)

* instance_hash

* change pi + copied sp1 templete

* get rid of host-side matches

* get rid of sol

* fix

* delete contracts

* fmt clippy

* fix ci

* fix

* delet test generated json

* fmt

* fix

* Update lib.rs

* Update lib/src/consts.rs

* fix

* apply comments

* fmt

* debug sp1

* unwrap_or_default

* fix: let config_path in config_dir (#233)

* fix: let config_path in config_dir

* fix: save updated config in new path

* chore(docker): use same image when pulling to avoid different binary id (#234)

Signed-off-by: smtmfft <[email protected]>

* feat(raiko): update chain spec (#235)

* update chain spec

Signed-off-by: smtmfft <[email protected]>

* update rpc & name

Signed-off-by: smtmfft <[email protected]>

---------

Signed-off-by: smtmfft <[email protected]>

* feat: use spec in setup (#236)

* feat: use spec in setup

* refactor: update docker-compose.yml to use correct file paths

* chore(docker): fix docker build (#237)

* fix docker build

Signed-off-by: smtmfft <[email protected]>

* fix: some docker stuff (#239)

---------

Signed-off-by: smtmfft <[email protected]>
Co-authored-by: johntaiko <[email protected]>

* chore(raiko): revert docker build changes (#240)

* Revert "chore(docker): fix docker build (#237)"

This reverts commit 520df33.

* Revert "feat: use spec in setup (#236)"

This reverts commit cd097a5.

* fix: docker stuff (#241)

* fix: docker stuff

* chore(docker): update entrypoint.sh to include L1 and L2 network options

* chore(docker): remove unnecessary echo command in entrypoint.sh

* fmt

* sgx_verifier_addr

* fix

* fmt

* skip_verify_blob false

* fmt

---------

Signed-off-by: smtmfft <[email protected]>
Co-authored-by: johntaiko <[email protected]>
Co-authored-by: smtmfft <[email protected]>
Co-authored-by: Brecht Devos <[email protected]>
  • Loading branch information
4 people authored May 25, 2024
1 parent 3953c2d commit ed37856
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 272 deletions.
52 changes: 48 additions & 4 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":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"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":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"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":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
Expand All @@ -107,9 +119,41 @@
"l2_contract": "0x1670000000000000000000000000000000010001",
"rpc": "https://rpc.mainnet.taiko.xyz",
"beacon_rpc": null,
"sgx_verifier_address": "0xb0f3186FC1963f774f52ff455DC86aEdD0b31F81",
"verifier_address": {
"SGX":"0xb0f3186FC1963f774f52ff455DC86aEdD0b31F81",
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
},
{
"name": "taiko_mainnet",
"chain_id": 167000,
"max_spec_id": "SHANGHAI",
"hard_forks": {
"SHANGHAI": {
"Block": 0
},
"CANCUN": "TBD"
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": "0x06a9Ab27c7e2255df1815E6CC0168d7755Feb19a",
"l2_contract": "0x1670000000000000000000000000000000010001",
"rpc": "https://rpc.mainnet.taiko.xyz",
"beacon_rpc": null,
"verifier_address": {
"SGX":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"SP1":null,
"RISC0":"0x0000000000000000000000000000000000000000"
}, "genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
}
]
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
26 changes: 19 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 {
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,7 +290,11 @@ 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,
Expand Down
Loading

0 comments on commit ed37856

Please sign in to comment.