Skip to content

fix: base the high fee warning on amount sent - #957

Open
kkdao wants to merge 1 commit into
selfcustody:developfrom
kkdao:fix/fee-percent-spend
Open

kkdao wants to merge 1 commit into
selfcustody:developfrom
kkdao:fix/fee-percent-spend

Conversation

@kkdao

@kkdao kkdao commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What is this PR for?

The 10% high fee warning divides the fee by every output, change included. A large change output can therefore suppress the warning even when the fee is high compared with what is sent.

Krux's own test data already shows it. In test_outputs_singlesig, paying 1,000 sat and sending 1,000 sat to the wallet itself with a 373 sat fee is 18.7% of what is sent, but Krux shows 3.9% and doesn't warn. In test_outputs_multisig, paying 100,000 sat and sending 200,000 sat to the wallet itself with a 61,592 sat fee is 20.6%, shown as 6.6% with no warning.

This PR measures the warning against what is sent: spends plus self transfers to the wallet's own receive addresses, since the user chose to create both, as suggested in review. Change is the base only when nothing else is sent. The fee percentage on the summary screen is unchanged and still divides by all outputs, so it keeps matching coordinators like Sparrow. #390 first divided by the spend, as the warning describes ("Warn if fees greater than 10% of what is spent" in home.py), and #392 switched to all outputs.

Only the warning's base changes. The summary, the absolute fee, the sat/vB estimate, the 10% threshold and the warning text are unchanged. Spends plus self transfers are never larger than all outputs, so the warning can only fire more often. Outputs count as change or self transfer only when the wallet descriptor owns them, which rebuilds and compares the full output script, so a coordinator cannot move a payment into the change or the self transfers. Single-sig wallets always have a descriptor. Multisig and miniscript wallets without a loaded descriptor count every output as spend, as before. Missing change derivation data can dilute the new percentage, but cannot make it lower than the previous all output calculation.

New tests cover a payment with a large change output, where the summary shows 1.1% and the warning uses 10.0%, the test_outputs_singlesig payment next to a self transfer, where the summary shows 3.9% and the warning uses 18.7%, a change only transaction, and a self transfer with and without change. No existing expectation changes. All tests pass (1198 passed, 1 xfailed).

Not changed here: the rounding is not a strict ceiling despite its comment (0.4086% shows as 0.4%).

Changes made to:

  • Code
  • Tests
  • Docs
  • CHANGELOG

Did you build the code and tested on device?

  • Yes, build and tested on

Not tested on device: only the number the warning divides by changes. The warning screen, its text and its threshold are the same ones develop already shows for any fee of 10% or more. An earlier revision of this PR was built for M5StickV, this one was not.

