Skip to content

fix: Include the trade miner fee in the block builder's buy slippage check - #9

Open
giaki3003 wants to merge 1 commit into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260627-1017-kimiclaw-confirm-openclaw--truthcoin-buy-slippage-limit-mismatch-makes-mine
Open

giaki3003 wants to merge 1 commit into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260627-1017-kimiclaw-confirm-openclaw--truthcoin-buy-slippage-limit-mismatch-makes-mine

Conversation

@giaki3003

Copy link
Copy Markdown

What's wrong

Node::check_trade_slippage in lib/node/mod.rs admits a buy when buy_cost.total_cost_sats > limit_sats is false. The connect-time check in apply_trade (lib/state/block.rs) uses total_trade_cost + TRADE_MINER_FEE_SATS > trade.limit_sats. Any buy whose cost lands within TRADE_MINER_FEE_SATS (1000) of its declared limit therefore passes block construction but comes back TradeApplyResult::Skipped at connect.

That divergence hurts the producer itself. get_transactions adds TRADE_MINER_FEE_SATS to the coinbase total for every trade it keeps, while BlockValidator::validate_fees skips the indices that connect_block skipped. The miner claims a fee for a transaction that is not credited, and its own block is rejected with NotEnoughFees.

The fix

Add TRADE_MINER_FEE_SATS (saturating) to the cost before the comparison in check_trade_slippage, so selection uses the same predicate apply_trade already 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.

…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant