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

fix: optimize tendermint zk light client #273

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified examples/chess/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/ed25519/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/fibonacci-io/program/elf/riscv32im-succinct-zkvm-elf
i-m-aditya marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file modified examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/io/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/json/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/regex/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/rsa/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
933 changes: 933 additions & 0 deletions examples/tendermint-benchmark/program/Cargo.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions examples/tendermint-benchmark/program/Cargo.toml
@@ -0,0 +1,19 @@
[workspace]
[package]
version = "0.1.0"
name = "tendermint-benchmark-program"
edition = "2021"

[dependencies]
sp1-zkvm = { path = "../../../zkvm/entrypoint" }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
tendermint = { version = "0.34.0", default-features = false }
tendermint-light-client-verifier = { version = "0.34.0", default-features = false, features = [
"rust-crypto",
] }

[patch.crates-io]
sha2-v0-9-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-v0.9.8" }
sha2-v0-10-6 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-v0.10.6" }
ed25519-consensus = { git = "https://github.com/sp1-patches/ed25519-consensus", branch = "patch-v2.1.0" }
Binary file not shown.
123 changes: 123 additions & 0 deletions examples/tendermint-benchmark/program/src/main.rs
@@ -0,0 +1,123 @@
#![no_main]
sp1_zkvm::entrypoint!(main);

use core::time::Duration;
use serde::Deserialize;
use tendermint::{node::Id, validator::Info};
use tendermint_light_client_verifier::{
options::Options,
types::{LightBlock, SignedHeader, ValidatorSet},
ProdVerifier, Verdict, Verifier,
};

#[derive(Debug, Deserialize)]
pub struct CommitResponse {
pub result: SignedHeaderWrapper,
}

#[derive(Debug, Deserialize)]
pub struct SignedHeaderWrapper {
pub signed_header: SignedHeader,
}

#[derive(Debug, Deserialize)]
pub struct ValidatorSetResponse {
pub result: BlockValidatorSet,
}

#[derive(Debug, Deserialize)]
pub struct BlockValidatorSet {
pub block_height: String,
pub validators: Vec<Info>,
pub count: String,
pub total: String,
}

fn main() {
let peer_id: [u8; 20] = [
0x72, 0x6b, 0xc8, 0xd2, 0x60, 0x38, 0x7c, 0xf5, 0x6e, 0xcf, 0xad, 0x3a, 0x6b, 0xf6, 0xfe,
0xcd, 0x90, 0x3e, 0x18, 0xa2,
];
// Generate the Light Block's without testgen
let file_content = include_bytes!("./fixtures/1/signed_header.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");

let commit_response: CommitResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let signed_header = commit_response.result.signed_header;

let file_content = include_bytes!("./fixtures/1/validators.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");
let validators_response: ValidatorSetResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let validators = validators_response.result;
let validators = ValidatorSet::new(validators.validators, None);

let file_content = include_bytes!("./fixtures/1/next_validators.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");
let next_validators_response: ValidatorSetResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let next_validators = next_validators_response.result;
let next_validators = ValidatorSet::new(next_validators.validators, None);

// Create a default light block with a valid chain-id for height `1` with a timestamp 20
// secs before now (to be treated as trusted state)
let light_block_1: LightBlock =
LightBlock::new(signed_header, validators, next_validators, Id::new(peer_id));

// // Generate the Light Block's without testgen
let file_content = include_bytes!("./fixtures/2/signed_header.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");

let commit_response: CommitResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let signed_header = commit_response.result.signed_header;

let file_content = include_bytes!("./fixtures/2/validators.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");
let validators_response: ValidatorSetResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let validators = validators_response.result;
let validators = ValidatorSet::new(validators.validators, None);

let file_content = include_bytes!("./fixtures/2/next_validators.json");
let file_content_str =
core::str::from_utf8(file_content).expect("Failed to convert file content to string");
let next_validators_response: ValidatorSetResponse =
serde_json::from_str(file_content_str).expect("Failed to parse JSON");
let next_validators = next_validators_response.result;
let next_validators = ValidatorSet::new(next_validators.validators, None);

// Create a default light block with a valid chain-id for height `1` with a timestamp 20
// secs before now (to be treated as trusted state)
let light_block_2: LightBlock =
LightBlock::new(signed_header, validators, next_validators, Id::new(peer_id));

let vp = ProdVerifier::default();
let opt = Options {
trust_threshold: Default::default(),
trusting_period: Duration::from_secs(500),
clock_drift: Default::default(),
};

let verify_time = light_block_2.time() + Duration::from_secs(20);

let verdict = vp.verify_update_header(
light_block_2.as_untrusted_state(),
light_block_1.as_trusted_state(),
&opt,
verify_time.unwrap(),
);

match verdict {
Verdict::Success => {
println!("success");
}
v => panic!("expected success, got: {:?}", v),
}
}