From 340230751e8acce44879c0842a8b835264b0539c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ceyhun=20=C5=9Een?= Date: Thu, 19 Dec 2024 11:01:33 +0300 Subject: [PATCH] cargo: Upgrade Bitcoin. --- Cargo.toml | 17 +++++----------- core/src/errors.rs | 6 +++--- core/src/header_chain_prover/prover.rs | 28 +++++++++++++------------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53da586e..152e8259 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,10 +18,10 @@ sqlx = { version = "0.7.4", default-features = false } serial_test = "3.2.0" # bitcoin -bitcoin = "0.31.0" +bitcoin = "0.32.5" bitcoincore-rpc = "0.18.0" musig2 = { version = "0.0.11", features = ["serde"] } -secp256k1 = { version = "0.28.1", features = ["serde", "rand-std"] } +secp256k1 = { version = "0.29.1", features = ["serde", "rand-std"] } bitcoin-script = { git = "https://github.com/BitVM/rust-bitcoin-script", branch= "StructuredScript" } # async + gRPC @@ -41,18 +41,11 @@ borsh = { version = "1.5.1", features = ["derive"] } k256 = { version = "=0.13.3", default-features = false } risc0-build = "1.2" risc0-zkvm = { version = "1.2" } -circuits = { git = "https://github.com/chainwayxyz/risc0-to-bitvm2", branch = "downgrade_dependencies" } -bitvm = { git = "https://github.com/BitVM/BitVM" } +circuits = { git = "https://github.com/chainwayxyz/risc0-to-bitvm2" } +bitvm = { git = "https://github.com/BitVM/BitVM", rev = "f9cb29e" } [patch.crates-io] -bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", branch = "downgrade_bitcoin" } -base58check = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} -bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} -bitcoin_hashes = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} -bitcoin-internals = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} -bitcoin-io = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} -bitcoin-units = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm"} - +bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } ark-ff = { git = "https://github.com/chainwayxyz/algebra/", branch = "new-ate-loop" } ark-ec = { git = "https://github.com/chainwayxyz/algebra/", branch = "new-ate-loop" } ark-poly = { git = "https://github.com/chainwayxyz/algebra/", branch = "new-ate-loop" } diff --git a/core/src/errors.rs b/core/src/errors.rs index 23be532d..89fa3e04 100644 --- a/core/src/errors.rs +++ b/core/src/errors.rs @@ -13,9 +13,9 @@ use thiserror::Error; #[derive(Debug, Error)] #[non_exhaustive] pub enum BridgeError { - // /// Returned when the secp256k1 crate returns an error - // #[error("Secpk256Error: {0}")] - // Secp256k1Error(#[from] secp256k1::Error), + /// Returned when the secp256k1 crate returns an error + #[error("Secpk256Error: {0}")] + Secp256k1Error(#[from] secp256k1::Error), /// Returned when the bitcoin crate returns an error in the sighash taproot module #[error("BitcoinSighashTaprootError: {0}")] BitcoinSighashTaprootError(#[from] bitcoin::sighash::TaprootError), diff --git a/core/src/header_chain_prover/prover.rs b/core/src/header_chain_prover/prover.rs index e283510b..10fd7718 100644 --- a/core/src/header_chain_prover/prover.rs +++ b/core/src/header_chain_prover/prover.rs @@ -5,7 +5,7 @@ use crate::{errors::BridgeError, header_chain_prover::HeaderChainProver}; use bitcoin::hashes::Hash; use circuits::header_chain::{ - BlockHeader, BlockHeaderCircuitOutput, HeaderChainCircuitInput, HeaderChainPrevProofType, + BlockHeaderCircuitOutput, CircuitBlockHeader, HeaderChainCircuitInput, HeaderChainPrevProofType }; use lazy_static::lazy_static; use risc0_zkvm::{compute_image_id, ExecutorEnv, Receipt}; @@ -33,10 +33,10 @@ impl HeaderChainProver { /// # Returns /// /// - [`Receipt`]: Proved block headers' proof receipt. - async fn prove_block_headers( + fn prove_block_headers( &self, prev_receipt: Option, - block_headers: Vec, + block_headers: Vec, ) -> Result { // Prepare proof input. let (prev_proof, method_id) = match &prev_receipt { @@ -103,7 +103,7 @@ impl HeaderChainProver { current_block_hash ); - let header = BlockHeader { + let header = CircuitBlockHeader { version: current_block_header.version.to_consensus(), prev_block_hash: current_block_header.prev_blockhash.to_byte_array(), merkle_root: current_block_header.merkle_root.to_byte_array(), @@ -113,7 +113,7 @@ impl HeaderChainProver { }; let receipt = prover .prove_block_headers(Some(previous_proof), vec![header.clone()]) - .await; + ; match receipt { Ok(receipt) => { @@ -149,16 +149,16 @@ mod tests { BlockHash, CompactTarget, TxMerkleNode, }; use borsh::BorshDeserialize; - use circuits::header_chain::{BlockHeader, BlockHeaderCircuitOutput}; + use circuits::header_chain::{CircuitBlockHeader, BlockHeaderCircuitOutput}; use std::{env, thread}; - fn get_headers() -> Vec { + fn get_headers() -> Vec { let headers = include_bytes!("../../../scripts/headers.bin"); headers .chunks(80) - .map(|header| BlockHeader::try_from_slice(header).unwrap()) - .collect::>() + .map(|header| CircuitBlockHeader::try_from_slice(header).unwrap()) + .collect::>() } #[tokio::test] @@ -173,7 +173,7 @@ mod tests { .await; let prover = HeaderChainProver::new(&config, rpc.clone()).await.unwrap(); - let receipt = prover.prove_block_headers(None, vec![]).await.unwrap(); + let receipt = prover.prove_block_headers(None, vec![]).unwrap(); let output: BlockHeaderCircuitOutput = borsh::from_slice(&receipt.journal.bytes).unwrap(); println!("Proof journal output: {:?}", output); @@ -198,12 +198,12 @@ mod tests { let prover = HeaderChainProver::new(&config, rpc.clone()).await.unwrap(); // Prove genesis block and get it's receipt. - let receipt = prover.prove_block_headers(None, vec![]).await.unwrap(); + let receipt = prover.prove_block_headers(None, vec![]).unwrap(); let block_headers = get_headers(); let receipt = prover .prove_block_headers(Some(receipt), block_headers[0..2].to_vec()) - .await + .unwrap(); let output: BlockHeaderCircuitOutput = borsh::from_slice(&receipt.journal.bytes).unwrap(); @@ -226,7 +226,7 @@ mod tests { let block_headers = get_headers(); // Prove genesis block. - let receipt = prover.prove_block_headers(None, vec![]).await.unwrap(); + let receipt = prover.prove_block_headers(None, vec![]).unwrap(); let hash = BlockHash::from_raw_hash(Hash::from_slice(&block_headers[1].prev_block_hash).unwrap()); let header = Header { @@ -258,7 +258,7 @@ mod tests { // Prove second block. let receipt = prover .prove_block_headers(Some(receipt), block_headers[0..2].to_vec()) - .await + .unwrap(); let hash = BlockHash::from_raw_hash(Hash::from_slice(&block_headers[2].prev_block_hash).unwrap());