Skip to content

Commit

Permalink
fix(raiko): removed panic stabilization (#232)
Browse files Browse the repository at this point in the history
* chore(install): source env if sp1 bin not in path

* chore: actual new line instead of `\n` symbols

* chore(log): tracing logs instead println; levels;

* chore: debug assertinos print inline

* chore: removed unnecesary re-init; prints in db;

* chore: warnings and cfg fixes

* fix: check_eq instead of assert_eq

* console only progress tracking

* fix

* feat: disable inplace print in container env

* chore: error propagation; warning cleanups

* chore: error formatting

* fix; merge conflict fixes

* chore: B256 instead of trait init; cleanup

* chore: psto-merge fixes

* chore: error debug formatting added

* fix: require_eq error printing; reduced clonning;

* fix: removed extra empty line; reverted home path;

* chore: imports fixes

---------

Co-authored-by: brechtpd <brechtp.devos@gmail.com>
Co-authored-by: john xu <john@taiko.xyz>
  • Loading branch information
3 people authored Jun 4, 2024
1 parent 67e6a62 commit 254ff6a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 33 deletions.
69 changes: 38 additions & 31 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use alloy_primitives::{Address, FixedBytes};
use crate::{
interfaces::{ProofRequest, RaikoError, RaikoResult},
preflight::preflight,
provider::BlockDataProvider,
};
use alloy_primitives::{Address, B256};
use alloy_rpc_types::EIP1186AccountProofResponse;
use raiko_lib::{
builder::{BlockBuilderStrategy, TaikoStrategy},
Expand All @@ -9,20 +14,14 @@ use raiko_lib::{
utils::HeaderHasher,
};
use serde_json::Value;
use std::collections::HashMap;
use std::{collections::HashMap, hint::black_box};
use tracing::{debug, error, info, warn};

pub mod interfaces;
pub mod preflight;
pub mod prover;
pub mod provider;

use crate::{
interfaces::{ProofRequest, RaikoError, RaikoResult},
preflight::preflight,
provider::BlockDataProvider,
};

pub type MerkleProof = HashMap<Address, EIP1186AccountProofResponse>;

pub struct Raiko {
Expand Down Expand Up @@ -51,8 +50,8 @@ impl Raiko {
preflight(
provider,
self.request.block_number,
self.l1_chain_spec.clone(),
self.taiko_chain_spec.clone(),
self.l1_chain_spec.to_owned(),
self.taiko_chain_spec.to_owned(),
TaikoProverData {
graffiti: self.request.graffiti,
prover: self.request.prover,
Expand Down Expand Up @@ -111,19 +110,15 @@ impl Raiko {
&header.parent_beacon_block_root,
"parent_beacon_block_root",
);
check_eq(
&exp.extra_data.clone(),
&header.extra_data.clone(),
"extra_data",
);
check_eq(&exp.extra_data, &header.extra_data, "extra_data");

// Make sure the blockhash from the node matches the one from the builder
assert_eq!(
Into::<FixedBytes<32>>::into(header.hash().0),
input.block_hash_reference,
"block hash unexpected for block {}",
input.block_number,
);
require_eq(
&B256::from(header.hash().0),
&input.block_hash_reference,
"block hash unexpected",
)?;

let output = GuestOutput::Success { header, hash: pi };

Ok(output)
Expand All @@ -138,32 +133,43 @@ impl Raiko {
}

pub async fn prove(&self, input: GuestInput, output: &GuestOutput) -> RaikoResult<Proof> {
let data = serde_json::to_value(&self.request)?;
self.request
.proof_type
.run_prover(
input.clone(),
output,
&serde_json::to_value(self.request.clone())?,
)
.run_prover(input, output, &data)
.await
}
}

fn check_eq<T: std::cmp::PartialEq + std::fmt::Debug>(expected: &T, actual: &T, message: &str) {
// printing out error, if any, but ignoring the result
// making sure it's not optimized out
let _ = black_box(require_eq(expected, actual, message));
}

fn require_eq<T: std::cmp::PartialEq + std::fmt::Debug>(
expected: &T,
actual: &T,
message: &str,
) -> RaikoResult<()> {
if expected != actual {
error!("Assertion failed: {message} - Expected: {expected:?}, Found: {actual:?}");
let msg =
format!("Assertion failed: {message} - Expected: {expected:?}, Found: {actual:?}",);
error!("{}", msg);
return Err(anyhow::Error::msg(msg).into());
}
Ok(())
}

/// Merges two json's together, overwriting `a` with the values of `b`
pub fn merge(a: &mut Value, b: &Value) {
match (a, b) {
(Value::Object(a), Value::Object(b)) => {
for (k, v) in b {
merge(a.entry(k.clone()).or_insert(Value::Null), v);
merge(a.entry(k).or_insert(Value::Null), v);
}
}
(a, b) if !b.is_null() => *a = b.clone(),
(a, b) if !b.is_null() => *a = b.to_owned(),
// If b is null, just keep a (which means do nothing).
_ => {}
}
Expand Down Expand Up @@ -230,12 +236,13 @@ mod tests {
let provider =
RpcBlockDataProvider::new(&taiko_chain_spec.rpc, proof_request.block_number - 1)
.expect("Could not create RpcBlockDataProvider");
let raiko = Raiko::new(l1_chain_spec, taiko_chain_spec, proof_request.clone());
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
.generate_input(provider)
.await
.expect("input generation failed");
if is_ci() && proof_request.proof_type == ProofType::Sp1 {
if is_ci() && proof_type == ProofType::Sp1 {
input.taiko.skip_verify_blob = true;
}
let output = raiko.get_output(&input).expect("output generation failed");
Expand Down
1 change: 1 addition & 0 deletions provers/risc0/guest/Cargo.lock

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

Binary file modified provers/sp1/guest/elf/bn254-add
Binary file not shown.
Binary file modified provers/sp1/guest/elf/bn254-mul
Binary file not shown.
Binary file modified provers/sp1/guest/elf/ecdsa
Binary file not shown.
Binary file modified provers/sp1/guest/elf/sha256
Binary file not shown.
Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.
Binary file modified provers/sp1/guest/elf/test-sp1-guest
Binary file not shown.
5 changes: 3 additions & 2 deletions provers/sp1/guest/src/zk_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ impl ZkvmOperator for Sp1Operator {
.map(|chunk| u32::from_le_bytes(chunk.try_into().unwrap()))
.collect::<Vec<u32>>()
.try_into()
.map_err(|e| Error::ZkvmOperation("Input point processing failed".to_string()))?;
.map_err(|e| {
Error::ZkvmOperation(format!("Input point processing failed. Details: {:?}", e))
})?;

p.mul_assign(&k);
Ok(point_to_be_bytes(p))
Expand Down Expand Up @@ -98,7 +100,6 @@ fn point_to_be_bytes(p: AffinePoint<Bn254, 16>) -> [u8; 64] {
([x, y]).concat().try_into().unwrap()
}


harness::zk_suits!(
pub mod tests {
use revm_precompile::bn128;
Expand Down

0 comments on commit 254ff6a

Please sign in to comment.