Skip to content

Commit

Permalink
update contracts artifects structure
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaZ030 committed Aug 1, 2024
1 parent 92884d8 commit 166247f
Show file tree
Hide file tree
Showing 9 changed files with 1,372 additions and 11 deletions.
17 changes: 17 additions & 0 deletions core/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ impl Prover for NativeProver {
Ok(())
}
}


#[cfg(feature = "sp1")]
#[cfg(test)]
#[test]
fn test_solidity_verification() {
use std::env;
use sp1_driver::CONTRACT_PATH;

let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not set");
println!("CARGO_MANIFEST_DIR: {:?}", manifest_dir);

let mut cmd = std::process::Command::new("forge");
cmd.arg("test").current_dir(CONTRACT_PATH);
println!("Running {:?}", &cmd);
cmd.status().unwrap();
}
2 changes: 1 addition & 1 deletion host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ mod memory {
let kbs = max_memory % 1_000_000;
debug!("{title}{mbs}.{kbs:06} MB");
}
}
}
2 changes: 1 addition & 1 deletion provers/sp1/contracts/src/RaikoVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {SP1Verifier} from "./SP1Verifier.sol";
import {SP1Verifier} from "./exports/SP1Verifier.sol";
import "forge-std/console.sol";


Expand Down
1,332 changes: 1,332 additions & 0 deletions provers/sp1/contracts/src/exports/PlonkVerifier.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ISP1Verifier, ISP1VerifierWithHash} from "./ISP1Verifier.sol";
import {ISP1Verifier, ISP1VerifierWithHash} from "../ISP1Verifier.sol";
import {PlonkVerifier} from "./PlonkVerifier.sol";

