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(prover): proof of equivalence using rust-kzg #295

Merged
merged 60 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d6e64fc
add cycle-tracker
CeciliaZ030 Jun 3, 2024
9e948fe
git = "https://github.com/ceciliaz030/alloy", branch = "175_4e22b9e-…
CeciliaZ030 Jun 4, 2024
c1ebdcb
revm v35_taiko_v2-cycls
CeciliaZ030 Jun 4, 2024
13774a5
make harness part of root workspace
CeciliaZ030 Jun 9, 2024
31ea291
Merge branch 'harness-to-root' into sp1-cycle-tracker
CeciliaZ030 Jun 9, 2024
42d9ed4
update Cargo.lock
CeciliaZ030 Jun 9, 2024
4728d66
[dev-dependencies]
CeciliaZ030 Jun 9, 2024
a2e97c2
Merge remote-tracking branch 'origin/main' into sp1-cycle-opt
CeciliaZ030 Jun 9, 2024
0528b2f
Merge branch 'sp1-cycle-tracker' into sp1-cycle-opt & add #[cfg(featu…
CeciliaZ030 Jun 9, 2024
6321fee
use [email protected]
CeciliaZ030 Jun 9, 2024
85ee0a3
cargo update
CeciliaZ030 Jun 11, 2024
27ce3f4
clippy & fmt
CeciliaZ030 Jun 11, 2024
0faf86e
remove typo
CeciliaZ030 Jun 11, 2024
4364c4a
add [features] sp1-cycle-tracker in guest
CeciliaZ030 Jun 11, 2024
c6986a0
apply comment
CeciliaZ030 Jun 15, 2024
05b46e8
struct CycleTracker
CeciliaZ030 Jun 15, 2024
6fdb0fa
Merge branch 'main' into sp1-cycle-opt
CeciliaZ030 Jun 15, 2024
08ba176
update
CeciliaZ030 Jun 15, 2024
642ea70
Merge branch 'sp1-cycle-opt' of https://github.com/taikoxyz/raiko int…
CeciliaZ030 Jun 15, 2024
8902974
fmt
CeciliaZ030 Jun 15, 2024
2fd2594
Update proof.rs
CeciliaZ030 Jun 16, 2024
94cf84f
Update proof.rs
CeciliaZ030 Jun 16, 2024
96ad58c
Update proof.rs
CeciliaZ030 Jun 16, 2024
188d711
primitives should not exist
CeciliaZ030 Jun 16, 2024
e6dc231
added rust-kzg
CeciliaZ030 Jun 18, 2024
e4d7077
wip
CeciliaZ030 Jun 21, 2024
3ff9474
Merge remote-tracking branch 'origin/main' into swap-rust-kzg
CeciliaZ030 Jun 21, 2024
eb2c674
clear c-kzg
CeciliaZ030 Jun 21, 2024
0130aba
mod eip4844 done
CeciliaZ030 Jun 21, 2024
835fe0e
output done
CeciliaZ030 Jun 22, 2024
8371598
type KzgGroup, KzgField + test
CeciliaZ030 Jun 22, 2024
142da60
test in mod eip4844
CeciliaZ030 Jun 22, 2024
78514e4
clippy & fmt
CeciliaZ030 Jun 22, 2024
886b04b
remove extra
CeciliaZ030 Jun 22, 2024
7ae6319
x = sha256(sha256(blob), kzg_commit(blob))
CeciliaZ030 Jun 24, 2024
8eca63a
updated dependencies
CeciliaZ030 Jun 24, 2024
b89d6bd
add 4844 precompile test + update sp1 patch name
CeciliaZ030 Jun 25, 2024
82bb5be
Merge remote-tracking branch 'origin/main' into swap-rust-kzg
CeciliaZ030 Jun 25, 2024
22aa6be
rust-kzg default-features = false + clippy & fmt
CeciliaZ030 Jun 25, 2024
2f02607
fmt all
CeciliaZ030 Jun 25, 2024
8e87b45
fixed diff & compiled client
CeciliaZ030 Jun 25, 2024
72f559f
add kzg flag
CeciliaZ030 Jun 25, 2024
dc5a5d5
Squashed commit of the following:
CeciliaZ030 Jun 25, 2024
958fbb7
fixed flgs, seeing errors
CeciliaZ030 Jun 26, 2024
3a74fb3
compiles
CeciliaZ030 Jun 26, 2024
f2eb48e
wip
CeciliaZ030 Jun 26, 2024
28d3e68
lib compile
CeciliaZ030 Jun 26, 2024
460e123
r0 compile
CeciliaZ030 Jun 26, 2024
53ea72e
Merge remote-tracking branch 'origin/main' into swap-rust-kzg
CeciliaZ030 Jun 26, 2024
ddbbbbb
compiled
CeciliaZ030 Jun 26, 2024
b2bed3d
user interface in ProofRequest
CeciliaZ030 Jun 27, 2024
f8de364
statically compiled KzgSetting deserizlized struct
CeciliaZ030 Jun 27, 2024
c727781
wip
CeciliaZ030 Jun 27, 2024
7377ded
fix serialization
CeciliaZ030 Jun 27, 2024
a61c87b
clippy & fmt fix
CeciliaZ030 Jun 27, 2024
8e504ce
clippy & fmt
CeciliaZ030 Jun 28, 2024
e7542a8
make rust-kzg/c-kzg play nice with eachother + misc changes
Brechtpd Jun 30, 2024
696f4a0
Merge remote-tracking branch 'origin/swap-rust-kzg' into swap-rust-kzg
Brechtpd Jun 30, 2024
30b1999
remove cached input from repo
Brechtpd Jun 30, 2024
3a59bf3
fix fmt + clippy
Brechtpd Jun 30, 2024
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
392 changes: 248 additions & 144 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ raiko-core = { path = "./core" }