What is the purpose of this pull request?

  • Bug fix
  • New feature
  • Docs update
  • Other

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.61%. Comparing base (9092846) to head (666bc7b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #957   +/-   ##
========================================
  Coverage    97.60%   97.61%           
========================================
  Files           84       84           
  Lines        11001    11005    +4     
========================================
+ Hits         10738    10742    +4     
  Misses         263      263           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@notTanveer

notTanveer commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

this PR makes the warning fire on most ordinary txs. extra confirm step on routine payments is bad UX, and users learn to ignore it.

before/after on amigo simulator (single-sig P2WPKH, testnet, one 1 BTC input):

outputs fee develop this PR
0.1 BTC spend, 0.89 change 0.01 BTC 1.1% 10.0%, warns
330 sat spend, 0.99999170 self-transfer 500 sat 0.1% 151.6%, warns
10k sat to own receive addr, rest change 1,000 sat 0.1% 10.0%, warns
2,000 sat spend, rest change 300 sat 0.1% 15.0%, warns
b

Only row 1 is an actually high fee. Other three are normal fees (300-1,000 sat), warn only because spend is small.

i think doing this will make the other rows go back to normal. (self transfer is still an amount i chose to send)

        percent_base = (spend_amount + self_amount) or change_amount

@jdlcdl

jdlcdl commented Oct 7, 2026

Copy link
Copy Markdown
Member

Only row 1 is an actually high fee

While the top example is obviously a high fee, I'll argue that so are the other 3 relative to their abnormally low spend amounts. Personally, I don't mind being warned about high fees in cases where I'm making a spend that is so small that I already know the fee is a significant part of it (in my head "why not lightning?"); I'd be expecting it or it wouldn't surprise me.

@jdlcdl
jdlcdl requested a review from tadeubas October 7, 2026 18:07
@joaozinhom

Copy link
Copy Markdown
Member

I was working on something very similar (joaozinhom#8) and reviewing AI-generated translations; I'll take a look at this PR and suggest some changes, if that's okay...

Comment thread src/krux/psbt.py Outdated
return prefix + BTC_SYMBOL + THIN_SPACE + "%s" % format_btc(amount)

def _get_resume_fee(self, inp_amount, out_amount, output_policy_count):
def _get_resume_fee(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The inspiration for this feature came from Sparrow Wallet. So it would be worth checking how Sparrow handles it before making any changes on the Krux side. In my tests, Krux behaved the same way as Sparrow, but I may have missed some scenarios. -tadeubas

Copied by jdlcdl from a post in krux-devs tg group by tadeu

@jdlcdl
jdlcdl removed the request for review from tadeubas October 7, 2026 20:50
@jdlcdl

jdlcdl commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

(self transfer is still an amount i chose to send)

        percent_base = (spend_amount + self_amount) or change_amount

I agree with this too. Breaking a large utxo into a spend and a few smaller self-transfer utxos is part of the amount being moved (user actively created these outputs); fee percentage arguable can be calculated off the sum of all spend and self-xfers.

Comment thread src/krux/psbt.py Resolved
@kkdao
kkdao force-pushed the fix/fee-percent-spend branch from c7a5442 to 4e4ae2b Compare October 8, 2026 13:08
@kkdao kkdao changed the title fix: measure fee percent against the amount spent fix: measure fee percent against the amount sent Oct 8, 2026
@kkdao

kkdao commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @notTanveer and @jdlcdl, applied: the fee percent is now based on spends plus self transfers, and on change only when nothing else is sent.

On the Sparrow check from @tadeubas: Sparrow divides the fee by all outputs including change, so this now differs from Sparrow on purpose, so a large change output no longer hides a high fee.

@tadeubas

tadeubas commented Oct 8, 2026

Copy link
Copy Markdown
Member

I think the feature should follow Sparrow's implementation. Sparrow has a wider user base, and people are already used to its behavior. It would be strange to see one behavior in Sparrow and another in Krux, as it could make it seem like either Sparrow or Krux is misbehaving.

So I think this discussion should happen in Sparrow first, and only if the behavior changes there should we make the corresponding change in Krux

@kkdao

kkdao commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Fair point, but I'd rather not wait on Sparrow. Krux's own fee warning is meant to be "10% of what is spent", so a large change output shouldn't hide a high fee. Krux's percentage can only come out higher than Sparrow's, and as the last check before signing, it's safer for Krux to warn when Sparrow doesn't.

@tadeubas

tadeubas commented Oct 9, 2026

Copy link
Copy Markdown
Member

It’s not just about the warning; it’s also about what the user sees in the transaction summary. Both Sparrow and Krux display a fee percentage, but if they calculate it using different bases, the same percentage label represents different things in each wallet. That can confuse users and make them think one of the wallets is behaving incorrectly.

@kkdao
kkdao force-pushed the fix/fee-percent-spend branch from 4e4ae2b to da5629e Compare October 10, 2026 03:36
@kkdao kkdao changed the title fix: measure fee percent against the amount sent fix: base the high fee warning on amount sent Oct 10, 2026
@kkdao

kkdao commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Updated: the summary percentage is now unchanged from develop, so it matches Sparrow, and only the high fee warning uses the amount sent.

@HarshPopat23 HarshPopat23 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I tested da5629e against 2937a29 with the same P2WPKH PSBT: 0.10 BTC to the recipient, 0.89 BTC change, and a 0.01 BTC fee. The base skipped the warning; this PR warns at 10.0%. Both show 1.1% in the summary and the same recipient, change, and fee. Declining stopped before the signing menu, and retrying and accepting reached it.

The full host suite had 1,198 passes and 1 expected failure. The new large-change test failed as expected on the base. I also confirmed the documented limitation: removing the change output’s derivation metadata makes Krux label it as a spend and skip the warning. No hardware testing.

One non-blocking suggestion: could the warning say “of the amount sent” when there’s a payment or self-transfer? Seeing “10.0% of the amount” followed by a 1.1% summary is hard to reconcile without knowing what each percentage includes.

@kkdao

kkdao commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

thanks for testing it. changing the wording means a new string in all 11 translations, so I'd keep this PR to the fix and change the text in a follow up if the maintainers want it.

@qlrd

qlrd commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

cACK da5629e (tACK in software, not in devices yet, while it could solve a issue found with krux-integration-tests)

@joaozinhom

Copy link
Copy Markdown
Member

Quick check before I clean things up: is the diff in kkdao#4 (suggestions with translations) still useful for this PR? If it's not relevant anymore, I'll close the sub-PR.

@qlrd

qlrd commented Nov 13, 2026

Copy link
Copy Markdown
Member

Quick check before I clean things up: is the diff in kkdao#4 (suggestions with translations) still useful for this PR? If it's not relevant anymore, I'll close the sub-PR.

Made a check on that and LGTM, i wthink it's worth

@kkdao

kkdao commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

thanks, it's a good idea. it adds a new warning and 11 translations, so I'd prefer it as its own PR after this one, but I'm happy to merge it here if the maintainers would rather have it in one.

The high fee warning divided the fee by every output, change included,
so a payment made from a large coin hid a high fee. In the existing
test data, paying 1,000 sat and sending 1,000 sat to the wallet itself
with a 373 sat fee is 18.7% of what is sent, yet it showed 3.9% and
never warned.

Measure the warning against what is sent instead: spends plus transfers
to the wallet's own receive addresses, since the user chose to create
both. Change is the base only when nothing else is sent. The summary
still divides by all outputs, so its percentage keeps matching
coordinators like Sparrow.
@kkdao
kkdao force-pushed the fix/fee-percent-spend branch from da5629e to 666bc7b Compare November 14, 2026 16:00
Comment thread src/krux/psbt.py
Comment on lines +437 to +438
out_amount = self_amount + change_amount + spend_amount
resume_fee_str, _ = self._get_resume_fee(

@notTanveer notTanveer Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nothing reads the second return value of _get_resume_fee anymore, only test_psbt.py:2306 does. could it return just resume_fee_str, with that test calling _fee_percent directly?

also the fee gets computed twice now, in there and again as inp_amount - out_amount at the warn_percent line. compute it once in outputs() and pass it to both so they can't drift.

edit: i tried, the change in my editor and didn't like it. FWIW, keep it as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, the fix is what left that second value unused, but since jdlcdl ACK'd 666bc7b I'd rather leave it and clean it up in a follow up.

@jdlcdl jdlcdl Nov 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No rush to merge kkdao, if you push another commit, I'll just edit my ack, as i do.

@jdlcdl jdlcdl added the prioritized Prioritized focus for near-term merge label Nov 15, 2026
@jdlcdl

jdlcdl commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

ACK at 666bc7b (as well as the next if it resolves tanveers comments), while hoping for more reviews/acks/approval.

Thank you kkdao, tanveer, joaozinho, tadeu and harshpopat for this proposal and the feedback. I think it's a great compromise to show what Sparrow sees while having an alternate warning.

@qlrd

qlrd commented Nov 15, 2026

Copy link
Copy Markdown
Member

ACK at 666bc7b

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prioritized Prioritized focus for near-term merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants