@@ -315,23 +315,25 @@ impl Exec {
315
315
unimplemented ! ( ) ;
316
316
}
317
317
318
- fn check_sig_pre_tap ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < ( ) , ExecError > {
318
+ fn check_sig_pre_tap ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < bool , ExecError > {
319
319
unimplemented ! ( ) ;
320
320
}
321
321
322
- fn check_sig_tap ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < ( ) , ExecError > {
322
+ fn check_sig_tap ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < bool , ExecError > {
323
323
if !sig. is_empty ( ) {
324
324
self . validation_weight -= VALIDATION_WEIGHT_PER_SIGOP_PASSED ;
325
325
if self . validation_weight < 0 {
326
326
return Err ( ExecError :: TapscriptValidationWeight ) ;
327
327
}
328
328
}
329
+
329
330
if pk. is_empty ( ) {
330
- return Err ( ExecError :: PubkeyType ) ;
331
+ Err ( ExecError :: PubkeyType )
331
332
} else if pk. len ( ) == 32 {
332
333
if !sig. is_empty ( ) {
333
334
self . check_sig_schnorr ( sig, pk) ?;
334
335
}
336
+ Ok ( true )
335
337
} else {
336
338
/*
337
339
* New public key version softforks should be defined before this `else` block.
@@ -342,11 +344,11 @@ impl Exec {
342
344
// return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE);
343
345
// }
344
346
//TODO(stevenroose) something with discourage stuff
347
+ Ok ( true )
345
348
}
346
- Ok ( ( ) )
347
349
}
348
350
349
- fn check_sig ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < ( ) , ExecError > {
351
+ fn check_sig ( & mut self , sig : & [ u8 ] , pk : & [ u8 ] ) -> Result < bool , ExecError > {
350
352
match self . ctx {
351
353
ExecCtx :: Legacy | ExecCtx :: SegwitV0 => self . check_sig_pre_tap ( sig, pk) ,
352
354
ExecCtx :: Tapscript => self . check_sig_tap ( sig, pk) ,
@@ -866,15 +868,15 @@ impl Exec {
866
868
OP_CHECKSIG | OP_CHECKSIGVERIFY => {
867
869
let sig = self . stacktop ( -2 ) ?. clone ( ) ;
868
870
let pk = self . stacktop ( -1 ) ?. clone ( ) ;
869
- self . check_sig ( & sig, & pk) ?;
871
+ let res = self . check_sig ( & sig, & pk) ?;
870
872
self . stack . pop ( ) . unwrap ( ) ;
871
873
self . stack . pop ( ) . unwrap ( ) ;
872
- //TODO(stevenroose) this code seems unreachable in core..
873
- // if op == OP_CHECKSIGVERIFY && !res {
874
- // return Err(ExecError::CheckSigVerify);
875
- // }
874
+ if op == OP_CHECKSIGVERIFY && !res {
875
+ return Err ( ExecError :: CheckSigVerify ) ;
876
+ }
876
877
if op == OP_CHECKSIG {
877
- self . stack . push ( item_true ( ) ) ;
878
+ let ret = if res { item_true ( ) } else { item_false ( ) } ;
879
+ self . stack . push ( ret) ;
878
880
}
879
881
}
880
882
@@ -886,13 +888,11 @@ impl Exec {
886
888
let num = self . stacktop ( -2 ) ?;
887
889
let mut n = read_scriptint ( & num, 4 , self . opt . require_minimal ) ?;
888
890
let pk = self . stacktop ( -1 ) ?. clone ( ) ;
889
- self . check_sig ( & sig, & pk) ?;
891
+ let res = self . check_sig ( & sig, & pk) ?;
890
892
self . stack . pop ( ) . unwrap ( ) ;
891
893
self . stack . pop ( ) . unwrap ( ) ;
892
894
self . stack . pop ( ) . unwrap ( ) ;
893
- //TODO(stevenroose) check this together with above
894
- let success = true ;
895
- if success {
895
+ if res {
896
896
n += 1 ;
897
897
}
898
898
self . stack . push ( script:: scriptint_vec ( n) ) ;
0 commit comments