@bananapus/core-v6 0.0.37 → 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 (287) 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 +19 -1
  5. package/src/JBMultiTerminal.sol +68 -34
  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/CodexMigrationFeeFailure.t.sol +0 -163
  74. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  75. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  76. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  77. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  78. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  79. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  80. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  81. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  82. package/test/formal/BondingCurveProperties.t.sol +0 -420
  83. package/test/formal/FeeProperties.t.sol +0 -252
  84. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  85. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  86. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  87. package/test/invariants/TokensInvariant.t.sol +0 -195
  88. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  89. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  90. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  91. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  92. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  93. package/test/invariants/handlers/TokensHandler.sol +0 -126
  94. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  95. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  96. package/test/trees/JBController/burnTokensOf.tree +0 -9
  97. package/test/trees/JBController/claimTokensFor.tree +0 -5
  98. package/test/trees/JBController/deployERC20For.tree +0 -5
  99. package/test/trees/JBController/getRulesetOf.tree +0 -5
  100. package/test/trees/JBController/launchProjectFor.tree +0 -12
  101. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  102. package/test/trees/JBController/migrateController.tree +0 -12
  103. package/test/trees/JBController/mintTokensOf.tree +0 -12
  104. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  105. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  106. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  107. package/test/trees/JBController/setMetadataOf.tree +0 -5
  108. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  109. package/test/trees/JBController/setTokenFor.tree +0 -5
  110. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  111. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  112. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  113. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  114. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  115. package/test/trees/JBERC20/initialize.tree +0 -7
  116. package/test/trees/JBERC20/name.tree +0 -5
  117. package/test/trees/JBERC20/nonces.tree +0 -5
  118. package/test/trees/JBERC20/symbol.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  120. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  122. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  123. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  124. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  125. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  126. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  127. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  128. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  129. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  131. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  132. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  133. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  134. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  135. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  136. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  137. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  138. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  139. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  140. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  141. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  142. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  143. package/test/trees/JBProjects/createFor.tree +0 -11
  144. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  145. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  146. package/test/trees/JBProjects/tokenURI.tree +0 -5
  147. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  148. package/test/trees/JBRulesets/currentOf.tree +0 -12
  149. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  150. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  151. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  152. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  153. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  154. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  155. package/test/trees/JBSplits/splitsOf.tree +0 -5
  156. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  157. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  158. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  159. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  160. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  161. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  162. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  163. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  164. package/test/trees/JBTokens/burnFrom.tree +0 -10
  165. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  166. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  167. package/test/trees/JBTokens/mintFor.tree +0 -10
  168. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  169. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  170. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  171. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  172. package/test/trees/mintTokensOf.tree +0 -12
  173. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  174. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  175. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  176. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  177. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  178. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  179. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  180. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  181. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  182. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  183. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  184. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  185. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  186. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  187. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  188. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  189. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  190. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  191. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  192. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  193. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  194. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  195. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  196. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  197. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  198. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  199. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  200. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  201. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  202. package/test/units/static/JBERC20/TestName.sol +0 -30
  203. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  204. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  205. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  206. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  207. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  208. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  210. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  211. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  212. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  214. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  215. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  217. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  218. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  220. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  221. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  222. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  223. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  224. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  225. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  226. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  227. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  228. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  229. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  230. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  231. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  232. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  233. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  234. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  235. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  236. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  237. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  238. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  239. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  240. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  241. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  242. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  243. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  244. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  245. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  246. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  247. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  248. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  249. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  250. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  251. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  252. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  253. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  254. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  255. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  256. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  257. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  258. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  259. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  260. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  261. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  262. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  263. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  264. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  265. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  266. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  267. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  268. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  269. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  270. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  271. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  272. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  273. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  274. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  275. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  276. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  277. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  278. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  279. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  280. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  281. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  282. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  283. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  284. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  285. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  286. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  287. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,420 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.17;
