Security[SEC-I01 H05]: whitelist code ID audit must exclude fee-on-transfer and rebase tokens [SEC-I02] #448
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#448
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?
Fee-on-transfer issue of I01 H05 gap
changed title from
Security: whitelist code ID audit must exclude fee-on-transfer and rebase tokens [SEC-I02]toSecurity[SEC-I01 H05]: whitelist code ID audit must exclude fee-on-transfer and rebase tokens [SEC-I02]changed the description
Summary
The limit order escrow system records the declared amount from CW20 Send messages without verifying that the actual balance received matches the declared value. If a whitelisted CW20 token deducts a fee on transfer, the pair credits the full declared amount to PENDING_ESCROW but receives less in its real balance. Repeated place-and-cancel cycles drain the pair's token balance below the sum of all outstanding PENDING_ESCROW values.
The root cause is not in the escrow logic itself (which uses correct checked arithmetic) but in the absence of an explicit constraint requiring that whitelisted code IDs be audited to confirm they do not implement fee-on-transfer or rebase mechanics before being added via AddWhitelistedCodeId.
What Was Checked
smartcontracts/contracts/pair/src/limit_placement.rslines 183-287: maker fee computed from declared amount field (plan.item.amount), not from actual balance delta received. PENDING_ESCROW incremented by declared_amount - maker_fee. Total_maker_fee queued as CW20 Transfer to treasury in the same Response.smartcontracts/contracts/factory/src/contract.rslines 200-212: CW20 code ID whitelist check runs at pair creation only. Not rechecked on swap, provide, or limit placement.docs/security-model.md: no explicit constraint on fee-on-transfer or rebase token admission via AddWhitelistedCodeId.Expected (per checklist)
docs/security-model.mdor a whitelist governance checklist explicitly states that code IDs submitted for whitelisting must be audited to confirm: no fee-on-transfer deduction, no rebase or elastic supply mechanics, no balance-manipulation on transfer. This constraint must be documented before governance adds any new code ID in production.Actual
No such constraint exists in any documentation. The whitelist governance process is not documented with token safety requirements.
Suggested Fix
Add a section to
docs/security-model.mdunder the CW20 whitelist policy stating:Verification Checklist
docs/security-model.mdincludes explicit constraint: whitelisted code IDs must be audited for fee-on-transfer and rebase mechanicsCc: @PlasticDigits
mentioned in issue #381
mentioned in merge request !985
Handled the docs side of this. The fee-on-transfer prohibition was already in (#377), but rebase / elastic-supply / reflection tokens weren't named, and there was no explicit audit-evidence requirement — which is the actual H05 gap.
security-model.md§ Code ID Whitelist: reframed the constraint as a balance-stability requirement covering BOTH fee-on-transfer and rebase/elastic-supply (balance changes after receipt with no transfer), and now requires source review + recorded audit evidence beforeAddWhitelistedCodeId, not checksum match alone.cw20-whitelist-policy.md: added rebase/elastic-supply to the prohibited list and the table, plus a source-review step (no balance mutation outside an explicit transfer) and an attach-audit-evidence step in pre-whitelist verification.Both balance-stability docs-check scripts still pass.
That covers checklist items 1 and 2. The optional item 3 (runtime balance-delta assertion in the limit-placement escrow funding) is a contract change, not docs — I left it tracked here as a separate follow-up rather than folding it in.
MR !985, branch
qa/448-token-whitelist-rebase-docs, commit1a8ab017. Needs review/merge @PlasticDigits — leaving open for verification.mentioned in commit
658aeae727Verification — #448 (SEC-I01 H05 / SEC-I02)
Verified on
mainat merge commit658aeae7(MR !985,1a8ab017).Checklist
docs/security-model.mdstates whitelisted code IDs must be audited for fee-on-transfer and rebase/elastic-supply mechanics, with source review + recorded audit evidence beforeAddWhitelistedCodeIdgrepondocs/security-model.md— Balance-stability requirement paragraph cites #377/#448, names fee-on-transfer/transfer-tax and rebase/elastic-supply/reflection, requires source review and audit evidence (not checksum match alone), linkscw20-whitelist-policy.md.docs/runbooks/cw20-whitelist-policy.md— prohibited templates table includes rebase/elastic-supply; pre-whitelist steps 4 (source review) and 5 (attach audit evidence). Cross-linked fromsecurity-model.mdand launch checklist Phase 0 (cw20-whitelist-policy.md).limit_placement.rshas no balance-delta check; issue comment and MR !985 note this as a separate follow-up.Additional checks
cd smartcontracts && cargo test fee_on_transfer -- --nocapture→fee_on_transfer_creates_reserve_imbalanceoksecurity-model.md,cw20-whitelist-policy.md); working tree clean onmain.Follow-ups (non-blocking)
Receive(optional item 3) — track as a separate contract issue if desired.docs/runbooks/launch-checklist.mdPhase 0 still says "No fee-on-transfer templates" in the bullet text (links to the full policy);docs/security-posture.mdanddocs/runbooks/cw20-code-id-ops.mdmention fee-on-transfer only. Consider naming rebase/elastic-supply in those summaries for operator skim-reads.make verify-issue-448(doc invariant script +fee_on_transfertest) mirroring other SEC doc gates.Closing — docs acceptance criteria satisfied on
main.mentioned in issue #447
mentioned in commit
9ff4ea7b60mentioned in merge request !1007
mentioned in issue #581
mentioned in issue #582
marked as related to #582