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: get app_hash at proof_height instead of latest #59

Merged
merged 7 commits into from
Jun 20, 2024

Conversation

dangush
Copy link
Contributor

@dangush dangush commented Jun 20, 2024

Closes #58

Instead of getting the latest app hash, I extract the app_hash from the primary_block which was queried and used during proof generation.

Should be a simple change, but I'm not familiar with the library so not sure if there's something I missed.

let status = client.status().await?;
let latest_app_hash = status.sync_info.latest_app_hash;
let latest_app_hash = primary_block.signed_header.header.app_hash;
Copy link
Member

Choose a reason for hiding this comment

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

This is the main change for the fix right @dangush?

@hu55a1n1
Copy link
Member

hu55a1n1 commented Jun 20, 2024

I just confirmed that this is indeed the root cause of the bug we were seeing yesterday by adding this sleep before we get the status (and latest app hash) ->

$ git diff src/main.rs
diff --git a/utils/tm-prover/src/main.rs b/utils/tm-prover/src/main.rs
index 1225048..738d709 100644
--- a/utils/tm-prover/src/main.rs
+++ b/utils/tm-prover/src/main.rs
@@ -228,6 +228,9 @@ async fn main() -> Result<()> {
     )
     .await?;
 
+    let ten_secs = std::time::Duration::from_secs(10);
+    std::thread::sleep(ten_secs);
+
     let status = client.status().await?;
     let latest_app_hash = status.sync_info.latest_app_hash;

The old code (without the fix in this PR) always fails. Also just confirmed that the fix works even with this delay.
Only thing left to verify is that the verifier side can succesfully check the proof.json.

@hu55a1n1
Copy link
Member

So the verifier was failing with this change. I solved this in a slightly different way by avoiding the extra status call altoghether ->

diff --git a/utils/tm-prover/src/main.rs b/utils/tm-prover/src/main.rs
index 1225048..d9fb05e 100644
--- a/utils/tm-prover/src/main.rs
+++ b/utils/tm-prover/src/main.rs
@@ -187,6 +187,7 @@ async fn main() -> Result<()> {
 
     let status = client.status().await?;
     let latest_height = status.sync_info.latest_block_height;
+    let latest_app_hash = status.sync_info.latest_app_hash;
 
     // `proof_height` is the height at which we want to query the blockchain's state
     // This is one less than than the `latest_height` because we want to verify the merkle-proof for
@@ -228,9 +229,6 @@ async fn main() -> Result<()> {
     )
     .await?;
 
-    let status = client.status().await?;
-    let latest_app_hash = status.sync_info.latest_app_hash;
-
     let path = WASM_STORE_KEY.to_owned();
     let data = CwAbciKey::new(args.contract_address, args.storage_key, None);

Will push soon. 🙏

@hu55a1n1 hu55a1n1 marked this pull request as ready for review June 20, 2024 19:45
@hu55a1n1 hu55a1n1 merged commit 9323278 into main Jun 20, 2024
5 checks passed
@hu55a1n1 hu55a1n1 deleted the dangush/fix-app-hash branch June 20, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Time-of-Check to Time-of-Use between proof of consensus and querying latest app hash
2 participants