Fix router minimum_receive on unwrap path (#469) #1003
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!1003
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-469-router-unwrap-minimum-receive"
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
Fixes GitLab #469: on the router
unwrap_outputpath,minimum_receiveis now asserted against the native amount delivered after wrap-mapper fee, not the pre-unwrap CW20 hop output.Config { fee_bps }and compareshop_output − floor(hop_output × fee_bps / 10_000)tominimum_receive.skills/AGENTS_ROUTER_MINIMUM_RECEIVE.md, and regression tests including the #469 repro (fee_bps = 50, floor = wrapped output → revert).Acceptance checklist
minimum_receiveon unwrap path uses post-mapper net, not wrapped hop outputcd smartcontracts && cargo test unwrap_minimum_receiveminimum_receiveunchangedcd smartcontracts && cargo test test_router_minimum_receive_assertiontest_unwrap_minimum_receive_rejects_when_mapper_fee_skims_below_floortest_unwrap_minimum_receive_succeeds_at_post_unwrap_netdocs/contracts-security-audit.md,skills/AGENTS_ROUTER_MINIMUM_RECEIVE.mdcargo fmt/ pre-commit hooksVerification checklist (third parties)
Expected: 5 tests pass (
test_router_minimum_receive_assertion,test_unwrap_output_minimum_receive, threetest_unwrap_minimum_receive_*).Manual invariant read:
reply_swap_hopinsmartcontracts/contracts/router/src/contract.rs—delivered_amountusesnet_after_wrap_mapper_unwrap_feewhenunwrap_outputis true.Security review
Commit reviewed:
c4335137decd7192f603bf51f86bf3853766c941Scope: Router
minimum_receiveenforcement onunwrap_outputfinal-hop path (net_after_wrap_mapper_unwrap_fee,reply_swap_hop), docs/playbook, regression tests (#469).Outcome:
FINDINGS: 0medium+Summary
This MR closes GitLab #469 (slippage floor checked against pre-unwrap CW20 hop output while the recipient receives post–wrap-mapper native net). The fix is directionally correct and does not introduce a new exploitable path in the reviewed diff.
Analysis (no medium+ issues)
Fee math parity —
net_after_wrap_mapper_unwrap_feeuses the same truncatingmultiply_ratio(fee_bps, 10_000)+ subtract pattern as wrap-mappercalculate_fee/ unwrapInstantWithdrawamount. Checked subtraction handles pathologicalfee_bpsresponses safely (revert, no partial payout).Attacker-controlled input → sink —
minimum_receiveremains user-supplied; the settlement sink now compares againstdelivered_amountderived from on-chainhop_output(R4 balance delta) and governance-configured wrap-mapperConfig.fee_bps. No unprivileged actor can lower the floor check or redirect unwrap proceeds.TOCTOU on
fee_bps— Config is queried inreply_swap_hopand unwrap executes as the next message in the same atomic transaction;SetFeeBpsis governance-only. A fee change mid-swap across blocks either reverts (fee up) or over-delivers (fee down); not a theft vector for external attackers.Malicious wrap-mapper — A mapper that lies on
ConfigvsUnwrapcould break slippage semantics, butWRAP_MAPPERis set only by router governance (SetWrapMapper). That is an deployment/trust-boundary concern outside this diff, not a new permission bypass.Atomicity —
minimum_receivefailure reverts the full transaction (including prior hops in the SubMsg chain). Unwrap failure after a passing check also rolls back the swap chain.Prior threads — No earlier security-review comments on this MR.
Inline threads: none (no medium+ findings).
Security review: no medium+ findings on this diff.