Skip to content

fix: Account for same-block AmplifyBeta deposits when pricing trades at build - #12

Open
giaki3003 wants to merge 4 commits into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260628-1746-openclaw-confirm-kimiclaw--truthcoin-dc-amplifybeta-can-make-a-same-block-s
Open

giaki3003 wants to merge 4 commits into
LayerTwo-Labs:masterfrom
giaki3003:fix/w3-20260628-1746-openclaw-confirm-kimiclaw--truthcoin-dc-amplifybeta-can-make-a-same-block-s

Conversation

@giaki3003

Copy link
Copy Markdown

What's wrong

During block construction, check_trade_slippage in lib/node/mod.rs derives beta via derive_market_beta, which uses the confirmed market.liquidity_base_sats only. At connect time, running_market_state in lib/state/block.rs folds the AmplifyBeta deposits already applied earlier in the same block into the liquidity base before deriving beta.

When a block carries an AmplifyBeta followed by a trade on the same market, the two sides price that trade at different betas. Near the trade's limit_sats they disagree on the outcome: the builder keeps the trade and credits TRADE_MINER_FEE_SATS for it, connect returns Skipped, and BlockValidator::validate_fees excludes skipped indices — so the producer's own block fails with NotEnoughFees.

The fix

Thread a cumulative_amplify: HashMap<MarketId, u64> through get_transactions, accumulate each selected AmplifyBeta amount (which is what apply_amplify_beta records as lmsr_cost_sats), and derive beta from liquidity_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.

giaki3003 and others added 4 commits July 29, 2026 11:00
…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)
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