Skip to content

Commit

Permalink
use Dummy OP_0 for sig instead of dummy sig
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Nov 20, 2014
1 parent 5627da6 commit c953f73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 0 additions & 3 deletions NBitcoin/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,6 @@ public static Script CombineSignatures(Script scriptPubKey, Transaction transact
var stack2 = context.Stack.Reverse().ToArray();

return CombineSignatures(scriptPubKey, transaction, n, stack1, stack2);



}

private static Script CombineSignatures(Script scriptPubKey, Transaction transaction, int n, byte[][] sigs1, byte[][] sigs2)
Expand Down
15 changes: 9 additions & 6 deletions NBitcoin/StandardScriptTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPu
var keyCount = (uint)pubKeyCount.GetValue();
if(1 + keyCount + 1 + 1 != ops.Length)
return false;
for(int i = 1 ; i < keyCount + 1; i++)
for(int i = 1 ; i < keyCount + 1 ; i++)
{
if(ops[i].PushData == null)
return false;
Expand All @@ -169,7 +169,7 @@ public PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Script scri

List<PubKey> keys = new List<PubKey>();
List<byte[]> invalidKeys = new List<byte[]>();
for(int i = 1 ; i < keyCount + 1; i++)
for(int i = 1 ; i < keyCount + 1 ; i++)
{
if(!PubKey.IsValidSize(ops[i].PushData.Length))
invalidKeys.Add(ops[i].PushData);
Expand Down Expand Up @@ -209,7 +209,7 @@ protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps,
return false;
if(scriptSigOps.Length == 1)
return false;
if(!scriptSigOps.Skip(1).All(s => TransactionSignature.ValidLength(s.PushData.Length)))
if(!scriptSigOps.Skip(1).All(s => TransactionSignature.ValidLength(s.PushData.Length) || s.Code == OpcodeType.OP_0))
return false;
if(scriptPubKeyOps != null)
{
Expand All @@ -231,7 +231,7 @@ public TransactionSignature[] ExtractScriptSigParameters(Script scriptSig)
return null;
try
{
return ops.Skip(1).Select(i => new TransactionSignature(i.PushData)).ToArray();
return ops.Skip(1).Select(i => i.Code == OpcodeType.OP_0 ? null : new TransactionSignature(i.PushData)).ToArray();
}
catch(FormatException)
{
Expand All @@ -253,7 +253,10 @@ public Script GenerateScriptSig(TransactionSignature[] signatures)
ops.Add(OpcodeType.OP_0);
foreach(var sig in signatures)
{
ops.Add(Op.GetPushOp(sig.ToBytes()));
if(sig == null)
ops.Add(OpcodeType.OP_0);
else
ops.Add(Op.GetPushOp(sig.ToBytes()));
}
return new Script(ops.ToArray());
}
Expand Down Expand Up @@ -341,7 +344,7 @@ public PayToScriptHashSigParameters ExtractScriptSigParameters(Script scriptSig)
ops
.Skip(multiSig ? 1 : 0)
.Take(ops.Length - 1 - (multiSig ? 1 : 0))
.Select(o => new TransactionSignature(o.PushData))
.Select(o => o.Code == OpcodeType.OP_0 ? null : new TransactionSignature(o.PushData))
.ToArray();
result.RedeemScript = new Script(ops[ops.Length - 1].PushData);
return result;
Expand Down
6 changes: 3 additions & 3 deletions NBitcoin/TransactionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,15 @@ private Script CreateScriptSig(TransactionSigningContext ctx, TxIn input, ICoin
.Select(p => FindKey(ctx, p))
.ToArray();

int sigCount = signatures.Where(s => s != TransactionSignature.Empty).Count();
int sigCount = signatures.Where(s => s != TransactionSignature.Empty && s != null).Count();
for(int i = 0 ; i < keys.Length ; i++)
{
if(sigCount == multiSigParams.SignatureCount)
break;

if(i >= signatures.Count)
{
signatures.Add(TransactionSignature.Empty);
signatures.Add(null);
}
if(keys[i] != null)
{
Expand All @@ -904,7 +904,7 @@ private Script CreateScriptSig(TransactionSigningContext ctx, TxIn input, ICoin

if(sigCount == multiSigParams.SignatureCount)
{
signatures = signatures.Where(s => s != TransactionSignature.Empty).ToList();
signatures = signatures.Where(s => s != TransactionSignature.Empty && s != null).ToList();
}

return PayToMultiSigTemplate.Instance.GenerateScriptSig(
Expand Down

4 comments on commit c953f73

@dthorpe
Copy link
Contributor

@dthorpe dthorpe commented on c953f73 Dec 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PayToScriptHashTemplate.Instance.GenerateScriptSig still barfs if the signature array contains nulls. Is this intended, or should it accept null sigs now also?

@NicolasDorier
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it should accept null sig will fix that !

@dthorpe
Copy link
Contributor

@dthorpe dthorpe commented on c953f73 Dec 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@NicolasDorier
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in my last commits 93c45ea

Please sign in to comment.