Fix: Harden hybrid max_spread no-belief guards (GitLab #273 followups) #307
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#307
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Current codebase
GitLab #273 added a no-belief hybrid guard in
smartcontracts/packages/dex-common/src/max_spread.rs:pool_net_return / pool_input) folds into spread numerator when bothpool_input > 0andbook_input > 0.pool_input == 0) is explicitly unbounded by this metric — deferred tobelief_price/min_receive.pool_input + book_input == offer_amount(enforced in pair/router) but callers can set extreme splits.Remaining gaps (follow-ups to #273):
pool_inputis tiny but non-zero,pool_net_return / pool_inputis a noisy/unstable reference; attacker or mistaken router can pass inflated book legs.book_input > 0on the no-belief path — e.g.pool_net_return > 0orpool_input >= minwhen book leg present.Tests in
max_spread.rsandlimit_order_tests.rs(#273 PoC section) document current behavior.Why this is needed
Without a material-pool-leg floor, integrators can route almost entire size through a degraded book while using a dust pool leg to manipulate the reference rate denominator/numerator asymmetry. Users relying on default
max_spread(1%) withoutbelief_pricemay accept bad hybrid fills.Constraints / guardrails
pool_input == 0) remains out of scope for this guard — still needsbelief_priceormin_receive.router/src/contract.rshybrid split checks).docs/contracts-security-audit.mdhybrid invariants.Relevant files
smartcontracts/packages/dex-common/src/max_spread.rssmartcontracts/contracts/pair/src/contract.rssmartcontracts/contracts/router/src/contract.rsmax_spread.rsunit tests,limit_order_tests.rs(#273)docs/contracts-security-audit.mdRecommended direction
MIN_POOL_INPUT_FOR_BOOK_HYBRID(or ratio vsoffer_amount) index-common— governance-tunable or constant.check_max_spreadno-belief branch: whenbook_input > 0, requirepool_input >= minandpool_net_return > 0before applying book shortfall; elseErr(MaxSpreadViolation)or dedicated error at execute layer.pool_inputbelow threshold — treat as pure-book (reject without belief).Acceptance criteria
book_input > 0and dustpool_inputrejected under defaultmax_spreadwithout belief.Test plan (all paths)
Attack / abuse / hack vectors
pool_net_returnvia manipulationVerification criteria
make test-contractsgreen.HybridSimulationmatches execute revert.marked as related to #273
mentioned in commit
6cf3d7a4ddImplementation pushed on branch
cursor/gitlab-issue-workflow-dc06. Material pool leg guard (#307) added on top of #273 book-shortfall index_common::max_spread: declaredpool_inputmust be ≥10% of offer whenbook_input > 0withoutbelief_price. Pure-book (declared_pool_input = 0) unchanged.Verification:
make test-contractsPASS;cargo test -p cl8y-dex-tests hybrid_no_beliefPASS; frontendswapMaxSpread.test.tsPASS.MR link will be posted when created.
mentioned in merge request !785
MR: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/67
mentioned in commit
27e7a61846mentioned in commit
845ea37c19mentioned in merge request !801
mentioned in issue #273
mentioned in issue #334
mentioned in merge request !819
mentioned in commit
76723cf513mentioned in merge request !847
mentioned in issue #341
mentioned in merge request !849
mentioned in issue #376
mentioned in issue #411
mentioned in issue #419
mentioned in issue #708