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

Induce verifier and message for euclid #1596

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
791fcaf
feat(coordinator): assign static prover first and avoid reassigning f…
yiweichi Dec 30, 2024
71acdb3
fix: lint
yiweichi Dec 30, 2024
8ce5121
fix: GetUnassignedBatchCount
yiweichi Dec 30, 2024
3e0589e
Merge branch 'develop' into feat-coordinator-assign-logic
yiweichi Dec 30, 2024
df92616
chore: remove extra files
yiweichi Dec 30, 2024
a75075d
fix: err log
yiweichi Dec 30, 2024
1c5d88d
fix: orm GetTaskOfProver
yiweichi Dec 30, 2024
e4c0779
fix: comments
yiweichi Dec 30, 2024
3da7567
feat(prover): support mutiple version of prover tasks
yiweichi Dec 31, 2024
37da7b8
chore: remove extra files
yiweichi Dec 31, 2024
4215b6b
fix: field is never read
yiweichi Dec 31, 2024
3e97105
refactor
yiweichi Dec 31, 2024
9e63761
fix: lint
yiweichi Dec 31, 2024
707267a
fix: lint
yiweichi Dec 31, 2024
6ba25dc
feat(prover): integrate proving-sdk
yiweichi Jan 5, 2025
f3cebe7
fix: lint
yiweichi Jan 5, 2025
1e2e253
chore: auto version bump [bot]
yiweichi Jan 5, 2025
6e2c29e
update dependencies
yiweichi Jan 6, 2025
e01d185
Revert "feat(coordinator): assign static prover first and avoid reass…
yiweichi Jan 6, 2025
fa87cfa
Merge branch 'feat-prover-integrate-proving-sdk' of https://github.co…
yiweichi Jan 6, 2025
da6be90
fix: comments
yiweichi Jan 6, 2025
139fd6e
Merge branch 'develop' into feat-prover-integrate-proving-sdk
yiweichi Jan 6, 2025
ddbb06d
chore: auto version bump [bot]
yiweichi Jan 6, 2025
5d58a35
remove unused files
yiweichi Jan 6, 2025
b1ee955
ci: update workflow prover fmt timeout
yiweichi Jan 6, 2025
4c4495d
Merge branch 'fix-ci-prover-fmt-timeout' into feat-prover-integrate-p…
yiweichi Jan 6, 2025
02ec1d9
test: update workflow prover fmt timeout
yiweichi Jan 6, 2025
9cf9bc3
Merge branch 'fix-ci-prover-fmt-timeout' into feat-prover-integrate-p…
yiweichi Jan 6, 2025
2acb405
revert test logic
yiweichi Jan 6, 2025
b67ff8f
revert test logic
yiweichi Jan 6, 2025
6ce5688
update config file
yiweichi Jan 6, 2025
625477f
update dependencies
yiweichi Jan 7, 2025
f431966
update cargo dependencies
yiweichi Jan 8, 2025
f9b9fd5
update example config file
yiweichi Jan 8, 2025
fc8856c
update example config file
yiweichi Jan 9, 2025
5ee0d7a
fix: init multi task type issue
yiweichi Jan 10, 2025
4c83394
revert AssetsDirEnvConfig
yiweichi Jan 10, 2025
574a802
Merge branch 'develop' into feat-prover-integrate-proving-sdk
yiweichi Jan 15, 2025
76a85a4
chore: auto version bump [bot]
yiweichi Jan 15, 2025
68fc9cf
remove prover.test
yiweichi Jan 16, 2025
215a503
fix: prover to use spawn_blocking (#1591)
yiweichi Jan 17, 2025
7c57b0a
fix: comments
yiweichi Jan 19, 2025
ef15752
remove unnecessary clone
yiweichi Jan 22, 2025
0ecbb1b
Merge branch 'develop' into feat-prover-integrate-proving-sdk
yiweichi Jan 24, 2025
40b15f7
Update to most recent SDK version
omerfirmak Jan 28, 2025
ded5417
induce zkvm for euclid
noel2004 Feb 2, 2025
f21feeb
induce message for zkvm
noel2004 Feb 3, 2025
3d1dc31
wip
omerfirmak Feb 3, 2025
27d7ab6
induce zkvm for libzkp
noel2004 Feb 3, 2025
9a206d1
induce eculid verifier for libzkp
noel2004 Feb 3, 2025
91de614
Merge remote-tracking branch 'origin/omerfirmak/euclid-prover' into f…
noel2004 Feb 3, 2025
403a7f7
resume lock
noel2004 Feb 3, 2025
5962912
update layout for verifier
noel2004 Feb 4, 2025
31ad3c9
use subdirectory for zkvm asset
noel2004 Feb 4, 2025
afccc3d
fix lint
noel2004 Feb 4, 2025
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
9,624 changes: 7,564 additions & 2,060 deletions common/libzkp/impl/Cargo.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions common/libzkp/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ halo2curves = { git = "https://github.com/scroll-tech/halo2curves", branch = "v0
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
# patched add rkyv support & MSRV 1.77
ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18" }
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
Expand All @@ -28,6 +36,9 @@ snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", br
prover_v4 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
# darwin_v2
prover_v5 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
# euclid
prover_v7 = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.1", package = "scroll-zkvm-prover" }
verifier_v7 = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.1", package = "scroll-zkvm-verifier" }

base64 = "0.13.0"
env_logger = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion common/libzkp/impl/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-12-03
nightly-2024-12-06
21 changes: 21 additions & 0 deletions common/libzkp/impl/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod darwin;
mod darwin_v2;
mod euclid;

use anyhow::{bail, Result};
use darwin::DarwinVerifier;
use darwin_v2::DarwinV2Verifier;
use euclid::EuclidVerifier;
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use prover_v4::utils::load_params;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -31,12 +33,14 @@ pub struct CircuitConfig {
pub struct VerifierConfig {
pub low_version_circuit: CircuitConfig,
pub high_version_circuit: CircuitConfig,
pub zkvm_circuit: CircuitConfig,
}

type HardForkName = String;

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

static mut VERIFIER_ZKVM: OnceCell<VerifierPair> = OnceCell::new();
static mut VERIFIER_HIGH: OnceCell<VerifierPair> = OnceCell::new();
static mut VERIFIER_LOW: OnceCell<VerifierPair> = OnceCell::new();
static mut PARAMS_MAP: OnceCell<BTreeMap<u32, ParamsKZG<Bn256>>> = OnceCell::new();
Expand Down Expand Up @@ -90,6 +94,17 @@ pub fn init(config: VerifierConfig) {
))
.unwrap_unchecked();
}
let zkvm_conf = config.zkvm_circuit;
let verifier =
EuclidVerifier::new(unsafe { PARAMS_MAP.get().unwrap() }, &high_conf.assets_path);
unsafe {
VERIFIER_ZKVM
.set(VerifierPair(
zkvm_conf.fork_name,
Rc::new(Box::new(verifier)),
))
.unwrap_unchecked();
}
}

