Commit 4882570
committed
fix(token-swap): use pool_b amount (not pool_a squared) in invariant check
The post-swap invariant check in `handle_swap_exact_tokens_for_tokens`
was comparing against `pool_account_a.amount * pool_account_a.amount`
instead of `pool_account_a.amount * pool_account_b.amount`.
The constant-product invariant is `a * b = k`, not `a * a`. With the
bug, the check was effectively meaningless for any real swap because
the squared single-side amount bears no relation to the swap's
mathematical correctness — the check would spuriously pass or fail
depending on pool sizes rather than catching actual invariant
violations.
Split out from 25399b25 ("Speed up CI") — that commit bundled
unrelated CI workflow changes with this math fix; separating so each
can be reviewed in isolation.1 parent b6133a7 commit 4882570
1 file changed
Lines changed: 1 addition & 1 deletion
File tree
- tokens/token-swap/anchor/programs/token-swap/src/instructions
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
0 commit comments