Skip to content

Commit

Permalink
fix(raiko): fix fixture dir and update sp1 contract test (#353)
Browse files Browse the repository at this point in the history
* clear warnings

* fix fixture dir and default config

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

---------

Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft authored Aug 30, 2024
1 parent 7356e8f commit ecbd621
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions host/config/chain_spec_list_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"beacon_rpc": null,
"verifier_address":{
"SGX":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"SP1":null,
"SP1":"0x13C845C4D4dc4c16d95Fc3B53F732e231245ae56",
"RISC0":"0x4fEd801C5a876D4289e869cbEfA1E1A448b10714"
},
"genesis_time": 0,
Expand Down Expand Up @@ -121,7 +121,7 @@
"beacon_rpc": null,
"verifier_address": {
"SGX":"0xb0f3186FC1963f774f52ff455DC86aEdD0b31F81",
"SP1":null,
"SP1":"0x13C845C4D4dc4c16d95Fc3B53F732e231245ae56",
"RISC0":"0x0000000000000000000000000000000000000000"
},
"genesis_time": 0,
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] = [
3081612924, 3607021821, 3447357908, 4021531326, 181386186, 1121032291, 3850993439, 1990175839,
2273192126, 3371600541, 2393149482, 649684540, 896534796, 3888705079, 1226654129, 1785271921,
];
6 changes: 3 additions & 3 deletions provers/sp1/contracts/src/fixtures/fixture.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"vkey": "0x006a375800c7a77e9ed22fc248190787a9ebca27704126e60e9b0228f480af8b",
"publicValues": "0xe2f6bba1ab5371f630a185baef72d98fced1b182b100007f02d466cc8a67d9a7",
"proof": "0xfedc1fcc10018eb9e98b844785221875f7ccfdcdca46886c63a5b9c8a1e9c025c5ecd04905d7eac92b207288e10e9d65289689806ab39297645cf24ee0669bb37508ca1612c07dc01542a1b97259995e361bb74e6798ac3ef132f681784d4fdc6650f5562604836da4498961f28cf450cb35931ef020fff143e384c6cc3d0f442563cb4f0903076bcf56edf1c3bacffd2c27375defb562a58bcd47428de37ba6d7da7495214b4f24dafec34545cf0e89fc1ff9cf3c849a79944e0625c0468d58106caef9171f129883f0aee0748f5716a4d11be1a2071a3b77450bcff47590b6c82184402d554bc64903ffbedbc6772299cbcaf2372ae090611adf0502897fc4937c1c84229c0f9de50f7ca24a8c7d2c4875ca4afd3ef6d65149d664e1acb691c19819b124af7e87490c2e117998549b3075b346a12dd8ace0870aaaa35667a357309bab2d17765fa27f152c3458fa0723aca6dfa6270bd4dd592d2e713cc963a8834c3f24efffef921eb3cc0f2813cb5a8a5da4aaa77074d784841b0659b4c7b955b1d81807f1ab57fdd07c59ed2b8851e41e5de28f52253cf48aa4c66ed3c52aac2a702c7a514f983cee20ebfc9ed4ee7c0c7ba20f99ec5d5803cbc2ac654abfb040fc1f7051df7d5d35ac7a4bf797612b06ca65c2e79e7a6534664818861b8b7cb7b511dcd20a003f4166db7e9a5e18b7e5a02866f31a021cd6a0cbf76b53422497520fdd5287dd6efb858875110df8571de591dc3eedd55c241b427623dcb320d7c1038431038c361aabfef92a2e4cb5e8372ce9eeff62f061e75d648ac94005995e0153a8adf34c4ac461781bb78cd9996ca51a34e3f1d195deee4362eb170ceb1026cc24a3cb189243e29b7d3e03d1e4ac3aef634a06a1aedc684883aff37741ca0cc4a3632c6b49af71fd3813fd58cb779a8cc77ad6000f469b20486e397be4b82f465bb5c0a911baf7dac5eb4e058815ce236799d5fb4eef75b40b0ddc7d26cf03fc6001346a3a1d96ffc3ccc411e256c68ee14b11b67ec7430ae911028b0da1087ba34c8f93e542c584d26575e3c12a0ca09ff0aef79e96e2a1bcad00b935fa0d7dac1d053d6e9101e3bfa2ff9146542e28a4f56becba2df794a849f732c9c50ab80648f0b7861c2ea21a9214424c732fbd6e3faba7d358dea1b8c3f391b11b069b73d2c59beac3b55dce919a8bf2ccddc6a4c8a6b12834ae186b0e6e234729"
"vkey": "0x008985ad6b5f2bcf7045ae495ae7e36ec0744befcd0881ecf0c3618541f21c9a",
"publicValues": "0xd7db857bd04a20b2af7f249e27770f6d3d71a3a7bfa7328251d32b274cf6dbec",
"proof": "0x616a42051d0b264598d3ce80b077e8e5d3d6209834817c3d5cc6ae9ef9282129999978a3262175276ff5cb3072fe862a210a50f81e7d8684944202c3a19672ad87bfb4a81699105748fa8516cce7c817e72717cf91cba986e01c82f72cbd3e0a5b18f9540ccde87997b79148c1c19689afa2d67b701b9d3705d93f39912a9e956016d7d027112ae07e51b658a565fde7c21b03d1ebd799f9fb92680cba9ed7903a690fc10b03b6b8bc3f29d487533ca9aecc762ddc297e0f54d2290038bb7673a3867e1217c52471a108298e34cb25ae15082832cf4ddc6ca13e3fe418c391e9ea053738116833c96667052033452ee4e97baf77acabf21673a7d650a84866124122e493256a9f1679db2f46c0722267a16efe6ba1ef6a0bf105f973ef6b5d98e0236a6c1e74c4c7c984fe7a61f89b9dd739c3a43947b44835202afe54bdef012e0945a22569c82f420ebd0e08b3552d1b07e15e7cd81a33c55fb12f3c83ebc114d25a5527b2f9a20ed48a5e8dbaeb000b21a7106f0d2538278d985a619fc2074999e79512adce8bbe362113c965400a8127f85543f909d6f65a909ea0e5bb7a6e867ed3261111ea8b12c041df1d70e02aa42b9fe30be06265d02ff4f0d29545c22339430c5164fd0496b03fb5ce39f4518402251450a2ebca06d1209a570e859702ff552bc7bae5b3118017bea5569dfc6188fe5442236fd0330879076ed37313cc04be11386895c911c06b72b63785656050e9858975a9b5280a89cf3edc109130619718159eeeb77a1b48773a0a0df65170aefdd3a82858ac729ead3aa0918b52a7f101ec6ee3baccbc890bed38622a157541153167dd5f497bf8778c886508bc172a179618294af48fcc69354c93f013e06666fe26b5006729a03728a7ddc319f66600b0bcdece21a82072b2a2036a97246f101138ee19cf39a90d24fb5f12f0c40b1aa9ccd2a70c96da3af9bc9b76cdbd37054291c9ee6974c9d40089bf68d525a612e992cf3de3acf7feb072b928852bfaf50d6c69c7672a08ed15d1bbcfaff22a0277ea85becd001bf9df5589050e71d8ee11e6d13b63365f445377aebcec33140d4b5ff2150633f2d1edddfe100a42f81b25f22fd667180056607c34fb808a7125b16ae2fb907f5629b987eb596377ff1e3e42042b9e14741e258c17d14e1ae91f178226c8b10798b84a7c5a93b282a7b6115f568cebf95c15b47e7e084d031c"
}
45 changes: 21 additions & 24 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ use sp1_sdk::{
proto::network::{ProofMode, UnclaimReason},
};
use sp1_sdk::{HashableKey, ProverClient, SP1Stdin, SP1VerifyingKey};
use std::fs;
use std::path::PathBuf;
use std::{env, path::Path};
use tracing::info;
use std::{
env, fs,
path::{Path, PathBuf},
};
use tracing::{debug, info};

