Security: no test verifies commission treasury is unchanged after a non-hook swap failure [SEC-C03] #402
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#402
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?
Checklist Item
SEC-C03: Verify commission/treasury transfer is atomic and pair does not retain fees unexpectedly. Verify: contract tests compare balances before/after successful and reverted swaps.
Summary
Treasury invariant tests exist for the wrap/unwrap treasury and hook-revert scenarios. However, no test snapshots the swap commission treasury before a swap that fails for non-hook reasons (max_spread exceeded, deadline expired, insufficient liquidity) and asserts the balance is unchanged after the revert.
What Was Checked
smartcontracts/tests/src/lib.rsline 11917:test_fees_accumulate_across_multiple_swaps-- accumulation on successsmartcontracts/tests/src/lib.rsline 15153:test_treasury_balance_audit-- wrap treasury invariantsmartcontracts/tests/src/lib.rsline 12923:test_state_consistent_after_hook_revert-- full state snapshot on hook failuresmartcontracts/tests/src/lib.rsline 8655:swap_fails_atomically_when_allowlisted_hook_reverts-- hook-caused revert testedExpected (per checklist)
Tests must compare the commission (fee) treasury balance before and after both successful swaps and reverted swaps. A reverted swap must leave the treasury balance exactly as it was before the attempt.
Actual
The hook-revert path is well tested and asserts all state is unchanged. The wrap/unwrap treasury invariant is also tested. No test covers commission treasury state after a swap fails for reasons unrelated to hooks (spread limit, deadline, or liquidity).
Evidence
smartcontracts/tests/src/lib.rsline 12923:test_state_consistent_after_hook_revertsnapshots state before a failed swap and verifies all state after -- hook failures onlySuggested Fix
Add a test that:
This confirms the commission transfer is part of the atomic swap execution and is rolled back with it.
Verification Checklist
Labels
security,pre-launchCc: @PlasticDigits
mentioned in issue #381
mentioned in commit
ccab0ae342mentioned in merge request !931
mentioned in commit
6d893483d3Verification complete — SEC-C03 (#402)
Verified on
main(no repo changes required).Acceptance checklist
audit_invariant_tests::commission_treasury_unchanged_after_max_spread_rejected_swapsnapshotstreasurytoken_a/token_b balances after a successful swap, then before the failing swap (smartcontracts/tests/src/lib.rs~L9029–9030)treasury_b_beforeunchanged afterMax spread assertionerror (~L9073–9076); also checks token_aaudit_invariant_tests::commission_treasury_unchanged_after_deadline_rejected_swap(~L9083–9146): advances block past deadline, snapshots treasury, asserts unchanged after deadline rejectioncargo test audit_invariant_tests::commission_treasury_unchanged→ 2 passed;make test-contracts→ exit 0Related coverage (unchanged, already present)
new_feature_tests::test_state_consistent_after_hook_reverttest_fees_accumulate_across_multiple_swapsdocs/security-model.md§ Treasury Management; invariant P10 indocs/contracts-security-audit.mdCommands run
Closing — SEC-C03 commission treasury atomicity on non-hook swap failures is covered by contract regression tests and documentation.