Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed May 30, 2024
1 parent af177aa commit c2a8e9e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ $ RUST_LOG=info SP1_PROVER=mock TENDERMINT_RPC_URL="https://rpc.celestia-mocha.c

5. Run the Tendermint operator.
```shell
cd operator
cargo run --bin operator --release
cd ../operator
RUST_LOG=info cargo run --bin operator --release
```

## Fixtures for Forge Tests
## Generate fixtures for forge tests

To generate fixtures for local testing run:

Expand Down
1 change: 1 addition & 0 deletions operator/Cargo.lock

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

1 change: 1 addition & 0 deletions operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tendermint-light-client-verifier = { version = "0.35.0", default-features = fals
"rust-crypto",
] }
alloy-sol-types = "0.7.2"
alloy-primitives = "0.7.2"
bincode = "1.3.3"
itertools = "0.12.1"
serde_cbor = "0.11.2"
Expand Down
19 changes: 12 additions & 7 deletions operator/bin/operator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_sol_types::{sol, SolCall};
use alloy_primitives::U256;
use alloy_sol_types::{sol, SolCall, SolValue};
use log::{debug, info};
use sp1_sdk::utils::setup_logger;
use std::time::Duration;
Expand All @@ -7,6 +8,7 @@ use tendermint_operator::{contract::ContractClient, util::TendermintRPCClient, T
sol! {
contract SP1Tendermint {
bytes32 public latestHeader;
uint64 public latestHeight;

function verifyTendermintProof(
bytes calldata proof,
Expand All @@ -32,13 +34,16 @@ async fn main() -> anyhow::Result<()> {

loop {
// Read the existing trusted header hash from the contract.
let latest_header_call_data = SP1Tendermint::latestHeaderCall {}.abi_encode();
let trusted_header_hash = contract_client.read(latest_header_call_data).await?;
let latest_height_call_data = SP1Tendermint::latestHeightCall {}.abi_encode();
let latest_height = contract_client.read(latest_height_call_data).await?;
let latest_height = U256::abi_decode(&latest_height, true).unwrap();
let trusted_block_height: u64 = latest_height.try_into().unwrap();

// let latest_height: u64 = latest_height.try_into().unwrap();
if trusted_block_height == 0 {
panic!("No trusted height found in the contract, likely using an outdated contract.");
}

// Generate a header update proof from the trusted block to the latest block.
let trusted_block_height = tendermint_rpc_client
.get_block_height_from_hash(&trusted_header_hash)
.await;
let latest_block_height = tendermint_rpc_client.get_latest_block_height().await;
let (trusted_light_block, target_light_block) = tendermint_rpc_client
.get_light_blocks(trusted_block_height, latest_block_height)
Expand Down

0 comments on commit c2a8e9e

Please sign in to comment.