Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Tests
on: [push, pull_request, pull_request_target]

env:
SCARB_VERSION: 2.8.4
SCARB_VERSION: 2.9.2

jobs:
scarb-tests:
Expand Down
8 changes: 4 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2024_07"

[dependencies]
starknet = "2.8.4"
openzeppelin = "0.18.0"
utils = { git = "https://github.com/keep-starknet-strange/raito.git", rev = "02a13045b7074ae2b3247431cd91f1ad76263fb2" }
starknet = "2.9.2"
openzeppelin = "0.20.0"
utils = { git = "https://github.com/keep-starknet-strange/raito.git", rev = "dc3d54e84118630efa5e7069eb5c414fd8fbae3f" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.31.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.34.0" }

[scripts]
test = "snforge test"
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoin/block.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{pow2::pow2_u128};
use utils::{hash::Digest, numeric::u32_byte_reverse, double_sha256::double_sha256_u32_array};
use crate::utils::{pow2::pow2_u128, numeric::{u32_byte_reverse, double_sha256_u32_array}};
use utils::hash::Digest;
use core::traits::DivRem;

/// Bitcoin block header structure based on:
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoin/coinbase.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use utils::{hash::Digest, double_sha256::double_sha256_byte_array};

use utils::hash::Digest;
use crate::utils::numeric::double_sha256_byte_array;

#[derive(Drop)]
pub struct CoinbaseData {
Expand Down
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod bitcoin {
pub mod utils {
pub mod digest;
pub mod pow2;
pub mod numeric;
}
#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/safety.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use utils::{hex::{from_hex, hex_to_hash_rev}};
use snforge_std::start_cheat_block_timestamp;
use utils::numeric::u32_byte_reverse;
use crate::utils::numeric::u32_byte_reverse;

#[test]
fn test_is_safe() {
Expand Down
34 changes: 34 additions & 0 deletions src/utils/numeric.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use utils::hash::{Digest, DigestTrait};
use utils::sha256::{compute_sha256_byte_array, compute_sha256_u32_array};

/// Reverses the byte order of a `u32`.
///
/// This function takes a 32-bit unsigned integer and reverses the order of its bytes.
/// It is useful for converting between big-endian and little-endian formats.
pub fn u32_byte_reverse(word: u32) -> u32 {
let byte0 = (word & 0x000000FF) * 0x1000000_u32;
let byte1 = (word & 0x0000FF00) * 0x00000100_u32;
let byte2 = (word & 0x00FF0000) / 0x00000100_u32;
let byte3 = (word & 0xFF000000) / 0x1000000_u32;
return byte0 + byte1 + byte2 + byte3;
}

/// Calculates double sha256 digest of bytes.
pub fn double_sha256_byte_array(bytes: @ByteArray) -> Digest {
let mut input2: Array<u32> = array![];
input2.append_span(compute_sha256_byte_array(bytes).span());

DigestTrait::new(compute_sha256_u32_array(input2, 0, 0))
}

/// Calculates double sha256 digest of an array of full 4 byte words.
///
/// It's important that there are no trailing bytes, otherwise the
/// data will be truncated.
pub fn double_sha256_u32_array(words: Array<u32>) -> Digest {
let mut input2: Array<u32> = array![];
input2.append_span(compute_sha256_u32_array(words, 0, 0).span());


DigestTrait::new(compute_sha256_u32_array(input2, 0, 0))
}
2 changes: 1 addition & 1 deletion src/utu_relay.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod UtuRelay {
use utils::hash::Digest;
use core::num::traits::zero::Zero;
use openzeppelin::{access::ownable::OwnableComponent, upgrades::UpgradeableComponent,};
use openzeppelin_upgrades::interface::IUpgradeable;
use openzeppelin::upgrades::interface::IUpgradeable;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);
Expand Down