Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Implement OP_CHECKSIGADD #263

Closed
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<a href="https://github.com/keep-starknet-strange/shinigami/actions/workflows/check.yml"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/keep-starknet-strange/shinigami/check.yml?style=for-the-badge" height=30></a>

<a href="https://bitcoin.org/"> <img alt="Bitcoin" src="https://img.shields.io/badge/Bitcoin-000?style=for-the-badge&logo=bitcoin&logoColor=white" height=30></a>
<a href="https://www.cairo-lang.org/"> <img alt="Cairo" src="https://img.shields.io/badge/Cairo-000?style=for-the-badge" height=30></a>
<a href="https://react.dev/"> <img alt="React" src="https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB" height=30></a>

<a href="https://exploration.starkware.co/"><img src="https://img.shields.io/badge/Exploration Team-000.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJhIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEgMTgxIj48ZGVmcz48c3R5bGU+LmJ7ZmlsbDojZmZmO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iYiIgZD0iTTE3Ni43Niw4OC4xOGwtMzYtMzcuNDNjLTEuMzMtMS40OC0zLjQxLTIuMDQtNS4zMS0xLjQybC0xMC42MiwyLjk4LTEyLjk1LDMuNjNoLjc4YzUu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MS42OC02LjA5bC0xMi45NS0xNC4xMmMtLjY0LS40NS0xLjE0LTEuMDgtMS40Mi0xLjgxbDE5LjA0LDUuMTgsMi41OSwuNzhjMi4wNCwuNzYsNC4zMywuMTQsNS43LTEuNTVsMTIuOTUtMTQuMzhzLjc4LTEuMDQsMS42OC0xLjE3Yy0xLjgxLDYuNi0yLjk4LDE0LjEyLTUuNDQsMjAuNDYtMS4wOCwyLjk2LS4wOCw2LjI4LDIuNDYsOC4xNiw0LjI3LDQuMTQsOC4yOSw4LjU1LDEyLjk1LDEyLjk1LDAsMCwxLjMsLjkxLDEuNDIsMi4wN2wtMTMuMzQtMy42M1oiLz48L3N2Zz4=" alt="Exploration Team" height="30"></a>
<a href="https://t.me/ShinigamiStarknet"><img src="https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram" height="30"></a>
<a href="https://x.com/BitcoinWildlife"><img src="https://img.shields.io/badge/BitcoinWildlife-%23000.svg?style=for-the-badge&logo=X&logoColor=white" alt="X" height="30"></a>

</div>

Expand Down
9 changes: 9 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ version = "0.1.0"
dependencies = [
"shinigami_compiler",
"shinigami_engine",
"shinigami_tests",
"shinigami_utils",
]

Expand All @@ -34,7 +35,15 @@ version = "0.1.0"
dependencies = [
"ripemd160",
"sha1",
"shinigami_utils",
]

[[package]]
name = "shinigami_tests"
version = "0.1.0"
dependencies = [
"shinigami_compiler",
"shinigami_engine",
"shinigami_utils",
]

Expand Down
1 change: 1 addition & 0 deletions packages/cmds/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024_07"
[dependencies]
shinigami_compiler = { path = "../compiler" }
shinigami_engine = { path = "../engine" }
shinigami_tests = { path = "../tests" }
shinigami_utils = { path = "../utils" }

[dev-dependencies]
Expand Down
64 changes: 44 additions & 20 deletions packages/cmds/src/main.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use shinigami_compiler::compiler::CompilerImpl;
use shinigami_engine::engine::EngineInternalImpl;
use shinigami_engine::transaction::{TransactionImpl, TransactionTrait};
use shinigami_engine::utxo::UTXO;
use shinigami_engine::validate;
use shinigami_engine::scriptflags;
use shinigami_engine::engine::{EngineImpl, EngineInternalImpl};
use shinigami_engine::transaction::{EngineInternalTransactionImpl, EngineInternalTransactionTrait};
use shinigami_engine::flags;
use shinigami_engine::witness;
use shinigami_engine::hash_cache::HashCacheImpl;
use shinigami_utils::byte_array::felt252_to_byte_array;
use shinigami_utils::bytecode::hex_to_bytecode;
use shinigami_tests::utxo::UTXO;
use shinigami_tests::validate;

