Harden CosmWasm hooks and document CW20/hook ops policy (#376) #377
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#377
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?
Parent
Remediation bundle for #376 — Full security report.
Covers approved findings: H-01, H-02, H-03, I-02.
Current codebase
smartcontracts/contracts/pair/src/contract.rscredit reserves from declared CW20amount, not balance deltas. Factory whitelists CW20 code IDs insmartcontracts/contracts/factory/src/contract.rs. Invariant P2 and adversarial testfee_on_transfer_creates_reserve_imbalanceinsmartcontracts/tests/src/adversarial_token.rsdocument the failure mode.docs/contracts-security-audit.mdanddocs/security-model.mdmention whitelist trust but lack an ops prohibition on fee-on-transfer templates.pair/src/contract.rs(~L1174–1224) dispatch as plainWasmMsg::Execute; hookErratomically reverts the swap (invariant H1).docs/runbooks/launch-checklist.mdsays "audited hooks only" but there is no dedicated hook registration playbook.smartcontracts/contracts/hooks/lp-burn-hook/src/contract.rsgates callers viaassert_allowed_pair(info.sender ∈ ALLOWED_PAIRS) but trusts thepairfield inAfterSwapfor burn math. Adversarial testlp_burn_hook_accepts_spoofed_pair_when_spoofer_allowlistedproves inflated burns when a non-pair spoofer is allowlisted.tax-hook,burn-hook, andlp-burn-hookcompute fees fromreturn_asset.amountbut transfer/burn only up to pre-funded hook balances (tax-hook/src/contract.rs,burn-hook/src/contract.rs,lp-burn-hook/src/contract.rs). Users receive full swap output; treasury subsidizes shortfalls.Why needed
Governance misconfiguration or hook admin mistakes can cause reserve desync, trading DoS, or treasury drain. Approved remediation is documentation + verification for H-01/H-02, on-chain hardening for H-03, and a charging model change for fee hooks (I-02).
Constraints / guardrails
SubMsg::reply_on_errorunless product explicitly changes policy.ALLOWED_PAIRSto verified pair contracts; requirepair == info.senderand query pair state before burning.Relevant files
smartcontracts/contracts/pair/src/contract.rs,smartcontracts/contracts/factory/src/contract.rssmartcontracts/contracts/hooks/lp-burn-hook/src/contract.rs,tax-hook/src/contract.rs,burn-hook/src/contract.rs,smartcontracts/contracts/hooks/README.mdsmartcontracts/tests/src/adversarial_token.rsdocs/contracts-security-audit.md,docs/security-model.md,docs/runbooks/launch-checklist.mdRecommended direction
CodeInfobefore whitelist.docs/runbooks/hook-registration.md(or expanddocs/security-model.md) covering: mandatory audit before registration, wasm review checklist, allowlist hygiene, and when blocking hooks are acceptable.execute_after_swap, requirepair == info.sender, query pair config/state (e.g. LP token, reserves) to validate caller is the configuredtarget_pair, reject spoofedoutput_amountpaths. Add regression test: allowlisted spoofer with mismatchedpairmust fail.Acceptance criteria
pair != info.senderor pair state does not match config; adversarial regression test passes.cargo test adversarialand hook unit tests pass.Test plan
cd smartcontracts && cargo test adversarialcd smartcontracts && cargo test -p cl8y-dex-lp-burn-hookcd smartcontracts && cargo test -p cl8y-dex-tax-hook -p cl8y-dex-burn-hook(or equivalent hook crate names)make test-contracts(full contract suite)docs/runbooks/anddocs/security-model.mdAttack / abuse test plan
fee_on_transfer_creates_reserve_imbalance— must still demonstrate risk when adversarial code ID whitelisted (documents why prohibition matters).lp_burn_hook_accepts_spoofed_pair_when_spoofer_allowlisted— must fail after H-03 fix.swap_fails_atomically_when_allowlisted_hook_reverts— must still pass (H-02 documents, does not change).Verification criteria
docs/security-model.mdor launch checklist.mentioned in issue #376
mentioned in commit
be82f63e28mentioned in merge request !901
mentioned in commit
d2dcb7a905mentioned in commit
29c47c132amentioned in commit
908618d2a7mentioned in commit
a688b6e5a8mentioned in merge request !905
mentioned in commit
5557301a09mentioned in commit
0ca7e9865amentioned in commit
fb7dad99abmentioned in merge request !907
mentioned in commit
5154e7bed7mentioned in commit
a7f2691ee7mentioned in commit
dd654b11f5Verification complete — all acceptance criteria PASS
Verified on
main@30cfd4be(merged viaverify/issue-377-hook-hardening).Acceptance criteria
docs/runbooks/cw20-whitelist-policy.md§ Prohibited templates;scripts/verify-cw20-code-ids.sh(SKIP without env — expected); cross-linked fromdocs/security-model.mdanddocs/runbooks/launch-checklist.mddocs/runbooks/hook-registration.md— audit checklist, allowlist hygiene, blocking-hook policy; referenced from security model + launch checklistassert_pair_callerrequirespair == info.sender+ pairliquidity_tokenmatch inlp-burn-hook/src/contract.rs;cargo test adversarial→lp_burn_hook_rejects_spoofed_pair_when_spoofer_allowlistedokdex-common::hook_settlement; hooks README documents flow;tax_hook_collects_from_swap_flow_with_zero_treasury_balanceokcargo test adversarial+ hook tests + full suitecargo test adversarial(9/9);cargo test -p cl8y-dex-lp-burn-hook;cargo test -p cl8y-dex-tax-hook -p cl8y-dex-burn-hook;make test-contracts(377/377)Attack / abuse test plan
fee_on_transfer_creates_reserve_imbalancelp_burn_hook_rejects_spoofed_pair_when_spoofer_allowlistedswap_fails_atomically_when_allowlisted_hook_revertstax_hook_collects_from_swap_flow_with_zero_treasury_balanceManual doc review
docs/runbooks/cw20-whitelist-policy.md,docs/runbooks/hook-registration.md,docs/security-model.md,smartcontracts/contracts/hooks/README.md,.cursor/skills/AGENTS_HOOK_CW20_OPS.md— consistent cross-links and invariant mapping.No repo changes required during this verify pass.
mentioned in issue #337
mentioned in merge request !985
mentioned in issue #448
mentioned in issue #558
mentioned in issue #581
mentioned in issue #582
marked as related to #582
mentioned in issue #589
mentioned in issue #627