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): bls12-381 & updates patches #350

Merged
merged 47 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
56cf0a0
51 block test
ctian1 Aug 21, 2024
225633b
patches
ctian1 Aug 21, 2024
17e391b
fix secp256k1
ctian1 Aug 21, 2024
c144e8b
script tweak
ctian1 Aug 22, 2024
fa086a4
cleanup
ctian1 Aug 22, 2024
3c97f07
update bn
ctian1 Aug 22, 2024
ece8ce4
merge
CeciliaZ030 Aug 23, 2024
6621b03
compile
CeciliaZ030 Aug 23, 2024
ef9fec2
running
CeciliaZ030 Aug 23, 2024
d90a27f
sweep
CeciliaZ030 Aug 23, 2024
3baa7ca
fmt
CeciliaZ030 Aug 23, 2024
57e7c20
add back zkop
CeciliaZ030 Aug 23, 2024
cd6bb61
zkop
CeciliaZ030 Aug 23, 2024
0faeda3
update default chain spec
smtmfft Aug 23, 2024
279aa24
est fork chain spec
smtmfft Aug 23, 2024
9020265
update
CeciliaZ030 Aug 25, 2024
75c2677
add missing chainspec feature
smtmfft Aug 25, 2024
0c9defc
fix risc0 cargo.lock
smtmfft Aug 25, 2024
b127a77
fix r0 compile
smtmfft Aug 25, 2024
47d2dbf
update default chain spec
smtmfft Aug 23, 2024
6acf378
est fork chain spec
smtmfft Aug 23, 2024
2209df4
add missing chainspec feature
smtmfft Aug 25, 2024
dc927de
update to ontake revm
smtmfft Aug 26, 2024
c4efd43
update sp1 dependency
smtmfft Aug 26, 2024
8773e2e
refine error return
smtmfft Aug 26, 2024
9b4e4d0
test rpc
smtmfft Aug 26, 2024
157250f
fix ci
smtmfft Aug 26, 2024
5c360bb
fix rebase error
smtmfft Aug 26, 2024
864dce0
update
CeciliaZ030 Aug 25, 2024
8eee886
Merge remote-tracking branch 'origin/update-ontake-revm' into bls12-381
CeciliaZ030 Aug 26, 2024
5e878ae
cargo lock
CeciliaZ030 Aug 26, 2024
10d3606
update input & script
CeciliaZ030 Aug 26, 2024
9dde5c3
update
CeciliaZ030 Aug 26, 2024
e16385d
fix test_native_prover
CeciliaZ030 Aug 26, 2024
c97e8c6
fix rpc
CeciliaZ030 Aug 26, 2024
48e4ea5
Update host/config/chain_spec_list_devnet.json
smtmfft Aug 27, 2024
d40536a
fix beacon rpc url
smtmfft Aug 27, 2024
c4ecc8d
apply comment & update contracts
CeciliaZ030 Aug 27, 2024
67cf48c
fix contracts
CeciliaZ030 Aug 27, 2024
2c3542d
fix contracts
CeciliaZ030 Aug 27, 2024
1387d44
fmt &clippy
CeciliaZ030 Aug 27, 2024
b95666d
Delete core/input-taiko_mainnet-182300.json
CeciliaZ030 Aug 27, 2024
b0ee9c5
delete Groth16
CeciliaZ030 Aug 27, 2024
fe00b47
typos
CeciliaZ030 Aug 27, 2024
319c1a9
cargo fmt
CeciliaZ030 Aug 27, 2024
21778f4
delete
CeciliaZ030 Aug 27, 2024
512fa94
ignore test_native_prover
CeciliaZ030 Aug 29, 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
1,380 changes: 888 additions & 492 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ reth-evm-ethereum = { git = "https://github.com/taikoxyz/taiko-reth.git", branch
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", 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-chainspec = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false, features = [
"taiko",
] }
reth-provider = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }

# risc zero
Expand All @@ -57,9 +59,9 @@ risc0-build = { version = "1.0.1" }
risc0-binfmt = { version = "1.0.1" }

# SP1
sp1-sdk = { version = "1.0.1" }
sp1-zkvm = { version = "1.0.1" }
sp1-helper = { version = "1.0.1" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }

