Skip to content

Commit

Permalink
Add prover types to make SDK feature complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Nov 21, 2024
1 parent 3a6548c commit b8efd16
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["client"]
default = ["client", "prover"]
client = ["dep:reqwest"]
prover = ["dep:base64"]

[dependencies]

# Encoding
base64 = { version = "0.22.1", default-features = false, optional = true }

# Ethereum basis.
alloy-primitives = { version = "=0.8.0", default-features = false, features = ["serde"] }

Expand Down
5 changes: 4 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

Base SDK used in integrating Scroll with Gevulot.

It provides client that implements copy of Scroll's `ProvingService` interface.
It provides:

- Client that implements copy of Scroll's `ProvingService` interface.
- Basic prover types - proof, tasks etc.
== Toolchain

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub const CIRCUIT_VERSION_0_13: &str = "v0.13.1";
#[cfg(feature = "client")]
pub mod client;

#[cfg(feature = "prover")]
pub mod prover;

#[derive(Deserialize, Serialize, Debug)]
pub struct GetVkRequest {
pub circuit_type: String,
Expand Down
98 changes: 98 additions & 0 deletions src/prover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use alloy_primitives::B256;
use serde::{Deserialize, Serialize};

pub mod base64 {
use base64::prelude::*;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// serialize bytes as base64
pub fn serialize<S>(data: &[u8], s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
String::serialize(&BASE64_STANDARD.encode(data), s)
}

/// deserialize base64 to bytes
pub fn deserialize<'de, D>(d: D) -> Result<Vec<u8>, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(d)?;
BASE64_STANDARD
.decode(s.as_bytes())
.map_err(serde::de::Error::custom)
}
}

#[derive(Debug, Clone, Deserialize)]
pub struct ChunkTaskDetail {
pub block_hashes: Vec<B256>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct BundleTaskDetail {
pub batch_proofs: Vec<BatchProof>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SubCircuitRowUsage {
pub name: String,
pub row_number: usize,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ChunkProof {
#[serde(with = "base64")]
pub protocol: Vec<u8>,
#[serde(flatten)]
pub proof: Proof,
pub chunk_info: ChunkInfo,
#[serde(default)]
pub row_usages: Vec<SubCircuitRowUsage>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BatchProof {
#[serde(with = "base64")]
pub protocol: Vec<u8>,
#[serde(flatten)]
proof: Proof,
pub batch_hash: B256,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BundleProof {
#[serde(flatten)]
on_chain_proof: Proof,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Proof {
#[serde(with = "base64")]
proof: Vec<u8>,
#[serde(with = "base64")]
instances: Vec<u8>,
#[serde(with = "base64")]
vk: Vec<u8>,
pub git_version: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ChunkInfo {
/// Chain identifier
pub chain_id: u64,
/// state root before this chunk
pub prev_state_root: B256,
/// state root after this chunk
pub post_state_root: B256,
/// the withdraw root after this chunk
pub withdraw_root: B256,
/// the data hash of this chunk
pub data_hash: B256,
/// Flattened L2 tx bytes (RLP-signed) in this chunk.
#[serde(with = "base64")]
pub tx_bytes: Vec<u8>,
/// if the chunk is a padded chunk
pub is_padding: bool,
}

0 comments on commit b8efd16

Please sign in to comment.