Verify #377: Harden CosmWasm hooks and CW20/hook ops policy #905
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!905
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 remediation bundle for #376 findings H-01, H-02, H-03, and I-02:
docs/runbooks/cw20-code-id-ops.mdforbids fee-on-transfer CW20 templates; launch checklist +scripts/verify-whitelist-cw20-code-ids.shfor GDEX/TerraPortCodeInfoverification.docs/runbooks/hook-registration.md— audit requirement, wasm checklist, allowlist hygiene, intentional swap-blocking policy.AfterSwap.pair == info.sender, validates pairliquidity_token; adversarial spoof test now expects rejection.OutputFee, forwards ask-token fees during settlement; tax/burn hooks no longer subsidize from pre-funded treasuries.Acceptance checklist
docs/runbooks/cw20-code-id-ops.md,scripts/verify-whitelist-cw20-code-ids.sh, launch-checklist Phase 0docs/runbooks/hook-registration.md; linked fromdocs/security-model.mdpaircd smartcontracts && cargo test lp_burn_hook_accepts_spoofed_pair→ PASS (expects Err)cargo test test_tax_hook_collects_from_swap_output_with_zero_treasury_balance test_burn_hook_called_on_swap→ PASScd smartcontracts && cargo test adversarial→ PASS (7/7)make test-contracts→ PASScargo test swap_fails_atomically_when_allowlisted_hook_reverts→ PASScargo test fee_on_transfer_creates_reserve_imbalance→ PASSdocs/security-model.md,docs/contracts-security-audit.mdH2,skills/AGENTS_HOOK_COMMISSION.mdTest plan
Manual: review
docs/runbooks/hook-registration.mdanddocs/runbooks/cw20-code-id-ops.md.Follow-ups
EXPECTED_CW20_CODE_IDS/ checksums in deploy docs when mainnet code IDs are frozen.Related: #377 (parent #376). Issue stays open until merge.
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
a688b6e5a8. Configure here.min_return ignores hook output fees
Medium Severity
Swap settlement now sends the receiver
total_returnminus summed hookOutputFeeamounts, butmin_returnis still compared to grosstotal_returnbefore those fees are computed. A swap can satisfymin_returnwhile the receiver’s CW20 transfer is lower than that floor whenever tax or burn hooks are active. Thereturn_amountwasm attribute still reports the gross total, not the net transfer.Additional Locations (1)
smartcontracts/contracts/pair/src/contract.rs#L1264-L1265Reviewed by Cursor Bugbot for commit
a688b6e5a8. Configure here.Security review — MR !905
Commit reviewed:
a688b6e5a8d5abe4667191623ce77e44074c600bScope: Pair swap settlement (
OutputFeequery + ask-token forwarding), tax/burn hook I-02 semantics, LP-burn hook H-03 caller/liquidity_tokenvalidation, ops runbooks (cw20-code-id-ops,hook-registration),scripts/verify-whitelist-cw20-code-ids.sh, and related test/doc updates.Method: Full MR diff review with attacker-controlled input tracing to sinks (hook registration auth,
AfterSwapcallbacks, CW20Transferrecipients,min_return/ slippage paths). Cross-checked againstdocs/contracts-security-audit.mdtrust model (non-governance attack paths). Rancargo test adversarial(7/7 pass).Outcome:
FINDINGS: 0medium+Summary: This MR hardens previously identified issues rather than introducing new exploitable paths for non-governance callers.
AfterSwap.pairmust equalinfo.sender; caller must matchtarget_pair; on-chainPair {}liquidity_tokenvalidated. Spoof test now expects rejection — closes prior allowlist griefing path.OutputFee, sums fees withchecked_add, rejects when fees exceedtotal_return, forwards fees before receiver payout, then dispatchesAfterSwap. Tax/burn no longer subsidize from pre-funded treasuries.SetPairHooksremains governance-only via factory; hookassert_allowed_pairunchanged. No new unauthenticated admin surface.if let OkOutputFeeskips fee forwarding but burn hookAfterSwaperrors on insufficient forwarded balance (atomic swap rollback). Tax hookAfterSwapis attribute-only post-settlement. Residual mis-collection requires a governance-registered hook — within documented trust model.min_returnvs net outputmin_returnstill asserted on grosstotal_returnbefore hook deductions; users on hooked pairs receivetotal_return − hook fees. Documented breaking integrator semantics; not a non-governance attack path (hook registration is governance-gated).verify-whitelist-cw20-code-ids.shis read-only LCDCodeInfoverification for trusted operators; no production runtime attack surface.Inline threads: None (no medium+ findings to anchor).
Security review: no medium+ findings on this diff.
added 1 commit
0e5b7505- fix(pair): enforce min_return against net output after hook feesCompare with previous version
changed the description
resolved all threads
changed this line in version 3 of the diff
added 11 commits
main5557301a- Merge branch 'main' into verify/issue-377-hook-hardeningCompare with previous version
Resolved merge conflicts with
mainby aligning with the already-merged #377 implementation onmain:hook_settlement(GetConfig-based fee deduction), LP-burnassert_pair_caller, netmin_returncheckshook-registration.md,cw20-whitelist-policy.md, audit/security cross-linkslp_burn_hook_rejects_spoofed_pair_*,tax_hook_min_return_checked_against_net_payout)Dropped verify-branch
OutputFeequery/msg drift that conflicted with main's settlement path.Sanity:
cargo test adversarial(9/9) and hook crate tests pass locally.changed the description
Security review — MR !905
Commit reviewed:
5557301a0997575bae25f084f2ae7ed6dec183fdScope (current diff vs
main):docs/runbooks/cw20-code-id-ops.mdandscripts/verify-whitelist-cw20-code-ids.shonly. Pair/hook contract remediation (#377 H-02/H-03/I-02) and netmin_returnsettlement are already onmainafter merge-conflict resolution; not re-reviewed here.Method: MR diff review with attacker-controlled input tracing on the ops script (
LCD_URL,EXPECTED_CW20_CODE_IDS,EXPECTED_CW20_CHECKSUMS→curlURL construction andjqparsing). Cross-checked prior threads (Bugbotmin_returnon gross output — stale for this diff; fixed onmainvianet_returnslippage check andtax_hook_min_return_checked_against_net_payout).Outcome:
FINDINGS: 0medium+CodeInfoqueries for trusted pre-launch operators. Env vars are quoted; no shell metacharacter expansion or command injection sink.code_idis path-segment interpolated into an HTTPS LCD URL — operator-controlled, not an on-chain or dapp user attack surface.EXPECTED_CW20_CHECKSUMSmismatch fails closed; does not whitelist or mutate chain state.min_returnvs hook fees targeted removed pair-settlement lines no longer in this MR;mainenforcesmin_returnagainstnet_returnafter hook fee deduction.Inline threads: None (no medium+ findings to anchor).
Security review: no medium+ findings on this diff.
mentioned in commit
0ca7e9865a