Skip to content

Commit d624ae5

Browse files
committed
Fix tapscript checksig and checksigadd
1 parent af1f0b4 commit d624ae5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/lib.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,25 @@ impl Exec {
315315
unimplemented!();
316316
}
317317

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> {
319319
unimplemented!();
320320
}
321321

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> {
323323
if !sig.is_empty() {
324324
self.validation_weight -= VALIDATION_WEIGHT_PER_SIGOP_PASSED;
325325
if self.validation_weight < 0 {
326326
return Err(ExecError::TapscriptValidationWeight);
327327
}
328328
}
329+
329330
if pk.is_empty() {
330-
return Err(ExecError::PubkeyType);
331+
Err(ExecError::PubkeyType)
331332
} else if pk.len() == 32 {
332333
if !sig.is_empty() {
333334
self.check_sig_schnorr(sig, pk)?;
334335
}
336+
Ok(true)
335337
} else {
336338
/*
337339
* New public key version softforks should be defined before this `else` block.
@@ -342,11 +344,11 @@ impl Exec {
342344
// return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE);
343345
// }
344346
//TODO(stevenroose) something with discourage stuff
347+
Ok(true)
345348
}
346-
Ok(())
347349
}
348350

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> {
350352
match self.ctx {
351353
ExecCtx::Legacy | ExecCtx::SegwitV0 => self.check_sig_pre_tap(sig, pk),
352354
ExecCtx::Tapscript => self.check_sig_tap(sig, pk),
@@ -866,15 +868,15 @@ impl Exec {
866868
OP_CHECKSIG | OP_CHECKSIGVERIFY => {
867869
let sig = self.stacktop(-2)?.clone();
868870
let pk = self.stacktop(-1)?.clone();
869-
self.check_sig(&sig, &pk)?;
871+
let res = self.check_sig(&sig, &pk)?;
870872
self.stack.pop().unwrap();
871873
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+
}
876877
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);
878880
}
879881
}
880882

@@ -886,13 +888,11 @@ impl Exec {
886888
let num = self.stacktop(-2)?;
887889
let mut n = read_scriptint(&num, 4, self.opt.require_minimal)?;
888890
let pk = self.stacktop(-1)?.clone();
889-
self.check_sig(&sig, &pk)?;
891+
let res = self.check_sig(&sig, &pk)?;
890892
self.stack.pop().unwrap();
891893
self.stack.pop().unwrap();
892894
self.stack.pop().unwrap();
893-
//TODO(stevenroose) check this together with above
894-
let success = true;
895-
if success {
895+
if res {
896896
n += 1;
897897
}
898898
self.stack.push(script::scriptint_vec(n));

0 commit comments

Comments
 (0)