#[derive(Clone, Drop)]
struct InputData {
Expand Down Expand Up @@ -40,9 +41,10 @@ fn run_with_flags(input: InputDataWithFlags) -> Result<(), felt252> {
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
let compiler = CompilerImpl::new();
let script_sig = compiler.compile(input.ScriptSig)?;
let tx = TransactionImpl::new_signed(script_sig);
let flags = scriptflags::parse_flags(input.Flags);
let mut engine = EngineInternalImpl::new(@script_pubkey, tx, 0, flags, 0)?;
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
let flags = flags::parse_flags(input.Flags);
let hash_cache = HashCacheImpl::new(@tx);
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, flags, 0, @hash_cache)?;
let _ = engine.execute()?;
Result::Ok(())
}
Expand All @@ -60,9 +62,13 @@ fn run_with_witness(input: InputDataWithWitness) -> Result<(), felt252> {
let compiler = CompilerImpl::new();
let script_sig = compiler.compile(input.ScriptSig)?;
let witness = witness::parse_witness_input(input.Witness);
let tx = TransactionImpl::new_signed_witness(script_sig, witness);
let flags = scriptflags::parse_flags(input.Flags);
let mut engine = EngineInternalImpl::new(@script_pubkey, tx, 0, flags, 0)?;
let value = 1; // TODO
let tx = EngineInternalTransactionImpl::new_signed_witness(
script_sig, script_pubkey.clone(), witness, value
);
let flags = flags::parse_flags(input.Flags);
let hash_cache = HashCacheImpl::new(@tx);
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, flags, value, @hash_cache)?;
let _ = engine.execute()?;
Result::Ok(())
}
Expand All @@ -77,8 +83,9 @@ fn run(input: InputData) -> Result<(), felt252> {
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
let compiler = CompilerImpl::new();
let script_sig = compiler.compile(input.ScriptSig)?;
let tx = TransactionImpl::new_signed(script_sig);
let mut engine = EngineInternalImpl::new(@script_pubkey, tx, 0, 0, 0)?;
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
let hash_cache = HashCacheImpl::new(@tx);
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
let _ = engine.execute()?;
Result::Ok(())
}
Expand All @@ -93,8 +100,9 @@ fn run_with_json(input: InputData) -> Result<(), felt252> {
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
let compiler = CompilerImpl::new();
let script_sig = compiler.compile(input.ScriptSig)?;
let tx = TransactionImpl::new_signed(script_sig);
let mut engine = EngineInternalImpl::new(@script_pubkey, tx, 0, 0, 0)?;
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
let hash_cache = HashCacheImpl::new(@tx);
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
let _ = engine.execute()?;
engine.json();
Result::Ok(())
Expand All @@ -110,8 +118,9 @@ fn debug(input: InputData) -> Result<bool, felt252> {
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
let compiler = CompilerImpl::new();
let script_sig = compiler.compile(input.ScriptSig)?;
let tx = TransactionImpl::new_signed(script_sig);
let mut engine = EngineInternalImpl::new(@script_pubkey, tx, 0, 0, 0)?;
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
let hash_cache = HashCacheImpl::new(@tx);
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
let mut res = Result::Ok(true);
while true {
res = engine.step();
Expand Down Expand Up @@ -188,11 +197,26 @@ struct ValidateRawInput {
utxo_hints: Array<UTXO>
}

fn run_raw_transaction(input: ValidateRawInput) -> u8 {
fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
println!("Running Bitcoin Script with raw transaction: '{}'", input.raw_transaction);
let raw_transaction = hex_to_bytecode(@input.raw_transaction);
let transaction = TransactionTrait::deserialize(raw_transaction);
let res = validate::validate_transaction(transaction, 0, input.utxo_hints);
let transaction = EngineInternalTransactionTrait::deserialize(raw_transaction);
let mut utxo_hints = array![];
for hint in input
.utxo_hints
.span() {
println!("UTXO hint: 'amount: {}, script_pubkey: {}'", hint.amount, hint.pubkey_script);
let pubkey_script = hex_to_bytecode(hint.pubkey_script);
utxo_hints
.append(
UTXO {
amount: *hint.amount,
pubkey_script: pubkey_script,
block_height: *hint.block_height,
}
);
};
let res = validate::validate_transaction(@transaction, 0, utxo_hints);
match res {
Result::Ok(_) => {
println!("Execution successful");
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/src/compiler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub impl CompilerImpl of CompilerTrait {
let mut compiler = Compiler { opcodes: Default::default() };
// Add the opcodes to the dict
compiler.add_opcode('OP_0', Opcode::OP_0);
compiler.add_opcode('OP_FALSE', Opcode::OP_0);
compiler.add_opcode('OP_FALSE', Opcode::OP_FALSE);
compiler.add_opcode('OP_DATA_1', Opcode::OP_DATA_1);
compiler.add_opcode('OP_DATA_2', Opcode::OP_DATA_2);
compiler.add_opcode('OP_DATA_3', Opcode::OP_DATA_3);
Expand Down Expand Up @@ -286,6 +286,8 @@ pub impl CompilerImpl of CompilerTrait {
compiler.add_opcode('OP_LSHIFT', Opcode::OP_LSHIFT);
compiler.add_opcode('OP_RSHIFT', Opcode::OP_RSHIFT);
compiler.add_opcode('OP_NOP1', Opcode::OP_NOP1);
compiler.add_opcode('OP_NOP2', Opcode::OP_NOP2);
compiler.add_opcode('OP_NOP3', Opcode::OP_NOP3);
compiler.add_opcode('OP_NOP4', Opcode::OP_NOP4);
compiler.add_opcode('OP_NOP5', Opcode::OP_NOP5);
compiler.add_opcode('OP_NOP6', Opcode::OP_NOP6);
Expand Down
1 change: 0 additions & 1 deletion packages/engine/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2024_07"
[dependencies]
ripemd160.workspace = true
sha1.workspace = true
shinigami_compiler = { path = "../compiler" }
shinigami_utils = { path = "../utils" }

[dev-dependencies]
Expand Down
Loading