Skip to content

Commit 05c8755

Browse files
authored
Ensure sha3 hasher and update RISC0 to v3 (#50)
* Upgrade to risc v3 * Upgrade to risc v3 * Update metadata and Enable Sha3-256 * Update metadata and Enable Sha3-256 * Update scripts * More logs * Update the sha3 hasher in prover
1 parent d61800f commit 05c8755

15 files changed

Lines changed: 415 additions & 268 deletions

File tree

Cargo.lock

Lines changed: 357 additions & 213 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lightclients/grandpa/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,20 @@ impl GrandpaLightClient {
9393
#[cfg(test)]
9494
mod tests {
9595
use crate::GrandpaLightClient;
96-
use gradium_client::subxt::gradium::runtime_types::bridge_common::Network;
9796
use gradium_client::subxt::{GradiumHeader, GradiumHost};
98-
use gradium_client::subxt_config::GradiumConfig;
9997
use grandpa_primitives::{
10098
bridge_pallet_outward_transfers_storage_key, OutwardTransferProofsWithFinalityProofs,
10199
StorageProofs,
102100
};
103-
use grandpa_prover::{GrandpaProver, ProverOptions};
104-
use grandpa_verifier_primitives::FinalityProof;
105101
use primitive_types::H256;
106102
use sp_core::bytes::from_hex;
107103
use std::str::FromStr;
104+
use super::*;
108105

109106
#[test]
110107
pub fn test_storage_key_generation() {
111108
let expected = from_hex("0xe6991a77b75772082ed70e0f6bfcb472ac2b29d8e83fcacefb4e9b52159a86ff9ea2d098b5f70192f96c06f38d3fbc970100000000000000").unwrap();
112-
let key = bridge_pallet_outward_transfers_storage_key(1).0;
109+
let key = bridge_pallet_outward_transfers_storage_key(1, super::Network::BSC).0;
113110
assert_eq!(key, expected);
114111
}
115112

@@ -120,11 +117,12 @@ mod tests {
120117
.await
121118
.unwrap();
122119
let previous_finalized_head =
123-
H256::from_str("0x2a06949fa43d0d2d0af10001ac9e9941ff0bd7f09a4b7f0bb673cca32ca13d94")
120+
H256::from_str("0x412e83325a312a308857fdc84e12a5830dde751835f8972f93b5411978a29e52")
124121
.unwrap();
125122
let last_finalized_header: GradiumHeader = host
126123
.fetch_header(previous_finalized_head.0.into())
127124
.await
125+
.unwrap()
128126
.unwrap();
129127
let last_finalized_head = host.fetch_last_finalized_head().await.unwrap();
130128
let initial_state = host
@@ -133,7 +131,7 @@ mod tests {
133131
.unwrap();
134132
let at = initial_state.latest_hash;
135133
let mut grandpa =
136-
GrandpaLightClient::initialize(initial_state.clone(), Network::BSC.into());
134+
GrandpaLightClient::initialize(initial_state.clone(), super::Network::BSC.into());
137135
println!("Initial: {}", grandpa.consensus_state.latest_height);
138136
let finality_proof = host
139137
.fetch_gradium_finality_proofs(initial_state.latest_height, 2000)
-40 Bytes
Binary file not shown.

network-clients/gradium/src/subxt.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::subxt::gradium::bridge::calls::types::initialize_bsc_lightclient::CurrentEpochHeader;
22
use crate::subxt::gradium::runtime_types::bridge_common::PendingTransactions;
33
use crate::subxt::gradium::runtime_types::tron_primitives::TronLightClientState;
4-
use crate::subxt_config::GradiumHeader;
4+
pub use crate::subxt_config::GradiumHeader;
55
use crate::subxt_config::{GradiumBlock, GradiumConfig};
66
use alloy::hex;
77
use anyhow::anyhow;
@@ -242,7 +242,7 @@ impl GradiumHost {
242242
}
243243

244244
let target_block_number = max_height;
245-
log::trace!(target:"gradium","Target block number: {target_block_number}");
245+
log::trace!(target:"gradium","previous_finalized_height: {previous_finalized_height}..Target block number: {target_block_number}");
246246

247247
let mut target_block_hash = None;
248248

@@ -256,7 +256,7 @@ impl GradiumHost {
256256
unknown_headers.push(header.clone());
257257

258258
if let Some(_) = find_scheduled_change(&header) {
259-
log::trace!(target:"gradium","Found set rotation at block number {height:?}");
259+
log::trace!(target:"gradium","Found set rotation at block number {height:?} with hash: {hash:?}");
260260
if height != previous_finalized_height {
261261
target_block_hash = Some(hash);
262262
// stop here
@@ -315,7 +315,7 @@ impl GradiumHost {
315315
}
316316
}
317317
}
318-
318+
log::trace!(target:"gradium","target_block_hash: {target_block_hash:?}");
319319
// If we didn't find any valid target block, return an error
320320
if target_block_hash.is_none() {
321321
return Err(anyhow!(
@@ -326,6 +326,7 @@ impl GradiumHost {
326326
let target_block_hash =
327327
target_block_hash.expect("Already checked that target_block_hash is Some; qed");
328328
let block = self.fetch_block(target_block_hash).await?;
329+
log::trace!(target:"gradium","target_block with hash: {target_block_hash:?} retrieved");
329330
// get GRANDPA justification
330331
let justification = block
331332
.justifications
@@ -339,6 +340,7 @@ impl GradiumHost {
339340
.fetch_block_hash(previous_finalized_height.into())
340341
.await?
341342
.ok_or(anyhow!("Block hash not found"))?;
343+
log::trace!(target:"gradium","previously_finalized_hash: {previously_finalized_hash:?}, previous_finalized_height: {previous_finalized_height:?}");
342344
let ancestry = AncestryChain::new(&unknown_headers);
343345
let canonical = ancestry
344346
.ancestry(

network-clients/gradium/src/subxt_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::subxt::gradium::runtime_types::fp_account::EthereumSignature;
22
use scale_codec::Decode;
33
use sp_core::H256;
44
use sp_runtime::traits::Hash;
5-
use subxt::config::substrate::{BlakeTwo256, SubstrateHeader};
5+
use subxt::config::substrate::{SubstrateHeader};
66
use subxt::config::{transaction_extensions, Hasher};
77
use subxt::ext::codec::Encode;
88
use subxt::ext::subxt_core::utils::AccountId20;
@@ -16,14 +16,14 @@ pub enum GradiumConfig {}
1616
pub type BlockNumber = u32;
1717

1818
/// The hashing algorithm used by the chain.
19-
// pub type Hashing = Sha3_256;
20-
pub type Hashing = BlakeTwo256;
19+
pub type Hashing = Sha3_256;
20+
// pub type Hashing = BlakeTwo256;
2121

2222
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
2323
pub type Signature = EthereumSignature;
2424

2525
/// Gradium header type
26-
pub type GradiumHeader = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
26+
pub type GradiumHeader = sp_runtime::generic::Header<u32, sha3_substrate_hashing::Sha3Hashing>;
2727
/// Gradium block type
2828
pub type GradiumBlock = sp_runtime::generic::SignedBlock<
2929
sp_runtime::generic::Block<GradiumHeader, sp_runtime::OpaqueExtrinsic>,

relayers/outward/evm/prover/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ clap = { workspace = true, features = ["derive"] }
1414
scale-codec = { workspace = true }
1515
hex = {workspace = true}
1616
quantova_methods = { path = "../quantova_methods" }
17-
risc0-zkvm = "2.2.0"
18-
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum.git", tag = "v2.2.2" }
17+
risc0-zkvm = "3.0.3"
18+
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum.git", tag = "v3.0.0" }
1919
tracing-subscriber = { workspace = true, features = ["env-filter"] }
2020
gradium-client = { path = "../../../../network-clients/gradium" }
2121
tokio = { workspace = true }

relayers/outward/evm/prover/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,22 @@ async fn main() -> anyhow::Result<()> {
107107
"Received last finalized header: {}",
108108
last_finalized_header.hash()
109109
);
110-
110+
println!("Fetching grandpa state...");
111111
// Fetch the grandpa state at the last finalized hash
112112
let grandpa_state = gradium_client
113113
.fetch_grandpa_state_at(Some(last_finalized_hash.0.into()))
114114
.await?;
115-
115+
println!("Fetching grandpa finality proofs...");
116116
// Fetch the finality proof from the last accepted hash to latest finalized block in gradium
117117
let finality_proof = gradium_client
118118
.fetch_gradium_finality_proofs(last_finalized_header.number, args.max_block_range)
119119
.await?;
120-
120+
println!("Fetching quantova last processed nonce...");
121121
// Look at the last processed nonce in Destination
122122
let last_processed_nonce = client.fetch_last_processed_nonce().await?;
123123

124124
let at = finality_proof.block.0;
125+
println!("Fetching read proofs...");
125126
// Look at last outgoing nonce in gradium
126127
let (read_proof, nonces) = gradium_client
127128
.fetch_read_proofs_for_pending_nonces(
@@ -156,6 +157,7 @@ async fn main() -> anyhow::Result<()> {
156157
// Proof information by proving the specified ELF binary.
157158
// This struct contains the receipt along with statistics about execution of the guest
158159
log::info!(target:"relayer","Proving...");
160+
println!("Proving...");
159161
let start = std::time::Instant::now();
160162
let prove_info = prover.prove_with_ctx(
161163
env,

relayers/outward/evm/prover/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use scale_codec::{Decode, Encode};
1414
use bridge_common::Network;
1515

1616
#[test]
17-
#[ignore]
1817
fn test_zk_proving() {
1918
let verifier_params = Groth16ReceiptVerifierParameters::default();
2019
println!("Control root: {:?}", verifier_params.control_root);

relayers/outward/evm/quantova_methods/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.0.0"
44
edition = "2021"
55

66
[build-dependencies]
7-
risc0-build = "2.2.0"
7+
risc0-build = "3.0.3"
88

99
[package.metadata.risc0]
1010
methods = ["grandpa"]

relayers/outward/evm/quantova_methods/grandpa/Cargo.lock

Lines changed: 30 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)