Limit input count
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
@@ -58,6 +58,30 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
}
}
+ [Fact]
+ public async Task TooManyInputsAsync()
+ {
+ MockArena arena = new();
+ Round round = new();
+ arena.OnTryGetRound = _ => round;
+
+ foreach (Phase phase in Enum.GetValues(typeof(Phase)))
+ {
+ if (phase != Phase.InputRegistration)
+ {
+ round.Phase = phase;
+ await using PostRequestHandler handler = new(new WabiSabiConfig() { MaxInputCountByAlice = 3 }, new Prison(), arena, new MockRpcClient());
+ var req = new InputsRegistrationRequest(
+ round.Id,
+ WabiSabiFactory.CreateInputRoundSignaturePairs(4),
+ null!,
+ null!);
+ var ex = await Assert.ThrowsAnyAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
+ Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
+ }
+ }
+ }
+
[Fact]
public async Task InputSpentAsync()
{

MODIFY
WalletWasabi/WabiSabi/Backend/Models/WabiSabiProtocolErrorCode.cs
WalletWasabi/WabiSabi/Backend/Models/WabiSabiProtocolErrorCode.cs
@@ -14,6 +14,7 @@ namespace WalletWasabi.WabiSabi.Backend.Models
InputUnconfirmed,
InputImmature,
InputScriptNotAllowed,
- WrongRoundSignature
+ WrongRoundSignature,
+ TooManyInputs
}
}

MODIFY
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
@@ -46,6 +46,10 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.WrongPhase);
}
+ if (Config.MaxInputCountByAlice < request.InputRoundSignaturePairs.Count())
+ {
+ throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.TooManyInputs);
+ }
foreach (var inputRoundSignaturePair in request.InputRoundSignaturePairs)
{

MODIFY
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
@@ -35,5 +35,9 @@ namespace WalletWasabi.WabiSabi.Backend
[DefaultValueStringCollection("[\"witness_v0_keyhash\"]")]
[JsonProperty(PropertyName = "AllowedScriptTypes", DefaultValueHandling = DefaultValueHandling.Populate)]
public IEnumerable<string> AllowedScriptTypes { get; set; } = new[] { "witness_v0_keyhash" };
+
+ [DefaultValue(2)]
+ [JsonProperty(PropertyName = "MaxInputCountByAlice", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public uint MaxInputCountByAlice { get; set; } = 2;
}
}

Limit input count