SEC-C01: swap math u128 and imbalance boundary tests (#401) #936
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!936
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-401-sec-c01-swap-boundary-tests"
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
Adds
sec_c01_swap_boundary_testsintegration tests for GitLab #401 / SEC-C01:u128::MAX / 2andu128::MAX - 1paired with minimal counter-reserve) confirm constant-product swap math completes without arithmetic overflow and gross output never exceeds the ask-side reserve.Verification checklist
cargo test -p cl8y-dex-tests sec_c01_swap_boundary::test_swap_reserves_near_u128_max_no_overflow→ PASS (3 cases, no panic/overflow)cargo test -p cl8y-dex-tests sec_c01_swap_boundary::test_swap_extreme_imbalance_one_to_one_million_offer_scarce_side→ PASS;…offer_abundant_side→ PASSmake test-contracts→ PASS (full workspacecargo test)test_no_zero_output_from_roundingstill PASS (documents sub-threshold zero-output boundary on 10M:10M pool); new boundary tests assertgross ≤ output_reserveand exact fee accounting (no over-withdrawal)test_swap_one_microunit,test_swap_large_amountstill present and passing undermake test-contractsFollow-ups
prop_k_maintained_*,prop_swap_output_never_exceeds_ideal) to sample reserve ratios up to 1:1_000_000 and larger reserve magnitudes (currently capped at1_000_000_000).Security review — MR !936
Commit reviewed:
72aedf30245be56ae4e7ba41c8822735c98ee0ccScope:
smartcontracts/tests/src/lib.rs— newsec_c01_swap_boundary_testsmodule (SEC-C01 / #401): u128-max reserve boundary tests, 1:1_000_000 imbalance swap tests, simulation + on-chain execution assertions.Outcome:
FINDINGS: 0medium+Summary: This MR adds integration tests only (
#[cfg(test)]); no production contract, router, factory, or dependency changes. Reviewed added helpers (setup_env_with_supply,pool_sim,assert_pool_swap_accounting,swap_with_belief) and all three test cases.Attack-path analysis (no exploitable sink in diff):
execute_swappath viacw_multi_test; the diff does not alter on-chain logic, auth gates, fee math, or invariant checks.max_spread: Some(Decimal::one())andbelief_price: Some(Decimal::one())appear only in the test harness to avoid slippage assertion failures in simulation/execution parity checks — not deployed code.u128::MAXtoken supply and near-max reserves are sandbox fixtures; they do not weaken production limits or introduce overflow-prone code in this diff.Prior review threads: None on this MR; no re-opened findings.
Inline threads: None (no medium+ findings).
mentioned in commit
7227ecd0e5