Skip to content

Commit 30dc455

Browse files
committed
merge with main
2 parents 5290ba3 + 7e8c05d commit 30dc455

48 files changed

Lines changed: 2165 additions & 731 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
scarb 2.8.2
1+
scarb 2.9.2

packages/cmds/src/main.cairo

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
11
use shinigami_compiler::compiler::CompilerImpl;
22
use shinigami_engine::engine::{EngineImpl, EngineInternalImpl};
3-
use shinigami_engine::transaction::{EngineInternalTransactionImpl, EngineInternalTransactionTrait};
3+
use shinigami_engine::transaction::{
4+
EngineInternalTransactionImpl, EngineInternalTransactionTrait, UTXO,
5+
};
46
use shinigami_engine::flags;
57
use shinigami_engine::witness;
68
use shinigami_engine::hash_cache::HashCacheImpl;
79
use shinigami_utils::byte_array::felt252_to_byte_array;
810
use shinigami_utils::bytecode::hex_to_bytecode;
9-
use shinigami_tests::utxo::UTXO;
1011
use shinigami_tests::validate;
1112

1213
#[derive(Clone, Drop)]
1314
struct InputData {
1415
ScriptSig: ByteArray,
15-
ScriptPubKey: ByteArray
16+
ScriptPubKey: ByteArray,
17+
txid: u256,
1618
}
1719

1820
#[derive(Clone, Drop)]
1921
struct InputDataWithFlags {
2022
ScriptSig: ByteArray,
2123
ScriptPubKey: ByteArray,
22-
Flags: ByteArray
24+
Flags: ByteArray,
25+
txid: u256,
2326
}
2427

2528
#[derive(Clone, Drop)]
2629
struct InputDataWithWitness {
2730
ScriptSig: ByteArray,
2831
ScriptPubKey: ByteArray,
2932
Flags: ByteArray,
30-
Witness: ByteArray
33+
Witness: ByteArray,
34+
txid: u256,
3135
}
3236

3337
fn run_with_flags(input: InputDataWithFlags) -> Result<(), felt252> {
3438
println!(
3539
"Running Bitcoin Script with ScriptSig: '{}', ScriptPubKey: '{}' and Flags: '{}'",
3640
input.ScriptSig,
3741
input.ScriptPubKey,
38-
input.Flags
42+
input.Flags,
3943
);
4044
let mut compiler = CompilerImpl::new();
4145
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
4246
let compiler = CompilerImpl::new();
4347
let script_sig = compiler.compile(input.ScriptSig)?;
44-
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
48+
let tx = EngineInternalTransactionImpl::new_signed(
49+
script_sig, script_pubkey.clone(), input.txid, array![],
50+
);
4551
let flags = flags::parse_flags(input.Flags);
4652
let hash_cache = HashCacheImpl::new(@tx);
4753
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, flags, 0, @hash_cache)?;
@@ -55,7 +61,7 @@ fn run_with_witness(input: InputDataWithWitness) -> Result<(), felt252> {
5561
input.ScriptSig,
5662
input.ScriptPubKey,
5763
input.Flags,
58-
input.Witness
64+
input.Witness,
5965
);
6066
let mut compiler = CompilerImpl::new();
6167
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
@@ -64,7 +70,7 @@ fn run_with_witness(input: InputDataWithWitness) -> Result<(), felt252> {
6470
let witness = witness::parse_witness_input(input.Witness);
6571
let value = 1; // TODO
6672
let tx = EngineInternalTransactionImpl::new_signed_witness(
67-
script_sig, script_pubkey.clone(), witness, value
73+
script_sig, script_pubkey.clone(), witness, value, input.txid, array![],
6874
);
6975
let flags = flags::parse_flags(input.Flags);
7076
let hash_cache = HashCacheImpl::new(@tx);
@@ -77,13 +83,15 @@ fn run(input: InputData) -> Result<(), felt252> {
7783
println!(
7884
"Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'",
7985
input.ScriptSig,
80-
input.ScriptPubKey
86+
input.ScriptPubKey,
8187
);
8288
let mut compiler = CompilerImpl::new();
8389
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
8490
let compiler = CompilerImpl::new();
8591
let script_sig = compiler.compile(input.ScriptSig)?;
86-
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
92+
let tx = EngineInternalTransactionImpl::new_signed(
93+
script_sig, script_pubkey.clone(), input.txid, array![],
94+
);
8795
let hash_cache = HashCacheImpl::new(@tx);
8896
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
8997
let res = engine.execute();
@@ -95,21 +103,23 @@ fn run(input: InputData) -> Result<(), felt252> {
95103
Result::Err(e) => {
96104
println!("Execution failed: {}", felt252_to_byte_array(e));
97105
Result::Err(e)
98-
}
106+
},
99107
}
100108
}
101109