pub fn get_verifier(fork_name: &str) -> Result<Rc<Box<dyn ProofVerifier>>> {
Expand All @@ -105,6 +120,12 @@ pub fn get_verifier(fork_name: &str) -> Result<Rc<Box<dyn ProofVerifier>>> {
return Ok(verifier.1.clone());
}
}

if let Some(verifier) = VERIFIER_ZKVM.get() {
if verifier.0 == fork_name {
return Ok(verifier.1.clone());
}
}
}
bail!("failed to get verifier, key not found, {}", fork_name)
}
60 changes: 60 additions & 0 deletions common/libzkp/impl/src/verifier/euclid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use super::{ProofVerifier, TaskType};

use anyhow::Result;
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};

use crate::utils::panic_catch;
use prover_v7::{BatchProof, BatchProver, BundleProof, BundleProver, ChunkProof, ChunkProver};
use std::{collections::BTreeMap, env, path::Path};

pub struct EuclidVerifier {
chunk_verifier: ChunkProver,
batch_verifier: BatchProver,
bundle_verifier: BundleProver,
}

impl EuclidVerifier {
// TODO: if only euclid verifier is used, it would just need params in the final evm
// layer so `bundle_verifier` can manage the params by itself
pub fn new(_params_map: &BTreeMap<u32, ParamsKZG<Bn256>>, assets_dir: &str) -> Self {
env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir);
let zkvm_release_path = Path::new(assets_dir).join("scroll-zkvm").join("current");
let chunk_asset_dir = Path::new(&zkvm_release_path).join("chunk");
let chunk_verifier = ChunkProver::setup(&chunk_asset_dir, &chunk_asset_dir, None).unwrap();

let batch_asset_dir = Path::new(&zkvm_release_path).join("batch");
let batch_verifier = BatchProver::setup(&batch_asset_dir, &batch_asset_dir, None).unwrap();

let bundle_asset_dir = Path::new(&zkvm_release_path).join("bundle");
let bundle_verifier =
BundleProver::setup(&bundle_asset_dir, &bundle_asset_dir, None).unwrap();

Self {
chunk_verifier,
batch_verifier,
bundle_verifier,
}
}
}

