Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeanmichel7 committed Jan 26, 2025
1 parent adb4aa0 commit a396509
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
5 changes: 5 additions & 0 deletions packages/engine/src/engine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub impl EngineImpl<
num_ops: 0,
hash_cache: hash_cache,
};

if engine.has_flag(ScriptFlags::ScriptVerifyCleanStack)
&& (!engine.has_flag(ScriptFlags::ScriptBip16)
&& !engine.has_flag(ScriptFlags::ScriptVerifyWitness)) {
Expand All @@ -161,6 +162,7 @@ pub impl EngineImpl<
&& !parser::is_push_only(script_sig) {
return Result::Err('Engine::new: not pushonly');
}

let mut bip16 = false;
if engine.has_flag(ScriptFlags::ScriptBip16) && parser::is_script_hash(script_pubkey) {
if !engine.has_flag(ScriptFlags::ScriptVerifySigPushOnly)
Expand All @@ -170,6 +172,7 @@ pub impl EngineImpl<
engine.bip16 = true;
bip16 = true;
}

let mut i = 0;
let mut valid_sizes = true;
let scripts_len = engine.scripts.len();
Expand All @@ -193,6 +196,7 @@ pub impl EngineImpl<
engine.dstack.verify_minimal_data = true;
engine.astack.verify_minimal_data = true;
}

if engine.has_flag(ScriptFlags::ScriptVerifyWitness) {
if !engine.has_flag(ScriptFlags::ScriptBip16) {
return Result::Err('Engine::new: witness in nonp2sh');
Expand Down Expand Up @@ -226,6 +230,7 @@ pub impl EngineImpl<
return Result::Err(Error::WITNESS_MALLEATED_P2SH);
}
}

if witness_program.len() != 0 {
let (witness_version, witness_program) = witness::parse_witness_program(
@witness_program,
Expand Down
17 changes: 0 additions & 17 deletions packages/engine/src/hash_cache.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use crate::transaction::{
EngineTransactionInputTrait, EngineTransactionOutputTrait, EngineTransactionTrait,
};
// use crate::engine::{EngineInternalTrait, EngineTrait, Engine};
use crate::flags::ScriptFlags;

use shinigami_utils::{bytecode::{write_var_int}, hash::{hash_to_u256, sha256_u256, simple_sha256}};
use core::sha256::compute_sha256_byte_array;
use crate::signature::utils::is_witness_v1_pub_key_hash;
// use core::dict::Felt252Dict;
// use core::poseidon::PoseidonTrait;
// use core::hash::{HashStateTrait, HashStateExTrait};

// SegwitSigHashMidstate is the sighash midstate used in the base segwit
// sighash calculation as defined in BIP 143.
Expand Down Expand Up @@ -235,9 +231,7 @@ pub trait HashCacheTrait<
>,
> {
fn new(tx: @T, flags: u32) -> HashCache<T>;
// fn add_sig_hashes(ref self: HashCache<T>, tx: @T);
fn get_sig_hashes(self: @HashCache<T>) -> Option<@TxSigHashes>;

fn get_hash_prevouts_v0(self: @HashCache<T>) -> u256;
fn get_hash_sequence_v0(self: @HashCache<T>) -> u256;
fn get_hash_outputs_v0(self: @HashCache<T>) -> u256;
Expand All @@ -262,9 +256,6 @@ pub impl HashCacheImpl<
+Drop<T>,
> of HashCacheTrait<I, O, T> {
fn new(tx: @T, flags: u32) -> HashCache<T> {
// First determine if segwit is active according to the scriptFlags. If
// it isn't then we don't need to interact with the HashCache.
// segwitActive := flags&txscript.ScriptVerifyWitness == txscript.ScriptVerifyWitness
let segwit_active = flags
& ScriptFlags::ScriptVerifyWitness.into() == ScriptFlags::ScriptVerifyWitness.into();

Expand All @@ -276,20 +267,12 @@ pub impl HashCacheImpl<
}
};

// If the hashcache doesn't yet has the sighash midstate for this
// transaction, then we'll compute them now so we can re-use them
// amongst all worker validation goroutines.
if (segwit_active && has_witness) {
return HashCache { sigHashes: Option::Some(SigHashMidstateTrait::new(tx)) };
}

return HashCache { sigHashes: Default::default() };
}

// fn add_sig_hashes(ref self: HashCache<T>, tx: @T) {
// self.sigHashes = Option::Some(SigHashMidstateTrait::new(tx));
// }

fn get_sig_hashes(self: @HashCache<T>) -> Option<@TxSigHashes> {
*self.sigHashes
}
Expand Down
3 changes: 0 additions & 3 deletions packages/engine/src/opcodes/crypto.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,6 @@ pub fn opcode_checksigadd<
if (verifier.verify(ref engine).is_err()) {
return Result::Err(Error::TAPROOT_INVALID_SIG);
}
// if (TaprootSigVerifierTrait::<I, O, T>::verify(verifier, ref engine).is_err()) {
// return Result::Err(Error::TAPROOT_INVALID_SIG);
// }

engine.dstack.push_int(n + 1);
Result::Ok(())
Expand Down
7 changes: 4 additions & 3 deletions packages/engine/src/taproot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ pub impl TaprootContextImpl of TaprootContextTrait {
annex = witness[witness.len() - 1];
}

let mut verifier = TaprootSigVerifierImpl::<
let verifier = TaprootSigVerifierImpl::<
T,
>::new(raw_sig, witness_program, annex, ref engine)?; // mut ?
let is_valid = TaprootSigVerifierImpl::<T>::verify(verifier, ref engine);
>::new(raw_sig, witness_program, annex, ref engine)?;

let is_valid = verifier.verify(ref engine);
if is_valid.is_err() {
return Result::Err(Error::TAPROOT_INVALID_SIG);
}
Expand Down

0 comments on commit a396509

Please sign in to comment.