102110
fn run_with_json(input: InputData) -> Result<(), felt252> {
103111
println!(
104112
"Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'",
105113
input.ScriptSig,
106-
input.ScriptPubKey
114+
input.ScriptPubKey,
107115
);
108116
let mut compiler = CompilerImpl::new();
109117
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
110118
let compiler = CompilerImpl::new();
111119
let script_sig = compiler.compile(input.ScriptSig)?;
112-
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
120+
let tx = EngineInternalTransactionImpl::new_signed(
121+
script_sig, script_pubkey.clone(), input.txid, array![],
122+
);
113123
let hash_cache = HashCacheImpl::new(@tx);
114124
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
115125
let _ = engine.execute()?;
@@ -121,13 +131,15 @@ fn debug(input: InputData) -> Result<bool, felt252> {
121131
println!(
122132
"Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'",
123133
input.ScriptSig,
124-
input.ScriptPubKey
134+
input.ScriptPubKey,
125135
);
126136
let mut compiler = CompilerImpl::new();
127137
let script_pubkey = compiler.compile(input.ScriptPubKey)?;
128138
let compiler = CompilerImpl::new();
129139
let script_sig = compiler.compile(input.ScriptSig)?;
130-
let tx = EngineInternalTransactionImpl::new_signed(script_sig, script_pubkey.clone());
140+
let tx = EngineInternalTransactionImpl::new_signed(
141+
script_sig, script_pubkey.clone(), input.txid, array![],
142+
);
131143
let hash_cache = HashCacheImpl::new(@tx);
132144
let mut engine = EngineImpl::new(@script_pubkey, @tx, 0, 0, 0, @hash_cache)?;
133145
let mut res = Result::Ok(true);
@@ -154,7 +166,7 @@ fn main(input: InputDataWithFlags) -> u8 {
154166
Result::Err(e) => {
155167
println!("Execution failed: {}", felt252_to_byte_array(e));
156168
0
157-
}
169+
},
158170
}
159171
}
160172

@@ -168,7 +180,7 @@ fn main_with_witness(input: InputDataWithWitness) -> u8 {
168180
Result::Err(e) => {
169181
println!("Execution failed: {}", felt252_to_byte_array(e));
170182
0
171-
}
183+
},
172184
}
173185
}
174186

@@ -182,7 +194,7 @@ fn backend_run(input: InputData) -> u8 {
182194
Result::Err(e) => {
183195
println!("Execution failed: {}", felt252_to_byte_array(e));
184196
0
185-
}
197+
},
186198
}
187199
}
188200

@@ -196,7 +208,7 @@ fn backend_debug(input: InputData) -> u8 {
196208
Result::Err(e) => {
197209
println!("Execution failed: {}", felt252_to_byte_array(e));
198210
0
199-
}
211+
},
200212
}
201213
}
202214

@@ -205,12 +217,12 @@ struct ValidateRawInput {
205217
raw_transaction: ByteArray,
206218
utxo_hints: Array<UTXO>,
207219
flags: ByteArray,
220+
txid: u256 // from raito or calculate from raw_transaction in decode ?
208221
}
209222

