Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provers): update Sp1 v1.0.1 #333

Merged
merged 20 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
296 changes: 207 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ risc0-build = { version = "1.0.1" }
risc0-binfmt = { version = "1.0.1" }

# SP1
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet"}
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet"}
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet"}
sp1-sdk = { version = "1.0.1" }
sp1-zkvm = { version = "1.0.1" }
sp1-helper = { version = "1.0.1" }

# alloy
alloy-rlp = { version = "0.3.4", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ The script `prove-block.sh` always sends a POST request to Raiko server and enqu
```shell
curl --location --request POST 'http://localhost:8080/proof/report'
```
To list all requested proofs with (chainID, blockhash, proofsys_id) and ID generated by the proof system:
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
```shell
curl --location --request POST 'http://localhost:8080/proof/list'
```
To prune all tasks (the cancellation feature that kills prover is still WIP):
```shell
curl --location --request POST 'http://localhost:8080/proof/prune'
Expand Down
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)]
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
#[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();
}
Binary file removed host/input-taiko_mainnet-196900.bin
Binary file not shown.
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");
}
}
}
6 changes: 5 additions & 1 deletion host/src/server/api/v1/proof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_core::interfaces::ProofRequest;
use raiko_lib::prover::Proof;
use raiko_tasks::get_task_manager;
use serde_json::Value;
use utoipa::OpenApi;

Expand Down Expand Up @@ -42,11 +43,14 @@ async fn proof_handler(
inc_host_req_count(proof_request.block_number);
inc_guest_req_count(&proof_request.proof_type, proof_request.block_number);

// In memory task manager only for V1, cannot feature = "sqlite"
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
let mut manager = get_task_manager(&raiko_tasks::TaskManagerOpts::default());

handle_proof(
&proof_request,
&prover_state.opts,
&prover_state.chain_specs,
None,
Some(&mut manager),
)
.await
.map_err(|e| {
Expand Down
36 changes: 36 additions & 0 deletions host/src/server/api/v2/proof/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use axum::{debug_handler, extract::State, routing::get, Json, Router};
use raiko_tasks::TaskManager;
use serde_json::Value;
use utoipa::OpenApi;

use crate::{interfaces::HostResult, ProverState};

#[utoipa::path(post, path = "/proof/list",
tag = "Proving",
responses (
(status = 200, description = "Successfully listed all proofs & Ids", body = CancelStatus)
)
)]
#[debug_handler(state = ProverState)]
/// List all tasks.
///
/// Retrieve a list of `{ chain_id, blockhash, prover_type, prover, status }` items.
async fn list_handler(State(prover_state): State<ProverState>) -> HostResult<Json<Value>> {
let mut manager = prover_state.task_manager();

let ids = manager.list_stored_ids().await?;

Ok(Json(serde_json::to_value(ids)?))
}

#[derive(OpenApi)]
#[openapi(paths(list_handler))]
struct Docs;

pub fn create_docs() -> utoipa::openapi::OpenApi {
Docs::openapi()
}

pub fn create_router() -> Router<ProverState> {
Router::new().route("/", get(list_handler))
}
3 changes: 3 additions & 0 deletions host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
mod cancel;
mod prune;
mod report;
mod list;

#[utoipa::path(post, path = "/proof",
tag = "Proving",
Expand Down Expand Up @@ -109,6 +110,7 @@ pub fn create_docs() -> utoipa::openapi::OpenApi {
[
cancel::create_docs(),
report::create_docs(),
list::create_docs(),
prune::create_docs(),
]
.into_iter()
Expand All @@ -123,5 +125,6 @@ pub fn create_router() -> Router<ProverState> {
.route("/", post(proof_handler))
.nest("/cancel", cancel::create_router())
.nest("/report", report::create_router())
.nest("/list", list::create_router())
.nest("/prune", prune::create_router())
}
4 changes: 4 additions & 0 deletions provers/sp1/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ docs/

# Dotenv file
.env

# Sp1 Artifacts
*.bin
*.json
20 changes: 12 additions & 8 deletions provers/sp1/contracts/src/ISP1Verifier.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.20;

/// @title SP1 Verifier Interface
/// @author Succinct Labs
/// @notice This contract is the interface for the SP1 Verifier.
interface ISP1Verifier {
/// @notice Returns the version of the SP1 Verifier.
function VERSION() external pure returns (string memory);

/// @notice Verifies a proof with given public values and vkey.
/// @param vkey The verification key for the RISC-V program.
/// @dev It is expected that the first 4 bytes of proofBytes must match the first 4 bytes of
/// target verifier's VERIFIER_HASH.
/// @param programVKey The verification key for the RISC-V program.
/// @param publicValues The public values encoded as bytes.
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes.
function verifyProof(
bytes32 vkey,
bytes memory publicValues,
bytes memory proofBytes
bytes32 programVKey,
bytes calldata publicValues,
bytes calldata proofBytes
) external view;
}

interface ISP1VerifierWithHash is ISP1Verifier {
/// @notice Returns the hash of the verifier.
function VERIFIER_HASH() external pure returns (bytes32);
}
40 changes: 20 additions & 20 deletions provers/sp1/contracts/src/PlonkVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,34 @@
uint256 private constant VK_DOMAIN_SIZE = 67108864;
uint256 private constant VK_INV_DOMAIN_SIZE = 21888242545679039938882419398440172875981108180010270949818755658014750055173;
uint256 private constant VK_OMEGA = 7419588552507395652481651088034484897579724952953562618697845598160172257810;
uint256 private constant VK_QL_COM_X = 11453021816558077199587453448133554449717227349905110102377551937287065432844;
uint256 private constant VK_QL_COM_Y = 9109454861639227276420512127158153200309304123653914732354951393328030738490;
uint256 private constant VK_QR_COM_X = 7821644493905086061243882786350714717685134318611500828127397521557784035499;
uint256 private constant VK_QR_COM_Y = 13041052004552404684631357942397749930688211338192136370697682907414153685909;
uint256 private constant VK_QM_COM_X = 1736617282271757071221168350710970296482875652045937117438551712909537507658;
uint256 private constant VK_QM_COM_Y = 5345542319716290612762422434959528912635502292626234402933058385633964347549;
uint256 private constant VK_QO_COM_X = 18014979952384567403919168968189231706227326297377482789091451813310066870667;
uint256 private constant VK_QO_COM_Y = 3708432301267678677786506706811217632085917639583680393547668223045541307479;
uint256 private constant VK_QK_COM_X = 865219285821188524465935330081001805464204673171276609279513133008346933102;
uint256 private constant VK_QK_COM_Y = 18703726972600526633323567676728586120328686581664702366183492539017488518098;
uint256 private constant VK_QL_COM_X = 1857909580169511349802659750796971843479875254100869630971241462994601728261;
uint256 private constant VK_QL_COM_Y = 9939759850806356864248111238536739205234573451362715673452883653355711153246;
uint256 private constant VK_QR_COM_X = 6682611358305124826092418545540029461432487755379853611917824622377793681568;
uint256 private constant VK_QR_COM_Y = 16146922041381506357194904478990761050971992194239724995214701093157406267535;
uint256 private constant VK_QM_COM_X = 15270607150655824285054831129475047993605012643483198806957835428128518328796;
uint256 private constant VK_QM_COM_Y = 8906362973243319533315777687407111724128929417944634665393917181717423040184;
uint256 private constant VK_QO_COM_X = 9238170507682156721257970724659753490472678230401730180879150452419856085130;
uint256 private constant VK_QO_COM_Y = 15002448341063781545868877705193346445491658209276170799557947939621037358673;
uint256 private constant VK_QK_COM_X = 4086391840028422412061902204531573940095106457258494694809601617012281376035;
uint256 private constant VK_QK_COM_Y = 6000044933528001852326622237429126033256712477967937051806041381512720593429;

uint256 private constant VK_S1_COM_X = 15838704022916757697514152719576664453825928657894015885754578605399919756856;
uint256 private constant VK_S1_COM_Y = 13387218978462600937448147418911963779105027838559913842027032523066810277894;
uint256 private constant VK_S1_COM_X = 18063299339199395103121690488363784429622765365901109337915377451812660612109;
uint256 private constant VK_S1_COM_Y = 2651903669339824861982388949922724224439321134438217364315690905899874053942;

uint256 private constant VK_S2_COM_X = 8305448485555792443785892674312793099639480632975263652331649209215498687903;
uint256 private constant VK_S2_COM_Y = 10616560339600329516818280331708877801874279040952666458845297443257568678018;
uint256 private constant VK_S2_COM_X = 10182215668646701259081683125255467829083669530554379855308469038959443338435;
uint256 private constant VK_S2_COM_Y = 9795420890085293666907175333011202594919622773371320681596120239068622591079;

uint256 private constant VK_S3_COM_X = 5758551426093048145915996102270540307839916135212724540929869593580613639236;
uint256 private constant VK_S3_COM_Y = 8329248325292414275499503861965434456596681093250791731115342865906364573529;
uint256 private constant VK_S3_COM_X = 11878547998011411033206750795964196348923817193060950180216147593592566658964;
uint256 private constant VK_S3_COM_Y = 2125473645138965118806391247175500356381463688616823813996167270375899160338;

uint256 private constant VK_COSET_SHIFT = 5;


uint256 private constant VK_QCP_0_X = 17635741098095958263934242315624493230424349111255370147390685295718328991108;
uint256 private constant VK_QCP_0_Y = 2694645204534071204078571296638854522310743386863537396039207026993856963119;
uint256 private constant VK_QCP_0_X = 13925008146309787259689624423365656079663403784687986805943581679042369678786;
uint256 private constant VK_QCP_0_Y = 18803925277742447221178851473422295758100099815833023568452434419788190270841;


uint256 private constant VK_INDEX_COMMIT_API_0 = 28657845;
uint256 private constant VK_INDEX_COMMIT_API_0 = 31810189;
uint256 private constant VK_NB_CUSTOM_GATES = 1;

// ------------------------------------------------
Expand Down Expand Up @@ -260,7 +260,7 @@
}

/// Called when one the openings is bigger than r
/// The openings are the claimed evaluations of a polynomial
/// The openings are the claimed evalutions of a polynomial

Check warning on line 263 in provers/sp1/contracts/src/PlonkVerifier.sol

View workflow job for this annotation

GitHub Actions / check-for-typos

"evalutions" should be "evaluations".
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
/// in a Kzg proof.
function error_proof_openings_size() {
let ptError := mload(0x40)
Expand Down
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
23 changes: 0 additions & 23 deletions provers/sp1/contracts/src/SP1MockVerifier.sol

This file was deleted.

38 changes: 0 additions & 38 deletions provers/sp1/contracts/src/SP1Verifier.sol

This file was deleted.

1 change: 1 addition & 0 deletions provers/sp1/contracts/src/SP1_COMMIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c3e6f5a44 v1.0.1
Loading
Loading