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

Clean code, better documentation and comments #439

Merged
merged 11 commits into from
Jan 22, 2025
2 changes: 0 additions & 2 deletions circuits/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::sha256_hash;
use crate::HashType;
use sha2::{Digest, Sha256};

// /// Data is generic type we use to represent 32 bytes of data
// pub type Data = [u8; 32];
pub type HeaderWithoutPrevBlockHash = (i32, HashType, u32, u32, u32);

pub fn validate_threshold_and_add_work(
Expand Down
50 changes: 0 additions & 50 deletions core/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ impl Actor {
txin_index: usize,
script_index: usize,
) -> Result<schnorr::Signature, BridgeError> {
// TODO: if sighash_cache exists in the TxHandler, use it
// else create a new one and save it to the TxHandler
let mut sighash_cache: SighashCache<&mut bitcoin::Transaction> =
SighashCache::new(&mut tx.tx);

Expand Down Expand Up @@ -247,8 +245,6 @@ impl Actor {
txin_index: usize,
script_index: usize,
) -> Result<schnorr::Signature, BridgeError> {
// TODO: if sighash_cache exists in the TxHandler, use it
// else create a new one and save it to the TxHandler
let mut sighash_cache: SighashCache<&mut bitcoin::Transaction> =
SighashCache::new(&mut tx_handler.tx);

Expand All @@ -265,52 +261,6 @@ impl Actor {
self.sign_with_tweak(sig_hash, None)
}

#[tracing::instrument(err(level = tracing::Level::ERROR), ret(level = tracing::Level::TRACE))]
pub fn convert_tx_to_sighash_script_spend(
tx_handler: &mut TxHandler,
txin_index: usize,
script_index: usize,
) -> Result<TapSighash, BridgeError> {
let mut sighash_cache: SighashCache<&mut bitcoin::Transaction> =
SighashCache::new(&mut tx_handler.tx);

let prevouts = bitcoin::sighash::Prevouts::All(&tx_handler.prevouts);
let leaf_hash = TapLeafHash::from_script(
tx_handler
.prev_scripts
.get(txin_index)
.ok_or(BridgeError::NoScriptsForTxIn(txin_index))?
.get(script_index)
.ok_or(BridgeError::NoScriptAtIndex(script_index))?,
LeafVersion::TapScript,
);
let sig_hash = sighash_cache.taproot_script_spend_signature_hash(
txin_index,
&prevouts,
leaf_hash,
bitcoin::sighash::TapSighashType::Default,
)?;

Ok(sig_hash)
}

#[tracing::instrument(err(level = tracing::Level::ERROR), ret(level = tracing::Level::TRACE))]
pub fn convert_tx_to_sighash_pubkey_spend(
tx: &mut TxHandler,
txin_index: usize,
) -> Result<TapSighash, BridgeError> {
let mut sighash_cache: SighashCache<&mut bitcoin::Transaction> =
SighashCache::new(&mut tx.tx);

let sig_hash = sighash_cache.taproot_key_spend_signature_hash(
txin_index,
&bitcoin::sighash::Prevouts::All(&tx.prevouts),
bitcoin::sighash::TapSighashType::Default,
)?;

Ok(sig_hash)
}

/// Returns derivied Winternitz secret key from given path.
fn get_derived_winternitz_sk(
&self,
Expand Down
Loading
Loading