210223
fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
211224
println!("Running Bitcoin Script with raw transaction: '{}'", input.raw_transaction);
212225
let raw_transaction = hex_to_bytecode(@input.raw_transaction);
213-
let transaction = EngineInternalTransactionTrait::deserialize(raw_transaction);
214226

215227
// Parse the flags
216228
let script_flags = flags::parse_flags(input.flags);
@@ -223,23 +235,25 @@ fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
223235
}
224236

225237
let mut utxo_hints = array![];
238+
for hint in input.utxo_hints.span() {
239+
println!("UTXO hint: 'amount: {}, script_pubkey: {}'", hint.amount, hint.pubkey_script);
240+
let pubkey_script = hex_to_bytecode(hint.pubkey_script);
241+
utxo_hints
242+
.append(
243+
UTXO {
244+
amount: *hint.amount,
245+
pubkey_script: pubkey_script,
246+
block_height: *hint.block_height,
247+
},
248+
);
249+
};
250+
251+
let transaction = EngineInternalTransactionTrait::deserialize(
252+
raw_transaction, input.txid, utxo_hints,
253+
);
254+
// transaction.set_utxos(utxo_hints);
226255

227-
for hint in input
228-
.utxo_hints
229-
.span() {
230-
println!("UTXO hint: 'amount: {}, script_pubkey: {}'", hint.amount, hint.pubkey_script);
231-
let pubkey_script = hex_to_bytecode(hint.pubkey_script);
232-
utxo_hints
233-
.append(
234-
UTXO {
235-
amount: *hint.amount,
236-
pubkey_script: pubkey_script,
237-
block_height: *hint.block_height,
238-
}
239-
);
240-
};
241-
242-
let res = validate::validate_transaction(@transaction, script_flags, utxo_hints);
256+
let res = validate::validate_transaction(@transaction, script_flags);
243257
match res {
244258
Result::Ok(_) => {
245259
println!("Execution successful");
@@ -248,6 +262,6 @@ fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
248262
Result::Err(e) => {
249263
println!("Execution failed: {}", felt252_to_byte_array(e));
250264
0
251-
}
265+
},
252266
}
253267
}

packages/compiler/src/compiler.cairo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::utils::{is_hex, is_number, is_string};
99
#[derive(Destruct)]
1010
pub struct Compiler {
1111
// Dict containing opcode names to their bytecode representation
12-
opcodes: Felt252Dict<Nullable<u8>>
12+
opcodes: Felt252Dict<Nullable<u8>>,
1313
}
1414

1515
pub trait CompilerTrait {
@@ -310,6 +310,7 @@ pub impl CompilerImpl of CompilerTrait {
310310
compiler.add_opcode('OP_CLTV', Opcode::OP_CHECKLOCKTIMEVERIFY);
311311
compiler.add_opcode('OP_CHECKSEQUENCEVERIFY', Opcode::OP_CHECKSEQUENCEVERIFY);
312312
compiler.add_opcode('OP_CSV', Opcode::OP_CHECKSEQUENCEVERIFY);
313+
compiler.add_opcode('OP_CHECKSIGADD', Opcode::OP_CHECKSIGADD);
313314

314315
compiler
315316
}

packages/engine/src/cond_stack.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct ConditionalStack {
99
#[generate_trait()]
1010
pub impl ConditionalStackImpl of ConditionalStackTrait {
1111
fn new() -> ConditionalStack {
12-
ConditionalStack { stack: Default::default(), len: 0, }
12+
ConditionalStack { stack: Default::default(), len: 0 }
1313
}
1414

1515
fn push(ref self: ConditionalStack, value: u8) {
@@ -43,7 +43,7 @@ pub impl ConditionalStackImpl of ConditionalStackTrait {
4343
0 => self.stack.insert(cond_idx.into(), 1),
4444
1 => self.stack.insert(cond_idx.into(), 0),
4545
2 => self.stack.insert(cond_idx.into(), 2),
46-
_ => panic!("Invalid condition")
46+
_ => panic!("Invalid condition"),
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)