impl ProofVerifier for EuclidVerifier {
fn verify(&self, task_type: super::TaskType, proof: Vec<u8>) -> Result<bool> {
let result = panic_catch(|| match task_type {
TaskType::Chunk => {
let proof = serde_json::from_slice::<ChunkProof>(proof.as_slice()).unwrap();
self.chunk_verifier.verify_proof(&proof).is_ok()
}
TaskType::Batch => {
let proof = serde_json::from_slice::<BatchProof>(proof.as_slice()).unwrap();
self.batch_verifier.verify_proof(&proof).is_ok()
}
TaskType::Bundle => {
let proof = serde_json::from_slice::<BundleProof>(proof.as_slice()).unwrap();
self.bundle_verifier.verify_proof_evm(&proof).is_ok()
}
});
let _ = result.is_ok();
Ok(true)
//result.map_err(|e| anyhow::anyhow!(e))
}
}
1 change: 1 addition & 0 deletions common/types/message/euclid/batch-proof-sample.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions common/types/message/euclid/bundle-proof-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"metadata":null,"proof":{"instances":[["31ff3e68c303b187643d62000000000000000000000000000000000000000000","511046535fbfe6acbaf95e000000000000000000000000000000000000000000","bdaf9874f99e5b6e9f2300000000000000000000000000000000000000000000","9fbd6d21e025994cef993a000000000000000000000000000000000000000000","6f951f0bd5843685da5145000000000000000000000000000000000000000000","05c058fddf264153a90e00000000000000000000000000000000000000000000","1390fef2e0288741926de4000000000000000000000000000000000000000000","f99a9f47b49fb6140d1e8e000000000000000000000000000000000000000000","b8d59cd7db9c22e0a00d00000000000000000000000000000000000000000000","c9edbf55224d3f8d6997dc000000000000000000000000000000000000000000","ce6fcc33ba079746f64fa2000000000000000000000000000000000000000000","81a8ceda3bdcaf48ed0600000000000000000000000000000000000000000000","850b8ad3be6fdc1b89b408c70a7fd0c5826237c495375f31e00be4067ee81600","0b99d439ed30ad5d4f8f46b70b14d0599016405dd4cb3492a3795fa086e63d00","7d00000000000000000000000000000000000000000000000000000000000000","1a00000000000000000000000000000000000000000000000000000000000000","b500000000000000000000000000000000000000000000000000000000000000","1a00000000000000000000000000000000000000000000000000000000000000","ac00000000000000000000000000000000000000000000000000000000000000","fa00000000000000000000000000000000000000000000000000000000000000","bc00000000000000000000000000000000000000000000000000000000000000","da00000000000000000000000000000000000000000000000000000000000000","1d00000000000000000000000000000000000000000000000000000000000000","1100000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","3400000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","4b00000000000000000000000000000000000000000000000000000000000000","4400000000000000000000000000000000000000000000000000000000000000","4600000000000000000000000000000000000000000000000000000000000000","f100000000000000000000000000000000000000000000000000000000000000","ec00000000000000000000000000000000000000000000000000000000000000","7b00000000000000000000000000000000000000000000000000000000000000","9e00000000000000000000000000000000000000000000000000000000000000","8300000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","8000000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","ef00000000000000000000000000000000000000000000000000000000000000","5e00000000000000000000000000000000000000000000000000000000000000","4800000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","2500000000000000000000000000000000000000000000000000000000000000","6600000000000000000000000000000000000000000000000000000000000000","f400000000000000000000000000000000000000000000000000000000000000"]],"proof":[43,162,92,146,126,74,14,56,40,52,177,85,254,141,143,124,185,195,222,180,201,38,165,234,217,104,76,76,221,165,112,190,2,246,172,84,194,17,17,136,185,54,180,156,203,89,112,189,229,116,108,248,212,143,122,110,104,193,140,70,224,42,255,88,16,44,109,144,22,110,57,64,148,168,120,137,16,48,92,127,22,152,112,172,62,137,184,91,127,210,166,220,228,201,197,248,33,254,183,11,63,56,118,22,116,81,161,197,37,103,222,47,66,228,202,94,246,120,65,79,153,42,189,142,91,83,44,226,45,70,225,208,140,37,183,142,103,236,126,103,20,5,17,22,198,15,132,88,239,161,189,105,55,234,126,199,188,235,191,201,5,177,104,8,13,135,214,158,215,140,68,107,115,39,20,148,162,235,209,21,158,131,112,169,253,194,78,72,149,89,25,70,19,48,252,228,121,53,118,43,111,65,177,125,15,145,152,55,86,128,155,159,111,21,19,64,158,31,117,240,58,26,249,255,8,145,233,176,3,79,254,56,51,15,104,18,53,139,41,61,171,203,174,94,167,81,88,174,192,55,53,171,241,136,129,189,31,29,207,109,193,125,49,188,162,165,142,247,173,100,232,198,93,76,98,119,233,109,237,241,162,90,37,28,205,110,111,70,45,121,231,76,16,202,148,91,222,62,183,179,4,32,66,13,25,44,129,159,131,2,156,52,73,151,123,255,240,135,3,241,38,141,129,123,113,56,66,66,51,75,221,214,249,123,239,244,254,132,19,136,161,178,120,48,232,10,141,141,21,119,109,16,43,224,165,195,161,232,181,168,232,196,146,13,245,58,147,139,27,28,49,18,16,189,114,184,207,100,59,30,69,184,254,185,39,9,176,49,49,211,50,173,128,87,187,129,138,122,206,1,209,179,220,223,170,215,92,211,86,46,245,105,105,153,137,236,18,82,239,156,220,79,149,18,100,78,103,77,128,101,142,88,143,106,204,140,74,227,155,214,230,0,33,54,23,236,125,197,16,147,203,205,17,200,9,148,29,207,243,115,165,201,222,5,189,187,176,193,134,168,154,235,17,81,41,221,196,234,114,56,34,141,172,190,98,168,253,255,0,201,88,180,254,48,29,0,36,142,242,181,86,42,105,227,198,27,83,77,133,101,98,241,26,119,252,91,249,48,39,245,202,241,183,120,10,190,109,239,182,179,37,194,28,249,3,46,224,146,15,171,246,31,165,227,18,127,90,51,11,169,108,255,239,59,56,223,219,146,130,195,128,59,228,32,47,38,82,138,146,123,127,27,49,95,56,37,39,110,248,136,126,130,148,189,129,153,248,125,73,54,138,231,114,217,118,102,50,21,169,169,243,71,138,137,13,59,168,0,21,139,228,111,222,203,69,108,181,36,132,151,1,36,219,115,142,140,239,34,156,248,7,248,82,121,190,34,15,200,186,226,23,13,73,78,80,117,135,74,84,25,242,242,119,240,15,240,247,59,103,164,59,17,179,236,112,10,32,12,73,67,176,16,37,5,223,55,201,35,104,202,28,151,166,49,176,78,235,227,160,148,48,115,22,248,76,21,148,25,174,182,47,29,245,31,16,56,114,246,161,201,209,217,242,23,82,212,185,21,196,162,64,192,166,250,198,211,87,105,219,100,78,41,218,74,202,128,24,192,88,11,211,68,142,3,34,63,248,113,180,146,211,58,164,96,139,125,13,227,110,3,96,175,132,15,237,28,15,6,31,193,116,36,191,42,209,129,73,18,177,243,27,248,33,141,163,136,59,66,244,254,81,51,95,191,212,91,227,222,111,18,42,14,20,14,47,0,159,126,212,88,27,216,39,78,21,56,162,227,5,143,171,132,29,178,43,84,188,138,243,181,24,125,11,139,140,241,88,145,79,76,142,158,16,187,194,152,191,174,88,219,13,70,58,225,123,119,239,141,139,70,100,103,65,113,3,79,150,9,72,255,133,97,116,33,253,134,161,86,213,197,180,26,236,191,20,201,105,44,9,23,51,112,144,197,151,50,36,183,35,17,208,114,103,111,89,141,61,74,115,184,169,231,18,17,71,229,253,253,72,126,253,63,87,160,195,221,90,179,21,149,232,4,151,96,192,141,124,0,231,3,199,204,70,52,130,95,56,112,34,250,212,125,138,162,19,136,135,93,249,160,6,97,124,214,233,250,49,255,247,169,229,195,230,29,197,213,209,89,59,14,177,14,249,168,16,63,46,99,222,144,110,255,32,235,37,168,180,167,28,122,12,211,62,198,237,69,52,201,222,20,108,120,115,102,198,93,79,186,244,240,82,33,76,89,23,103,51,27,139,123,167,47,157,60,196,25,9,63,95,29,248,232,103,99,239,234,44,156,121,252,198,205,55,36,22,197,43,165,253,154,225,131,81,10,30,251,35,200,106,75,14,192,149,101,29,94,4,79,174,41,139,168,37,96,37,243,54,92,11,111,32,154,218,3,216,81,119,89,25,106,78,64,237,240,215,19,40,210,85,134,107,162,164,87,89,105,114,1,109,158,39,36,40,51,196,150,166,157,181,103,134,47,224,45,34,103,65,249,131,235,18,156,84,10,246,122,118,77,54,57,238,139,46,4,219,207,245,145,144,174,255,34,125,16,32,88,229,137,63,50,24,126,174,11,113,168,142,6,122,231,241,160,227,0,36,84,49,231,10,196,3,90,37,12,141,146,255,130,149,37,148,155,89,255,250,92,62,3,231,91,252,205,228,50,102,140,37,75,40,40,8,182,169,106,222,172,169,214,53,50,132,203,68,158,198,43,224,253,99,10,41,90,102,151,127,39,148,53,15,5,244,233,240,53,89,195,99,59,220,237,218,32,7,239,187,197,183,184,130,113,108,47,123,223,124,76,151,86,201,218,29,189,11,59,69,203,197,69,0,40,95,118,186,119,144,105,48,235,127,149,46,189,48,12,244,140,137,215,37,178,154,19,42,82,0,183,1,48,152,251,23,39,132,214,30,109,75,193,165,28,213,243,189,7,76,76,108,191,57,185,149,96,32,94,30,77,111,21,81,193,171,60,76,23,158,166,50,111,194,232,226,73,37,233,132,218,67,32,169,223,17,166,76,119,88,85]},"git_version":"1407454"}
169 changes: 169 additions & 0 deletions common/types/message/euclid/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package euclid