/// @title SP1 Verifier
Expand Down
1 change: 1 addition & 0 deletions provers/sp1/contracts/src/exports/SP1_COMMIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c3e6f5a44 v1.0.1
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": "0x0091291e1720278ffef4db247bb63cec9e87198d9502278ac5848c49f421859b",
"publicValues": "0x800abd891902937f62acfa0d7e89ae31d8e6af585664cdfcda46e8a3e806eae4",
"proof": "[254, 220, 31, 204, 4, 41, 156, 188, 217, 131, 255, 242, 238, 69, 157, 185, 152, 151, 37, 141, 112, 131, 247, 36, 111, 162, 224, 97, 42, 110, 110, 50, 67, 64, 70, 209, 8, 105, 146, 16, 202, 158, 81, 139, 30, 95, 163, 46, 44, 231, 54, 145, 118, 137, 94, 128, 186, 225, 99, 214, 94, 138, 37, 148, 72, 230, 130, 111, 20, 192, 80, 84, 219, 82, 105, 215, 86, 15, 156, 177, 214, 250, 87, 168, 118, 4, 204, 197, 234, 15, 199, 204, 205, 132, 233, 248, 56, 86, 87, 78, 38, 11, 217, 59, 137, 181, 7, 125, 154, 157, 116, 59, 72, 134, 114, 101, 185, 249, 125, 245, 23, 41, 230, 126, 49, 89, 109, 137, 61, 182, 145, 87, 18, 176, 73, 209, 114, 13, 206, 34, 171, 7, 247, 1, 127, 133, 66, 75, 162, 49, 194, 121, 36, 113, 186, 184, 122, 36, 187, 240, 143, 177, 34, 236, 19, 147, 239, 51, 232, 176, 244, 49, 91, 121, 87, 240, 157, 163, 139, 21, 227, 133, 198, 130, 5, 1, 190, 75, 178, 24, 241, 118, 128, 74, 41, 161, 27, 111, 137, 28, 105, 111, 69, 70, 213, 33, 136, 198, 220, 178, 120, 65, 173, 113, 225, 7, 138, 89, 220, 136, 34, 150, 94, 203, 232, 69, 89, 1, 0, 226, 39, 24, 95, 75, 134, 159, 233, 128, 244, 104, 249, 133, 205, 57, 71, 81, 228, 187, 193, 221, 127, 108, 46, 19, 175, 188, 173, 159, 91, 222, 42, 72, 253, 131, 104, 21, 197, 222, 134, 185, 240, 102, 171, 235, 96, 79, 61, 152, 93, 239, 95, 225, 100, 13, 149, 232, 90, 150, 50, 248, 160, 72, 26, 229, 141, 2, 186, 27, 128, 40, 59, 59, 44, 211, 95, 204, 179, 175, 169, 87, 101, 170, 136, 51, 38, 10, 182, 77, 191, 69, 95, 243, 241, 91, 11, 79, 84, 49, 210, 137, 237, 37, 213, 217, 152, 210, 245, 247, 116, 138, 141, 86, 39, 225, 142, 237, 114, 12, 228, 225, 72, 244, 159, 32, 41, 183, 4, 176, 97, 95, 231, 166, 21, 140, 208, 221, 33, 176, 167, 125, 183, 175, 134, 237, 89, 21, 91, 201, 191, 18, 107, 54, 111, 102, 239, 46, 121, 173, 7, 22, 18, 189, 210, 221, 124, 249, 60, 8, 181, 253, 210, 118, 89, 108, 145, 86, 205, 255, 248, 205, 228, 67, 222, 234, 237, 51, 178, 10, 232, 146, 44, 149, 11, 101, 187, 200, 136, 11, 168, 158, 189, 101, 237, 21, 239, 82, 140, 0, 104, 90, 67, 61, 169, 150, 129, 24, 112, 141, 222, 47, 74, 83, 8, 55, 255, 154, 114, 109, 88, 62, 238, 100, 31, 215, 207, 75, 6, 89, 191, 3, 91, 104, 16, 69, 195, 69, 50, 74, 184, 76, 160, 178, 180, 246, 43, 48, 197, 158, 216, 95, 55, 255, 109, 152, 192, 198, 21, 69, 219, 138, 131, 36, 248, 253, 39, 104, 32, 89, 66, 67, 164, 12, 194, 218, 57, 20, 19, 91, 83, 65, 184, 173, 40, 89, 94, 7, 177, 231, 8, 210, 181, 73, 35, 11, 155, 157, 7, 238, 203, 192, 125, 75, 245, 228, 71, 168, 104, 160, 36, 162, 251, 67, 37, 207, 147, 198, 151, 203, 127, 209, 219, 248, 34, 37, 244, 29, 13, 187, 61, 53, 247, 183, 193, 27, 181, 22, 164, 74, 217, 169, 8, 121, 236, 202, 99, 143, 88, 137, 174, 74, 138, 172, 217, 45, 72, 127, 105, 104, 6, 210, 45, 100, 27, 160, 49, 2, 89, 10, 58, 23, 1, 144, 46, 219, 175, 212, 26, 95, 230, 64, 101, 102, 10, 150, 142, 218, 92, 95, 174, 84, 171, 29, 25, 78, 161, 156, 5, 57, 134, 82, 219, 116, 255, 198, 3, 164, 46, 223, 21, 36, 223, 249, 156, 77, 12, 132, 219, 98, 16, 78, 205, 217, 124, 94, 147, 42, 118, 49, 73, 185, 42, 107, 166, 19, 42, 65, 48, 73, 123, 96, 184, 158, 241, 93, 143, 224, 106, 230, 61, 193, 196, 147, 71, 154, 209, 88, 121, 20, 92, 229, 227, 211, 244, 252, 60, 181, 159, 97, 29, 25, 120, 184, 235, 132, 64, 54, 118, 65, 135, 7, 95, 126, 229, 189, 100, 233, 231, 202, 222, 207, 228, 71, 123, 48, 7, 229, 5, 36, 188, 78, 36, 216, 230, 247, 162, 48, 199, 30, 94, 0, 146, 133, 52, 23, 42, 106, 61, 98, 157, 201, 109, 82, 248, 201, 19, 6, 254, 155, 232, 187, 216, 188, 43, 238, 201, 250, 73, 3, 68, 27, 218, 230, 167, 162, 109, 85, 52, 79, 88, 157, 209, 157, 20, 76, 186, 112, 204, 34, 29, 119, 27, 177, 251, 104, 22, 87, 49, 124, 226, 89, 22, 231, 240, 154, 101, 236, 179, 216, 121, 183, 214, 111, 6, 91, 22, 209, 188, 111, 93, 233, 64, 190, 39, 111, 212, 85, 8, 98, 34, 184, 105, 89, 61, 193, 236, 210, 120, 205, 234, 92, 150, 44, 250, 96, 104, 195, 178, 212, 98, 56, 167, 76, 253, 96, 15, 91, 113, 234]"
"vkey": "0x006a375800c7a77e9ed22fc248190787a9ebca27704126e60e9b0228f480af8b",
"publicValues": "0xe2f6bba1ab5371f630a185baef72d98fced1b182b100007f02d466cc8a67d9a7",
"proof": "0xfedc1fcc10018eb9e98b844785221875f7ccfdcdca46886c63a5b9c8a1e9c025c5ecd04905d7eac92b207288e10e9d65289689806ab39297645cf24ee0669bb37508ca1612c07dc01542a1b97259995e361bb74e6798ac3ef132f681784d4fdc6650f5562604836da4498961f28cf450cb35931ef020fff143e384c6cc3d0f442563cb4f0903076bcf56edf1c3bacffd2c27375defb562a58bcd47428de37ba6d7da7495214b4f24dafec34545cf0e89fc1ff9cf3c849a79944e0625c0468d58106caef9171f129883f0aee0748f5716a4d11be1a2071a3b77450bcff47590b6c82184402d554bc64903ffbedbc6772299cbcaf2372ae090611adf0502897fc4937c1c84229c0f9de50f7ca24a8c7d2c4875ca4afd3ef6d65149d664e1acb691c19819b124af7e87490c2e117998549b3075b346a12dd8ace0870aaaa35667a357309bab2d17765fa27f152c3458fa0723aca6dfa6270bd4dd592d2e713cc963a8834c3f24efffef921eb3cc0f2813cb5a8a5da4aaa77074d784841b0659b4c7b955b1d81807f1ab57fdd07c59ed2b8851e41e5de28f52253cf48aa4c66ed3c52aac2a702c7a514f983cee20ebfc9ed4ee7c0c7ba20f99ec5d5803cbc2ac654abfb040fc1f7051df7d5d35ac7a4bf797612b06ca65c2e79e7a6534664818861b8b7cb7b511dcd20a003f4166db7e9a5e18b7e5a02866f31a021cd6a0cbf76b53422497520fdd5287dd6efb858875110df8571de591dc3eedd55c241b427623dcb320d7c1038431038c361aabfef92a2e4cb5e8372ce9eeff62f061e75d648ac94005995e0153a8adf34c4ac461781bb78cd9996ca51a34e3f1d195deee4362eb170ceb1026cc24a3cb189243e29b7d3e03d1e4ac3aef634a06a1aedc684883aff37741ca0cc4a3632c6b49af71fd3813fd58cb779a8cc77ad6000f469b20486e397be4b82f465bb5c0a911baf7dac5eb4e058815ce236799d5fb4eef75b40b0ddc7d26cf03fc6001346a3a1d96ffc3ccc411e256c68ee14b11b67ec7430ae911028b0da1087ba34c8f93e542c584d26575e3c12a0ca09ff0aef79e96e2a1bcad00b935fa0d7dac1d053d6e9101e3bfa2ff9146542e28a4f56becba2df794a849f732c9c50ab80648f0b7861c2ea21a9214424c732fbd6e3faba7d358dea1b8c3f391b11b069b73d2c59beac3b55dce919a8bf2ccddc6a4c8a6b12834ae186b0e6e234729"
}
15 changes: 13 additions & 2 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{env, thread::sleep, time::Duration};

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";
pub const CONTRACT_PATH: &str = "./provers/sp1/contracts/src/exports/";
const SP1_PROVER_CODE: u8 = 1;

