fix: Include the trade miner fee in the block builder's buy slippage check - #9
Open
giaki3003 wants to merge 1 commit into
Conversation
…fee blocks Bug: w3-20260627-1017-kimiclaw-confirm-openclaw- (primary) Finding: findings/20260627-1017-kimiclaw-confirm-openclaw-truthcoin-dc-buy-limit-fee-mismatch.md Severity: R5-T2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit b72676b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
Node::check_trade_slippageinlib/node/mod.rsadmits a buy whenbuy_cost.total_cost_sats > limit_satsis false. The connect-time check inapply_trade(lib/state/block.rs) usestotal_trade_cost + TRADE_MINER_FEE_SATS > trade.limit_sats. Any buy whose cost lands withinTRADE_MINER_FEE_SATS(1000) of its declared limit therefore passes block construction but comes backTradeApplyResult::Skippedat connect.That divergence hurts the producer itself.
get_transactionsaddsTRADE_MINER_FEE_SATSto the coinbase total for every trade it keeps, whileBlockValidator::validate_feesskips the indices thatconnect_blockskipped. The miner claims a fee for a transaction that is not credited, and its own block is rejected withNotEnoughFees.The fix
Add
TRADE_MINER_FEE_SATS(saturating) to the cost before the comparison incheck_trade_slippage, so selection uses the same predicateapply_tradealready uses, and update the log line to show both terms. This is not a new consensus rule — the connect-time rule is unchanged; the builder simply stops selecting transactions connect will skip.Finding report (access-controlled): https://giaki3003.tech/#/findings/20260627-1017-kimiclaw-confirm-openclaw-truthcoin-dc-buy-limit-fee-mismatch
First of a short series of 4 fixes for this repo, based on
master. The rest build on this branch and will follow.