import (
"errors"
"fmt"

"github.com/scroll-tech/go-ethereum/common"
)

// RespStatus represents status code from prover to scroll
type RespStatus uint32

const (
// StatusOk means generate proof success
StatusOk RespStatus = iota
// StatusProofError means generate proof failed
StatusProofError
)

// ChunkTaskDetail is a type containing informations require to build ChunkTask.
type ChunkTaskDetail struct {
BlockHashes []common.Hash `json:"block_hashes"`
}

// BatchTask
type BatchTask struct {
ChunkProofs []*ChunkProof `json:"chunk_proofs"`
BatchHeader interface{} `json:"batch_header"`
BlobBytes []byte `json:"blob_bytes"`
}

// BundleTask
type BundleTask struct {
BatchProofs []*BatchProof `json:"batch_proofs"`
}

// Proof for flatten VM proof
type VmProof struct {
Proof interface{} `json:"proofs"`
PublicValues []uint32 `json:"public_values"`
Vk []byte `json:"vk,omitempty"`
}

// Proof for flatten EVM proof
type EVmProof struct {
Proof []byte `json:"proof"`
Instances [][]string `json:"instances"`
Vk []byte `json:"vk,omitempty"`
}

// ChunkInfo is for calculating pi_hash for chunk
type ChunkInfo struct {
ChainID uint64 `json:"chain_id"`
PrevStateRoot common.Hash `json:"prev_state_root"`
PostStateRoot common.Hash `json:"post_state_root"`
WithdrawRoot common.Hash `json:"withdraw_root"`
DataHash common.Hash `json:"data_hash"`
TxBytesHash common.Hash `json:"tx_data_digest"`
}

