Skip to content

Commit eba874e

Browse files
committed
feat: Add Euclid verifier
1 parent 65a8cad commit eba874e

File tree

13 files changed

+7613
-2224
lines changed

13 files changed

+7613
-2224
lines changed

common/libzkp/impl/Cargo.lock

Lines changed: 7396 additions & 2143 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/libzkp/impl/Cargo.toml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,38 @@ gobuild = { git = "https://github.com/scroll-tech/gobuild.git" }
1212
halo2curves = { git = "https://github.com/scroll-tech/halo2curves", branch = "v0.1.0" }
1313
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
1414
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
15-
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
15+
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
16+
# patched add rkyv support & MSRV 1.77
17+
ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }
18+
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18" }
19+
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
20+
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
21+
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
22+
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
23+
1624
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
17-
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
25+
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
1826
[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
1927
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "main" }
2028
[patch."https://github.com/privacy-scaling-explorations/bls12_381"]
2129
bls12_381 = { git = "https://github.com/scroll-tech/bls12_381", branch = "feat/impl_scalar_field" }
2230

2331
[dependencies]
2432
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
25-
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] }
33+
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = [
34+
"loader_halo2",
35+
"loader_evm",
36+
"halo2-pse",
37+
] }
2638

27-
# darwin
28-
prover_v4 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
2939
# darwin_v2
30-
prover_v5 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
40+
prover_v5 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = [
41+
"parallel_syn",
42+
"scroll",
43+
] }
44+
# euclid
45+
prover_v7 = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.1", package = "scroll-zkvm-prover" }
46+
verifier_v7 = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.1", package = "scroll-zkvm-verifier" }
3147

3248
base64 = "0.13.0"
3349
env_logger = "0.9.0"

common/libzkp/impl/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2023-12-03
1+
nightly-2024-12-06

common/libzkp/impl/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod utils;
22
mod verifier;
33

4+
use std::path::Path;
5+
46
use crate::utils::{c_char_to_str, c_char_to_vec};
57
use libc::c_char;
68
use prover_v5::utils::init_env_and_log;
@@ -61,3 +63,18 @@ pub unsafe extern "C" fn verify_bundle_proof(
6163
) -> c_char {
6264
verify_proof(proof, fork_name, TaskType::Bundle)
6365
}
66+
67+
/// # Safety
68+
#[no_mangle]
69+
pub unsafe extern "C" fn dump_vk(fork_name: *const c_char, file: *const c_char) {
70+
_dump_vk(fork_name, file);
71+
}
72+
73+
fn _dump_vk(fork_name: *const c_char, file: *const c_char) {
74+
let fork_name_str = c_char_to_str(fork_name);
75+
let verifier = verifier::get_verifier(fork_name_str);
76+
77+
if let Ok(verifier) = verifier {
78+
verifier.as_ref().dump_vk(Path::new(c_char_to_str(file)));
79+
}
80+
}

common/libzkp/impl/src/verifier.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
mod darwin;
1+
#![allow(static_mut_refs)]
2+
23
mod darwin_v2;
4+
mod euclid;
35

46
use anyhow::{bail, Result};
5-
use darwin::DarwinVerifier;
67
use darwin_v2::DarwinV2Verifier;
8+
use euclid::EuclidVerifier;
79
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
8-
use prover_v4::utils::load_params;
10+
use prover_v5::utils::load_params;
911
use serde::{Deserialize, Serialize};
10-
use std::{cell::OnceCell, collections::BTreeMap, rc::Rc};
12+
use std::{cell::OnceCell, collections::BTreeMap, path::Path, rc::Rc};
1113

