Commit c1ed5a3
authored
[ANCHOR-1226]: SEP-6 deposit/withdraw-exchange skips the quote buy-asset check SEP-24 enforces, binding a quote to a mismatched destination asset (#1969)
### Description
SEP-6 `deposit-exchange`/`withdraw-exchange` never checked that a SEP-38
quote's buy asset matched the request's `destination_asset`.
`ExchangeAmountsCalculator.calculateFromQuote` — the only entry point
SEP-6 uses — hardcoded the buy-asset argument to `null` when calling
`validateQuoteAgainstRequestInfo`, skipping the buy-asset-mismatch check
that method already implements (and that SEP-24 already relies on via a
different entry point). A user could bind a quote priced for a cheap
asset to a transaction recorded against a different, valuable
`destination_asset`, causing the operator to lose the difference at
settlement.
**Changes**
- [x] `ExchangeAmountsCalculator.calculateFromQuote`: signature changed
to accept `buyAsset`, forwarded into `validateQuoteAgainstRequestInfo`
instead of `null`. No new overload — the 3-arg version was
unconditionally unsafe and had exactly two callers, both already fixed
below.
- [x] `Sep6Service.depositExchange`/`withdrawExchange`: both now pass
their already-resolved destination/buy asset into the call.
- [x] `ExchangeAmountsCalculatorTest`: updated all 8 existing calls for
the new signature; added tests proving the fixed method rejects a
mismatched buy asset and accepts a matching one.
- [x] `Sep6ServiceTest`: updated all 8 mock stubs for the new arity;
added two tests (deposit-exchange, withdraw-exchange) capturing the
`calculateFromQuote` call and asserting the resolved destination asset
is what's actually passed as `buyAsset`.
**Acceptance Criteria**
- [x] `deposit-exchange`/`withdraw-exchange` reject a quote whose buy
asset doesn't match `destination_asset`.
- [x] A quote whose buy asset matches `destination_asset` succeeds
unchanged.
- [x] No other caller of `calculateFromQuote` exists or broke (only the
two `Sep6Service` call sites in production code).
### Context
#3815607
### Testing
- Unit: `./gradlew :core:test --tests
"org.stellar.anchor.util.ExchangeAmountsCalculatorTest"`
- Unit: `./gradlew :core:test --tests
"org.stellar.anchor.sep6.Sep6ServiceTest"`
- Full suite: `./gradlew :core:build`
### Documentation
N/A
### Known limitations
None.1 parent 546503b commit c1ed5a3
4 files changed
Lines changed: 150 additions & 22 deletions
File tree
- core/src
- main/java/org/stellar/anchor
- sep6
- util
- test/kotlin/org/stellar/anchor
- sep6
- util
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
| 227 | + | |
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
Lines changed: 98 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
485 | | - | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
486 | 489 | | |
487 | 490 | | |
488 | 491 | | |
| |||
520 | 523 | | |
521 | 524 | | |
522 | 525 | | |
523 | | - | |
| 526 | + | |
524 | 527 | | |
525 | 528 | | |
526 | 529 | | |
| |||
561 | 564 | | |
562 | 565 | | |
563 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
564 | 606 | | |
565 | 607 | | |
566 | 608 | | |
| |||
1066 | 1108 | | |
1067 | 1109 | | |
1068 | 1110 | | |
1069 | | - | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
1070 | 1114 | | |
1071 | 1115 | | |
1072 | 1116 | | |
| |||
1105 | 1149 | | |
1106 | 1150 | | |
1107 | 1151 | | |
1108 | | - | |
| 1152 | + | |
1109 | 1153 | | |
1110 | 1154 | | |
1111 | 1155 | | |
| |||
1137 | 1181 | | |
1138 | 1182 | | |
1139 | 1183 | | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1140 | 1222 | | |
1141 | 1223 | | |
1142 | 1224 | | |
| |||
1708 | 1790 | | |
1709 | 1791 | | |
1710 | 1792 | | |
1711 | | - | |
1712 | | - | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1713 | 1796 | | |
1714 | 1797 | | |
1715 | 1798 | | |
| |||
1725 | 1808 | | |
1726 | 1809 | | |
1727 | 1810 | | |
1728 | | - | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
1729 | 1814 | | |
1730 | 1815 | | |
1731 | 1816 | | |
| |||
1751 | 1836 | | |
1752 | 1837 | | |
1753 | 1838 | | |
1754 | | - | |
1755 | | - | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
1756 | 1842 | | |
1757 | 1843 | | |
1758 | 1844 | | |
| |||
1767 | 1853 | | |
1768 | 1854 | | |
1769 | 1855 | | |
1770 | | - | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
1771 | 1859 | | |
1772 | 1860 | | |
1773 | 1861 | | |
| |||
Lines changed: 46 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
136 | 174 | | |
137 | 175 | | |
138 | 176 | | |
139 | 177 | | |
140 | 178 | | |
141 | 179 | | |
142 | 180 | | |
143 | | - | |
| 181 | + | |
144 | 182 | | |
145 | 183 | | |
146 | 184 | | |
| |||
179 | 217 | | |
180 | 218 | | |
181 | 219 | | |
182 | | - | |
| 220 | + | |
183 | 221 | | |
184 | 222 | | |
185 | 223 | | |
| |||
0 commit comments