Permalink
Browse files

Refactor script verification, so it throws error back.

  • Loading branch information...
nopara73 committed Oct 28, 2018
1 parent 00544dc commit d729b65f95b422abb2e88195a0a6d52db7e97f24
Showing with 11 additions and 4 deletions.
  1. +11 −4 WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -624,12 +624,19 @@ public async Task<IActionResult> PostSignaturesAsync([FromQuery]string uniqueId,
}
// Verify witness.
var cjCopy = Transaction.Parse(round.UnsignedCoinJoin.ToHex(), Network);
// 1. Copy UnsignedCoinJoin.
Transaction cjCopy = Transaction.Parse(round.UnsignedCoinJoin.ToHex(), Network);
// 2. Sign the copy.
cjCopy.Inputs[index].WitScript = witness;
TxOut output = alice.Inputs.Single(x => x.OutPoint == cjCopy.Inputs[index].PrevOut).Output;
if (!Script.VerifyScript(output.ScriptPubKey, cjCopy, index, output.Value, ScriptVerify.Standard, SigHash.All))
// 3. Convert the current input to IndexedTxIn.
IndexedTxIn currentIndexedInput = cjCopy.Inputs.AsIndexedInputs().Skip(index).First();
// 4. Find the corresponding registered input and convert it to Coin.
(OutPoint OutPoint, TxOut Output) registeredInput = alice.Inputs.Single(x => x.OutPoint == cjCopy.Inputs[index].PrevOut);
Coin registeredCoin = new Coin(registeredInput.OutPoint, registeredInput.Output);
// 5. Verify if currentIndexedInput is correctly signed, if not, return the specific error.
if (!currentIndexedInput.VerifyScript(registeredCoin, out ScriptError error))
{
return BadRequest($"Invalid witness is provided.");
return BadRequest($"Invalid witness is provided. ScriptError: {error}.");
}
// Finally add it to our CJ.

0 comments on commit d729b65

Please sign in to comment.