fix: Account for same-block AmplifyBeta deposits when pricing trades at build - #12
Open
giaki3003 wants to merge 4 commits 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)
Bug: w3-20260701-2209-kimiclaw-confirm-glmclaw-t (primary) Finding: findings/20260701-2209-kimiclaw-confirm-glmclaw-truthcoin-dc-submitvote-voting-period-prevalidate-gap.md Severity: R5-T2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 3d6fd24)
…ut fail connect Bug: w3-20260705-0214-kimiclaw-confirm-openclaw- (primary) Finding: findings/20260705-0214-kimiclaw-confirm-openclaw-truthcoin-dc-createmarket-duplicate-dim-prevalidate-gap.md Severity: R5-T2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 341f111)
…nnect after producer acceptance Bug: w3-20260628-1746-openclaw-confirm-kimiclaw- (primary) Finding: findings/20260628-1746-openclaw-confirm-kimiclaw-truthcoin-dc-amplifybeta-sell-slippage-divergence.md Severity: R5-INFO Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 511c401)
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
During block construction,
check_trade_slippageinlib/node/mod.rsderives beta viaderive_market_beta, which uses the confirmedmarket.liquidity_base_satsonly. At connect time,running_market_stateinlib/state/block.rsfolds theAmplifyBetadeposits already applied earlier in the same block into the liquidity base before deriving beta.When a block carries an
AmplifyBetafollowed by a trade on the same market, the two sides price that trade at different betas. Near the trade'slimit_satsthey disagree on the outcome: the builder keeps the trade and creditsTRADE_MINER_FEE_SATSfor it, connect returnsSkipped, andBlockValidator::validate_feesexcludes skipped indices — so the producer's own block fails withNotEnoughFees.The fix
Thread a
cumulative_amplify: HashMap<MarketId, u64>throughget_transactions, accumulate each selectedAmplifyBetaamount (which is whatapply_amplify_betarecords aslmsr_cost_sats), and derive beta fromliquidity_base_sats + pending_amplify. Block-construction change only; the connect-time rule is unchanged.This sits on top of the buy-limit miner-fee fix, which touches the same function — happy to rebase or reorder if you'd prefer them independent.
Finding report (access-controlled): https://giaki3003.tech/#/findings/20260628-1746-openclaw-confirm-kimiclaw-truthcoin-dc-amplifybeta-sell-slippage-divergence
Part of a short series for this repo (fix 4 of 4); builds on #11, so it reads best merged after that one. Happy to rebase or split if you'd prefer them independent.