Skip to content

Commit 378664f

Browse files
committed
feat: union VerifierType and ProofType
1 parent 2c71c7a commit 378664f

File tree

7 files changed

+34
-55
lines changed

7 files changed

+34
-55
lines changed

core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Raiko {
9191

9292
Ok(GuestOutput {
9393
header: header.clone(),
94-
hash: ProtocolInstance::new(input, &header, self.request.proof_type.into())?
94+
hash: ProtocolInstance::new(input, &header, self.request.proof_type)?
9595
.instance_hash(),
9696
})
9797
}

core/src/prover.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::path::Path;
22

33
use raiko_lib::{
4-
consts::VerifierType,
54
input::{GuestInput, GuestOutput},
5+
proof_type::ProofType,
66
protocol_instance::ProtocolInstance,
77
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverConfig, ProverError, ProverResult},
88
};
@@ -49,7 +49,7 @@ impl Prover for NativeProver {
4949

5050
trace!("Running the native prover for input {input:?}");
5151

52-
let pi = ProtocolInstance::new(&input, &output.header, VerifierType::None)
52+
let pi = ProtocolInstance::new(&input, &output.header, ProofType::Native)
5353
.map_err(|e| ProverError::GuestError(e.to_string()))?;
5454
if pi.instance_hash() != output.hash {
5555
return Err(ProverError::GuestError(

lib/src/consts.rs

+16-39
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
//! Constants for the Ethereum protocol.
22
extern crate alloc;
33

4+
use crate::primitives::{uint, BlockNumber, ChainId, U256};
5+
use crate::proof_type::ProofType;
46
use alloc::collections::BTreeMap;
5-
67
use alloy_primitives::Address;
78
use anyhow::{anyhow, bail, Result};
9+
use once_cell::sync::Lazy;
810
use reth_primitives::revm_primitives::SpecId;
911
use serde::{Deserialize, Serialize};
1012
use serde_json::Value;
11-
12-
#[cfg(not(feature = "std"))]
13-
use crate::no_std::*;
14-
use crate::primitives::{uint, BlockNumber, ChainId, U256};
15-
16-
use once_cell::sync::Lazy;
1713
use std::path::PathBuf;
1814
use std::{collections::HashMap, env::var};
1915

20-
use crate::proof_type::ProofType;
16+
#[cfg(not(feature = "std"))]
17+
use crate::no_std::*;
2118

2219
/// U256 representation of 0.
2320
pub const ZERO: U256 = U256::ZERO;
@@ -129,26 +126,6 @@ impl Default for Eip1559Constants {
129126
}
130127
}
131128

132-
#[repr(u8)]
133-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
134-
pub enum VerifierType {
135-
None,
136-
SGX,
137-
SP1,
138-
RISC0,
139-
}
140-
141-
impl From<ProofType> for VerifierType {
142-
fn from(val: ProofType) -> Self {
143-
match val {
144-
ProofType::Native => VerifierType::None,
145-
ProofType::Sgx => VerifierType::SGX,
146-
ProofType::Sp1 => VerifierType::SP1,
147-
ProofType::Risc0 => VerifierType::RISC0,
148-
}
149-
}
150-
}
151-
152129
/// Specification of a specific chain.
153130
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
154131
pub struct ChainSpec {
@@ -161,7 +138,7 @@ pub struct ChainSpec {
161138
pub l2_contract: Option<Address>,
162139
pub rpc: String,
163140
pub beacon_rpc: Option<String>,
164-
pub verifier_address_forks: BTreeMap<SpecId, BTreeMap<VerifierType, Option<Address>>>,
141+
pub verifier_address_forks: BTreeMap<SpecId, BTreeMap<ProofType, Option<Address>>>,
165142
pub genesis_time: u64,
166143
pub seconds_per_slot: u64,
167144
pub is_taiko: bool,
@@ -229,14 +206,14 @@ impl ChainSpec {
229206
pub fn get_fork_verifier_address(
230207
&self,
231208
block_num: u64,
232-
verifier_type: VerifierType,
209+
proof_type: ProofType,
233210
) -> Result<Address> {
234211
// fall down to the first fork that is active as default
235212
for (spec_id, fork) in self.hard_forks.iter().rev() {
236213
if fork.active(block_num, 0u64) {
237214
if let Some(fork_verifier) = self.verifier_address_forks.get(spec_id) {
238215
return fork_verifier
239-
.get(&verifier_type)
216+
.get(&proof_type)
240217
.ok_or_else(|| anyhow!("Verifier type not found"))
241218
.and_then(|address| {
242219
address.ok_or_else(|| anyhow!("Verifier address not found"))
@@ -344,7 +321,7 @@ mod tests {
344321
.get_chain_spec(&Network::Ethereum.to_string())
345322
.unwrap();
346323
let verifier_address = eth_mainnet_spec
347-
.get_fork_verifier_address(15_537_394, VerifierType::SGX)
324+
.get_fork_verifier_address(15_537_394, ProofType::Sgx)
348325
.unwrap();
349326
assert_eq!(
350327
verifier_address,
@@ -355,14 +332,14 @@ mod tests {
355332
.get_chain_spec(&Network::TaikoA7.to_string())
356333
.unwrap();
357334
let verifier_address = hekla_mainnet_spec
358-
.get_fork_verifier_address(12345, VerifierType::SGX)
335+
.get_fork_verifier_address(12345, ProofType::Sgx)
359336
.unwrap();
360337
assert_eq!(
361338
verifier_address,
362339
address!("532efbf6d62720d0b2a2bb9d11066e8588cae6d9")
363340
);
364341
let verifier_address = hekla_mainnet_spec
365-
.get_fork_verifier_address(15_537_394, VerifierType::SGX)
342+
.get_fork_verifier_address(15_537_394, ProofType::Sgx)
366343
.unwrap();
367344
assert_eq!(
368345
verifier_address,
@@ -371,12 +348,12 @@ mod tests {
371348
}
372349

373350
#[test]
374-
fn forked_none_verifier_address() {
351+
fn forked_native_verifier_address() {
375352
let eth_mainnet_spec = SupportedChainSpecs::default()
376353
.get_chain_spec(&Network::Ethereum.to_string())
377354
.unwrap();
378355
let verifier_address = eth_mainnet_spec
379-
.get_fork_verifier_address(15_537_394, VerifierType::None)
356+
.get_fork_verifier_address(15_537_394, ProofType::Native)
380357
.unwrap_or_default();
381358
assert_eq!(verifier_address, Address::ZERO);
382359
}
@@ -407,9 +384,9 @@ mod tests {
407384
verifier_address_forks: BTreeMap::from([(
408385
SpecId::FRONTIER,
409386
BTreeMap::from([
410-
(VerifierType::SGX, Some(Address::default())),
411-
(VerifierType::SP1, None),
412-
(VerifierType::RISC0, Some(Address::default())),
387+
(ProofType::Sgx, Some(Address::default())),
388+
(ProofType::Sp1, None),
389+
(ProofType::Risc0, Some(Address::default())),
413390
]),
414391
)]),
415392
genesis_time: 0u64,

lib/src/protocol_instance.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use reth_primitives::Header;
66
#[cfg(not(feature = "std"))]
77
use crate::no_std::*;
88
use crate::{
9-
consts::{SupportedChainSpecs, VerifierType},
9+
consts::SupportedChainSpecs,
1010
input::{
1111
ontake::{BlockMetadataV2, BlockProposedV2},
1212
BlobProofType, BlockMetadata, BlockProposed, BlockProposedFork, EthDeposit, GuestInput,
@@ -16,6 +16,7 @@ use crate::{
1616
eip4844::{self, commitment_to_version_hash},
1717
keccak::keccak,
1818
},
19+
proof_type::ProofType,
1920
CycleTracker,
2021
};
2122
use reth_evm_ethereum::taiko::ANCHOR_GAS_LIMIT;
@@ -138,7 +139,7 @@ pub struct ProtocolInstance {
138139
}
139140

140141
impl ProtocolInstance {
141-
pub fn new(input: &GuestInput, header: &Header, proof_type: VerifierType) -> Result<Self> {
142+
pub fn new(input: &GuestInput, header: &Header, proof_type: ProofType) -> Result<Self> {
142143
let blob_used = input.taiko.block_proposed.blob_used();
143144
// If blob is used, tx_list_hash is the commitment to the blob
144145
// and we need to verify the blob hash matches the blob data.
@@ -307,16 +308,16 @@ impl ProtocolInstance {
307308

308309
// Make sure the verifier supports the blob proof type
309310
fn get_blob_proof_type(
310-
proof_type: VerifierType,
311+
proof_type: ProofType,
311312
blob_proof_type_hint: BlobProofType,
312313
) -> BlobProofType {
313314
// Enforce different blob proof type for different provers
314315
// due to performance considerations
315316
match proof_type {
316-
VerifierType::None => blob_proof_type_hint,
317-
VerifierType::SGX => BlobProofType::KzgVersionedHash,
318-
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
319-
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
317+
ProofType::Native => blob_proof_type_hint,
318+
ProofType::Sgx => BlobProofType::KzgVersionedHash,
319+
ProofType::Sp1 => BlobProofType::ProofOfEquivalence,
320+
ProofType::Risc0 => BlobProofType::ProofOfEquivalence,
320321
}
321322
}
322323

provers/sgx/guest/src/one_shot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use anyhow::{anyhow, bail, Context, Error, Result};
99
use base64_serde::base64_serde_type;
1010
use raiko_lib::{
1111
builder::calculate_block_header,
12-
consts::VerifierType,
1312
input::{GuestInput, RawAggregationGuestInput},
1413
primitives::{keccak, Address, B256},
14+
proof_type::ProofType,
1515
protocol_instance::{aggregation_output_combine, ProtocolInstance},
1616
};
1717
use secp256k1::{Keypair, SecretKey};
@@ -134,7 +134,7 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
134134
// Process the block
135135
let header = calculate_block_header(&input);
136136
// Calculate the public input hash
137-
let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)?.sgx_instance(new_instance);
137+
let pi = ProtocolInstance::new(&input, &header, ProofType::Sgx)?.sgx_instance(new_instance);
138138
let pi_hash = pi.instance_hash();
139139

140140
println!(

provers/sgx/setup/src/setup_bootstrap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use anyhow::{anyhow, Context, Result};
1010
use file_lock::{FileLock, FileOptions};
11-
use raiko_lib::consts::{SupportedChainSpecs, VerifierType};
11+
use raiko_lib::{consts::SupportedChainSpecs, proof_type::ProofType};
1212
use serde_json::{Number, Value};
1313
use sgx_prover::{
1414
bootstrap, check_bootstrap, get_instance_id, register_sgx_instance, remove_instance_id,
@@ -69,8 +69,8 @@ pub(crate) async fn setup_bootstrap(
6969
// clean check file
7070
remove_instance_id(&config_dir)?;
7171
let bootstrap_proof = bootstrap(secret_dir, gramine_cmd()).await?;
72-
let verifier_address = taiko_chain_spec
73-
.get_fork_verifier_address(bootstrap_args.block_num, VerifierType::SGX)?;
72+
let verifier_address =
73+
taiko_chain_spec.get_fork_verifier_address(bootstrap_args.block_num, ProofType::Sgx)?;
7474
let register_id = register_sgx_instance(
7575
&bootstrap_proof.quote,
7676
&l1_chain_spec.rpc,

provers/sp1/driver/src/verifier.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use alloy_primitives::B256;
33
use raiko_lib::builder::calculate_block_header;
44
use raiko_lib::consts::VerifierType;
55
use raiko_lib::input::{BlobProofType, GuestInput, GuestOutput};
6+
use raiko_lib::proof_type::ProofType;
67
use raiko_lib::protocol_instance::ProtocolInstance;
78
use raiko_lib::prover::Prover;
89
use raiko_lib::Measurement;
@@ -39,7 +40,7 @@ async fn main() {
3940

4041
let header = calculate_block_header(&input);
4142

42-
let _pi = ProtocolInstance::new(&input, &header, VerifierType::SP1)
43+
let _pi = ProtocolInstance::new(&input, &header, ProofType::SP1)
4344
.unwrap()
4445
.instance_hash();
4546

0 commit comments

Comments
 (0)