Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions NBitcoin.Tests/MiniscriptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ public void CanRoundtripMiniscript(string miniscript)
Assert.Equal(miniscript, actual);
}

[Theory]
// https://github.com/MetacoSA/NBitcoin/issues/1283
[InlineData("older(000000002088829000)", false)]
[InlineData("older(01)", false)]
[InlineData("after(01)", false)]
[InlineData("multi(01,A,B)", false)]
[InlineData("older(0)", true)]
[InlineData("older(1000)", true)]
[InlineData("after(1000)", true)]
public void RejectsNonCanonicalNumbers(string miniscript, bool expected)
{
var settings = new MiniscriptParsingSettings(Network.RegTest, KeyType.Classic) { AllowedParameters = ParameterTypeFlags.All };
Assert.Equal(expected, Miniscript.TryParse(miniscript, settings, out _));
}

[Theory]
[InlineData(ParameterTypeFlags.All, "pkh(A)", true)]
[InlineData(ParameterTypeFlags.All, "pkh(@0/**)", true)]
Expand Down
10 changes: 10 additions & 0 deletions NBitcoin/WalletPolicies/Miniscript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ private static bool TryParseParameterCount(ParsingContext ctx, [MaybeNullWhen(tr
error = null;
node = null;
var match = Regex.Match(ctx.Remaining, @"^[0-9]+");
if (match.Value.Length > 1 && match.Value[0] == '0')
{
error = new MiniscriptError.CountExpected(ctx.Offset);
return false;
}
if (uint.TryParse(match.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var v) && v < Int32.MaxValue)
{
ctx.Advance(match.Length);
Expand Down Expand Up @@ -257,6 +262,11 @@ private static bool TryParseLocktime(ParsingContext ctx, [MaybeNullWhen(true)] o
node = null;
error = null;
var match = Regex.Match(ctx.Remaining, @"^[0-9]+");
if (match.Value.Length > 1 && match.Value[0] == '0')
{
error = new MiniscriptError.LocktimeExpected(ctx.Offset);
return false;
}
if (uint.TryParse(match.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var v))
{
ctx.Advance(match.Length);
Expand Down
Loading