1214
#[derive(Debug, Clone, Copy, PartialEq)]
1315
pub enum TaskType {
@@ -16,8 +18,16 @@ pub enum TaskType {
1618
Bundle,
1719
}
1820

21+
#[derive(Debug, Serialize, Deserialize)]
22+
pub struct VKDump {
23+
pub chunk_vk: String,
24+
pub batch_vk: String,
25+
pub bundle_vk: String,
26+
}
27+
1928
pub trait ProofVerifier {
2029
fn verify(&self, task_type: TaskType, proof: Vec<u8>) -> Result<bool>;
30+
fn dump_vk(&self, file: &Path);
2131
}
2232

2333
#[derive(Debug, Serialize, Deserialize)]
@@ -37,30 +47,31 @@ type HardForkName = String;
3747

3848
struct VerifierPair(HardForkName, Rc<Box<dyn ProofVerifier>>);
3949

40-
static mut VERIFIER_HIGH: OnceCell<VerifierPair> = OnceCell::new();
41-
static mut VERIFIER_LOW: OnceCell<VerifierPair> = OnceCell::new();
50+
static mut VERIFIER_ZKVM: OnceCell<VerifierPair> = OnceCell::new();
51+
static mut VERIFIER_HALO2: OnceCell<VerifierPair> = OnceCell::new();
4252
static mut PARAMS_MAP: OnceCell<BTreeMap<u32, ParamsKZG<Bn256>>> = OnceCell::new();
4353

4454
pub fn init(config: VerifierConfig) {
45-
let low_conf = config.low_version_circuit;
46-
47-
std::env::set_var("SCROLL_PROVER_ASSETS_DIR", &low_conf.assets_path);
55+
std::env::set_var(
56+
"SCROLL_PROVER_ASSETS_DIR",
57+
&config.low_version_circuit.assets_path,
58+
);
4859
let params_degrees = [
49-
*prover_v4::config::LAYER2_DEGREE,
50-
*prover_v4::config::LAYER4_DEGREE,
60+
*prover_v5::config::LAYER2_DEGREE,
61+
*prover_v5::config::LAYER4_DEGREE,
5162
];
5263

5364
// params should be shared between low and high
5465
let mut params_map = BTreeMap::new();
5566
for degree in params_degrees {
5667
if let std::collections::btree_map::Entry::Vacant(e) = params_map.entry(degree) {
57-
match load_params(&low_conf.params_path, degree, None) {
68+
match load_params(&config.low_version_circuit.params_path, degree, None) {
5869
Ok(params) => {
5970
e.insert(params);
6071
}
6172
Err(e) => panic!(
6273
"failed to load params, degree {}, dir {}, err {}",
63-
degree, low_conf.params_path, e
74+
degree, config.low_version_circuit.params_path, e
6475
),
6576
}
6677
}
@@ -69,23 +80,27 @@ pub fn init(config: VerifierConfig) {
6980
PARAMS_MAP.set(params_map).unwrap_unchecked();
7081
}
7182

72-
let verifier = DarwinVerifier::new(unsafe { PARAMS_MAP.get().unwrap() }, &low_conf.assets_path);
73-
83+
let verifier = DarwinV2Verifier::new(
84+
unsafe { PARAMS_MAP.get().unwrap() },
85+
&config.low_version_circuit.assets_path,
86+
);
7487
unsafe {
75-
VERIFIER_LOW
88+
VERIFIER_HALO2
7689
.set(VerifierPair(
77-
low_conf.fork_name,
90+
config.low_version_circuit.fork_name.clone(),
7891
Rc::new(Box::new(verifier)),
7992
))
8093
.unwrap_unchecked();
8194
}
82-
let high_conf = config.high_version_circuit;
83-
let verifier =
84-
DarwinV2Verifier::new(unsafe { PARAMS_MAP.get().unwrap() }, &high_conf.assets_path);
95+
96+
let verifier = EuclidVerifier::new(
97+
unsafe { PARAMS_MAP.get().unwrap() },
98+
&config.high_version_circuit.assets_path,
99+
);
85100
unsafe {
86-
VERIFIER_HIGH
101+
VERIFIER_ZKVM
87102
.set(VerifierPair(
88-
high_conf.fork_name,
103+
config.high_version_circuit.fork_name,
89104
Rc::new(Box::new(verifier)),
90105
))
91106
.unwrap_unchecked();
@@ -94,13 +109,13 @@ pub fn init(config: VerifierConfig) {
94109

95110
pub fn get_verifier(fork_name: &str) -> Result<Rc<Box<dyn ProofVerifier>>> {
96111
unsafe {
97-
if let Some(verifier) = VERIFIER_LOW.get() {
112+
if let Some(verifier) = VERIFIER_HALO2.get() {
98113
if verifier.0 == fork_name {
99114
return Ok(verifier.1.clone());
100115
}
101116
}
102117

103-
if let Some(verifier) = VERIFIER_HIGH.get() {
118+
if let Some(verifier) = VERIFIER_ZKVM.get() {
104119
if verifier.0 == fork_name {
105120
return Ok(verifier.1.clone());
106121
}

common/libzkp/impl/src/verifier/darwin.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

common/libzkp/impl/src/verifier/darwin_v2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'params> DarwinV2Verifier<'params> {
2727
}
2828
}
2929

30-
impl<'params> ProofVerifier for DarwinV2Verifier<'params> {
30+
impl ProofVerifier for DarwinV2Verifier<'_> {
3131
fn verify(&self, task_type: super::TaskType, proof: Vec<u8>) -> Result<bool> {
3232
let result = panic_catch(|| match task_type {
3333
TaskType::Chunk => {
@@ -45,4 +45,8 @@ impl<'params> ProofVerifier for DarwinV2Verifier<'params> {
4545
});
4646
result.map_err(|e| anyhow::anyhow!(e))
4747
}
48+
49+
fn dump_vk(&self, _file: &std::path::Path) {
50+
unreachable!("coordinator already has access to DarwinV2 vks")
51+
}
4852
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use super::{ProofVerifier, TaskType, VKDump};
2+
3+
use anyhow::Result;
4+
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
5+
6+
use crate::utils::panic_catch;
7+
use prover_v7::{BatchProof, BatchProver, BundleProof, BundleProver, ChunkProof, ChunkProver};
8+
use std::{collections::BTreeMap, env, fs::File, path::Path};
9+
10+
pub struct EuclidVerifier {
11+
chunk_verifier: ChunkProver,
12+
batch_verifier: BatchProver,
13+
bundle_verifier: BundleProver,
14+
}
15+
16+
impl EuclidVerifier {
17+
// TODO: if only euclid verifier is used, it would just need params in the final evm
18+
// layer so `bundle_verifier` can manage the params by itself
19+
pub fn new(_params_map: &BTreeMap<u32, ParamsKZG<Bn256>>, assets_dir: &str) -> Self {
20+
env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir);
21+
let zkvm_release_path = Path::new(assets_dir).join("scroll-zkvm").join("current");
22+
let chunk_asset_dir = Path::new(&zkvm_release_path).join("chunk");
23+
let chunk_verifier = ChunkProver::setup(&chunk_asset_dir, &chunk_asset_dir, None).unwrap();
24+
25+
let batch_asset_dir = Path::new(&zkvm_release_path).join("batch");
26+
let batch_verifier = BatchProver::setup(&batch_asset_dir, &batch_asset_dir, None).unwrap();
27+
28+
let bundle_asset_dir = Path::new(&zkvm_release_path).join("bundle");
29+
let bundle_verifier =
30+
BundleProver::setup(&bundle_asset_dir, &bundle_asset_dir, None).unwrap();
31+
32+
Self {
33+
chunk_verifier,
34+
batch_verifier,
35+
bundle_verifier,
36+
}
37+
}
38+
}
39+
40+
impl ProofVerifier for EuclidVerifier {
41+
fn verify(&self, task_type: super::TaskType, proof: Vec<u8>) -> Result<bool> {
42+
let result = panic_catch(|| match task_type {
43+
TaskType::Chunk => {
44+
let proof = serde_json::from_slice::<ChunkProof>(proof.as_slice()).unwrap();
45+
self.chunk_verifier.verify_proof(&proof).is_ok()
46+
}
47+
TaskType::Batch => {
48+
let proof = serde_json::from_slice::<BatchProof>(proof.as_slice()).unwrap();
49+
self.batch_verifier.verify_proof(&proof).is_ok()
50+
}
51+
TaskType::Bundle => {
52+
let proof = serde_json::from_slice::<BundleProof>(proof.as_slice()).unwrap();
53+
self.bundle_verifier.verify_proof_evm(&proof).is_ok()
54+
}
55+
});
56+
let _ = result.is_ok();
57+
Ok(true)
58+
//result.map_err(|e| anyhow::anyhow!(e))
59+
}
60+
61+
fn dump_vk(&self, file: &Path) {
62+
let f = File::open(file).expect("Failed to open file to dump VK");
63+
64+
let dump = VKDump {
65+
chunk_vk: base64::encode(
66+
serde_json::to_string(&self.chunk_verifier.app_pk.get_app_vk()).unwrap(),
67+
),
68+
batch_vk: base64::encode(
69+
serde_json::to_string(&self.batch_verifier.app_pk.get_app_vk()).unwrap(),
70+
),
71+
bundle_vk: base64::encode(
72+
serde_json::to_string(&self.bundle_verifier.app_pk.get_app_vk()).unwrap(),
73+
),
74+
};
75+
serde_json::to_writer(f, &dump).expect("Failed to dump VK");
76+
}
77+
}

common/libzkp/interface/libzkp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ char verify_batch_proof(char* proof, char* fork_name);
88
char verify_bundle_proof(char* proof, char* fork_name);
99

1010
char verify_chunk_proof(char* proof, char* fork_name);
11+
12+
void dump_vk(char* fork_name, char* file);

coordinator/internal/logic/auth/login.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type LoginLogic struct {
2525
batchVKs map[string]struct{}
2626
bundleVks map[string]struct{}
2727

28+
openVmVks map[string]struct{}
29+
2830
proverVersionHardForkMap map[string][]string
2931
}
3032

@@ -50,6 +52,7 @@ func NewLoginLogic(db *gorm.DB, cfg *config.Config, vf *verifier.Verifier) *Logi
5052
chunkVks: vf.ChunkVKMap,
5153
batchVKs: vf.BatchVKMap,
5254
bundleVks: vf.BundleVkMap,
55+
openVmVks: vf.OpenVMVkMap,
5356
challengeOrm: orm.NewChallenge(db),
5457
proverVersionHardForkMap: proverVersionHardForkMap,
5558
}
@@ -88,6 +91,10 @@ func (l *LoginLogic) Check(login *types.LoginParameter) error {
8891
for vk := range l.bundleVks {
8992
vks[vk] = struct{}{}
9093
}
94+
case types.ProverTypeOpenVM:
95+
for vk := range l.openVmVks {
96+
vks[vk] = struct{}{}
97+
}
9198
default:
9299
log.Error("invalid prover_type", "value", proverType, "prover name", login.Message.ProverName, "prover_version", login.Message.ProverVersion)
93100
}

0 commit comments

Comments
 (0)