Harden CosmWasm hooks and document CW20/hook ops policy (#377) #901
No reviewers
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!901
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-377-harden-hooks-cw20-policy"
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?
Summary
Remediation for GitLab #377 (parent #376): H-01, H-02, H-03, I-02.
scripts/verify-cw20-code-ids.sh+ launch-checklist cross-links.docs/runbooks/hook-registration.md) documents audit requirement and intentional swap-blocking policy.AfterSwap.pair == info.sender, queries pairliquidity_token, and rejects non-pair allowlist entries.dex-common::hook_settlement; net return to receiver is reduced accordingly.Acceptance checklist
docs/runbooks/cw20-whitelist-policy.md,scripts/verify-cw20-code-ids.shdocs/runbooks/hook-registration.md,docs/security-model.mdcd smartcontracts && cargo test lp_burn_hook_rejectscd smartcontracts && cargo test tax_hook_collects_from_swap_flowcargo test adversarial+ hook tests +make test-contractsVerification checklist (third parties)
Manual doc review:
docs/runbooks/cw20-whitelist-policy.mddocs/runbooks/hook-registration.mddocs/security-model.md(Hook safety + whitelist sections)smartcontracts/contracts/hooks/README.mdTest plan
fee_on_transfer_creates_reserve_imbalancestill passes (documents H-01 risk)lp_burn_hook_rejects_spoofed_pair_when_spoofer_allowlistedfails attack pathswap_fails_atomically_when_allowlisted_hook_revertsunchanged (H-02)tax_hook_collects_from_swap_flow_with_zero_treasury_balanceadded (I-02)Related: #377
changed the description
changed the description
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.
Reviewed by Cursor Bugbot for commit
be82f63e28. Configure here.min_return ignores hook fee deductions
Medium Severity
The swap
min_returncheck still compares against grosstotal_return, but the taker CW20 transfer usesnet_returnafter tax/burn hook settlement. A swap can passmin_returnwhile the receiver gets less than that floor once hook fees apply.Reviewed by Cursor Bugbot for commit
be82f63e28. Configure here.Medium — Slippage floor checked on gross return, user paid net
min_returnis asserted againsttotal_return(L1149–1155) before hook settlement, but the taker CW20 transfer usesnet_returnafter tax/burn deductions (this hunk).Impact: On pairs with registered tax/burn hooks, a swap can succeed while the receiver gets less than
min_return(e.g. gross 1000, 10% hook,min_return=950→ net 900, tx passes).Attack path: No privileged caller required beyond normal hooked-pair swaps. Integrators/bots that set
min_returnfrom simulationreturn_amount(gross) or users specifying a wallet floor are not protected from hook fee deductions introduced by I-02 settlement.Fix: Assert
min_returnagainstnet_returnaftercollect_fee_hook_deductions, or document and enforce gross semantics explicitly in API + simulation.added 1 commit
d2dcb7a9- fix(pair): enforce min_return against net payout after hook feesCompare with previous version
Security review — MR !901
Commit reviewed:
be82f63e28c7dfed807e0ea7e40db23312319f00Scope: CosmWasm hook hardening (H-03 LP-burn caller validation, I-02 pair-side tax/burn settlement),
dex-common::hook_settlement, adversarial test updates, ops runbooks/scripts.Outcome:
FINDINGS: 1medium+Summary
Reviewed added/modified contract paths for auth bypass, settlement accounting, hook spoofing, and slippage controls. H-03 LP-burn changes (
pair == info.sender, pairliquidity_tokencheck, non-pair allowlist rejection) close the documented spoof path. I-02 settlement correctly deducts hook fees from ask-token flow withHookFeeExceedsReturnguard; tax/burn hooks no longer pull from pre-funded balances.One medium finding remains (inline thread on
pair/src/contract.rs~L1187):min_returnis still checked against grosstotal_returnbefore hook fee deductions, while the taker transfer paysnet_return. Swaps on hooked pairs can succeed below the user/integrator slippage floor — regression introduced by I-02 settlement.No other medium+ injection, authz bypass, or treasury drain paths identified on this diff.
Label:
block:securityapplied pending fix or accepted-risk disposition.changed the description
mentioned in commit
29c47c132aadded 1 commit
29c47c13- test(adversarial): assert min_return enforced on net payout with tax hookCompare with previous version
Security remediation — MR !901
Commits:
d2dcb7a9(pair fix),29c47c13(regression test)Finding → fix
min_returnchecked against grosstotal_returnwhile taker receivesnet_returnafter tax/burn hook deductions (Bugbot + inline onpair/src/contract.rs)collect_fee_hook_deductionsruns first;min_returnis asserted againstnet_return(post-hook), matching the CW20 transfer to the receiver. Regression:tax_hook_min_return_checked_against_net_payout.Verification
No other medium+ findings from the prior review remain open on this diff.
changed the description
Security review — MR !901
Commit reviewed:
29c47c132a1a64a56ab51317719a8c09d06bd6fdScope: CosmWasm hook hardening (H-03 LP-burn caller validation, I-02 pair-side tax/burn settlement via
dex-common::hook_settlement),min_return/ net-payout accounting, adversarial test updates, ops runbooks (cw20-whitelist-policy,hook-registration),scripts/verify-cw20-code-ids.sh.Outcome:
FINDINGS: 0— Security review: no medium+ findings on this diff.Prior thread disposition
The earlier medium finding (
min_returnchecked against grosstotal_returnwhile taker receivednet_returnafter hook fees) is remediated on this SHA:collect_fee_hook_deductionsruns before the slippage floor;MinReturnAssertioncomparesnet_return(matches the CW20 transfer). Regression:tax_hook_min_return_checked_against_net_payout.Review notes (no new issues)
pair == info.sender, pairPair {}query +liquidity_tokenmatch, non-pair addresses rejected inUpdateAllowedPairs. Spoof path in adversarial tests now rejects.GetConfig, emits tax/burn CW20 transfers from ask-token flow before net payout;HookFeeExceedsReturnguards over-deduction; tax hook no longer pulls from pre-funded balance; burn hook errors if settlement tokens missing.AfterSwaphook dispatch; burn hook balance is populated before callback in the same tx.minimum_receiveuses router balance delta (post-pair net payout); per-hopmin_returndelegates to hardened pair logic.SetPairHooksremain governance/admin gated; no non-privileged auth bypass identified on modified paths.Inline threads: none (no medium+ findings to anchor).
block:securitynot applied.mentioned in commit
908618d2a7