diff --git a/scripts/Cargo.toml b/scripts/Cargo.toml index 33e0a9a..fc275f3 100644 --- a/scripts/Cargo.toml +++ b/scripts/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +bitvm = { git = "https://github.com/bitlayer-org/BitVM.git" } bitcoin-script = { git = "https://github.com/bitlayer-org/rust-bitcoin-script" } bitcoin = { git = "https://github.com/bitlayer-org/rust-bitcoin", branch = "bf-stark" } bitcoin-scriptexec = { git = "https://github.com/bitlayer-org/rust-bitcoin-scriptexec" } diff --git a/scripts/src/hashes/blake3.rs b/scripts/src/hashes/blake3.rs deleted file mode 100644 index d02b16e..0000000 --- a/scripts/src/hashes/blake3.rs +++ /dev/null @@ -1,590 +0,0 @@ -#![allow(non_snake_case)] -use std::collections::HashMap; - -use crate::pseudo::push_to_stack; -use crate::treepp::{pushable, script, Script}; -use crate::u32::u32_std::{u32_equalverify, u32_roll}; -use crate::u32::{ - u32_add::u32_add, - u32_rrot::u32_rrot, - u32_std::{u32_drop, u32_fromaltstack, u32_push, u32_toaltstack}, - u32_xor::{u32_xor, u8_drop_xor_table, u8_push_xor_table}, - // unroll, -}; - -// -// Environment -// - -// A pointer to address elements on the stack -#[derive(Eq, Hash, PartialEq, Debug, Clone, Copy)] -pub enum Ptr { - State(u32), - Message(u32), -} - -pub fn S(i: u32) -> Ptr { - Ptr::State(i) -} - -pub fn M(i: u32) -> Ptr { - Ptr::Message(i) -} - -// An environment to track elements on the stack -type Env = HashMap; - -pub fn ptr_init() -> Env { - // Initial positions for state and message - let mut env: Env = Env::new(); - for i in 0..16 { - env.insert(S(i), i); - // The message's offset is the size of the state - // plus the u32 size of our XOR table - env.insert(M(i), i + 16 + 256 / 4); - } - env -} - -pub fn ptr_init_160() -> Env { - // Initial positions for state and message - let mut env: Env = Env::new(); - for i in 0..16 { - env.insert(S(i), i); - // The message's offset is the size of the state - // plus the u32 size of our XOR table - let value: i32 = i as i32 - + 16 - + 256 / 4 - + match i < 10 { - true => 6, - false => -10, - }; - env.insert(M(i), value as u32); - } - env -} - -pub trait EnvTrait { - // Get the position of `ptr` - fn ptr(&mut self, ptr: Ptr) -> u32; - - /// Get the position of `ptr`, then delete it - fn ptr_extract(&mut self, ptr: Ptr) -> u32; - - /// Set the position of `ptr` to the top stack ptr - fn ptr_insert(&mut self, ptr: Ptr); -} - -impl EnvTrait for Env { - fn ptr_insert(&mut self, ptr: Ptr) { - for (_, value) in self.iter_mut() { - *value += 1; - } - self.insert(ptr, 0); - } - - fn ptr_extract(&mut self, ptr: Ptr) -> u32 { - match self.remove(&ptr) { - Some(index) => { - for (_, value) in self.iter_mut() { - if index < *value { - *value -= 1; - } - } - index - } - None => panic!("{:?}", ptr), - } - } - - fn ptr(&mut self, ptr: Ptr) -> u32 { - *self.get(&ptr).unwrap() - } -} - -// -// Blake 3 Algorithm -// - -const IV: [u32; 8] = [ - 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, -]; - -const MSG_PERMUTATION: [u32; 16] = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8]; - -pub fn initial_state(block_len: u32) -> Vec