Skip to content

Commit a300fa2

Browse files
committed
separate prover bin
Signed-off-by: noelwei <[email protected]>
1 parent 932be72 commit a300fa2

File tree

11 files changed

+456
-310
lines changed

11 files changed

+456
-310
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3+
"common/types-rs",
34
"common/types-rs/base",
45
"common/types-rs/circuit",
56
"common/types-rs/aggregation",
@@ -30,6 +31,7 @@ sbv-core = { git = "https://github.com/scroll-tech/stateless-block-verifier", br
3031
sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade", features = ["scroll"] }
3132
sbv-kv = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade" }
3233
sbv-trie = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade" }
34+
sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade" }
3335

3436
alloy = { version = "0.11", default-features = false }
3537
alloy-primitives = { version = "0.8", default-features = false }

common/types-rs/Cargo.toml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,10 @@ repository.workspace = true
88
version = "0.2.0"
99

1010
[dependencies]
11-
alloy-primitives = { workspace = true, default-features = false, features = ["std", "map-hashbrown", "map-fxhash", "rkyv"] }
12-
rkyv.workspace = true
13-
sbv-trie = { workspace = true }
14-
sbv-core = { workspace = true }
15-
sbv-primitives = { workspace = true }
16-
sbv-kv = { workspace = true }
17-
vm-zstd = { workspace = true }
18-
serde.workspace = true
19-
itertools.workspace = true
20-
tiny-keccak = { workspace = true }
11+
types-base = { path = "base", package = "scroll-zkvm-circuit-input-types-base"}
12+
types-agg = { path = "aggregation", package = "scroll-zkvm-circuit-input-types-aggregation"}
13+
types-chunk = { path = "chunk", package = "scroll-zkvm-circuit-input-types-chunk"}
14+
types-batch = { path = "batch", package = "scroll-zkvm-circuit-input-types-batch"}
15+
types-bundle = { path = "bundle", package = "scroll-zkvm-circuit-input-types-bundle"}
2116

22-
openvm = { workspace = true, features = ["std"] }
23-
openvm-rv32im-guest = { workspace = true }
24-
openvm-custom-insn = { workspace = true }
25-
sha3 = "0.10.8"
26-
sha2 = "0.10.8"
2717

28-
[features]
29-
default = []
30-
openvm = ["sbv-trie/openvm", "sbv-core/openvm", "sbv-primitives/openvm", "tiny-keccak/openvm"]

common/types-rs/circuit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rkyv.workspace = true
1313
serde.workspace = true
1414
openvm = { workspace = true, features = ["std"] }
1515
tiny-keccak = { workspace = true, features = ["openvm"]}
16+
itertools.workspace = true
1617

1718
types-base = { path = "../base", package = "scroll-zkvm-circuit-input-types-base"}
1819
types-agg = { path = "../aggregation", package = "scroll-zkvm-circuit-input-types-aggregation"}

common/types-rs/circuit/src/lib.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pub use io::read_witnesses;
33

44
use alloy_primitives::B256;
55
use types_base::public_inputs::PublicInputs;
6+
use types_agg::{ProofCarryingWitness, ProgramCommitment, AggregationInput, verify_proof};
7+
use itertools::Itertools;
68

79
/// Reveal the public-input values as openvm public values.
810
pub fn reveal_pi_hash(pi_hash: B256) {
@@ -35,3 +37,60 @@ pub trait Circuit {
3537
reveal_pi_hash(pi.pi_hash())
3638
}
3739
}
40+
41+
42+
/// Circuit that additional aggregates proofs from other [`Circuits`][Circuit].
43+
pub trait AggCircuit: Circuit
44+
where
45+
Self::Witness: ProofCarryingWitness,
46+
{
47+
/// The public-input values of the proofs being aggregated.
48+
type AggregatedPublicInputs: PublicInputs;
49+
50+
/// Check if the commitment in proof is valid (from program(s)
51+
/// we have expected)
52+
fn verify_commitments(commitment: &ProgramCommitment);
53+
54+
/// Verify the proofs being aggregated.
55+
///
56+
/// Also returns the root proofs being aggregated.
57+
fn verify_proofs(witness: &Self::Witness) -> Vec<AggregationInput> {
58+
let proofs = witness.get_proofs();
59+
60+
for proof in proofs.iter() {
61+
Self::verify_commitments(&proof.commitment);
62+
verify_proof(&proof.commitment, proof.public_values.as_slice());
63+
}
64+
65+
proofs
66+
}
67+
68+
/// Derive the public-input values of the proofs being aggregated from the witness.
69+
fn aggregated_public_inputs(witness: &Self::Witness) -> Vec<Self::AggregatedPublicInputs>;
70+
71+
/// Derive the public-input hashes of the aggregated proofs from the proofs itself.
72+
fn aggregated_pi_hashes(proofs: &[AggregationInput]) -> Vec<B256>;
73+
74+
/// Validate that the public-input values of the aggregated proofs are well-formed.
75+
///
76+
/// - That the public-inputs of contiguous chunks/batches are valid
77+
/// - That the public-input values in fact hash to the pi_hash values from the root proofs.
78+
fn validate_aggregated_pi(agg_pis: &[Self::AggregatedPublicInputs], agg_pi_hashes: &[B256]) {
79+
// There should be at least a single proof being aggregated.
80+
assert!(!agg_pis.is_empty(), "at least 1 pi to aggregate");
81+
82+
// Validation for the contiguous public-input values.
83+
for w in agg_pis.windows(2) {
84+
w[1].validate(&w[0]);
85+
}
86+
87+
// Validation for public-input values hash being the pi_hash from root proof.
88+
for (agg_pi, &agg_pi_hash) in agg_pis.iter().zip_eq(agg_pi_hashes.iter()) {
89+
assert_eq!(
90+
agg_pi.pi_hash(),
91+
agg_pi_hash,
92+
"pi hash mismatch between proofs and witness computed"
93+
);
94+
}
95+
}
96+
}

common/types-rs/src/lib.rs

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +0,0 @@
1-
#![feature(lazy_get)]
2-
use alloy_primitives::B256;
3-
use itertools::Itertools;
4-
5-
pub mod batch;
6-
7-
pub mod bundle;
8-
9-
pub mod chunk;
10-
11-
pub mod proof;
12-
13-
pub mod utils;
14-
15-
/// Defines behaviour to be implemented by types representing the public-input values of a circuit.
16-
pub trait PublicInputs {
17-
/// Keccak-256 digest of the public inputs. The public-input hash are revealed as public values
18-
/// via [`openvm::io::reveal`].
19-
fn pi_hash(&self) -> B256;
20-
21-
/// Validation logic between public inputs of two contiguous instances.
22-
fn validate(&self, prev_pi: &Self);
23-
}
24-
25-
/// Circuit defines the higher-level behaviour to be observed by a [`openvm`] guest program.
26-
pub trait Circuit {
27-
/// The witness provided to the circuit.
28-
type Witness;
29-
30-
/// The public-input values for the circuit.
31-
type PublicInputs: PublicInputs;
32-
33-
/// Setup openvm extensions as a preliminary step.
34-
fn setup();
35-
36-
/// Reads bytes from openvm StdIn.
37-
fn read_witness_bytes() -> Vec<u8>;
38-
39-
/// Deserialize raw bytes into the circuit's witness type.
40-
fn deserialize_witness(witness_bytes: &[u8]) -> &Self::Witness;
41-
42-
/// Validate the witness to produce the circuit's public inputs.
43-
fn validate(witness: &Self::Witness) -> Self::PublicInputs;
44-
45-
/// Reveal the public inputs.
46-
fn reveal_pi(pi: &Self::PublicInputs) {
47-
reveal_pi_hash(pi.pi_hash())
48-
}
49-
}
50-
51-
/// Reveal the public-input values as openvm public values.
52-
pub fn reveal_pi_hash(pi_hash: B256) {
53-
openvm::io::println(format!("pi_hash = {pi_hash:?}"));
54-
openvm::io::reveal_bytes32(*pi_hash);
55-
}
56-
57-
/// Circuit that additional aggregates proofs from other [`Circuits`][Circuit].
58-
pub trait AggCircuit: Circuit
59-
where
60-
Self::Witness: ProofCarryingWitness,
61-
{
62-
/// The public-input values of the proofs being aggregated.
63-
type AggregatedPublicInputs: PublicInputs;
64-
65-
/// Check if the commitment in proof is valid (from program(s)
66-
/// we have expected)
67-
fn verify_commitments(commitment: &proof::ProgramCommitment);
68-
69-
/// Verify the proofs being aggregated.
70-
///
71-
/// Also returns the root proofs being aggregated.
72-
fn verify_proofs(witness: &Self::Witness) -> Vec<proof::AggregationInput> {
73-
let proofs = witness.get_proofs();
74-
75-
for proof in proofs.iter() {
76-
Self::verify_commitments(&proof.commitment);
77-
proof::verify_proof(&proof.commitment, proof.public_values.as_slice());
78-
}
79-
80-
proofs
81-
}
82-
83-
/// Derive the public-input values of the proofs being aggregated from the witness.
84-
fn aggregated_public_inputs(witness: &Self::Witness) -> Vec<Self::AggregatedPublicInputs>;
85-
86-
/// Derive the public-input hashes of the aggregated proofs from the proofs itself.
87-
fn aggregated_pi_hashes(proofs: &[proof::AggregationInput]) -> Vec<B256>;
88-
89-
/// Validate that the public-input values of the aggregated proofs are well-formed.
90-
///
91-
/// - That the public-inputs of contiguous chunks/batches are valid
92-
/// - That the public-input values in fact hash to the pi_hash values from the root proofs.
93-
fn validate_aggregated_pi(agg_pis: &[Self::AggregatedPublicInputs], agg_pi_hashes: &[B256]) {
94-
// There should be at least a single proof being aggregated.
95-
assert!(!agg_pis.is_empty(), "at least 1 pi to aggregate");
96-
97-
// Validation for the contiguous public-input values.
98-
for w in agg_pis.windows(2) {
99-
w[1].validate(&w[0]);
100-
}
101-
102-
// Validation for public-input values hash being the pi_hash from root proof.
103-
for (agg_pi, &agg_pi_hash) in agg_pis.iter().zip_eq(agg_pi_hashes.iter()) {
104-
assert_eq!(
105-
agg_pi.pi_hash(),
106-
agg_pi_hash,
107-
"pi hash mismatch between proofs and witness computed"
108-
);
109-
}
110-
}
111-
}
112-
113-
/// Witness for an [`AggregationCircuit`][AggCircuit] that also carries proofs that are being
114-
/// aggregated.
115-
pub trait ProofCarryingWitness {
116-
/// Get the root proofs from the witness.
117-
fn get_proofs(&self) -> Vec<proof::AggregationInput>;
118-
}

common/types-rs/src/proof.rs

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

zkvm-prover/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tracing = "0.1"
1616
futures = "0.3"
1717
alloy = { workspace = true, features = ["provider-http", "transport-http", "reqwest", "reqwest-rustls-tls", "json-rpc"] }
1818
itertools.workspace = true
19+
url = ">=2.5.3"
1920

2021
# Re-export from proving-sdk
2122
reqwest = { version = "0.12.4", features = ["gzip"] }
@@ -31,5 +32,6 @@ tiny-keccak = { workspace = true, features = ["sha3", "keccak"] }
3132
scroll-zkvm-prover-euclid.workspace = true
3233
scroll-proving-sdk = { git = "https://github.com/scroll-tech/scroll-proving-sdk.git", branch = "refactor/scroll"}
3334
sbv-primitives.workspace = true
35+
sbv-utils = { workspace = true, features = ["scroll"] }
3436
serde.workspace = true
3537
serde_json.workspace = true

0 commit comments

Comments
 (0)