Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
feat: fixtures can be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jun 23, 2024
1 parent 18a5824 commit 040e75d
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ ibc-client-tendermint-types = { version = "0.53.0", default-features = false }
serde = { version = "1.0", default-features = false }
sha2 = { version = "0.10.8", default-features = false }
alloy-sol-types = "0.7.2"
serde_cbor = "0.11.2"
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# Used by the operator
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.7-testnet" }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
tendermint = { version = "0.36.0", default-features = false }
ibc-core-client-types = { version = "0.53.0", default-features = false }
ibc-core-commitment-types = { version = "0.53.0", default-features = false }
Expand All @@ -49,7 +50,6 @@ time = { version = "0.3", default-features = false, features = ["macros", "parsi
alloy-primitives = "0.7.2"
bincode = "1.3.3"
itertools = "0.12.1"
serde_cbor = "0.11.2"
dotenv = "0.15.0"
subtle-encoding = "0.5.1"
ethers = "2.0.14"
Expand Down
9 changes: 9 additions & 0 deletions contracts/fixtures/mock_fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trustedClientState": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c200000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000000044c1ff2520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"trustedConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetHeight": 2110668,
"vkey": "0x0028d036f6404b30d0c8b3fdb4e64852b04f78d54115702b299f18afb8b00ef4",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017db9e47e5d87cc800000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"proof": "0x00000000"
}
8 changes: 0 additions & 8 deletions contracts/src/fixtures/fixture.json

This file was deleted.

Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
2 changes: 1 addition & 1 deletion operator/bin/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn main() -> anyhow::Result<()> {

// Generate a header update proof for the specified blocks.
let proof_data = tendermint_prover.generate_ics07_update_client_proof(
&trusted_consensus_state,
&trusted_consensus_state.clone().into(),
&proposed_header,
&contract_env,
);
Expand Down
2 changes: 1 addition & 1 deletion operator/bin/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn main() -> anyhow::Result<()> {

// Generate a proof of the transition from the trusted block to the target block.
let proof_data = prover.generate_ics07_update_client_proof(
&trusted_consensus_state.into(),
&trusted_consensus_state,
&proposed_header,
&contract_env,
);
Expand Down
6 changes: 4 additions & 2 deletions operator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use ibc_client_tendermint::types::{ConsensusState, Header};
use alloy_sol_types::SolValue;
use ibc_client_tendermint::types::Header;
use sp1_ics07_tendermint_shared::types::ics07_tendermint::ConsensusState;
use sp1_ics07_tendermint_update_client::types::validation::Env;
use sp1_sdk::{ProverClient, SP1PlonkBn254Proof, SP1ProvingKey, SP1Stdin, SP1VerifyingKey};

Expand Down Expand Up @@ -44,7 +46,7 @@ impl SP1ICS07TendermintProver {
) -> SP1PlonkBn254Proof {
// Encode the light blocks to be input into our program.
// TODO: make sure the encoding is correct.
let encoded_1 = serde_cbor::to_vec(trusted_consensus_state).unwrap();
let encoded_1 = trusted_consensus_state.abi_encode();
let encoded_2 = serde_cbor::to_vec(proposed_header).unwrap();
let encoded_3 = serde_cbor::to_vec(contract_env).unwrap();

Expand Down
2 changes: 2 additions & 0 deletions programs/update-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ ibc-core-handler-types = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
alloy-sol-types = { workspace = true }
serde_cbor = { workspace = true }
serde_json = { workspace = true }
26 changes: 17 additions & 9 deletions programs/update-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use ibc_client_tendermint::{
types::{ConsensusState, Header, TENDERMINT_CLIENT_TYPE},
};
use ibc_core_host::types::identifiers::{ChainId, ClientId};
use sp1_ics07_tendermint_shared::types::ics07_tendermint;
use sp1_ics07_tendermint_shared::types::ics07_tendermint::{
self, ConsensusState as SolConsensusState,
};
use sp1_ics07_tendermint_update_client::types;
use tendermint_light_client_verifier::{options::Options, ProdVerifier};

Expand All @@ -28,12 +30,16 @@ use tendermint_light_client_verifier::{options::Options, ProdVerifier};
/// # Panics
/// Panics if the verification fails.
pub fn main() {
// input 1: the trusted consensus state
let trusted_consensus_state = sp1_zkvm::io::read::<ConsensusState>();
// input 2: the proposed header
let proposed_header = sp1_zkvm::io::read::<Header>();
let encoded_1 = sp1_zkvm::io::read_vec();
let encoded_2 = sp1_zkvm::io::read_vec();
let encoded_3 = sp1_zkvm::io::read_vec();

// input 3: environment
let env = sp1_zkvm::io::read::<types::validation::Env>();
let env = serde_cbor::from_slice::<types::validation::Env>(&encoded_3).unwrap();
// input 2: the proposed header
let proposed_header = serde_cbor::from_slice::<Header>(&encoded_2).unwrap();
// input 1: the trusted consensus state
let trusted_consensus_state = SolConsensusState::abi_decode(&encoded_1, true).unwrap();

let client_id = ClientId::new(TENDERMINT_CLIENT_TYPE, 0).unwrap();
let chain_id = ChainId::from_str(&env.chain_id).unwrap();
Expand All @@ -42,8 +48,10 @@ pub fn main() {
trusting_period: Duration::from_nanos(env.trusting_period),
clock_drift: Duration::default(),
};
let ctx =
types::validation::ClientValidationCtx::new(env.clone(), trusted_consensus_state.clone());
let ctx = types::validation::ClientValidationCtx::new(
env.clone(),
trusted_consensus_state.clone().into(),
);

verify_header::<_, sha2::Sha256>(
&ctx,
Expand All @@ -66,7 +74,7 @@ pub fn main() {
let new_consensus_state = ConsensusState::from(proposed_header);

let output = types::output::SP1ICS07TendermintOutput {
trusted_consensus_state: trusted_consensus_state.into(),
trusted_consensus_state,
new_consensus_state: new_consensus_state.into(),
env,
trusted_height,
Expand Down

0 comments on commit 040e75d

Please sign in to comment.