pub const ELF: &[u8] = include_bytes!("../../guest/elf/sp1-guest");
pub const FIXTURE_PATH: &str = "./provers/sp1/contracts/src/fixtures/";
pub const CONTRACT_PATH: &str = "./provers/sp1/contracts/src/exports/";
const SP1_PROVER_CODE: u8 = 1;
static FIXTURE_PATH: Lazy<PathBuf> =
Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("../contracts/src/fixtures/"));
static CONTRACT_PATH: Lazy<PathBuf> =
Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("../contracts/src/exports/"));

pub static VERIFIER: Lazy<Result<PathBuf, ProverError>> = Lazy::new(init_verifier);
#[serde_as]
Expand Down Expand Up @@ -196,18 +199,11 @@ fn get_env_mock() -> ProverMode {

fn init_verifier() -> Result<PathBuf, ProverError> {
// In cargo run, Cargo sets the working directory to the root of the workspace
let mut current_dir = std::env::current_dir().unwrap();
println!("Current dir: {:?}", current_dir);
if current_dir.ends_with("driver") {
env::set_current_dir(current_dir.join("../../../"))
.expect("Failed to set current directory");
current_dir = std::env::current_dir().unwrap();
}
println!("Current dir: {:?}", current_dir);
let output_dir: PathBuf = current_dir.join(&CONTRACT_PATH);
let contract_path = &*CONTRACT_PATH;
info!("Contract dir: {:?}", contract_path);
let artifacts_dir = sp1_sdk::install::try_install_circuit_artifacts();
// Create the destination directory if it doesn't exist
fs::create_dir_all(&output_dir)?;
fs::create_dir_all(&contract_path)?;

// Read the entries in the source directory
for entry in fs::read_dir(artifacts_dir)? {
Expand All @@ -216,12 +212,12 @@ fn init_verifier() -> Result<PathBuf, ProverError> {

// Check if the entry is a file and ends with .sol
if src.is_file() && src.extension().map(|s| s == "sol").unwrap_or(false) {
let out = output_dir.join(src.file_name().unwrap());
let out = contract_path.join(src.file_name().unwrap());
fs::copy(&src, &out)?;
println!("Copied: {:?}", src.file_name().unwrap());
}
}
Ok(output_dir)
Ok(contract_path.clone())
}

/// A fixture that can be used to test the verification of SP1 zkVM proofs inside Solidity.
Expand All @@ -248,13 +244,14 @@ pub fn verify_sol(
public_values: B256::from_slice(&pi_hash).to_string(),
proof: format!("0x{}", reth_primitives::hex::encode(proof.bytes())),
};
println!("===> Fixture: {:#?}", fixture);
debug!("===> Fixture: {:#?}", fixture);

// Save the fixture to a file.
println!("Writing fixture to: {:?}", FIXTURE_PATH);
let fixture_path = PathBuf::from(FIXTURE_PATH);
let fixture_path = &*FIXTURE_PATH;
info!("Writing fixture to: {:?}", fixture_path);

if !fixture_path.exists() {
std::fs::create_dir_all(&fixture_path).map_err(|e| {
std::fs::create_dir_all(fixture_path).map_err(|e| {
ProverError::GuestError(format!("Failed to create fixture path: {}", e))
})?;
}
Expand All @@ -266,10 +263,10 @@ pub fn verify_sol(

let child = std::process::Command::new("forge")
.arg("test")
.current_dir(CONTRACT_PATH)
.current_dir(&*CONTRACT_PATH)
.stdout(std::process::Stdio::inherit()) // Inherit the parent process' stdout
.spawn();
println!("Verification started {:?}", child);
info!("Verification started {:?}", child);
child.map_err(|e| ProverError::GuestError(format!("Failed to run forge: {}", e)))?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion provers/sp1/driver/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn main() {

let header = calculate_block_header(&input);

let pi = ProtocolInstance::new(&input, &header, VerifierType::SP1)
let _pi = ProtocolInstance::new(&input, &header, VerifierType::SP1)
.unwrap()
.instance_hash();

Expand Down
Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.
4 changes: 1 addition & 3 deletions provers/sp1/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use raiko_lib::{
builder::calculate_block_header, consts::VerifierType, input::GuestInput,
protocol_instance::ProtocolInstance, CycleTracker,
};
use revm_precompile::zk_op::ZkOperation;
use zk_op::Sp1Operator;

pub mod sys;
pub use sys::*;
Expand Down Expand Up @@ -55,7 +53,7 @@ harness::zk_suits!(
"daf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53",
)
.unwrap();
let signer = signature.recover_signer(hash).unwrap();
signature.recover_signer(hash).unwrap();
}
}
);
3 changes: 3 additions & 0 deletions script/prove-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if [ "$proof" == "native" ]; then
elif [ "$proof" == "sp1" ]; then
proofParam='
"proof_type": "sp1",
"blob_proof_type": "proof_of_equivalence",
"sp1": {
"recursion": "core",
"prover": "mock",
Expand All @@ -71,6 +72,7 @@ elif [ "$proof" == "sgx" ]; then
elif [ "$proof" == "risc0" ]; then
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
"bonsai": false,
"snark": false,
Expand All @@ -81,6 +83,7 @@ elif [ "$proof" == "risc0" ]; then
elif [ "$proof" == "risc0-bonsai" ]; then
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
"bonsai": true,
"snark": true,
Expand Down

0 comments on commit ecbd621

Please sign in to comment.