pub static VERIFIER: Lazy<Result<PathBuf, ProverError>> = Lazy::new(init_verifier);
Expand Down Expand Up @@ -167,6 +167,7 @@ impl Prover for Sp1Prover {
}

fn init_verifier() -> Result<PathBuf, ProverError> {
// In cargo run, Cargo sets the working directory to the root of the workspace
let output_dir: PathBuf = CONTRACT_PATH.into();
let artifacts_dir = sp1_sdk::install::try_install_plonk_bn254_artifacts();
if !artifacts_dir.join("SP1Verifier.sol").exists() {
Expand Down Expand Up @@ -198,7 +199,7 @@ fn copy_dir_all(src: impl AsRef<std::path::Path>, dst: impl AsRef<std::path::Pat
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RaikoProofFixture {
vkey: String,
vkey: String,
public_values: String,
proof: String,
}
Expand Down Expand Up @@ -252,6 +253,16 @@ mod test {
assert!(VERIFIER.is_ok());
}

#[test]
fn test_solidity_verification() {
let mut cmd = std::process::Command::new("forge");
// In test, Cargo sets the working dir to the package being tested
// not the workspace root
cmd.arg("test").current_dir("../contracts");
println!("Running {:?}", &cmd);
cmd.status().unwrap();
}

#[test]
fn run_unittest_elf() {
// TODO(Cecilia): imple GuestInput::mock() for unit test
Expand Down
6 changes: 3 additions & 3 deletions provers/sp1/driver/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ async fn main() {
// Param has higher priority than .env
let param = json!({
"sp1" : {
"recursion": "core",
"prover": "mock",
"verify": false
"recursion": "plonk",
"prover": "network",
"verify": true
}
});
let time = Measurement::start("prove_groth16 & verify", false);
Expand Down

0 comments on commit 166247f

Please sign in to comment.