Skip to content

Commit

Permalink
add helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bloomingpeach committed Oct 17, 2024
1 parent 5c8994c commit ef78175
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/engine/src/opcodes/crypto.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::signature::signature;
use crate::signature::sighash;
use crate::signature::signature::BaseSigVerifierTrait;
use starknet::secp256_trait::{is_valid_signature};
use shinigami_utils::hash::sha256_byte_array;
use shinigami_utils::hash::{sha256_byte_array, double_sha256_bytearray};
use crate::opcodes::utils;
use crate::scriptnum::ScriptNum;
use crate::errors::Error;
Expand All @@ -32,9 +32,8 @@ pub fn opcode_hash160<T, +Drop<T>>(ref engine: Engine<T>) -> Result<(), felt252>

pub fn opcode_hash256<T, +Drop<T>>(ref engine: Engine<T>) -> Result<(), felt252> {
let m = engine.dstack.pop_byte_array()?;
let res = sha256_byte_array(@m);
let res2 = sha256_byte_array(@res);
engine.dstack.push_byte_array(res2);
let res = double_sha256_bytearray(@m);
engine.dstack.push_byte_array(res.into());
return Result::Ok(());
}

Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/hash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub fn sha256_byte_array(byte: @ByteArray) -> ByteArray {
hash_value
}

pub fn double_sha256_bytearray(byte: @ByteArray) -> ByteArray {
return sha256_byte_array(@sha256_byte_array(byte));
}

pub fn double_sha256(byte: @ByteArray) -> u256 {
let msg_hash = compute_sha256_byte_array(byte);
let mut res_bytes = "";
Expand Down

0 comments on commit ef78175

Please sign in to comment.