| Crates.io | stacksat128 |
| lib.rs | stacksat128 |
| version | 0.1.0 |
| created_at | 2025-04-25 16:35:52.245996+00 |
| updated_at | 2025-04-25 16:35:52.245996+00 |
| description | A 256-bit cryptographic hash function optimized for Bitcoin Script environments |
| homepage | |
| repository | https://github.com/AbdelStark/stacksat128 |
| max_upload_size | |
| id | 1649211 |
| size | 40,288 |
STACKSAT-128 is a 256-bit cryptographic hash function designed for resource-constrained environments, specifically Bitcoin Script. It aims to provide 128-bit security against standard attacks (collision, preimage) while exclusively using operations efficient and available on the Bitcoin mainnet today.
Advanced Bitcoin protocols like BitVM, zero-knowledge proof verifiers often require cryptographic hashing directly within Bitcoin Script. However, Bitcoin Script lacks many fundamental operations (bitwise logic like XOR, shifts/rotations, concatenation) used by standard hashes like SHA-256, SHA-3, or BLAKE3. Emulating these operations in Script leads to extremely large and inefficient scripts (hundreds of kilobytes), hindering practical deployment. Conversely, ZK-friendly hashes (Poseidon, Rescue) rely heavily on finite field multiplication, also unavailable in Script.
STACKSAT-128 bridges this gap by constructing a secure hash function using only the primitive operations available:
OP_PICK).STACKSAT-128 is built upon well-understood cryptographic principles (Sponge, SPN) but tailored for Script:
add16 (addition mod 16).add16) of 4 nibbles in its column from the state before this step (y[r] = x[r] + x[r+1] + x[r+2] + x[r+3] mod 16).The primary goal is efficient implementation within Bitcoin Script (specifically Taproot scripts):
add16 maps to OP_ADD, OP_LESSTHAN, OP_IF, OP_SUB, OP_ENDIF.OP_PICK.OP_SWAP, OP_ROLL, OP_PICK).OP_PICK to access previous state values during computation.The target is for a full hash computation script to be significantly smaller and faster than scripted versions of SHA-256/BLAKE3, aiming for well under the 10KB Taproot limit. Note: A full, optimized Bitcoin Script implementation is future work and necessary to confirm final size and performance.
no_std compatible)Add the crate to your Cargo.toml:
[dependencies]
stacksat128 = "0.1.0" # Check crates.io for latest version
Example:
use stacksat128::stacksat_hash;
fn main() {
let message = b"Hello, Bitcoin Script!";
let digest = stacksat_hash(message);
// Print as hex (requires `hex` crate)
// println!("Message: {:?}", message);
// println!("Digest: {}", hex::encode(digest));
// Example Output (will change if algorithm updated):
// Hash(''): 3d6a580b16379e75b15cf86e2a42189e634f5bd2b63fe18658891a24005f8dc0
// Hash('abc'): 1eb95ba9134591818b1f4c6c2d1e6ea3562802812d8bf744f90ac513075db275
// Use digest...
}
The detailed algorithmic specification can be found in SPECIFICATION.md.
This project is licensed under the MIT License. See the LICENSE file for details.