Skip to content

Commit

Permalink
feat(raiko): prove risc0 proof in devnet (#335)
Browse files Browse the repository at this point in the history
* prove risc0 proof in devnet

1. by default use kzg versioned hash.
2. update devnet config for r0 verifier.

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

* fix CI

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

* fix CI

* use snake_case to deserize BlobProofType to align behavior with from_str

---------

Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft authored Aug 6, 2024
1 parent 048df9f commit dcbad01
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl TryFrom<ProofRequestOpt> for ProofRequest {
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?,
blob_proof_type: value
.blob_proof_type
.unwrap_or("ProofOfCommitment".to_string())
.unwrap_or("kzg_versioned_hash".to_string())
.parse()
.map_err(|_| {
RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string())
Expand Down
2 changes: 1 addition & 1 deletion data/input-ethereum-20335518.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/input-ethereum-20378340.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/input-taiko-mainnet-192319.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/input-taiko_mainnet-182300.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/input.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions host/config/chain_spec_list_devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"SP1": null,
"RISC0": null
},
"genesis_time": 1721296000,
"genesis_time": 1722392400,
"seconds_per_slot": 12,
"is_taiko": false
},
Expand All @@ -49,14 +49,14 @@
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": "0xcdE816aFd1B7db50f09831097e71F99877809218",
"l1_contract": "0x558E38a3286916934Cb63ced04558A52F7Ce67a9",
"l2_contract": "0x1670010000000000000000000000000000010001",
"rpc": "https://rpc.internal.taiko.xyz",
"beacon_rpc": null,
"verifier_address":{
"SGX":"0xC069c3d2a9f2479F559AD34485698ad5199C555f",
"SP1":null,
"RISC0":"0xde28533011Ef2d6484A03beFD8ffbF31d179AE6A"
"verifier_address": {
"SGX": "0xC069c3d2a9f2479F559AD34485698ad5199C555f",
"SP1": null,
"RISC0": "0x28336BC4116B9672000E7C6Ab96B1454D9d138f7"
},
"genesis_time": 0,
"seconds_per_slot": 1,
Expand Down
2 changes: 1 addition & 1 deletion host/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mod test {
graffiti: B256::ZERO,
prover: Address::ZERO,
proof_type: ProofType::Native,
blob_proof_type: BlobProofType::ProofOfCommitment,
blob_proof_type: BlobProofType::KzgVersionedHash,
prover_args: Default::default(),
};
let raiko = Raiko::new(
Expand Down
5 changes: 3 additions & 2 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ impl TryFrom<Vec<TransactionSigned>> for TaikoGuestInput {
}

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum BlobProofType {
/// Guest runs through the entire computation from blob to Kzg commitment
/// then to version hash
#[default]
ProofOfCommitment,
KzgVersionedHash,
/// Simplified Proof of Equivalence with fiat input in non-aligned field
/// Referencing https://notes.ethereum.org/@dankrad/kzg_commitments_in_proofs
/// with impl details in https://github.com/taikoxyz/raiko/issues/292
Expand All @@ -106,7 +107,7 @@ impl FromStr for BlobProofType {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim() {
"proof_of_equivalence" => Ok(BlobProofType::ProofOfEquivalence),
"proof_of_commitment" => Ok(BlobProofType::ProofOfCommitment),
"kzg_versioned_hash" => Ok(BlobProofType::KzgVersionedHash),
_ => Err(anyhow!("invalid blob proof type")),
}
}
Expand Down
16 changes: 10 additions & 6 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ProtocolInstance {
proof_of_equivalence =
(U256::from_le_bytes(points.0), U256::from_le_bytes(points.1));
}
crate::input::BlobProofType::ProofOfCommitment => {
crate::input::BlobProofType::KzgVersionedHash => {
let ct = CycleTracker::start("proof_of_commitment");
ensure!(
commitment == &eip4844::calc_kzg_proof_commitment(&input.taiko.tx_data)?
Expand Down Expand Up @@ -195,11 +195,15 @@ fn get_blob_proof_type(
proof_type: VerifierType,
blob_proof_type_hint: BlobProofType,
) -> BlobProofType {
match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::ProofOfCommitment,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
if cfg!(feature = "proof_of_equivalence") {
match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::KzgVersionedHash,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
}
} else {
BlobProofType::KzgVersionedHash
}
}

Expand Down
5 changes: 2 additions & 3 deletions provers/risc0/driver/src/bonsai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@ pub fn prove_locally(
}

let segment_dir = PathBuf::from("/tmp/risc0-cache");
if segment_dir.exists() {
fs::remove_dir_all(segment_dir.clone()).unwrap();
if !segment_dir.exists() {
fs::create_dir(segment_dir.clone()).unwrap();
}
fs::create_dir(segment_dir.clone()).unwrap();
let env = env_builder.segment_path(segment_dir).build().unwrap();
let mut exec = ExecutorImpl::from_elf(env, elf).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_guest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_GUEST_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
pub const RISC0_GUEST_ID: [u32; 8] = [
787132199, 2892282185, 27418400, 1074917401, 1318334946, 2605934429, 883312765, 3835530072,
4175756782, 445162214, 4177377390, 1094180202, 3909523218, 3532437525, 1083104193, 3682235852,
];
26 changes: 19 additions & 7 deletions provers/risc0/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions provers/sp1/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.

0 comments on commit dcbad01

Please sign in to comment.