// ChunkProof includes the proof info that are required for chunk verification and rollup.
type ChunkProof struct {
MetaData struct {
ChunkInfo *ChunkInfo `json:"chunk_info"`
} `json:"metadata"`

Proof *VmProof `json:"proof"`
GitVersion string `json:"git_version,omitempty"`
}

// BatchInfo is for calculating pi_hash for batch header
type BatchInfo struct {
ParentBatchHash common.Hash `json:"parent_batch_hash"`
ParentStateRoot common.Hash `json:"parent_state_root"`
StateRoot common.Hash `json:"state_root"`
WithdrawRoot common.Hash `json:"withdraw_root"`
BatchHash common.Hash `json:"batch_hash"`
ChainID uint64 `json:"chain_id"`
}

// BatchProof includes the proof info that are required for batch verification and rollup.
type BatchProof struct {
MetaData struct {
BatchInfo *BatchInfo `json:"batch_info"`
BatchHash common.Hash `json:"batch_hash"`
} `json:"metadata"`

Proof *VmProof `json:"proof"`
GitVersion string `json:"git_version,omitempty"`
}

// SanityCheck checks whether a BatchProof is in a legal format
func (ap *BatchProof) SanityCheck() error {
if ap == nil {
return errors.New("agg_proof is nil")
}
if ap.MetaData.BatchInfo == nil {
return errors.New("batch info not ready")
}

if ap.Proof == nil {
return errors.New("proof not ready")
} else {
pf := ap.Proof
if pf.Proof == nil {
return errors.New("proof data not ready")
}

// TODO: resume this after rc2
// if len(pf.Vk) == 0 {
// return errors.New("vk not ready")
// }
}

return nil
}

