@bananapus/core-v6 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/foundry.lock +1 -7
  2. package/foundry.toml +1 -1
  3. package/package.json +19 -7
  4. package/src/JBController.sol +26 -5
  5. package/src/JBMultiTerminal.sol +85 -47
  6. package/src/JBTerminalStore.sol +6 -6
  7. package/src/interfaces/IJBController.sol +4 -1
  8. package/src/libraries/JBFees.sol +47 -9
  9. package/src/libraries/JBPayoutSplitGroupLib.sol +2 -2
  10. package/src/periphery/JBMatchingPriceFeed.sol +1 -1
  11. package/test/mock/MockMaliciousBeneficiary.sol +15 -15
  12. package/ADMINISTRATION.md +0 -103
  13. package/ARCHITECTURE.md +0 -133
  14. package/AUDIT_INSTRUCTIONS.md +0 -139
  15. package/RISKS.md +0 -215
  16. package/SKILLS.md +0 -55
  17. package/STYLE_GUIDE.md +0 -610
  18. package/USER_JOURNEYS.md +0 -215
  19. package/script/Deploy.s.sol +0 -124
  20. package/script/DeployPeriphery.s.sol +0 -354
  21. package/slither-ci.config.json +0 -10
  22. package/test/AuditFixes.t.sol +0 -808
  23. package/test/ComprehensiveInvariant.t.sol +0 -306
  24. package/test/CoreExploitTests.t.sol +0 -2741
  25. package/test/EconomicSimulation.t.sol +0 -348
  26. package/test/EntryPointPermutations.t.sol +0 -684
  27. package/test/FlashLoanAttacks.t.sol +0 -797
  28. package/test/PermissionEscalation.t.sol +0 -711
  29. package/test/PermissionsInvariant.t.sol +0 -403
  30. package/test/RulesetTransitions.t.sol +0 -713
  31. package/test/SplitLoopTests.t.sol +0 -752
  32. package/test/TestAccessToFunds.sol +0 -2683
  33. package/test/TestAuditResponseDesignProofs.sol +0 -434
  34. package/test/TestCashOut.sol +0 -198
  35. package/test/TestCashOutCountFor.sol +0 -271
  36. package/test/TestCashOutHooks.sol +0 -351
  37. package/test/TestCashOutTimingEdge.sol +0 -241
  38. package/test/TestDataHookFuzzing.sol +0 -524
  39. package/test/TestDurationUnderflow.sol +0 -233
  40. package/test/TestFeeFreeCashOutBypass.sol +0 -949
  41. package/test/TestFeeProcessingFailure.sol +0 -218
  42. package/test/TestFees.sol +0 -619
  43. package/test/TestForwardedTokenConsumption.sol +0 -425
  44. package/test/TestInterfaceSupport.sol +0 -81
  45. package/test/TestJBERC20Inheritance.sol +0 -103
  46. package/test/TestL2SequencerPriceFeed.sol +0 -292
  47. package/test/TestLaunchProject.sol +0 -188
  48. package/test/TestMetaTx.sol +0 -217
  49. package/test/TestMetadataOffsetOverflow.sol +0 -179
  50. package/test/TestMetadataParserLib.sol +0 -471
  51. package/test/TestMigrationHeldFees.sol +0 -255
  52. package/test/TestMintTokensOf.sol +0 -185
  53. package/test/TestMultiTerminalSurplus.sol +0 -348
  54. package/test/TestMultiTokenSurplus.sol +0 -202
  55. package/test/TestMultipleAccessLimits.sol +0 -664
  56. package/test/TestPayBurnRedeemFlow.sol +0 -195
  57. package/test/TestPayHooks.sol +0 -209
  58. package/test/TestPermissions.sol +0 -324
  59. package/test/TestPermissionsEdge.sol +0 -290
  60. package/test/TestPermit2DataHook.t.sol +0 -360
  61. package/test/TestPermit2Terminal.sol +0 -372
  62. package/test/TestRulesetQueueing.sol +0 -1025
  63. package/test/TestRulesetQueuingStress.sol +0 -806
  64. package/test/TestRulesetWeightCaching.sol +0 -178
  65. package/test/TestSplits.sol +0 -391
  66. package/test/TestTerminalMigration.sol +0 -274
  67. package/test/TestTerminalPreviewParity.sol +0 -208
  68. package/test/TestTokenFlow.sol +0 -191
  69. package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
  70. package/test/WeirdTokenTests.t.sol +0 -817
  71. package/test/audit/CashOutReenterPay.t.sol +0 -501
  72. package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
  73. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  74. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  75. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  76. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  77. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  78. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  79. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  80. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  81. package/test/formal/BondingCurveProperties.t.sol +0 -420
  82. package/test/formal/FeeProperties.t.sol +0 -252
  83. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  84. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  85. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  86. package/test/invariants/TokensInvariant.t.sol +0 -195
  87. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  88. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  89. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  90. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  91. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  92. package/test/invariants/handlers/TokensHandler.sol +0 -126
  93. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  94. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  95. package/test/trees/JBController/burnTokensOf.tree +0 -9
  96. package/test/trees/JBController/claimTokensFor.tree +0 -5
  97. package/test/trees/JBController/deployERC20For.tree +0 -5
  98. package/test/trees/JBController/getRulesetOf.tree +0 -5
  99. package/test/trees/JBController/launchProjectFor.tree +0 -12
  100. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  101. package/test/trees/JBController/migrateController.tree +0 -12
  102. package/test/trees/JBController/mintTokensOf.tree +0 -12
  103. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  104. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  105. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  106. package/test/trees/JBController/setMetadataOf.tree +0 -5
  107. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  108. package/test/trees/JBController/setTokenFor.tree +0 -5
  109. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  110. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  111. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  112. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  113. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  114. package/test/trees/JBERC20/initialize.tree +0 -7
  115. package/test/trees/JBERC20/name.tree +0 -5
  116. package/test/trees/JBERC20/nonces.tree +0 -5
  117. package/test/trees/JBERC20/symbol.tree +0 -5
  118. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  120. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  122. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  123. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  124. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  125. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  126. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  127. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  128. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  129. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  131. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  132. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  133. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  134. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  135. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  136. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  137. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  138. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  139. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  140. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  141. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  142. package/test/trees/JBProjects/createFor.tree +0 -11
  143. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  144. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  145. package/test/trees/JBProjects/tokenURI.tree +0 -5
  146. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  147. package/test/trees/JBRulesets/currentOf.tree +0 -12
  148. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  149. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  150. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  151. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  152. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  153. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  154. package/test/trees/JBSplits/splitsOf.tree +0 -5
  155. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  156. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  157. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  158. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  159. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  160. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  161. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  162. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  163. package/test/trees/JBTokens/burnFrom.tree +0 -10
  164. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  165. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  166. package/test/trees/JBTokens/mintFor.tree +0 -10
  167. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  168. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  169. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  170. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  171. package/test/trees/mintTokensOf.tree +0 -12
  172. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  173. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  174. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  175. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  176. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  177. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  178. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  179. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  180. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  181. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  182. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  183. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  184. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  185. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  186. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  187. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  188. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  189. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  190. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  191. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  192. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  193. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  194. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  195. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  196. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  197. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  198. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  199. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  200. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  201. package/test/units/static/JBERC20/TestName.sol +0 -30
  202. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  203. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  204. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  205. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  206. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  207. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  208. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  210. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  211. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  212. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  214. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  215. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  217. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  218. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  220. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  221. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  222. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  223. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  224. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  225. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  226. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  227. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  228. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  229. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  230. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  231. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  232. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  233. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  234. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  235. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  236. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  237. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  238. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  239. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  240. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  241. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  242. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  243. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  244. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  245. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  246. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  247. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  248. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  249. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  250. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  251. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  252. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  253. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  254. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  255. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  256. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  257. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  258. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  259. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  260. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  261. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  262. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  263. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  264. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  265. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  266. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  267. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  268. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  269. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  270. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  271. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  272. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  273. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  274. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  275. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  276. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  277. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  278. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  279. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  280. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  281. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  282. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  283. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  284. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  285. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  286. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,797 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "./helpers/TestBaseWorkflow.sol";
