Skip to content

Commit

Permalink
cargo: Upgrade Bitcoin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Dec 19, 2024
1 parent e2b8c49 commit 3402307
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
17 changes: 5 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }
Expand Down
6 changes: 3 additions & 3 deletions core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
28 changes: 14 additions & 14 deletions core/src/header_chain_prover/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Receipt>,
block_headers: Vec<BlockHeader>,
block_headers: Vec<CircuitBlockHeader>,
) -> Result<Receipt, BridgeError> {
// Prepare proof input.
let (prev_proof, method_id) = match &prev_receipt {
Expand Down Expand Up @@ -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(),
Expand All @@ -113,7 +113,7 @@ impl HeaderChainProver {
};
let receipt = prover
.prove_block_headers(Some(previous_proof), vec![header.clone()])
.await;
;

match receipt {
Ok(receipt) => {
Expand Down Expand Up @@ -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<BlockHeader> {
fn get_headers() -> Vec<CircuitBlockHeader> {
let headers = include_bytes!("../../../scripts/headers.bin");

headers
.chunks(80)
.map(|header| BlockHeader::try_from_slice(header).unwrap())
.collect::<Vec<BlockHeader>>()
.map(|header| CircuitBlockHeader::try_from_slice(header).unwrap())
.collect::<Vec<CircuitBlockHeader>>()
}

#[tokio::test]
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 3402307

Please sign in to comment.