Verify #377: Harden CosmWasm hooks and CW20/hook ops policy #907
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!907
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "verify/issue-377-hook-hardening"
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
Implements GitLab #377 remediation for security findings H-01, H-02, H-03, and I-02:
docs/runbooks/cw20-whitelist-ops.mdforbids fee-on-transfer CW20 templates; launch checklist cross-links;scripts/qa/verify-cw20-code-ids.shfor pre-whitelist LCDCodeInfochecks.docs/runbooks/hook-registration.md— audit requirement, allowlist hygiene, intentional swap-blocking policy.pair == info.senderand on-chain LP token validation; adversarial spoof test now expects rejection.HookQueryMsg::ComputeSwapFeeand deducts tax/burn fees from swap output beforeAfterSwap; tax hook collects with zero hook treasury balance.Verification checklist
docs/runbooks/cw20-whitelist-ops.md;bash scripts/qa/verify-cw20-code-ids.sh --lcd <lcd> <code_id>docs/runbooks/hook-registration.md; linked fromdocs/security-model.mdand launch checklistpaircd smartcontracts && cargo test lp_burn_hook_rejects_spoofed→ PASScd smartcontracts && cargo test test_tax_hook_collects_from_swap_with_zero_hook_balance→ PASScargo test adversarialcargo test tax_hook,cargo test burn_hook,cargo test lp_burn_hook→ PASSmake test-contracts→ PASSfee_on_transfer_creates_reserve_imbalancestill demonstrates risklp_burn_hook_accepts_spoofed_pairrenamed → must faillp_burn_hook_rejects_spoofed_pair_when_spoofer_allowlisted→ PASSswap_fails_atomically_when_allowlisted_hook_revertssecurity-model.md,contracts-security-audit.md,hooks/README.md, launch checklistTest plan
cd smartcontracts && cargo test adversarialcd smartcontracts && cargo test -p cl8y-dex-lp-burn-hook(0 unit; integration via cl8y-dex-tests)cd smartcontracts && cargo test tax_hook burn_hook lp_burn_hookmake test-contractsdocs/runbooks/hook-registration.md,docs/runbooks/cw20-whitelist-ops.md,docs/security-model.mdFollow-ups
make verify-issue-377wrapper script if CI should gate this bundle explicitly.changed the description
changed the description
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit
fb7dad99ab. Configure here.Simulation omits hook fees
Medium Severity
HybridSimulationstill returnsreturn_amountas the full book-plus-pool net (total_out) and never queries registered hooks forComputeSwapFee. Off-chain quotes and UIs using simulation will overstate what traders actually receive after pair settlement deducts tax/burn hook fees.Reviewed by Cursor Bugbot for commit
fb7dad99ab. Configure here.Min return ignores hook fees
Medium Severity
min_returnis enforced againsttotal_returnbefore hook settlement, while the receiver’s CW20 transfer usesuser_return(total_returnminus hook fees). A swap can succeed when gross output meets the floor but the trader receives less thanmin_return. The swapreturn_amountwasm attribute still reports the gross total, not the net credited amount.Additional Locations (1)
smartcontracts/contracts/pair/src/contract.rs#L1267-L1268Reviewed by Cursor Bugbot for commit
fb7dad99ab. Configure here.Security review — MR !907
Commit reviewed:
fb7dad99ab88e7989185698cd5b4060a7c1ab428Scope: Pair swap settlement (
ComputeSwapFee/ hook fee transfers), tax/burn/lp-burn hook hardening, adversarial spoof tests, ops runbooks (cw20-whitelist-ops.md,hook-registration.md),verify-cw20-code-ids.sh.Outcome:
FINDINGS: 0medium+ — Security review: no medium+ findings on this diff.Inline threads: none
Summary
Reviewed attacker-controlled inputs through real sinks on the modified paths:
pair == info.senderplus on-chainPairLP-token validation closes the allowlisted-spooferAfterSwap.pairforgery path; spoof tests now expect rejection.ComputeSwapFeesettlementchecked_add;user_return = total_return - total_hook_feesuseschecked_sub(reverts if hooks over-claim).settlement_recipientrequired whenfee_amount > 0. Hook registration remains factory-governance-only (SetPairHooks→UpdateHooks).ComputeSwapFeeand settlement math are consistent; pair transfers fees beforeAfterSwap, removing pre-funded treasury subsidy (I-02).Note (below medium):
min_returnis still asserted against grosstotal_returnbefore hook-fee deduction, so direct pair swaps on hooked pools may deliveruser_return < min_returnwhen fees are non-zero. This is a slippage-floor correctness gap for integrators, not an unprivileged theft path (hooks are governance-registered; fee rates are hook-configured).No
block:securitylabel applied.changed this line in version 1 of the diff
changed this line in version 1 of the diff
added 30 commits
main5154e7be- Merge main into verify/issue-377-hook-hardening.Compare with previous version
Conflict resolution
Merged
mainintoverify/issue-377-hook-hardeningand resolved 11 conflicted files.Approach:
mainalready landed #377 viahook_settlement(collect_fee_hook_deductions/GetConfig),cw20-whitelist-policy.md, and the mainhook-registration.mdplaybook. Conflicts were resolved by takingmainfor all overlapping code and docs.Dropped MR-only duplicates:
ComputeSwapFeequery path (pair + hook msg/query),docs/runbooks/cw20-whitelist-ops.md, andscripts/qa/verify-cw20-code-ids.sh(superseded byscripts/verify-cw20-code-ids.shonmain).Sanity checks:
cargo test adversarialand hook-related tests pass locally.resolved all threads
changed the description
Security review — MR !907
Commit reviewed:
5154e7bed725c0b5ddcc6d4715212a0f07fb236bScope: Post-merge verification of #377 hook/CW20 hardening (pair
hook_settlementfee deductions, tax/burn/lp-burn hooks, adversarial spoof tests, ops runbooks/scripts). Latest MR diff version has 0 changed files (branch tree matchesmainafter conflict resolution per !907 discussion).Outcome:
FINDINGS: 0medium+ — Security review: no medium+ findings on this diff.Inline threads: none (empty MR diff; prior Bugbot threads on
min_return/HybridSimulationresolved or below threshold)Summary
Re-traced attacker-controlled inputs on the security-relevant paths now on
main(identical to this MR head):pair == info.sender, on-chainPair {}query, and LP-token match block allowlisted-spooferAfterSwap.pairforgery;UpdateAllowedPairsrejects non-pair contracts (lp_burn_hook_rejects_spoofed_pair_when_spoofer_allowlisted).collect_fee_hook_deductionsqueries hookGetConfig; fees summed withchecked_add;net_return = total_return - hook_fee_totalwithHookFeeExceedsReturnguard; user transfer usesnet_return. Hook registration remains factory-governance-only (SetPairHooks→UpdateHooks).min_return(prior Bugbot)main: slippage floor enforced againstnet_returnafter hook-fee deduction (pair/src/contract.rs~L1180–L1186), not grosstotal_return.AfterSwap; tax hook callback is event-only; burn hook burns transferred settlement balance.tax_hook_collects_from_swap_flow_with_zero_treasury_balancepasses.CodeInfotooling only; no production attack surface.Below medium (not reported):
HybridSimulation/ router multi-hop simulation still quote grossreturn_amountwithout hook-fee deduction. This can mislead off-chain quotes when governance-registered fee hooks are active, but there is no unprivileged fund-extraction path (hooks are governance-gated; execute-timemin_returnuses net output).No
block:securitylabel applied.mentioned in commit
a7f2691ee7