5
- import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
6
- import {JBConstants} from "../src/libraries/JBConstants.sol";
7
- import {JBRulesetMetadataResolver} from "../src/libraries/JBRulesetMetadataResolver.sol";
8
- import {JBCurrencyAmount} from "../src/structs/JBCurrencyAmount.sol";
9
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
10
- import {JBRuleset} from "../src/structs/JBRuleset.sol";
11
- import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
12
- import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
13
- import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
14
- import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
15
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
16
-
17
- /// @notice Tests that flash-loan style atomic pay+cashOut attacks cannot extract profit.
18
- contract FlashLoanAttacks_Local is TestBaseWorkflow {
19
- using JBRulesetMetadataResolver for JBRuleset;
20
-
21
- uint256 public projectId;
22
- address public projectOwner;
23
-
24
- function setUp() public override {
25
- super.setUp();
26
- projectOwner = multisig();
27
-
28
- // ── Launch fee collector project (#1)
29
- // ────────────────────────
30
- _launchFeeProject();
31
-
32
- // ── Launch test project (#2): 0% reserved, 30% cashOutTax ──
33
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
34
- rulesetConfig[0].mustStartAtOrAfter = 0;
35
- rulesetConfig[0].duration = 0;
36
- rulesetConfig[0].weight = 1000e18;
37
- rulesetConfig[0].weightCutPercent = 0;
38
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
39
- rulesetConfig[0].metadata = JBRulesetMetadata({
40
- reservedPercent: 0,
41
- cashOutTaxRate: 3000, // 30%
42
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
43
- pausePay: false,
44
- pauseCreditTransfers: false,
45
- allowOwnerMinting: true,
46
- allowSetCustomToken: true,
47
- allowTerminalMigration: false,
48
- allowSetTerminals: false,
49
- ownerMustSendPayouts: false,
50
- allowSetController: false,
51
- allowAddAccountingContext: true,
52
- allowAddPriceFeed: false,
53
- holdFees: false,
54
- useTotalSurplusForCashOuts: false,
55
- useDataHookForPay: false,
56
- useDataHookForCashOut: false,
57
- dataHook: address(0),
58
- metadata: 0
59
- });
60
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
61
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
62
-
63
- JBTerminalConfig[] memory terminalConfigurations = _defaultTerminalConfig();
64
-
65
- projectId = jbController()
66
- .launchProjectFor({
67
- owner: projectOwner,
68
- projectUri: "flashLoanTest",
69
- rulesetConfigurations: rulesetConfig,
70
- terminalConfigurations: terminalConfigurations,
71
- memo: ""
72
- });
73
-
74
- vm.prank(projectOwner);
75
- jbController().deployERC20For(projectId, "FlashToken", "FT", bytes32(0));
76
- }
77
-
78
- // ═══════════════════════════════════════════════════════════════════
79
- // Helpers
80
- // ═══════════════════════════════════════════════════════════════════
81
-
82
- function _launchFeeProject() internal {
83
- JBRulesetConfig[] memory feeRulesetConfig = new JBRulesetConfig[](1);
84
- feeRulesetConfig[0].mustStartAtOrAfter = 0;
85
- feeRulesetConfig[0].duration = 0;
86
- feeRulesetConfig[0].weight = 1000e18;
87
- feeRulesetConfig[0].weightCutPercent = 0;
88
- feeRulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
89
- feeRulesetConfig[0].metadata = JBRulesetMetadata({
90
- reservedPercent: 0,
91
- cashOutTaxRate: 0,
92
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
93
- pausePay: false,
94
- pauseCreditTransfers: false,
95
- allowOwnerMinting: false,
96
- allowSetCustomToken: false,
97
- allowTerminalMigration: false,
98
- allowSetTerminals: false,
99
- ownerMustSendPayouts: false,
100
- allowSetController: false,
101
- allowAddAccountingContext: true,
102
- allowAddPriceFeed: false,
103
- holdFees: false,
104
- useTotalSurplusForCashOuts: false,
105
- useDataHookForPay: false,
106
- useDataHookForCashOut: false,
107
- dataHook: address(0),
108
- metadata: 0
109
- });
110
- feeRulesetConfig[0].splitGroups = new JBSplitGroup[](0);
111
- feeRulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
112
-
113
- JBTerminalConfig[] memory terminalConfigurations = _defaultTerminalConfig();
114
-
115
- jbController()
116
- .launchProjectFor({
117
- owner: address(420),
118
- projectUri: "feeCollector",
119
- rulesetConfigurations: feeRulesetConfig,
120
- terminalConfigurations: terminalConfigurations,
121
- memo: ""
122
- });
123
- }
124
-
125
- function _defaultTerminalConfig() internal view returns (JBTerminalConfig[] memory) {
126
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
127
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
128
- tokensToAccept[0] = JBAccountingContext({
129
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
130
- });
131
- terminalConfigurations[0] =
132
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
133
- return terminalConfigurations;
134
- }
135
-
136
- function _payProject(address payer, uint256 amount) internal returns (uint256 tokenCount) {
137
- vm.deal(payer, amount);
138
- vm.prank(payer);
139
- tokenCount = jbMultiTerminal().pay{value: amount}({
140
- projectId: projectId,
141
- token: JBConstants.NATIVE_TOKEN,
142
- amount: amount,
143
- beneficiary: payer,
144
- minReturnedTokens: 0,
145
- memo: "",
146
- metadata: new bytes(0)
147
- });
148
- }
149
-
150
- function _cashOut(address holder, uint256 count) internal returns (uint256 reclaimAmount) {
151
- vm.prank(holder);
152
- reclaimAmount = jbMultiTerminal()
153
- .cashOutTokensOf({
154
- holder: holder,
155
- projectId: projectId,
156
- cashOutCount: count,
157
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
158
- minTokensReclaimed: 0,
159
- beneficiary: payable(holder),
160
- metadata: new bytes(0)
161
- });
162
- }
163
-
164
- // ═══════════════════════════════════════════════════════════════════
165
- // Test 1: Atomic pay+cashOut — no profit
166
- // ═══════════════════════════════════════════════════════════════════
167
-
168
- function test_flashLoan_payAndCashOut_noProfit() public {
169
- address attacker = address(0xA77AC0);
170
- uint256 payAmount = 10 ether;
171
-
172
- // Seed the project with some existing funds
173
- _payProject(address(0x5EED), 10 ether);
174
-
175
- // Attacker pays and immediately cashes out
176
- uint256 tokensReceived = _payProject(attacker, payAmount);
177
- uint256 reclaimAmount = _cashOut(attacker, tokensReceived);
178
-
179
- // Key invariant: reclaim amount must not exceed what was paid
180
- assertLe(reclaimAmount, payAmount, "Flash loan must not return more than paid");
181
- }
182
-
183
- // ═══════════════════════════════════════════════════════════════════
184
- // Test 2: Multiple payers, proportional reclaim
185
- // ═══════════════════════════════════════════════════════════════════
186
-
187
- function test_flashLoan_payAndCashOut_multiplePayers() public {
188
- address alice = address(0xA11CE);
189
- address bob = address(0xB0B);
190
-
191
- // Both pay in same block
192
- uint256 aliceTokens = _payProject(alice, 5 ether);
193
- uint256 bobTokens = _payProject(bob, 5 ether);
194
-
195
- // Both have equal tokens
196
- assertEq(aliceTokens, bobTokens, "Equal payments should mint equal tokens");
197
-
198
- // Alice cashes out
199
- uint256 aliceReclaim = _cashOut(alice, aliceTokens);
200
- // Bob cashes out
201
- uint256 bobReclaim = _cashOut(bob, bobTokens);
202
-
203
- // With cash out tax, the second casher benefits from the first one's tax.
204
- // This is expected behavior (not a bug). The key invariant is:
205
- // total reclaimed <= total paid in (no value created from nothing)
206
- assertLe(aliceReclaim + bobReclaim, 10 ether, "Total reclaimed must not exceed total paid in");
207
-
208
- // Alice (first casher) always gets less than her payment due to tax
209
- assertLt(aliceReclaim, 5 ether, "First casher pays the tax penalty");
210
- }
211
-
212
- // ═══════════════════════════════════════════════════════════════════
213
- // Test 3: addToBalance inflates surplus but attacker has 0 tokens
214
- // ═══════════════════════════════════════════════════════════════════
215
-
216
- function test_addToBalance_inflateAndCashOut_zeroTokens() public {
217
- address attacker = address(0xA77AC0);
218
-
219
- // Attacker adds to balance (gets no tokens)
220
- vm.deal(attacker, 10 ether);
221
- vm.prank(attacker);
222
- jbMultiTerminal().addToBalanceOf{value: 10 ether}({
223
- projectId: projectId,
224
- token: JBConstants.NATIVE_TOKEN,
225
- amount: 10 ether,
226
- shouldReturnHeldFees: false,
227
- memo: "",
228
- metadata: new bytes(0)
229
- });
230
-
231
- // Attacker has 0 tokens — cannot extract
232
- uint256 balance = jbTokens().totalBalanceOf(attacker, projectId);
233
- assertEq(balance, 0, "addToBalance must not mint tokens");
234
- }
235
-
236
- // ═══════════════════════════════════════════════════════════════════
237
- // Test 4: addToBalance benefits existing holders proportionally
238
- // ═══════════════════════════════════════════════════════════════════
239
-
240
- function test_addToBalance_noExploitIfTokensExist() public {
241
- address alice = address(0xA11CE);
242
- address bob = address(0xB0B);
243
-
244
- // Alice and Bob pay in
245
- uint256 aliceTokens = _payProject(alice, 5 ether);
246
- uint256 bobTokens = _payProject(bob, 5 ether);
247
-
248
- // Someone adds to balance (donation)
249
- vm.deal(address(0xD000), 10 ether);
250
- vm.prank(address(0xD000));
251
- jbMultiTerminal().addToBalanceOf{value: 10 ether}({
252
- projectId: projectId,
253
- token: JBConstants.NATIVE_TOKEN,
254
- amount: 10 ether,
255
- shouldReturnHeldFees: false,
256
- memo: "",
257
- metadata: new bytes(0)
258
- });
259
-
260
- // Alice cashes out — gets her share of the surplus
261
- uint256 aliceReclaim = _cashOut(alice, aliceTokens);
262
- // Bob cashes out
263
- uint256 bobReclaim = _cashOut(bob, bobTokens);
264
-
265
- // Both should get proportional shares (with cashOutTax reducing it)
266
- // Key check: they should get roughly equal amounts since they have equal tokens
267
- // Alice cashes out first, so she gets slightly more due to reduced supply.
268
- // But the proportional split should be reasonable.
269
- assertTrue(aliceReclaim > 0, "Alice should get some reclaim");
270
- assertTrue(bobReclaim > 0, "Bob should get some reclaim");
271
- }
272
-
273
- // ═══════════════════════════════════════════════════════════════════
274
- // Test 5: Regression — cashOut(0) with totalSupply==0 must return 0
275
- // ═══════════════════════════════════════════════════════════════════
276
-
277
- /// @notice Regression test: cashOut(0) with totalSupply==0 previously returned the entire surplus.
278
- /// @dev In V5, `cashOutCount >= totalSupply` (0 >= 0) was true and returned the full surplus before
279
- /// checking for zero cashOutCount. Fixed since V5.1: `JBCashOuts.cashOutFrom` returns 0 when
280
- /// cashOutCount==0 (line 31) before reaching the `cashOutCount >= totalSupply` check (line 37).
281
- /// This test verifies the fix holds.
282
- function test_variant_addToBalance_zeroCashOut() public {
283
- // Add to balance when no tokens exist
284
- vm.deal(address(0xD000), 5 ether);
285
- vm.prank(address(0xD000));
286
- jbMultiTerminal().addToBalanceOf{value: 5 ether}({
287
- projectId: projectId,
288
- token: JBConstants.NATIVE_TOKEN,
289
- amount: 5 ether,
290
- shouldReturnHeldFees: false,
291
- memo: "",
292
- metadata: new bytes(0)
293
- });
294
-
295
- // cashOut(0) with totalSupply==0 must reclaim nothing.
296
- address attacker = address(0xA77AC0);
297
- vm.prank(attacker);
298
- uint256 reclaimAmount = jbMultiTerminal()
299
- .cashOutTokensOf({
300
- holder: attacker,
301
- projectId: projectId,
302
- cashOutCount: 0,
303
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
304
- minTokensReclaimed: 0,
305
- beneficiary: payable(attacker),
306
- metadata: new bytes(0)
307
- });
308
-
309
- assertEq(reclaimAmount, 0, "Regression: cashOut(0) must return 0");
310
- }
311
-
312
- // ═══════════════════════════════════════════════════════════════════
313
- // Test 6: Pay hook reentrancy — cashOut during pay
314
- // ═══════════════════════════════════════════════════════════════════
315
-
316
- function test_payHookReentrancy_cashOutDuringPay() public {
317
- // For this test we verify that even if an attacker could call cashOut
318
- // from a pay callback, they have no tokens at that point (tokens are
319
- // minted after the store records, before hooks execute).
320
- // Without a data hook configured, no hooks fire, so we just verify
321
- // the normal flow is safe.
322
- address attacker = address(0xA77AC0);
323
-
324
- // Seed project
325
- _payProject(address(0x5EED), 10 ether);
326
-
327
- // Attacker pays — tokens are minted atomically
328
- uint256 tokens = _payProject(attacker, 5 ether);
329
- assertTrue(tokens > 0, "Tokens should be minted");
330
-
331
- // Attacker cashes out — state is consistent
332
- uint256 reclaim = _cashOut(attacker, tokens);
333
- assertLe(reclaim, 5 ether, "Reclaim must not exceed payment");
334
- }
335
-
336
- // ═══════════════════════════════════════════════════════════════════
337
- // Test 7: Cash out hook reentrancy — pay during cashOut
338
- // ═══════════════════════════════════════════════════════════════════
339
-
340
- function test_cashOutHookReentrancy_payDuringCashOut() public {
341
- // Without data hooks, cash out hooks don't fire.
342
- // Verify: pay after cashOut uses already-decremented balance.
343
- address alice = address(0xA11CE);
344
-
345
- uint256 aliceTokens = _payProject(alice, 10 ether);
346
-
347
- // Alice cashes out half
348
- uint256 halfTokens = aliceTokens / 2;
349
- uint256 reclaimFirst = _cashOut(alice, halfTokens);
350
-
351
- // Alice pays again with the reclaimed ETH
352
- uint256 newTokens = _payProject(alice, reclaimFirst);
353
-
354
- // Cash out the new tokens
355
- uint256 reclaimSecond = _cashOut(alice, newTokens);
356
-
357
- // Each round she loses to cashOutTax, so she should progressively lose
358
- assertLt(reclaimSecond, reclaimFirst, "Second reclaim should be less due to compounding tax");
359
- }
360
-
361
- // ═══════════════════════════════════════════════════════════════════
362
- // Test 8: Reserved token inflation — cashOut timing
363
- // ═══════════════════════════════════════════════════════════════════
364
-
365
- function test_reservedTokenInflation_cashOutTiming() public {
366
- // Launch a project with 20% reserved to test inflation
367
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
368
- rulesetConfig[0].mustStartAtOrAfter = 0;
369
- rulesetConfig[0].duration = 0;
370
- rulesetConfig[0].weight = 1000e18;
371
- rulesetConfig[0].weightCutPercent = 0;
372
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
373
- rulesetConfig[0].metadata = JBRulesetMetadata({
374
- reservedPercent: 2000, // 20%
375
- cashOutTaxRate: 0, // No tax for cleaner test
376
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
377
- pausePay: false,
378
- pauseCreditTransfers: false,
379
- allowOwnerMinting: true,
380
- allowSetCustomToken: true,
381
- allowTerminalMigration: false,
382
- allowSetTerminals: false,
383
- ownerMustSendPayouts: false,
384
- allowSetController: false,
385
- allowAddAccountingContext: true,
386
- allowAddPriceFeed: false,
387
- holdFees: false,
388
- useTotalSurplusForCashOuts: false,
389
- useDataHookForPay: false,
390
- useDataHookForCashOut: false,
391
- dataHook: address(0),
392
- metadata: 0
393
- });
394
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
395
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
396
-
397
- uint256 reservedProjectId = jbController()
398
- .launchProjectFor({
399
- owner: projectOwner,
400
- projectUri: "reservedTest",
401
- rulesetConfigurations: rulesetConfig,
402
- terminalConfigurations: _defaultTerminalConfig(),
403
- memo: ""
404
- });
405
-
406
- vm.prank(projectOwner);
407
- jbController().deployERC20For(reservedProjectId, "ResToken", "RT", bytes32(0));
408
-
409
- // Pay in
410
- address alice = address(0xA11CE);
411
- vm.deal(alice, 10 ether);
412
- vm.prank(alice);
413
- uint256 aliceTokens = jbMultiTerminal().pay{value: 10 ether}({
414
- projectId: reservedProjectId,
415
- token: JBConstants.NATIVE_TOKEN,
416
- amount: 10 ether,
417
- beneficiary: alice,
418
- minReturnedTokens: 0,
419
- memo: "",
420
- metadata: new bytes(0)
421
- });
422
-
423
- // Check pending reserved
424
- uint256 pendingBefore = jbController().pendingReservedTokenBalanceOf(reservedProjectId);
425
- assertTrue(pendingBefore > 0, "Should have pending reserved tokens");
426
-
427
- // Cash out BEFORE distributing reserves — Alice has higher share of supply
428
- uint256 totalSupplyBefore = jbTokens().totalSupplyOf(reservedProjectId);
429
- uint256 aliceShareBefore = (aliceTokens * 1e18) / totalSupplyBefore;
430
-
431
- // Now distribute reserved tokens
432
- jbController().sendReservedTokensToSplitsOf(reservedProjectId);
433
-
434
- // Total supply increased
435
- uint256 totalSupplyAfter = jbTokens().totalSupplyOf(reservedProjectId);
436
- assertGt(totalSupplyAfter, totalSupplyBefore, "Supply should increase after distributing reserves");
437
-
438
- // Alice's share decreased
439
- uint256 aliceShareAfter = (aliceTokens * 1e18) / totalSupplyAfter;
440
- assertLt(aliceShareAfter, aliceShareBefore, "Alice's share should decrease after reserve distribution");
441
- }
442
-
443
- // ═══════════════════════════════════════════════════════════════════
444
- // Test 9: 100 rounds of tiny pay+cashOut — no profit from rounding
445
- // ═══════════════════════════════════════════════════════════════════
446
-
447
- function test_multiplePayCashOutRounds_accumulatedRounding() public {
448
- address attacker = address(0xA77AC0);
449
-
450
- // Seed the project
451
- _payProject(address(0x5EED), 100 ether);
452
-
453
- uint256 startBalance = 10 ether;
454
- vm.deal(attacker, startBalance);
455
- uint256 currentBalance = startBalance;
456
-
457
- for (uint256 i = 0; i < 100; i++) {
458
- if (currentBalance < 0.001 ether) break;
459
-
460
- vm.prank(attacker);
461
- uint256 tokens = jbMultiTerminal().pay{value: currentBalance}({
462
- projectId: projectId,
463
- token: JBConstants.NATIVE_TOKEN,
464
- amount: currentBalance,
465
- beneficiary: attacker,
466
- minReturnedTokens: 0,
467
- memo: "",
468
- metadata: new bytes(0)
469
- });
470
-
471
- if (tokens == 0) break;
472
-
473
- vm.prank(attacker);
474
- currentBalance = jbMultiTerminal()
475
- .cashOutTokensOf({
476
- holder: attacker,
477
- projectId: projectId,
478
- cashOutCount: tokens,
479
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
480
- minTokensReclaimed: 0,
481
- beneficiary: payable(attacker),
482
- metadata: new bytes(0)
483
- });
484
- }
485
-
486
- assertLe(currentBalance, startBalance, "100 rounds of pay+cashOut must not accumulate profit from rounding");
487
- }
488
-
489
- // ═══════════════════════════════════════════════════════════════════
490
- // Test 10: Sandwich attack around sendPayoutsOf
491
- // ═══════════════════════════════════════════════════════════════════
492
-
493
- function test_sandwichAttack_payBeforeAndAfterPayout() public {
494
- // Configure payout limit
495
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
496
- rulesetConfig[0].mustStartAtOrAfter = 0;
497
- rulesetConfig[0].duration = 0;
498
- rulesetConfig[0].weight = 1000e18;
499
- rulesetConfig[0].weightCutPercent = 0;
500
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
501
- rulesetConfig[0].metadata = JBRulesetMetadata({
502
- reservedPercent: 0,
503
- cashOutTaxRate: 3000,
504
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
505
- pausePay: false,
506
- pauseCreditTransfers: false,
507
- allowOwnerMinting: true,
508
- allowSetCustomToken: true,
509
- allowTerminalMigration: false,
510
- allowSetTerminals: false,
511
- ownerMustSendPayouts: false,
512
- allowSetController: false,
513
- allowAddAccountingContext: true,
514
- allowAddPriceFeed: false,
515
- holdFees: false,
516
- useTotalSurplusForCashOuts: false,
517
- useDataHookForPay: false,
518
- useDataHookForCashOut: false,
519
- dataHook: address(0),
520
- metadata: 0
521
- });
522
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
523
-
524
- JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
525
- payoutLimits[0] = JBCurrencyAmount({amount: 5 ether, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
526
-
527
- JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
528
- fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
529
- terminal: address(jbMultiTerminal()),
530
- token: JBConstants.NATIVE_TOKEN,
531
- payoutLimits: payoutLimits,
532
- surplusAllowances: new JBCurrencyAmount[](0)
533
- });
534
- rulesetConfig[0].fundAccessLimitGroups = fundAccessLimitGroups;
535
-
536
- uint256 sandwichProjectId = jbController()
537
- .launchProjectFor({
538
- owner: projectOwner,
539
- projectUri: "sandwichTest",
540
- rulesetConfigurations: rulesetConfig,
541
- terminalConfigurations: _defaultTerminalConfig(),
542
- memo: ""
543
- });
544
-
545
- // Seed
546
- address seeder = address(0x5EED);
547
- vm.deal(seeder, 20 ether);
548
- vm.prank(seeder);
549
- jbMultiTerminal().pay{value: 20 ether}({
550
- projectId: sandwichProjectId,
551
- token: JBConstants.NATIVE_TOKEN,
552
- amount: 20 ether,
553
- beneficiary: seeder,
554
- minReturnedTokens: 0,
555
- memo: "",
556
- metadata: new bytes(0)
557
- });
558
-
559
- // Attacker front-runs: pays right before payout
560
- address attacker = address(0xA77AC0);
561
- // forge-lint: disable-next-line(mixed-case-variable)
562
- uint256 attackerInitialETH = 10 ether;
563
- vm.deal(attacker, attackerInitialETH);
564
- vm.prank(attacker);
565
- uint256 attackerTokens = jbMultiTerminal().pay{value: attackerInitialETH}({
566
- projectId: sandwichProjectId,
567
- token: JBConstants.NATIVE_TOKEN,
568
- amount: attackerInitialETH,
569
- beneficiary: attacker,
570
- minReturnedTokens: 0,
571
- memo: "",
572
- metadata: new bytes(0)
573
- });
574
-
575
- // Payout happens
576
- vm.prank(projectOwner);
577
- jbMultiTerminal()
578
- .sendPayoutsOf({
579
- projectId: sandwichProjectId,
580
- token: JBConstants.NATIVE_TOKEN,
581
- amount: 5 ether,
582
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
583
- minTokensPaidOut: 0
584
- });
585
-
586
- // Attacker back-runs: cashes out
587
- vm.prank(attacker);
588
- uint256 reclaimAmount = jbMultiTerminal()
589
- .cashOutTokensOf({
590
- holder: attacker,
591
- projectId: sandwichProjectId,
592
- cashOutCount: attackerTokens,
593
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
594
- minTokensReclaimed: 0,
595
- beneficiary: payable(attacker),
596
- metadata: new bytes(0)
597
- });
598
-
599
- // Attacker should NOT profit
600
- assertLe(reclaimAmount, attackerInitialETH, "Sandwich attacker must not profit from payout timing");
601
- }
602
-
603
- // ═══════════════════════════════════════════════════════════════════
604
- // Test 11: Flash loan across two terminals with useTotalSurplus
605
- // ═══════════════════════════════════════════════════════════════════
606
-
607
- function test_flashLoan_acrossTwoTerminals() public {
608
- // Launch project with useTotalSurplusForCashOuts and two terminals
609
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
610
- rulesetConfig[0].mustStartAtOrAfter = 0;
611
- rulesetConfig[0].duration = 0;
612
- rulesetConfig[0].weight = 1000e18;
613
- rulesetConfig[0].weightCutPercent = 0;
614
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
615
- rulesetConfig[0].metadata = JBRulesetMetadata({
616
- reservedPercent: 0,
617
- cashOutTaxRate: 3000,
618
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
619
- pausePay: false,
620
- pauseCreditTransfers: false,
621
- allowOwnerMinting: true,
622
- allowSetCustomToken: true,
623
- allowTerminalMigration: false,
624
- allowSetTerminals: true,
625
- ownerMustSendPayouts: false,
626
- allowSetController: false,
627
- allowAddAccountingContext: true,
628
- allowAddPriceFeed: false,
629
- holdFees: false,
630
- useTotalSurplusForCashOuts: true,
631
- useDataHookForPay: false,
632
- useDataHookForCashOut: false,
633
- dataHook: address(0),
634
- metadata: 0
635
- });
636
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
637
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
638
-
639
- // Two terminals
640
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](2);
641
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
642
- tokensToAccept[0] = JBAccountingContext({
643
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
644
- });
645
- terminalConfigurations[0] =
646
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
647
- terminalConfigurations[1] =
648
- JBTerminalConfig({terminal: jbMultiTerminal2(), accountingContextsToAccept: tokensToAccept});
649
-
650
- uint256 twoTermProjectId = jbController()
651
- .launchProjectFor({
652
- owner: projectOwner,
653
- projectUri: "twoTermTest",
654
- rulesetConfigurations: rulesetConfig,
655
- terminalConfigurations: terminalConfigurations,
656
- memo: ""
657
- });
658
-
659
- // Seed terminal 1
660
- address seeder = address(0x5EED);
661
- vm.deal(seeder, 10 ether);
662
- vm.prank(seeder);
663
- jbMultiTerminal().pay{value: 10 ether}({
664
- projectId: twoTermProjectId,
665
- token: JBConstants.NATIVE_TOKEN,
666
- amount: 10 ether,
667
- beneficiary: seeder,
668
- minReturnedTokens: 0,
669
- memo: "",
670
- metadata: new bytes(0)
671
- });
672
-
673
- // Attacker pays terminal 2
674
- address attacker = address(0xA77AC0);
675
- vm.deal(attacker, 5 ether);
676
- vm.prank(attacker);
677
- uint256 attackerTokens = jbMultiTerminal2().pay{value: 5 ether}({
678
- projectId: twoTermProjectId,
679
- token: JBConstants.NATIVE_TOKEN,
680
- amount: 5 ether,
681
- beneficiary: attacker,
682
- minReturnedTokens: 0,
683
- memo: "",
684
- metadata: new bytes(0)
685
- });
686
-
687
- // Cash out from terminal 2 using total surplus from both terminals
688
- vm.prank(attacker);
689
- uint256 reclaimAmount = jbMultiTerminal2()
690
- .cashOutTokensOf({
691
- holder: attacker,
692
- projectId: twoTermProjectId,
693
- cashOutCount: attackerTokens,
694
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
695
- minTokensReclaimed: 0,
696
- beneficiary: payable(attacker),
697
- metadata: new bytes(0)
698
- });
699
-
700
- assertLe(reclaimAmount, 5 ether, "Cross-terminal cashOut must not profit");
701
- }
702
-
703
- // ═══════════════════════════════════════════════════════════════════
704
- // Test 12: Fuzz — same-block pay+cashOut NEVER profitable
705
- // ═══════════════════════════════════════════════════════════════════
706
-
707
- function testFuzz_payAndCashOut_neverProfitable(uint256 payAmount, uint16 cashOutTaxRate) public {
708
- payAmount = bound(payAmount, 0.01 ether, 1000 ether);
709
- cashOutTaxRate = uint16(bound(uint256(cashOutTaxRate), 0, 10_000));
710
-
711
- // Launch a fresh project with the fuzzed tax rate
712
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
713
- rulesetConfig[0].mustStartAtOrAfter = 0;
714
- rulesetConfig[0].duration = 0;
715
- rulesetConfig[0].weight = 1000e18;
716
- rulesetConfig[0].weightCutPercent = 0;
717
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
718
- rulesetConfig[0].metadata = JBRulesetMetadata({
719
- reservedPercent: 0,
720
- cashOutTaxRate: cashOutTaxRate,
721
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
722
- pausePay: false,
723
- pauseCreditTransfers: false,
724
- allowOwnerMinting: true,
725
- allowSetCustomToken: true,
726
- allowTerminalMigration: false,
727
- allowSetTerminals: false,
728
- ownerMustSendPayouts: false,
729
- allowSetController: false,
730
- allowAddAccountingContext: true,
731
- allowAddPriceFeed: false,
732
- holdFees: false,
733
- useTotalSurplusForCashOuts: false,
734
- useDataHookForPay: false,
735
- useDataHookForCashOut: false,
736
- dataHook: address(0),
737
- metadata: 0
738
- });
739
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
740
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
741
-
742
- uint256 fuzzProjectId = jbController()
743
- .launchProjectFor({
744
- owner: projectOwner,
745
- projectUri: "fuzzTest",
746
- rulesetConfigurations: rulesetConfig,
747
- terminalConfigurations: _defaultTerminalConfig(),
748
- memo: ""
749
- });
750
-
751
- // Seed project
752
- address seeder = address(0x5EED);
753
- vm.deal(seeder, 100 ether);
754
- vm.prank(seeder);
755
- jbMultiTerminal().pay{value: 100 ether}({
756
- projectId: fuzzProjectId,
757
- token: JBConstants.NATIVE_TOKEN,
758
- amount: 100 ether,
759
- beneficiary: seeder,
760
- minReturnedTokens: 0,
761
- memo: "",
762
- metadata: new bytes(0)
763
- });
764
-
765
- // Attacker atomic pay+cashOut
766
- address attacker = address(0xA77AC0);
767
- vm.deal(attacker, payAmount);
768
- vm.prank(attacker);
769
- uint256 tokens = jbMultiTerminal().pay{value: payAmount}({
770
- projectId: fuzzProjectId,
771
- token: JBConstants.NATIVE_TOKEN,
772
- amount: payAmount,
773
- beneficiary: attacker,
774
- minReturnedTokens: 0,
775
- memo: "",
776
- metadata: new bytes(0)
777
- });
778
-
779
- if (tokens == 0) return;
780
-
781
- vm.prank(attacker);
782
- uint256 reclaimAmount = jbMultiTerminal()
783
- .cashOutTokensOf({
784
- holder: attacker,
785
- projectId: fuzzProjectId,
786
- cashOutCount: tokens,
787
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
788
- minTokensReclaimed: 0,
789
- beneficiary: payable(attacker),
790
- metadata: new bytes(0)
791
- });
792
-
793
- assertLe(reclaimAmount, payAmount, "FUZZ: Atomic pay+cashOut must never return more than paid");
794
- }
795
-
796
- receive() external payable {}
797
- }