# alloy
alloy-rlp = { version = "0.3.4", default-features = false }
Expand Down Expand Up @@ -141,8 +143,8 @@ url = "2.5.0"
async-trait = "0.1.80"

# crypto
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 }
kzg = { package = "rust-kzg-zkcrypto", git = "https://github.com/ceciliaz030/rust-kzg.git", branch = "brecht/sp1-patch", default-features = false }
kzg_traits = { package = "kzg", git = "https://github.com/ceciliaz030/rust-kzg.git", branch = "brecht/sp1-patch", default-features = false }
sha3 = { version = "0.10", default-features = false }
sha2 = "0.10.8"
secp256k1 = { version = "0.29", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG BUILD_FLAGS=""

WORKDIR /opt/raiko
COPY . .
RUN cargo build --release ${BUILD_FLAGS} --features "sgx,risc0" --features "docker_build"
RUN cargo build --release ${BUILD_FLAGS} --features "sgx" --features "docker_build"

FROM gramineproject/gramine:1.6-jammy as runtime
ENV DEBIAN_FRONTEND=noninteractive
Expand Down
20 changes: 1 addition & 19 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use clap::{Args, ValueEnum};
use raiko_lib::{
consts::VerifierType,
input::{BlobProofType, GuestInput, GuestOutput},
primitives::eip4844::{calc_kzg_proof, commitment_to_version_hash, kzg_proof_to_bytes},
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverError},
};
use reth_primitives::hex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::{serde_as, DisplayFromStr};
Expand Down Expand Up @@ -174,7 +172,7 @@ impl ProofType {
config: &Value,
store: Option<&mut dyn IdWrite>,
) -> RaikoResult<Proof> {
let mut proof = match self {
match self {
ProofType::Native => NativeProver::run(input.clone(), output, config, store)
.await
.map_err(<ProverError as Into<RaikoError>>::into),
Expand Down Expand Up @@ -202,23 +200,7 @@ impl ProofType {
#[cfg(not(feature = "sgx"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
}?;

// 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().map_err(|_| {
RaikoError::Conversion(
"Could not convert blob commitment to version hash".to_owned(),
)
})?),
)
.map_err(|e| anyhow::anyhow!(e))?;
proof.kzg_proof = Some(hex::encode(kzg_proof_to_bytes(&kzg_proof)));
}

Ok(proof)
}