3
-
4
- import {Test} from "forge-std/Test.sol";
5
- import {JBCashOuts} from "../../src/libraries/JBCashOuts.sol";
6
- import {JBFees} from "../../src/libraries/JBFees.sol";
7
- import {JBConstants} from "../../src/libraries/JBConstants.sol";
8
- import {JBRulesetMetadataResolver} from "../../src/libraries/JBRulesetMetadataResolver.sol";
9
- import {JBRuleset} from "../../src/structs/JBRuleset.sol";
10
- import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
11
-
12
- /// @title BondingCurveProperties
13
- /// @notice Formal verification of bonding curve properties using symbolic execution.
14
- /// @dev Works with both Halmos (check_* pattern) and forge test (test_* pattern).
15
- /// Each property is dual-implemented: `check_` for Halmos and `testFuzz_` for forge.
16
- contract BondingCurveProperties is Test {
17
- uint256 constant MAX_TAX = JBConstants.MAX_CASH_OUT_TAX_RATE; // 10_000
18
- uint256 constant MAX_FEE = JBConstants.MAX_FEE; // 1_000
19
-
20
- // =========================================================================
21
- // Property 1: Boundedness — cashOutFrom never exceeds surplus
22
- // =========================================================================
23
- /// @notice cashOutFrom(S, c, T, r) <= S for all valid inputs.
24
- // forge-lint: disable-next-line(mixed-case-function)
25
- function check_cashOut_boundedness(
26
- uint256 surplus,
27
- uint256 cashOutCount,
28
- uint256 totalSupply,
29
- uint256 cashOutTaxRate
30
- )
31
- public
32
- pure
33
- {
34
- // Bound inputs to valid ranges
35
- vm.assume(surplus > 0 && surplus <= type(uint128).max);
36
- vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
37
- vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
38
- vm.assume(cashOutTaxRate <= MAX_TAX);
39
-
40
- uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, cashOutTaxRate);
41
- assert(result <= surplus);
42
- }
43
-
44
- function testFuzz_cashOut_boundedness(
45
- uint128 surplus,
46
- uint128 totalSupply,
47
- uint128 cashOutCount,
48
- uint16 cashOutTaxRate
49
- )
50
- public
51
- pure
52
- {
53
- vm.assume(surplus > 0);
54
- vm.assume(totalSupply > 0);
55
- vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
56
- vm.assume(cashOutTaxRate <= MAX_TAX);
57
-
58
- uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, cashOutTaxRate);
59
- assertLe(result, surplus, "Boundedness: cashOutFrom should never exceed surplus");
60
- }
61
-
62
- // =========================================================================
63
- // Property 2: Monotonicity — more tokens → more reclaim
64
- // =========================================================================
65
- /// @notice cashOutFrom(S, c1, T, r) <= cashOutFrom(S, c2, T, r) when c1 <= c2.
66
- // forge-lint: disable-next-line(mixed-case-function)
67
- function check_cashOut_monotonicity(
68
- uint256 surplus,
69
- uint256 c1,
70
- uint256 c2,
71
- uint256 totalSupply,
72
- uint256 cashOutTaxRate
73
- )
74
- public
75
- pure
76
- {
77
- vm.assume(surplus > 0 && surplus <= type(uint128).max);
78
- vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
79
- vm.assume(c1 > 0 && c2 > 0);
80
- vm.assume(c1 <= c2);
81
- vm.assume(c2 <= totalSupply);
82
- vm.assume(cashOutTaxRate <= MAX_TAX);
83
-
84
- uint256 result1 = JBCashOuts.cashOutFrom(surplus, c1, totalSupply, cashOutTaxRate);
85
- uint256 result2 = JBCashOuts.cashOutFrom(surplus, c2, totalSupply, cashOutTaxRate);
86
-
87
- assert(result1 <= result2);
88
- }
89
-
90
- function testFuzz_cashOut_monotonicity(
91
- uint128 surplus,
92
- uint128 totalSupply,
93
- uint128 c1,
94
- uint128 c2,
95
- uint16 cashOutTaxRate
96
- )
97
- public
98
- pure
99
- {
100
- vm.assume(surplus > 0);
101
- vm.assume(totalSupply > 0);
102
- vm.assume(c1 > 0 && c2 > 0);
103
- if (c1 > c2) (c1, c2) = (c2, c1); // Ensure c1 <= c2
104
- vm.assume(c2 <= totalSupply);
105
- vm.assume(cashOutTaxRate <= MAX_TAX);
106
-
107
- uint256 result1 = JBCashOuts.cashOutFrom(surplus, c1, totalSupply, cashOutTaxRate);
108
- uint256 result2 = JBCashOuts.cashOutFrom(surplus, c2, totalSupply, cashOutTaxRate);
109
-
110
- assertLe(result1, result2, "Monotonicity: more tokens should yield >= reclaim");
111
- }
112
-
113
- // =========================================================================
114
- // Property 3: Full redemption — when c >= T, result is S (full surplus)
115
- // =========================================================================
116
- /// @notice When cashOutCount >= totalSupply, the full surplus is returned.
117
- // forge-lint: disable-next-line(mixed-case-function)
118
- function check_cashOut_fullRedemption(uint256 surplus, uint256 totalSupply, uint256 cashOutTaxRate) public pure {
119
- vm.assume(surplus > 0 && surplus <= type(uint128).max);
120
- vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
121
- vm.assume(cashOutTaxRate <= MAX_TAX);
122
- vm.assume(cashOutTaxRate < MAX_TAX); // Exclude max tax (which returns 0)
123
-
124
- // When cashing out the entire supply
125
- uint256 result = JBCashOuts.cashOutFrom(surplus, totalSupply, totalSupply, cashOutTaxRate);
126
- assert(result == surplus);
127
- }
128
-
129
- function testFuzz_cashOut_fullRedemption(uint128 surplus, uint128 totalSupply, uint16 cashOutTaxRate) public pure {
130
- vm.assume(surplus > 0);
131
- vm.assume(totalSupply > 0);
132
- vm.assume(cashOutTaxRate < MAX_TAX); // Exclude max tax
133
-
134
- uint256 result = JBCashOuts.cashOutFrom(surplus, totalSupply, totalSupply, cashOutTaxRate);
135
- assertEq(result, surplus, "Full redemption should return entire surplus");
136
- }
137
-
138
- // =========================================================================
139
- // Property 4: Max tax → zero reclaim
140
- // =========================================================================
141
- /// @notice When cashOutTaxRate == MAX_CASH_OUT_TAX_RATE, result is 0.
142
- // forge-lint: disable-next-line(mixed-case-function)
143
- function check_cashOut_maxTaxIsZero(uint256 surplus, uint256 cashOutCount, uint256 totalSupply) public pure {
144
- vm.assume(surplus > 0 && surplus <= type(uint128).max);
145
- vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
146
- vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
147
-
148
- uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, MAX_TAX);
149
- assert(result == 0);
150
- }
151
-
152
- function testFuzz_cashOut_maxTaxIsZero(uint128 surplus, uint128 totalSupply, uint128 cashOutCount) public pure {
153
- vm.assume(surplus > 0);
154
- vm.assume(totalSupply > 0);
155
- vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
156
-
157
- uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, MAX_TAX);
158
- assertEq(result, 0, "Max tax rate should return 0");
159
- }
160
-
161
- // =========================================================================
162
- // Property 5: No-arbitrage (subadditivity)
163
- // =========================================================================
164
- /// @notice Splitting a cash out into two parts should never yield more than a single cash out.
165
- /// cashOutFrom(S, a, T, r) + cashOutFrom(S', b, T', r) <= cashOutFrom(S, a+b, T, r)
166
- /// where S' = S - cashOutFrom(S, a, T, r) and T' = T - a
167
- // forge-lint: disable-next-line(mixed-case-function)
168
- function check_cashOut_noArbitrage(
169
- uint256 surplus,
170
- uint256 a,
171
- uint256 b,
172
- uint256 totalSupply,
173
- uint256 cashOutTaxRate
174
- )
175
- public
176
- pure
177
- {
178
- vm.assume(surplus > 0 && surplus <= type(uint96).max);
179
- vm.assume(totalSupply > 0 && totalSupply <= type(uint96).max);
180
- vm.assume(a > 0 && b > 0);
181
- vm.assume(a + b <= totalSupply);
182
- vm.assume(cashOutTaxRate <= MAX_TAX);
183
- vm.assume(cashOutTaxRate < MAX_TAX); // Exclude 100% tax (trivially 0)
184
-
185
- // Single cash out of a+b
186
- uint256 singleResult = JBCashOuts.cashOutFrom(surplus, a + b, totalSupply, cashOutTaxRate);
187
-
188
- // First part: cash out a
189
- uint256 firstResult = JBCashOuts.cashOutFrom(surplus, a, totalSupply, cashOutTaxRate);
190
-
191
- // After first cash out: reduced surplus and supply
192
- uint256 remainingSurplus = surplus - firstResult;
193
- uint256 remainingSupply = totalSupply - a;
194
-
195
- // Second part: cash out b from remaining state
196
- uint256 secondResult = JBCashOuts.cashOutFrom(remainingSurplus, b, remainingSupply, cashOutTaxRate);
197
-
198
- // NOTE: Strict subadditivity (firstResult + secondResult <= singleResult) was proven to be
199
- // violated due to mulDiv rounding accumulation.
200
- // The violation is bounded by rounding precision and is economically insignificant (~0.00001%).
201
- // We verify the weaker property: the excess is bounded by rounding tolerance.
202
- if (firstResult + secondResult > singleResult) {
203
- // The excess should be tiny relative to the result
204
- uint256 excess = (firstResult + secondResult) - singleResult;
205
- // Allow up to 2 wei absolute (for small values) or 0.01% relative
206
- assert(excess <= 2 || excess * 10_000 <= singleResult);
207
- }
208
- }
209
-
210
- function testFuzz_cashOut_noArbitrage(
211
- uint96 surplus,
212
- uint96 totalSupply,
213
- uint96 a,
214
- uint96 b,
215
- uint16 cashOutTaxRate
216
- )
217
- public
218
- pure
219
- {
220
- vm.assume(surplus > 0);
221
- vm.assume(totalSupply > 0);
222
- vm.assume(a > 0 && b > 0);
223
- vm.assume(uint256(a) + uint256(b) <= totalSupply);
224
- vm.assume(cashOutTaxRate <= MAX_TAX);
225
- vm.assume(cashOutTaxRate < MAX_TAX);
226
-
227
- uint256 singleResult = JBCashOuts.cashOutFrom(surplus, uint256(a) + b, totalSupply, cashOutTaxRate);
228
- uint256 firstResult = JBCashOuts.cashOutFrom(surplus, a, totalSupply, cashOutTaxRate);
229
-
230
- uint256 remainingSurplus = surplus - firstResult;
231
- uint256 remainingSupply = totalSupply - a;
232
-
233
- uint256 secondResult = JBCashOuts.cashOutFrom(remainingSurplus, b, remainingSupply, cashOutTaxRate);
234
-
235
- // NOTE: Strict subadditivity violated due to mulDiv rounding.
236
- // Verify the weaker property: excess bounded by rounding tolerance (<=2 wei or < 0.01%).
237
- if (firstResult + secondResult > singleResult) {
238
- uint256 excess = (firstResult + secondResult) - singleResult;
239
- assertTrue(
240
- excess <= 2 || excess * 10_000 <= singleResult,
241
- "No-arbitrage: rounding excess should be <= 2 wei or < 0.01%"
242
- );
243
- }
244
- }
245
-
246
- // =========================================================================
247
- // Property 6: Fee round-trip — fee amounts are consistent
248
- // =========================================================================
249
- /// @notice The forward and reverse fee functions should be consistent:
250
- /// amount - feeAmountFrom(amount, fee) + feeAmountResultingIn(net, fee) >= feeAmountFrom(amount, fee)
251
- /// where net = amount - feeAmountFrom(amount, fee)
252
- // forge-lint: disable-next-line(mixed-case-function)
253
- function check_fee_roundTrip(uint256 amount, uint256 feePercent) public pure {
254
- vm.assume(amount > 0 && amount <= type(uint128).max);
255
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
256
-
257
- uint256 feeForward = JBFees.feeAmountFrom(amount, feePercent);
258
- uint256 netAmount = amount - feeForward;
259
-
260
- // Reverse fee: what fee would result in netAmount after deduction?
261
- uint256 feeReverse = JBFees.feeAmountResultingIn(netAmount, feePercent);
262
-
263
- // The reverse fee should be >= the forward fee (due to rounding direction)
264
- // This ensures the protocol never undercharges
265
- assert(feeReverse >= feeForward);
266
- }
267
-
268
- function testFuzz_fee_roundTrip(uint128 amount, uint16 feePercent) public pure {
269
- vm.assume(amount > 0);
270
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
271
-
272
- uint256 feeForward = JBFees.feeAmountFrom(amount, feePercent);
273
- uint256 netAmount = amount - feeForward;
274
-
275
- uint256 feeReverse = JBFees.feeAmountResultingIn(netAmount, feePercent);
276
-
277
- assertGe(feeReverse, feeForward, "Fee round-trip: reverse fee should be >= forward fee");
278
- }
279
-
280
- // =========================================================================
281
- // Property 7: Metadata packing round-trip
282
- // =========================================================================
283
- /// @notice packRulesetMetadata(m) → expandMetadata should return the original metadata.
284
- // forge-lint: disable-next-line(mixed-case-function)
285
- function check_metadataPacking_roundTrip(
286
- uint16 reservedPercent,
287
- uint16 cashOutTaxRate,
288
- uint32 baseCurrency,
289
- uint16 boolFlags, // Pack 14 bools into a uint16
290
- address dataHook,
291
- uint16 extraMetadata
292
- )
293
- public
294
- pure
295
- {
296
- vm.assume(reservedPercent <= 10_000);
297
- vm.assume(cashOutTaxRate <= 10_000);
298
- vm.assume(extraMetadata <= 0x3FFF);
299
-
300
- JBRulesetMetadata memory original = JBRulesetMetadata({
301
- reservedPercent: reservedPercent,
302
- cashOutTaxRate: cashOutTaxRate,
303
- baseCurrency: baseCurrency,
304
- pausePay: boolFlags & 1 != 0,
305
- pauseCreditTransfers: boolFlags & 2 != 0,
306
- allowOwnerMinting: boolFlags & 4 != 0,
307
- allowSetCustomToken: boolFlags & 8 != 0,
308
- allowTerminalMigration: boolFlags & 16 != 0,
309
- allowSetTerminals: boolFlags & 32 != 0,
310
- allowSetController: boolFlags & 64 != 0,
311
- allowAddAccountingContext: boolFlags & 128 != 0,
312
- allowAddPriceFeed: boolFlags & 256 != 0,
313
- ownerMustSendPayouts: boolFlags & 512 != 0,
314
- holdFees: boolFlags & 1024 != 0,
315
- useTotalSurplusForCashOuts: boolFlags & 2048 != 0,
316
- useDataHookForPay: boolFlags & 4096 != 0,
317
- useDataHookForCashOut: boolFlags & 8192 != 0,
318
- dataHook: dataHook,
319
- metadata: extraMetadata
320
- });
321
-
322
- uint256 packed = JBRulesetMetadataResolver.packRulesetMetadata(original);
323
-
324
- JBRuleset memory ruleset;
325
- ruleset.metadata = packed;
326
-
327
- JBRulesetMetadata memory roundTripped = JBRulesetMetadataResolver.expandMetadata(ruleset);
328
-
329
- assert(roundTripped.reservedPercent == original.reservedPercent);
330
- assert(roundTripped.cashOutTaxRate == original.cashOutTaxRate);
331
- assert(roundTripped.baseCurrency == original.baseCurrency);
332
- assert(roundTripped.pausePay == original.pausePay);
333
- assert(roundTripped.pauseCreditTransfers == original.pauseCreditTransfers);
334
- assert(roundTripped.allowOwnerMinting == original.allowOwnerMinting);
335
- assert(roundTripped.allowSetCustomToken == original.allowSetCustomToken);
336
- assert(roundTripped.allowTerminalMigration == original.allowTerminalMigration);
337
- assert(roundTripped.allowSetTerminals == original.allowSetTerminals);
338
- assert(roundTripped.allowSetController == original.allowSetController);
339
- assert(roundTripped.allowAddAccountingContext == original.allowAddAccountingContext);
340
- assert(roundTripped.allowAddPriceFeed == original.allowAddPriceFeed);
341
- assert(roundTripped.ownerMustSendPayouts == original.ownerMustSendPayouts);
342
- assert(roundTripped.holdFees == original.holdFees);
343
- assert(roundTripped.useTotalSurplusForCashOuts == original.useTotalSurplusForCashOuts);
344
- assert(roundTripped.useDataHookForPay == original.useDataHookForPay);
345
- assert(roundTripped.useDataHookForCashOut == original.useDataHookForCashOut);
346
- assert(roundTripped.dataHook == original.dataHook);
347
- assert(roundTripped.metadata == original.metadata);
348
- }
349
-
350
- function testFuzz_metadataPacking_roundTrip(
351
- uint16 reservedPercent,
352
- uint16 cashOutTaxRate,
353
- uint32 baseCurrency,
354
- uint16 boolFlags, // Pack 14 bools into a uint16
355
- address dataHook,
356
- uint16 extraMetadata
357
- )
358
- public
359
- pure
360
- {
361
- vm.assume(reservedPercent <= 10_000);
362
- vm.assume(cashOutTaxRate <= 10_000);
363
- vm.assume(extraMetadata <= 0x3FFF);
364
-
365
- JBRulesetMetadata memory original = JBRulesetMetadata({
366
- reservedPercent: reservedPercent,
367
- cashOutTaxRate: cashOutTaxRate,
368
- baseCurrency: baseCurrency,
369
- pausePay: boolFlags & 1 != 0,
370
- pauseCreditTransfers: boolFlags & 2 != 0,
371
- allowOwnerMinting: boolFlags & 4 != 0,
372
- allowSetCustomToken: boolFlags & 8 != 0,
373
- allowTerminalMigration: boolFlags & 16 != 0,
374
- allowSetTerminals: boolFlags & 32 != 0,
375
- allowSetController: boolFlags & 64 != 0,
376
- allowAddAccountingContext: boolFlags & 128 != 0,
377
- allowAddPriceFeed: boolFlags & 256 != 0,
378
- ownerMustSendPayouts: boolFlags & 512 != 0,
379
- holdFees: boolFlags & 1024 != 0,
380
- useTotalSurplusForCashOuts: boolFlags & 2048 != 0,
381
- useDataHookForPay: boolFlags & 4096 != 0,
382
- useDataHookForCashOut: boolFlags & 8192 != 0,
383
- dataHook: dataHook,
384
- metadata: extraMetadata
385
- });
386
-
387
- uint256 packed = JBRulesetMetadataResolver.packRulesetMetadata(original);
388
-
389
- JBRuleset memory ruleset;
390
- ruleset.metadata = packed;
391
-
392
- JBRulesetMetadata memory result = JBRulesetMetadataResolver.expandMetadata(ruleset);
393
-
394
- assertEq(result.reservedPercent, original.reservedPercent, "reservedPercent mismatch");
395
- assertEq(result.cashOutTaxRate, original.cashOutTaxRate, "cashOutTaxRate mismatch");
396
- assertEq(result.baseCurrency, original.baseCurrency, "baseCurrency mismatch");
397
- assertEq(result.pausePay, original.pausePay, "pausePay mismatch");
398
- assertEq(result.pauseCreditTransfers, original.pauseCreditTransfers, "pauseCreditTransfers mismatch");
399
- assertEq(result.allowOwnerMinting, original.allowOwnerMinting, "allowOwnerMinting mismatch");
400
- assertEq(result.allowSetCustomToken, original.allowSetCustomToken, "allowSetCustomToken mismatch");
401
- assertEq(result.allowTerminalMigration, original.allowTerminalMigration, "allowTerminalMigration mismatch");
402
- assertEq(result.allowSetTerminals, original.allowSetTerminals, "allowSetTerminals mismatch");
403
- assertEq(result.allowSetController, original.allowSetController, "allowSetController mismatch");
404
- assertEq(
405
- result.allowAddAccountingContext, original.allowAddAccountingContext, "allowAddAccountingContext mismatch"
406
- );
407
- assertEq(result.allowAddPriceFeed, original.allowAddPriceFeed, "allowAddPriceFeed mismatch");
408
- assertEq(result.ownerMustSendPayouts, original.ownerMustSendPayouts, "ownerMustSendPayouts mismatch");
409
- assertEq(result.holdFees, original.holdFees, "holdFees mismatch");
410
- assertEq(
411
- result.useTotalSurplusForCashOuts,
412
- original.useTotalSurplusForCashOuts,
413
- "useTotalSurplusForCashOuts mismatch"
414
- );
415
- assertEq(result.useDataHookForPay, original.useDataHookForPay, "useDataHookForPay mismatch");
416
- assertEq(result.useDataHookForCashOut, original.useDataHookForCashOut, "useDataHookForCashOut mismatch");
417
- assertEq(result.dataHook, original.dataHook, "dataHook mismatch");
418
- assertEq(result.metadata, original.metadata, "metadata mismatch");
419
- }
420
- }
@@ -1,252 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.17;
3
-
4
- import {Test} from "forge-std/Test.sol";
5
- import {JBFees} from "../../src/libraries/JBFees.sol";
6
- import {JBConstants} from "../../src/libraries/JBConstants.sol";
7
-
8
- /// @title FeeProperties
9
- /// @notice Formal verification of fee arithmetic properties using symbolic execution.
10
- /// @dev Works with both Halmos (check_* pattern) and forge test (testFuzz_* pattern).
11
- /// Each property is dual-implemented: `check_` for Halmos and `testFuzz_` for forge.
12
- contract FeeProperties is Test {
13
- uint256 constant MAX_FEE = JBConstants.MAX_FEE; // 1_000
14
-
15
- // =========================================================================
16
- // Property 1: Fee additivity error bound
17
- // =========================================================================
18
- /// @notice feeAmountFrom(a+b, fee) vs feeAmountFrom(a, fee) + feeAmountFrom(b, fee)
19
- /// differ by at most 1 wei due to mulDiv rounding.
20
- // forge-lint: disable-next-line(mixed-case-function)
21
- function check_fee_additivity(uint256 a, uint256 b, uint256 feePercent) public pure {
22
- vm.assume(a > 0 && b > 0);
23
- vm.assume(a <= type(uint128).max && b <= type(uint128).max);
24
- vm.assume(a + b <= type(uint128).max); // No overflow
25
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
26
-
27
- uint256 feeCombined = JBFees.feeAmountFrom(a + b, feePercent);
28
- uint256 feeSeparate = JBFees.feeAmountFrom(a, feePercent) + JBFees.feeAmountFrom(b, feePercent);
29
-
30
- // The difference should be at most 1 wei
31
- if (feeCombined >= feeSeparate) {
32
- assert(feeCombined - feeSeparate <= 1);
33
- } else {
34
- assert(feeSeparate - feeCombined <= 1);
35
- }
36
- }
37
-
38
- function testFuzz_fee_additivity(uint128 a, uint128 b, uint16 feePercent) public pure {
39
- vm.assume(a > 0 && b > 0);
40
- vm.assume(uint256(a) + uint256(b) <= type(uint128).max);
41
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
42
-
43
- uint256 feeCombined = JBFees.feeAmountFrom(uint256(a) + uint256(b), feePercent);
44
- uint256 feeSeparate = JBFees.feeAmountFrom(a, feePercent) + JBFees.feeAmountFrom(b, feePercent);
45
-
46
- uint256 diff = feeCombined >= feeSeparate ? feeCombined - feeSeparate : feeSeparate - feeCombined;
47
-
48
- assertLe(diff, 1, "Additivity: fee(a+b) and fee(a)+fee(b) should differ by at most 1 wei");
49
- }
50
-
51
- // =========================================================================
52
- // Property 2: Return fee consistency (protocol never undercharges)
53
- // =========================================================================
54
- /// @notice feeAmountResultingIn(netAmount, fee) >= feeAmountFrom(netAmount + feeAmountResultingIn(netAmount, fee),
55
- // fee) / The reverse fee is always >= the forward fee on the gross amount, ensuring
56
- /// the protocol never undercharges when returning held fees.
57
- // forge-lint: disable-next-line(mixed-case-function)
58
- function check_fee_returnConsistency(uint256 netAmount, uint256 feePercent) public pure {
59
- vm.assume(netAmount > 0 && netAmount <= type(uint128).max);
60
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
61
-
62
- uint256 reverseFee = JBFees.feeAmountResultingIn(netAmount, feePercent);
63
- uint256 grossAmount = netAmount + reverseFee;
64
- uint256 forwardFee = JBFees.feeAmountFrom(grossAmount, feePercent);
65
-
66
- // The reverse fee should be >= the forward fee on the reconstructed gross
67
- // This means the protocol never undercharges
68
- assert(reverseFee >= forwardFee);
69
- }
70
-
71
- function testFuzz_fee_returnConsistency(uint128 netAmount, uint16 feePercent) public pure {
72
- vm.assume(netAmount > 0);
73
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
74
-
75
- uint256 reverseFee = JBFees.feeAmountResultingIn(netAmount, feePercent);
76
- uint256 grossAmount = uint256(netAmount) + reverseFee;
77
- uint256 forwardFee = JBFees.feeAmountFrom(grossAmount, feePercent);
78
-
79
- assertGe(
80
- reverseFee,
81
- forwardFee,
82
- "Return consistency: reverse fee should be >= forward fee (protocol never undercharges)"
83
- );
84
- }
85
-
86
- // =========================================================================
87
- // Property 3: Fee-return round trip (reconstructed gross >= original, bounded overshoot)
88
- // =========================================================================
89
- /// @notice Take fee: fee1 = feeAmountFrom(amount, feePercent), net = amount - fee1.
90
- /// Return fee: fee2 = feeAmountResultingIn(net, feePercent).
91
- /// The reconstructed gross (net + fee2) should always be >= the original amount
92
- /// (protocol never undercharges on fee return).
93
- /// The overshoot is bounded by MAX_FEE / (MAX_FEE - feePercent): the rounding
94
- /// error in fee1 (at most 1 wei of net) gets amplified by the fee ratio when
95
- /// computing the reverse fee, plus 1 for the reverse mulDiv rounding itself.
96
- // forge-lint: disable-next-line(mixed-case-function)
97
- function check_fee_roundTrip(uint256 amount, uint256 feePercent) public pure {
98
- vm.assume(amount > 0 && amount <= type(uint128).max);
99
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
100
-
101
- uint256 fee1 = JBFees.feeAmountFrom(amount, feePercent);
102
- uint256 net = amount - fee1;
103
-
104
- uint256 fee2 = JBFees.feeAmountResultingIn(net, feePercent);
105
-
106
- // Reconstructed gross should always be >= original (never undercharge)
107
- assert(net + fee2 >= amount);
108
-
109
- // Overshoot is bounded by the fee ratio amplification of rounding error.
110
- // The forward mulDiv floors by at most 1, making net up to 1 too large.
111
- // The reverse multiplies net by MAX_FEE/(MAX_FEE-fee), amplifying that error.
112
- uint256 maxOvershoot = MAX_FEE / (MAX_FEE - feePercent) + 1;
113
- assert(net + fee2 <= amount + maxOvershoot);
114
- }
115
-
116
- function testFuzz_fee_roundTrip(uint128 amount, uint16 feePercent) public pure {
117
- vm.assume(amount > 0);
118
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
119
-
120
- uint256 fee1 = JBFees.feeAmountFrom(amount, feePercent);
121
- uint256 net = uint256(amount) - fee1;
122
-
123
- uint256 fee2 = JBFees.feeAmountResultingIn(net, feePercent);
124
-
125
- assertGe(net + fee2, amount, "Round trip: reconstructed gross should be >= original (never undercharge)");
126
-
127
- uint256 maxOvershoot = MAX_FEE / (MAX_FEE - uint256(feePercent)) + 1;
128
- assertLe(
129
- net + fee2,
130
- uint256(amount) + maxOvershoot,
131
- "Round trip: overshoot should be bounded by fee ratio amplification"
132
- );
133
- }
134
-
135
- // =========================================================================
136
- // Property 4: Partial return monotonicity
137
- // =========================================================================
138
- /// @notice feeAmountResultingIn(a, fee) <= feeAmountResultingIn(b, fee) when a <= b.
139
- // forge-lint: disable-next-line(mixed-case-function)
140
- function check_fee_partialReturnMonotonicity(uint256 a, uint256 b, uint256 feePercent) public pure {
141
- vm.assume(a > 0 && b > 0);
142
- vm.assume(a <= type(uint128).max && b <= type(uint128).max);
143
- vm.assume(a <= b);
144
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
145
-
146
- uint256 feeA = JBFees.feeAmountResultingIn(a, feePercent);
147
- uint256 feeB = JBFees.feeAmountResultingIn(b, feePercent);
148
-
149
- assert(feeA <= feeB);
150
- }
151
-
152
- function testFuzz_fee_partialReturnMonotonicity(uint128 a, uint128 b, uint16 feePercent) public pure {
153
- vm.assume(a > 0 && b > 0);
154
- if (a > b) (a, b) = (b, a); // Ensure a <= b
155
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
156
-
157
- uint256 feeA = JBFees.feeAmountResultingIn(a, feePercent);
158
- uint256 feeB = JBFees.feeAmountResultingIn(b, feePercent);
159
-
160
- assertLe(feeA, feeB, "Monotonicity: feeAmountResultingIn(a) <= feeAmountResultingIn(b) when a <= b");
161
- }
162
-
163
- // =========================================================================
164
- // Property 5: Held fee subtraction safety (fee never exceeds amount)
165
- // =========================================================================
166
- /// @notice For any heldFeeAmount > 0 and valid feePercent:
167
- /// fee = feeAmountFrom(heldFeeAmount, feePercent) <= heldFeeAmount.
168
- /// This guarantees leftover = heldFeeAmount - fee never underflows, and
169
- /// leftover + fee == heldFeeAmount (exact decomposition).
170
- // forge-lint: disable-next-line(mixed-case-function)
171
- function check_fee_subtractionSafety(uint256 heldFeeAmount, uint256 feePercent) public pure {
172
- vm.assume(heldFeeAmount > 0 && heldFeeAmount <= type(uint128).max);
173
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
174
-
175
- uint256 fee = JBFees.feeAmountFrom(heldFeeAmount, feePercent);
176
-
177
- // Fee must never exceed the held amount (no underflow on subtraction)
178
- assert(fee <= heldFeeAmount);
179
-
180
- // Exact decomposition: leftover + fee == heldFeeAmount
181
- uint256 leftover = heldFeeAmount - fee;
182
- assert(leftover + fee == heldFeeAmount);
183
- }
184
-
185
- function testFuzz_fee_subtractionSafety(uint128 heldFeeAmount, uint16 feePercent) public pure {
186
- vm.assume(heldFeeAmount > 0);
187
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
188
-
189
- uint256 fee = JBFees.feeAmountFrom(heldFeeAmount, feePercent);
190
-
191
- assertLe(fee, heldFeeAmount, "Subtraction safety: fee should never exceed held amount");
192
-
193
- uint256 leftover = uint256(heldFeeAmount) - fee;
194
- assertEq(leftover + fee, heldFeeAmount, "Subtraction safety: leftover + fee should exactly equal held amount");
195
- }
196
-
197
- // =========================================================================
198
- // Property 6: Multi-split fee accumulation error bound
199
- // =========================================================================
200
- /// @notice After N splits each paying fee, total fee error vs single-payment fee
201
- /// is bounded by N wei. For N=10: sum(feeAmountFrom(amount/N, fee), N times)
202
- /// vs feeAmountFrom(amount, fee) differ by at most N.
203
- // forge-lint: disable-next-line(mixed-case-function)
204
- function check_fee_multiSplitAccumulation(uint256 amount, uint256 feePercent) public pure {
205
- vm.assume(amount >= 10); // Must be divisible into 10 parts
206
- vm.assume(amount <= type(uint128).max);
207
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
208
-
209
- uint256 N = 10;
210
- uint256 perSplit = amount / N;
211
- uint256 remainder = amount - (perSplit * N);
212
-
213
- // Single fee on total amount
214
- uint256 singleFee = JBFees.feeAmountFrom(amount, feePercent);
215
-
216
- // Sum of fees on each split
217
- uint256 splitFeeSum = 0;
218
- for (uint256 i = 0; i < N; i++) {
219
- // Last split gets any remainder from integer division
220
- uint256 splitAmount = (i == N - 1) ? perSplit + remainder : perSplit;
221
- splitFeeSum += JBFees.feeAmountFrom(splitAmount, feePercent);
222
- }
223
-
224
- // Difference should be bounded by N
225
- if (singleFee >= splitFeeSum) {
226
- assert(singleFee - splitFeeSum <= N);
227
- } else {
228
- assert(splitFeeSum - singleFee <= N);
229
- }
230
- }
231
-
232
- function testFuzz_fee_multiSplitAccumulation(uint128 amount, uint16 feePercent) public pure {
233
- vm.assume(amount >= 10);
234
- vm.assume(feePercent > 0 && feePercent < MAX_FEE);
235
-
236
- uint256 N = 10;
237
- uint256 perSplit = uint256(amount) / N;
238
- uint256 remainder = uint256(amount) - (perSplit * N);
239
-
240
- uint256 singleFee = JBFees.feeAmountFrom(amount, feePercent);
241
-
242
- uint256 splitFeeSum = 0;
243
- for (uint256 i = 0; i < N; i++) {
244
- uint256 splitAmount = (i == N - 1) ? perSplit + remainder : perSplit;
245
- splitFeeSum += JBFees.feeAmountFrom(splitAmount, feePercent);
246
- }
247
-
248
- uint256 diff = singleFee >= splitFeeSum ? singleFee - splitFeeSum : splitFeeSum - singleFee;
249
-
250
- assertLe(diff, N, "Multi-split accumulation: total rounding error should be bounded by N wei");
251
- }
252
- }