-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimize tendermint zk light client (#273)
Co-authored-by: Uma Roy <uma.roy.us@gmail.com>
- Loading branch information
1 parent
c22dc58
commit c3f906a
Showing
37 changed files
with
4,732 additions
and
259 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-84 Bytes
(100%)
examples/fibonacci-io/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file modified
BIN
+48 Bytes
(100%)
examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+28 Bytes
(100%)
examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#![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, | ||
]; | ||
|
||
println!("cycle-tracker-start: io"); | ||
// 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)); | ||
println!("cycle-tracker-end: io"); | ||
|
||
println!("cycle-tracker-start: verify"); | ||
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(), | ||
); | ||
println!("cycle-tracker-end: verify"); | ||
|
||
match verdict { | ||
Verdict::Success => { | ||
println!("success"); | ||
} | ||
v => panic!("expected success, got: {:?}", v), | ||
} | ||
} |
Oops, something went wrong.