pub async fn cancel_proof(
Expand Down
35 changes: 30 additions & 5 deletions core/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use alloy_sol_types::{SolCall, SolEvent};
use anyhow::{anyhow, bail, ensure, Result};
use kzg_traits::{
eip_4844::{blob_to_kzg_commitment_rust, Blob},
G1,
Fr, G1,
};
use raiko_lib::{
builder::{OptimisticDatabase, RethBlockBuilder},
Expand Down Expand Up @@ -240,7 +240,12 @@ async fn prepare_taiko_chain_input(
.await?;

// Fetch the tx data from either calldata or blobdata
let (tx_data, blob_commitment) = if proposal_event.meta.blobUsed {
let (tx_data, blob_commitment, blob_proof) = if proposal_event.meta.blobUsed {
use eip4844::{
calc_kzg_proof_commitment, calc_kzg_proof_with_point, commitment_to_version_hash,
proof_of_equivalence,
};
use kzg::kzg_types::ZFr;
debug!("blob active");
// Get the blob hashes attached to the propose tx
let blob_hashes = proposal_tx.blob_versioned_hashes.unwrap_or_default();
Expand All @@ -257,14 +262,33 @@ async fn prepare_taiko_chain_input(
RaikoError::Preflight("Beacon RPC URL is required for Taiko chains".to_owned())
})?;
let blob = get_blob_data(&beacon_rpc_url, slot_id, blob_hash).await?;
let commitment = eip4844::calc_kzg_proof_commitment(&blob).map_err(|e| anyhow!(e))?;
let commitment = calc_kzg_proof_commitment(&blob).map_err(|e| anyhow!(e))?;
let blob_proof = match blob_proof_type {
BlobProofType::KzgVersionedHash => None,
BlobProofType::ProofOfEquivalence => {
let (x, y) = proof_of_equivalence(&blob, &commitment_to_version_hash(&commitment))
.map_err(|e| anyhow!(e))?;

debug!("x {:?} y {:?}", x, y);
debug!(
"calc_kzg_proof_with_point {:?}",
calc_kzg_proof_with_point(&blob, ZFr::from_bytes(&x).unwrap()).unwrap()
);

Some(
calc_kzg_proof_with_point(&blob, ZFr::from_bytes(&x).unwrap())
.map(|g1| g1.to_bytes().to_vec())
.map_err(|e| anyhow!(e))?,
)
}
};

(blob, Some(commitment.to_vec()))
(blob, Some(commitment.to_vec()), blob_proof)
} else {
// Get the tx list data directly from the propose transaction data
let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false)
.map_err(|_| RaikoError::Preflight("Could not decode proposeBlockCall".to_owned()))?;
(proposal_call.txList.as_ref().to_owned(), None)
(proposal_call.txList.as_ref().to_owned(), None, None)
};

// Create the input struct without the block data set
Expand All @@ -273,6 +297,7 @@ async fn prepare_taiko_chain_input(
tx_data,
anchor_tx: Some(anchor_tx.clone()),
blob_commitment,
blob_proof,
block_proposed: proposal_event,
prover_data,
blob_proof_type,
Expand Down
36 changes: 35 additions & 1 deletion core/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,45 @@ impl Prover for NativeProver {
Ok(Proof {
proof: None,
quote: None,
kzg_proof: None,
})
}

async fn cancel(_proof_key: ProofKey, _read: Box<&mut dyn IdStore>) -> ProverResult<()> {
Ok(())
}
}

#[ignore = "Only used to test serialized data"]
#[tokio::test(flavor = "multi_thread")]
async fn test_native_prover() {
CeciliaZ030 marked this conversation as resolved.
Show resolved Hide resolved
use serde_json::json;

// Get the current working directory
let current_dir = std::env::current_dir().expect("Failed to get current directory");

// Adjust as needed based on your tests
let file_name = "ethereum-20612846.json";
let path = current_dir.join("../data").join(file_name);

// Check if the path exists
if !path.exists() {
panic!("File does not exist: {}", path.display());
}
let json = std::fs::read_to_string(path).unwrap();

// Deserialize the input.
let input: GuestInput = serde_json::from_str(&json).unwrap();
let output = GuestOutput {
header: reth_primitives::Header::default(),
hash: reth_primitives::B256::default(),
};

let param = json!({
"native": {
"json_guest_input": null
}
});
NativeProver::run(input, &output, &param, None)
.await
.expect_err("Default output should not match input.");
}
16 changes: 9 additions & 7 deletions core/src/provider/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ impl BlockDataProvider for RpcBlockDataProvider {
));
}

batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
batch.send().await.map_err(|e| {
RaikoError::RPC(format!(
"Error sending batch request for block {:?}: {e}",
blocks_to_fetch
))
})?;

let mut blocks = Vec::with_capacity(max_batch_size);
// Collect the data from the batch
Expand Down Expand Up @@ -132,7 +134,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request {e}")))?;

let mut accounts = vec![];
// Collect the data from the batch
Expand Down Expand Up @@ -197,7 +199,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request {e}")))?;

let mut values = Vec::with_capacity(max_batch_size);
// Collect the data from the batch
Expand Down Expand Up @@ -299,7 +301,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request {e}")))?;