# reth
reth-primitives = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false, features = ["alloy-compat", "taiko"] }
reth-evm-ethereum = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko" }
reth-evm-ethereum = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }
reth-evm = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }
reth-rpc-types = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko" }
reth-revm = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko" }
reth-chainspec = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko" }
reth-rpc-types = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }
reth-revm = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }
reth-chainspec = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }
reth-provider = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }

# risc zero
Expand All @@ -66,22 +66,26 @@ alloy-primitives = { version = "0.7.2", default-features = false }
alloy-sol-types = { version = "0.7.2", default-features = false }
reqwest_alloy = { package = "reqwest", version = "0.12.4", features = ["json"] }

alloy-rpc-types = { version = "0.1" }
alloy-rpc-client = { version = "0.1" }
alloy-consensus = { version = "0.1", features = [
alloy-rpc-types = { version = "0.1", default-features = false }
alloy-rpc-client = { version = "0.1", default-features = false }
alloy-consensus = { version = "0.1", default-features = false, features = [
"serde",
] }
alloy-network = { version = "0.1", default-features = false, features = [
"k256",
] }
alloy-contract = { version = "0.1" }
alloy-contract = { version = "0.1", default-features = false }
alloy-eips = { version = "0.1", default-features = false, features = [
"serde",
] }
alloy-provider = { version = "0.1" }
alloy-transport-http = { version = "0.1" }
alloy-signer = { version = "0.1" }
alloy-signer-local = { version = "0.1" }
alloy-provider = { version = "0.1", default-features = false, features = [
"reqwest",
] }
alloy-transport-http = { version = "0.1",default-features = false, features = [
"reqwest",
] }
alloy-signer = { version = "0.1", default-features = false}
alloy-signer-local = { version = "0.1", default-features = false }

# ethers (TODO: remove)
ethers-contract = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" }
Expand Down Expand Up @@ -133,15 +137,12 @@ reqwest = { version = "0.11.22", features = ["json"] }
url = "2.5.0"

# crypto
c-kzg = { git = "https://github.com/brechtpd/c-kzg-4844", branch = "for-alpha7", default-features = false, features = [
"preload-kzg-settings",
"no-threads",
] }
kzg = { package = "rust-kzg-zkcrypto", git = "https://github.com/brechtpd/rust-kzg.git", branch = "sp1-patch", default-features = false }
kzg_traits = { package = "kzg", git = "https://github.com/brechtpd/rust-kzg.git", branch = "sp1-patch", default-features = false }
sha3 = { version = "0.10", default-features = false }
sha2 = "0.10.8"
secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch", features = [
'global-context',
"rand",
secp256k1 = { version = "0.29", default-features = false, features = [
"global-context",
"recovery",
] }

Expand Down Expand Up @@ -177,5 +178,6 @@ pathdiff = "0.2.1"
[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
c-kzg = { git = "https://github.com/brechtpd/c-kzg-4844", branch = "for-alpha7" }
secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch" }
blst = { git = "https://github.com/CeciliaZ030/blst.git", branch = "v0.3.12-serialize" }
6 changes: 4 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ risc0-driver = { path = "../provers/risc0/driver", optional = true }
sgx-prover = { path = "../provers/sgx/prover", optional = true }

# raiko
raiko-lib = { workspace = true, features = ["c-kzg"] }
raiko-lib = { workspace = true }

# reth
reth-primitives.workspace = true
Expand All @@ -34,6 +34,7 @@ alloy-rpc-client = { workspace = true }

# tracing and logging
tracing = { workspace = true }
bincode = { workspace = true }

# errors
anyhow = { workspace = true }
Expand All @@ -45,7 +46,8 @@ serde_json = { workspace = true }
serde_with = { workspace = true }

# c-kzg
c-kzg = { workspace = true }
kzg = { workspace = true }
kzg_traits = { workspace = true }

# async
tokio = { workspace = true }
Expand Down
47 changes: 40 additions & 7 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::{merge, prover::NativeProver};
use alloy_primitives::{Address, B256};
use clap::{Args, ValueEnum};
use raiko_lib::{
input::{GuestInput, GuestOutput},
input::{BlobProofType, GuestInput, GuestOutput},
primitives::eip4844::{calc_kzg_proof, commitment_to_version_hash, kzg_proof_to_bytes},
prover::{Proof, Prover, ProverError},
};
use reth_primitives::hex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::{serde_as, DisplayFromStr};
Expand All @@ -17,6 +19,10 @@ pub enum RaikoError {
#[error("Unknown proof type: {0}")]
InvalidProofType(String),

/// For invalid proof type generation request.
#[error("Unknown proof type: {0}")]
InvalidBlobOption(String),

/// For invalid proof request configuration.
#[error("Invalid proof request: {0}")]
InvalidRequestConfig(String),
Expand Down Expand Up @@ -128,35 +134,51 @@ impl ProofType {
output: &GuestOutput,
config: &Value,
) -> RaikoResult<Proof> {
match self {
ProofType::Native => NativeProver::run(input, output, config)
let mut proof = match self {
ProofType::Native => NativeProver::run(input.clone(), output, config)
.await
.map_err(|e| e.into()),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return sp1_driver::Sp1Prover::run(input, output, config)
return sp1_driver::Sp1Prover::run(input.clone(), output, config)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "sp1"))]
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return risc0_driver::Risc0Prover::run(input, output, config)
return risc0_driver::Risc0Prover::run(input.clone(), output, config)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return sgx_prover::SgxProver::run(input, output, config)
return sgx_prover::SgxProver::run(input.clone(), output, config)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "sgx"))]
Err(RaikoError::FeatureNotSupportedError(self.clone()))
}
}?;

