Skip to content

Commit e8c8961

Browse files
OttoAllmendingerllm-git
andcommitted
fix(abstract-utxo): correct fee calculation in backup recovery
Fix dimension calculation for backup key recovery to include the recovery destination output. Without this, the approximated transaction fee would be incorrect, potentially creating transactions with insufficient fees. Issue: BTC-2891 Co-authored-by: llm-git <[email protected]>
1 parent 4bad0f8 commit e8c8961

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/abstract-utxo/src/recovery/backupKeyRecovery.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ export async function backupKeyRecovery(
341341
? params.feeRate
342342
: await getRecoveryFeePerBytes(coin, { defaultValue: DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V2 });
343343

344-
// KRS recovery transactions have a 2nd output to pay the recovery fee, like paygo fees.
345-
const dimensions = Dimensions.fromPsbt(psbt).plus(isKrsRecovery ? Dimensions.SingleOutput.p2wsh : Dimensions.ZERO);
346-
const approximateFee = BigInt(dimensions.getVSize() * feePerByte);
347-
348344
txInfo.inputs =
349345
responseTxFormat === 'legacy'
350346
? unspents.map((u) => ({ ...u, value: Number(u.value), valueString: u.value.toString(), prevTx: undefined }))
@@ -354,6 +350,13 @@ export async function backupKeyRecovery(
354350
utxolib.bitgo.addWalletUnspentToPsbt(psbt, unspent, walletKeys, 'user', 'backup');
355351
});
356352

353+
const dimensions = Dimensions.fromPsbt(psbt)
354+
// Add the recovery output
355+
.plus(Dimensions.fromOutput({ script: utxolib.address.toOutputScript(params.recoveryDestination, coin.network) }))
356+
// KRS recovery transactions have a 2nd output to pay the recovery fee, like paygo fees.
357+
.plus(isKrsRecovery ? Dimensions.SingleOutput.p2wsh : Dimensions.ZERO);
358+
const approximateFee = BigInt(dimensions.getVSize() * feePerByte);
359+
357360
let krsFee = BigInt(0);
358361
if (isKrsRecovery && params.krsProvider) {
359362
try {

0 commit comments

Comments
 (0)