// Collect the data from the batch
for request in requests {
Expand Down
1 change: 1 addition & 0 deletions data/ethereum-20612842.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/ethereum-20612843.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/ethereum-20612844.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/ethereum-20612845.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/ethereum-20612846.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion data/input-ethereum-20335518.json

This file was deleted.

1 change: 0 additions & 1 deletion data/input-ethereum-20378340.json

This file was deleted.

1 change: 0 additions & 1 deletion data/input-taiko-mainnet-192319.json

This file was deleted.

1 change: 0 additions & 1 deletion data/input-taiko_mainnet-182300.json

This file was deleted.

1 change: 0 additions & 1 deletion data/input.json

This file was deleted.

1 change: 1 addition & 0 deletions data/taiko-mainnet-328805.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko-mainnet-328808.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko_mainnet-328833.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko_mainnet-328834.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko_mainnet-328835.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko_mainnet-328836.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/taiko_mainnet-328837.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions host/config/chain_spec_list_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"l1_contract": null,
"l2_contract": null,
"rpc": "https://rpc.ankr.com/eth",
"rpc": "https://ethereum-rpc.publicnode.com",
"beacon_rpc": "https://ethereum-beacon-api.publicnode.com",
"verifier_address": {
"SGX":"0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
Expand Down Expand Up @@ -73,9 +73,9 @@
{
"name": "taiko_a7",
"chain_id": 167009,
"max_spec_id": "SHANGHAI",
"max_spec_id": "HEKLA",
"hard_forks": {
"SHANGHAI": {
"HEKLA": {
"Block": 0
},
"CANCUN": "TBD"
Expand All @@ -102,9 +102,9 @@
{
"name": "taiko_mainnet",
"chain_id": 167000,
"max_spec_id": "SHANGHAI",
"max_spec_id": "HEKLA",
"hard_forks": {
"SHANGHAI": {
"HEKLA": {
"Block": 0
},
"CANCUN": "TBD"
Expand Down
4 changes: 2 additions & 2 deletions host/config/chain_spec_list_devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
{
"name": "taiko_dev",
"chain_id": 167001,
"max_spec_id": "SHANGHAI",
"max_spec_id": "HEKLA",
"hard_forks": {
"SHANGHAI": {
"HEKLA": {
"Block": 0
},
"CANCUN": "TBD"
Expand Down
2 changes: 1 addition & 1 deletion host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ProofActor {
result = Self::handle_message(proof_request, key.clone(), &opts, &chain_specs) => {
match result {
Ok(()) => {
info!("Proof generated");
info!("Host handling message");
}
Err(error) => {
error!("Worker failed due to: {error:?}");
Expand Down
3 changes: 1 addition & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ std = [
sgx = []
sp1 = []
risc0 = []
sp1-cycle-tracker = []
proof_of_equivalence = []
sp1-cycle-tracker = []
10 changes: 8 additions & 2 deletions lib/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use reth_primitives::revm_primitives::{
Account, AccountInfo, AccountStatus, Bytecode, Bytes, HashMap,
};
use reth_primitives::{Address, BlockWithSenders, Header, B256, KECCAK_EMPTY, U256};
use tracing::debug;
use tracing::{debug, error};

pub fn calculate_block_header(input: &GuestInput) -> Header {
let cycle_tracker = CycleTracker::start("initialize_database");
Expand Down Expand Up @@ -116,6 +116,7 @@ impl<DB: Database<Error = ProviderError> + DatabaseCommit + OptimisticDatabase>
l1_header: self.input.taiko.l1_header.clone(),
parent_header: self.input.parent_header.clone(),
l2_contract: self.input.chain_spec.l2_contract.unwrap_or_default(),
..Default::default()
})
.optimistic(optimistic);
let BlockExecutionOutput {
Expand All @@ -125,7 +126,12 @@ impl<DB: Database<Error = ProviderError> + DatabaseCommit + OptimisticDatabase>
gas_used: _,
db: full_state,
valid_transaction_indices,
} = executor.execute((&block, total_difficulty).into())?;
} = executor
.execute((&block, total_difficulty).into())
.map_err(|e| {
error!("Error executing block: {:?}", e);
e
})?;
// Filter out the valid transactions so that the header checks only take these into account
block.body = valid_transaction_indices
.iter()
Expand Down
8 changes: 8 additions & 0 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ mod tests {
);
}

#[test]
fn revm_taiko_a7_spec_id() {
let taiko_a7_spec = SupportedChainSpecs::default()
.get_chain_spec(&Network::TaikoA7.to_string())
.unwrap();
assert_eq!(taiko_a7_spec.spec_id(1, 0), Some(SpecId::HEKLA));
}

#[ignore]
#[test]
fn serde_chain_spec() {
Expand Down
1 change: 1 addition & 0 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct TaikoGuestInput {
pub block_proposed: BlockProposed,
pub prover_data: TaikoProverData,
pub blob_commitment: Option<Vec<u8>>,
pub blob_proof: Option<Vec<u8>>,
pub blob_proof_type: BlobProofType,
}

Expand Down
Loading
Loading