Add WitnessScaleFactor constant
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Crypto;
+using WalletWasabi.Helpers;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Crypto.ZeroKnowledge;
using WalletWasabi.Tests.UnitTests;
@@ -289,7 +290,7 @@ namespace WalletWasabi.Tests.Helpers
try
{
- weight ??= script.EstimateOutputVsize() * 4;
+ weight ??= Constants.WitnessScaleFactor * script.EstimateOutputVsize();
}
catch (NotImplementedException)
{
@@ -316,7 +317,7 @@ namespace WalletWasabi.Tests.Helpers
var alice = round.Alices.First(x => x.Id == ccresp.aliceId);
var startingWeightCredentialAmount = alice.CalculateRemainingWeightCredentials(round!.RegistrableWeightCredentials);
var script = BitcoinFactory.CreateScript();
- var weight = script.EstimateOutputVsize() * 4;
+ var weight = Constants.WitnessScaleFactor * script.EstimateOutputVsize();
ret.Add(new OutputRegistrationRequest(
round.Id,
script,

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
@@ -61,7 +61,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
Money.Coins(.25m)
};
- var inputWeight = 4 * Constants.P2wpkhInputVirtualSize;
+ var inputWeight = Constants.WitnessScaleFactor * Constants.P2wpkhInputVirtualSize;
var inputRemainingWeights = new[] { protocolMaxWeightPerAlice - inputWeight };
// Phase: Input Registration

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -18,6 +18,8 @@ namespace WalletWasabi.Helpers
public const uint ProtocolVersionWitnessVersion = 70012;
+ public const int WitnessScaleFactor = 4;
+
public const int P2wpkhInputSizeInBytes = 41;
public const int P2wpkhInputVirtualSize = 68;
public const int P2pkhInputSizeInBytes = 145;

MODIFY
WalletWasabi/WabiSabi/Backend/Models/Alice.cs
WalletWasabi/WabiSabi/Backend/Models/Alice.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WalletWasabi.Helpers;
namespace WalletWasabi.WabiSabi.Backend.Models
{
@@ -20,7 +21,7 @@ namespace WalletWasabi.WabiSabi.Backend.Models
public IEnumerable<Coin> Coins { get; }
public IDictionary<Coin, byte[]> CoinRoundSignaturePairs { get; }
public Money TotalInputAmount => Coins.Sum(x => x.Amount);
- public long TotalInputWeight => TotalInputVsize * 4;
+ public long TotalInputWeight => Constants.WitnessScaleFactor * TotalInputVsize;
public int TotalInputVsize => Coins.Sum(x => x.ScriptPubKey.EstimateInputVsize());
public bool ConfirmedConnetion { get; set; } = false;

MODIFY
WalletWasabi/WabiSabi/Backend/Models/Bob.cs
WalletWasabi/WabiSabi/Backend/Models/Bob.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WalletWasabi.Helpers;
namespace WalletWasabi.WabiSabi.Backend.Models
{
@@ -22,6 +23,6 @@ namespace WalletWasabi.WabiSabi.Backend.Models
=> CredentialAmount - feeRate.GetFee(OutputVsize);
public long CalculateWeight()
- => OutputVsize * 4;
+ => Constants.WitnessScaleFactor * OutputVsize;
}
}

MODIFY
WalletWasabi/WabiSabi/Backend/PostRequests/InputRegistrationHandler.cs
WalletWasabi/WabiSabi/Backend/PostRequests/InputRegistrationHandler.cs
@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.Crypto;
+using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.Models;
@@ -105,7 +106,7 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
inputValueSum += coin.TxOut.Value;
// Convert conservative P2WPKH size in virtual bytes to weight units.
- inputWeightSum += coin.TxOut.ScriptPubKey.EstimateInputVsize() * 4;
+ inputWeightSum += Constants.WitnessScaleFactor * coin.TxOut.ScriptPubKey.EstimateInputVsize();
}
if (inputValueSum < round.MinRegistrableAmount)

MODIFY
WalletWasabi/WabiSabi/Client/ArenaClient.cs
WalletWasabi/WabiSabi/Client/ArenaClient.cs
@@ -82,7 +82,7 @@ namespace WalletWasabi.WabiSabi.Client
var presentedWeight = weightCredentialsToPresent.Sum(x => (long)x.Amount.ToUlong());
var (realWeightCredentialRequest, realWeightCredentialResponseValidation) = WeightCredentialClient.CreateRequest(
- new[] { presentedWeight - 4 * scriptPubKey.EstimateOutputVsize() },
+ new[] { presentedWeight - Constants.WitnessScaleFactor * scriptPubKey.EstimateOutputVsize() },
weightCredentialsToPresent);
var outputRegistrationResponse = await RequestHandler.RegisterOutputAsync(

Add WitnessScaleFactor constant