From 55339149daeee14b394ea6158d8cdfa5824b344c Mon Sep 17 00:00:00 2001 From: smtmfft <99081233+smtmfft@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:06:49 +0800 Subject: [PATCH] fix(raiko): set default behavior and fix proof format (#354) * set default behavior and fix proof format Signed-off-by: smtmfft * update devnet setting --------- Signed-off-by: smtmfft --- core/src/interfaces.rs | 2 +- host/config/chain_spec_list_devnet.json | 6 +-- provers/sp1/driver/src/lib.rs | 52 ++++++++++++++++++------ provers/sp1/guest/elf/sp1-guest | Bin 6981616 -> 6981616 bytes 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/core/src/interfaces.rs b/core/src/interfaces.rs index 47094fefb..28f712bd3 100644 --- a/core/src/interfaces.rs +++ b/core/src/interfaces.rs @@ -381,7 +381,7 @@ impl TryFrom for ProofRequest { .map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?, blob_proof_type: value .blob_proof_type - .unwrap_or("kzg_versioned_hash".to_string()) + .unwrap_or("proof_of_equivalence".to_string()) .parse() .map_err(|_| { RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string()) diff --git a/host/config/chain_spec_list_devnet.json b/host/config/chain_spec_list_devnet.json index 7bde6142d..a3b9abbba 100644 --- a/host/config/chain_spec_list_devnet.json +++ b/host/config/chain_spec_list_devnet.json @@ -29,7 +29,7 @@ "SP1": null, "RISC0": null }, - "genesis_time": 1722392400, + "genesis_time": 1724760400, "seconds_per_slot": 12, "is_taiko": false }, @@ -49,13 +49,13 @@ "base_fee_max_decrease_denominator": "0x8", "elasticity_multiplier": "0x2" }, - "l1_contract": "0x558E38a3286916934Cb63ced04558A52F7Ce67a9", + "l1_contract": "0xcdE816aFd1B7db50f09831097e71F99877809218", "l2_contract": "0x1670010000000000000000000000000000010001", "rpc": "https://rpc.internal.taiko.xyz", "beacon_rpc": null, "verifier_address": { "SGX": "0xC069c3d2a9f2479F559AD34485698ad5199C555f", - "SP1": null, + "SP1": "0x5F7eD46Ce19E12639D05a5020C64045273842C83", "RISC0": "0x28336BC4116B9672000E7C6Ab96B1454D9d138f7" }, "genesis_time": 0, diff --git a/provers/sp1/driver/src/lib.rs b/provers/sp1/driver/src/lib.rs index b431606b1..37af627da 100644 --- a/provers/sp1/driver/src/lib.rs +++ b/provers/sp1/driver/src/lib.rs @@ -17,6 +17,7 @@ use sp1_sdk::{ }; use sp1_sdk::{HashableKey, ProverClient, SP1Stdin, SP1VerifyingKey}; use std::{ + borrow::BorrowMut, env, fs, path::{Path, PathBuf}, }; @@ -33,12 +34,14 @@ pub static VERIFIER: Lazy> = Lazy::new(init_verifie #[serde_as] #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Sp1Param { + #[serde(default = "RecursionMode::default")] pub recursion: RecursionMode, pub prover: Option, + #[serde(default = "bool::default")] pub verify: bool, } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Default)] #[serde(rename_all = "lowercase")] pub enum RecursionMode { /// The proof mode for an SP1 core proof. @@ -46,6 +49,7 @@ pub enum RecursionMode { /// The proof mode for a compressed proof. Compressed, /// The proof mode for a PlonK proof. + #[default] Plonk, } @@ -107,6 +111,11 @@ impl Prover for Sp1Prover { .unwrap_or_else(ProverClient::new); let (pk, vk) = client.setup(ELF); + info!( + "Sp1 Prover: block {:?} with vk {:?}", + output.header.number, + vk.bytes32() + ); let prove_action = action::Prove::new(client.prover.as_ref(), &pk, stdin.clone()); let prove_result = if !matches!(mode, ProverMode::Network) { @@ -146,18 +155,34 @@ impl Prover for Sp1Prover { .unwrap() }; - let proof = Proof { - proof: serde_json::to_string(&prove_result).ok(), - quote: None, - }; - + let proof_bytes = prove_result.bytes(); if param.verify { let time = Measurement::start("verify", false); - verify_sol(vk, prove_result)?; + let pi_hash = prove_result + .clone() + .borrow_mut() + .public_values + .read::<[u8; 32]>(); + verify_sol(&vk, &proof_bytes, &pi_hash)?; time.stop_with("==> Verification complete"); } - Ok::<_, ProverError>(proof) + Ok::<_, ProverError>(Proof { + proof: { + if proof_bytes.is_empty() { + None + } else { + // 0x + 64 bytes of the vkey + the proof + // vkey itself contains 0x prefix + Some(format!( + "{}{}", + vk.bytes32(), + reth_primitives::hex::encode(proof_bytes) + )) + } + }, + quote: None, + }) } async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> { @@ -230,19 +255,20 @@ struct RaikoProofFixture { } pub fn verify_sol( - vk: SP1VerifyingKey, - mut proof: sp1_sdk::SP1ProofWithPublicValues, + vk: &SP1VerifyingKey, + proof_bytes: &[u8], + pi_hash: &[u8; 32], ) -> ProverResult<()> { assert!(VERIFIER.is_ok()); // Deserialize the public values. - let pi_hash = proof.public_values.read::<[u8; 32]>(); + // let pi_hash = proof.public_values.read::<[u8; 32]>(); // Create the testing fixture so we can test things end-to-end. let fixture = RaikoProofFixture { vkey: vk.bytes32().to_string(), - public_values: B256::from_slice(&pi_hash).to_string(), - proof: format!("0x{}", reth_primitives::hex::encode(proof.bytes())), + public_values: B256::from_slice(pi_hash).to_string(), + proof: format!("0x{}", reth_primitives::hex::encode(proof_bytes)), }; debug!("===> Fixture: {:#?}", fixture); diff --git a/provers/sp1/guest/elf/sp1-guest b/provers/sp1/guest/elf/sp1-guest index f5594104781badd140fbf4736ed2889c8e0c0082..77850dd70c92f73cfeaa774efc538d33e86b405b 100755 GIT binary patch delta 1445 zcmb8tOGs2v7zc24oNBaE$9#@unrWKO>po^~YNg{dd)q@tv+?NYTri?dn+RQeV6I|{ zIMAX^fzYZKT(vZnf^21*c7xB33(JNNqzcj@|l(-QPk48@X( z;>b)JXd`VR3&m3cZKf@>l@ck5lF3Rbw2e|JjnXNDGAWB}lug@d2j$RC%B4KoMftRw z3aF6wP!Sc=UMitdvOjVB9xhU9J;7>O^#xs8jmxb{TD4Q@P@Hb3PnDgr;`T^h+3oX6 zdHmr6N2XCR;&^QOzozbizA*Y z)ImKoz#(Xa!*B$S!ZA1wC*UMB!6`TmXW%R}Lksw!724n&w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