// BundleInfo is for calculating pi_hash for bundle header
type BundleInfo struct {
ChainID uint64 `json:"chain_id"`
PrevStateRoot common.Hash `json:"prev_state_root"`
PostStateRoot common.Hash `json:"post_state_root"`
WithdrawRoot common.Hash `json:"withdraw_root"`
NumBatches uint32 `json:"num_batches"`
PrevBatchHash common.Hash `json:"prev_batch_hash"`
BatchHash common.Hash `json:"batch_hash"`
}

// BundleProof includes the proof info that are required for verification of a bundle of batch proofs.
type BundleProof struct {
MetaData struct {
BundleInfo *BundleInfo `json:"bundle_info"`
BunndlePIHash common.Hash `json:"bundle_pi_hash"`
} `json:"metadata"`

Proof *EVmProof `json:"proof"`
GitVersion string `json:"git_version,omitempty"`
}

// SanityCheck checks whether a BundleProof is in a legal format
func (ap *BundleProof) SanityCheck() error {
if ap == nil {
return errors.New("agg_proof is nil")
}
// TODO: resume this after metadata of bundle info is ready
// if ap.MetaData.BundleInfo == nil {
// return errors.New("bundle info not ready")
// }

if ap.Proof == nil {
return errors.New("proof not ready")
} else {
pf := ap.Proof
if len(pf.Proof)%32 != 0 {
return fmt.Errorf("proof buffer length must be a multiple of 32, got: %d", len(pf.Proof))
}

if len(pf.Instances) == 0 {
return errors.New("instance not ready")
}

// TODO: resume this after rc2
// if len(pf.Vk) == 0 {
// return errors.New("vk not ready")
// }
}

return nil
}
Loading
Loading