// Add the kzg proof to the proof if needed
if let Some(blob_commitment) = input.taiko.blob_commitment.clone() {
let kzg_proof = calc_kzg_proof(
&input.taiko.tx_data,
&commitment_to_version_hash(&blob_commitment.try_into().unwrap()),
)
.unwrap();
let kzg_proof_hex = hex::encode(kzg_proof_to_bytes(&kzg_proof));
proof
.as_object_mut()
.unwrap()
.insert("kzg_proof".to_string(), Value::String(kzg_proof_hex));
}

Ok(proof)
}
}

Expand All @@ -168,7 +190,7 @@ pub struct ProofRequest {
pub block_number: u64,
/// The network to generate the proof for.
pub network: String,
/// The L1 network to grnerate the proof for.
/// The L1 network to generate the proof for.
pub l1_network: String,
/// Graffiti.
pub graffiti: B256,
Expand All @@ -177,6 +199,8 @@ pub struct ProofRequest {
pub prover: Address,
/// The proof type.
pub proof_type: ProofType,
/// Blob proof type.
pub blob_proof_type: BlobProofType,
#[serde(flatten)]
/// Additional prover params.
pub prover_args: HashMap<String, Value>,
Expand Down Expand Up @@ -204,6 +228,8 @@ pub struct ProofRequestOpt {
#[arg(long, require_equals = true)]
/// The proof type.
pub proof_type: Option<String>,
/// Blob proof type.
pub blob_proof_type: Option<String>,
#[command(flatten)]
#[serde(flatten)]
/// Any additional prover params in JSON format.
Expand Down Expand Up @@ -294,6 +320,13 @@ impl TryFrom<ProofRequestOpt> for ProofRequest {
))?
.parse()
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?,
blob_proof_type: value
.blob_proof_type
.unwrap_or("ProofOfCommitment".to_string())
.parse()
.map_err(|_| {
RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string())
})?,
prover_args: value.prover_args.into(),
})
}
Expand Down
40 changes: 34 additions & 6 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Raiko {
graffiti: self.request.graffiti,
prover: self.request.prover,
},
self.request.blob_proof_type.clone(),
)
.await
.map_err(Into::<RaikoError>::into)
Expand Down Expand Up @@ -197,6 +198,7 @@ mod tests {
use clap::ValueEnum;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
input::BlobProofType,
primitives::B256,
};
use serde_json::{json, Value};
Expand Down Expand Up @@ -255,15 +257,11 @@ mod tests {
let provider =
RpcBlockDataProvider::new(&taiko_chain_spec.rpc, proof_request.block_number - 1)
.expect("Could not create RpcBlockDataProvider");
let proof_type = proof_request.proof_type.to_owned();
let raiko = Raiko::new(l1_chain_spec, taiko_chain_spec, proof_request);
let mut input = raiko
let raiko = Raiko::new(l1_chain_spec, taiko_chain_spec, proof_request.clone());
let input = raiko
.generate_input(provider)
.await
.expect("input generation failed");
if is_ci() && proof_type == ProofType::Sp1 {
input.taiko.skip_verify_blob = true;
}
let output = raiko.get_output(&input).expect("output generation failed");
let _proof = raiko
.prove(input, &output)
Expand Down Expand Up @@ -293,6 +291,7 @@ mod tests {
prover: Address::ZERO,
l1_network,
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(),
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
Expand All @@ -319,6 +318,35 @@ mod tests {
prover: Address::ZERO,
l1_network,
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(),
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_taiko_mainnet() {
let proof_type = get_proof_type_from_env();
// Skip test on SP1 for now because it's too slow on CI
if !(is_ci() && proof_type == ProofType::Sp1) {
let network = Network::TaikoMainnet.to_string();
let l1_network = Network::Ethereum.to_string();
let block_number = 88970;
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&network)
.unwrap();
let l1_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&l1_network)
.unwrap();
let proof_request = ProofRequest {
block_number,
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
l1_network,
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(),
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
Expand Down
Loading
Loading