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(raiko): use feature to enable proof-of-equivalence #317

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod tests {
ChainSpec, Raiko,
};
use alloy_primitives::Address;
use alloy_provider::Provider;
use clap::ValueEnum;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
Expand Down Expand Up @@ -300,20 +301,30 @@ mod tests {
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}

async fn get_recent_block_num(chain_spec: &ChainSpec) -> u64 {
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, 0).unwrap();
let height = provider.provider.get_block_number().await.unwrap();
height - 100
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_ethereum() {
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::Ethereum.to_string();
let l1_network = Network::Ethereum.to_string();
let block_number = 19907175;
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&network)
.unwrap();
let l1_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&l1_network)
.unwrap();
let block_number = get_recent_block_num(&taiko_chain_spec).await;
println!(
"test_prove_block_ethereum in block_number: {}",
block_number
);
let proof_request = ProofRequest {
block_number,
network,
Expand All @@ -335,13 +346,17 @@ mod tests {
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 block_number = get_recent_block_num(&taiko_chain_spec).await;
println!(
"test_prove_block_taiko_mainnet in block_number: {}",
block_number
);
let proof_request = ProofRequest {
block_number,
network,
Expand Down
3 changes: 2 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ std = [
sgx = []
sp1 = []
risc0 = []
sp1-cycle-tracker = []
sp1-cycle-tracker = []
proof_of_equivalence = []
8 changes: 4 additions & 4 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ pub struct TaikoGuestInput {

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub enum BlobProofType {
/// Guest runs through the entire computation from blob to Kzg commitment
/// then to version hash
#[default]
ProofOfCommitment,
/// Simplified Proof of Equivalence with fiat input in non-aligned field
/// Referencing https://notes.ethereum.org/@dankrad/kzg_commitments_in_proofs
/// with impl details in https://github.com/taikoxyz/raiko/issues/292
/// Guest proves the KZG evaluation of the a fiat-shamir input x and output result y
/// x = sha256(sha256(blob), kzg_commit(blob))
/// y = f(x)
/// where f is the KZG polynomial
#[default]
ProofOfEquivalence,
/// Guest runs through the entire computation from blob to Kzg commitment
/// then to version hash
ProofOfCommitment,
}

impl FromStr for BlobProofType {
Expand Down
26 changes: 16 additions & 10 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,22 @@ impl ProtocolInstance {
pub fn instance_hash(&self) -> B256 {
// packages/protocol/contracts/verifiers/libs/LibPublicInput.sol
// "VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash
let mut data = (
let data = (
"VERIFY_PROOF",
self.chain_id,
self.verifier_address,
self.transition.clone(),
self.sgx_instance,
self.prover,
self.meta_hash(),
#[cfg(feature = "proof_of_equivalence")]
self.proof_of_equivalence,
)
.abi_encode();
if self.sgx_instance != Address::default() {
data = data.iter().copied().skip(32).collect::<Vec<u8>>();
}
.abi_encode()
.iter()
.skip(32)
.copied()
.collect::<Vec<u8>>();
keccak(data).into()
}
}
Expand All @@ -188,11 +190,15 @@ fn get_blob_proof_type(
proof_type: VerifierType,
blob_proof_type_hint: BlobProofType,
) -> BlobProofType {
match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::ProofOfCommitment,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
if cfg!(feature = "proof_of_equivalence") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it's merged but making a note:
should not flag at this location, this function only controls what's run within PI hash, it does not impact the output anyway. If we want to temporariliy disable POE in PI then just flag PI.

match proof_type {
VerifierType::None => blob_proof_type_hint,
VerifierType::SGX => BlobProofType::ProofOfCommitment,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
}
} else {
BlobProofType::ProofOfCommitment
}
}

Expand Down
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_guest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_GUEST_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
pub const RISC0_GUEST_ID: [u32; 8] = [
3656027178, 4281856604, 2184891755, 3275826590, 1143313757, 1779451290, 3242125827, 14009949,
1914784930, 3634152083, 2963332796, 2630159414, 3104046433, 3092402903, 3447446567, 3034579556,
];
Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.
Loading