@bananapus/core-v6 0.0.37 → 0.0.39
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.
- package/foundry.lock +1 -7
- package/foundry.toml +1 -1
- package/package.json +19 -7
- package/src/JBChainlinkV3PriceFeed.sol +4 -1
- package/src/JBChainlinkV3SequencerPriceFeed.sol +4 -2
- package/src/JBController.sol +71 -44
- package/src/JBDeadline.sol +4 -4
- package/src/JBDirectory.sol +34 -32
- package/src/JBERC20.sol +5 -4
- package/src/JBFeelessAddresses.sol +6 -3
- package/src/JBFundAccessLimits.sol +25 -21
- package/src/JBMultiTerminal.sol +121 -84
- package/src/JBPermissions.sol +34 -37
- package/src/JBPrices.sol +23 -18
- package/src/JBProjects.sol +6 -3
- package/src/JBRulesets.sol +44 -41
- package/src/JBSplits.sol +18 -16
- package/src/JBTerminalStore.sol +32 -25
- package/src/JBTokens.sol +36 -26
- package/src/abstract/JBControlled.sol +3 -1
- package/src/abstract/JBPermissioned.sol +3 -1
- package/src/enums/JBApprovalStatus.sol +7 -1
- package/src/interfaces/IJBController.sol +7 -3
- package/src/interfaces/IJBDirectory.sol +3 -1
- package/src/interfaces/IJBMultiTerminal.sol +3 -2
- package/src/interfaces/IJBPermissions.sol +2 -1
- package/src/interfaces/IJBPrices.sol +3 -1
- package/src/interfaces/IJBRulesets.sol +2 -1
- package/src/interfaces/IJBSplits.sol +2 -1
- package/src/interfaces/IJBTerminal.sol +3 -1
- package/src/interfaces/IJBTerminalStore.sol +3 -1
- package/src/interfaces/IJBTokens.sol +2 -1
- package/src/libraries/JBCashOuts.sol +6 -1
- package/src/libraries/JBConstants.sol +12 -3
- package/src/libraries/JBCurrencyIds.sol +2 -0
- package/src/libraries/JBFees.sol +52 -10
- package/src/libraries/JBFixedPointNumber.sol +2 -0
- package/src/libraries/JBPayoutSplitGroupLib.sol +7 -4
- package/src/libraries/JBRulesetMetadataResolver.sol +4 -0
- package/src/libraries/JBSplitGroupIds.sol +2 -1
- package/src/libraries/JBSurplus.sol +3 -1
- package/src/periphery/JBMatchingPriceFeed.sol +3 -1
- package/src/structs/JBAccountingContext.sol +7 -4
- package/src/structs/JBFundAccessLimitGroup.sol +10 -17
- package/src/structs/JBRuleset.sol +18 -26
- package/src/structs/JBRulesetConfig.sol +13 -25
- package/src/structs/JBRulesetMetadata.sol +25 -32
- package/test/mock/MockMaliciousBeneficiary.sol +15 -15
- package/ADMINISTRATION.md +0 -103
- package/ARCHITECTURE.md +0 -133
- package/AUDIT_INSTRUCTIONS.md +0 -139
- package/RISKS.md +0 -215
- package/SKILLS.md +0 -55
- package/STYLE_GUIDE.md +0 -610
- package/USER_JOURNEYS.md +0 -215
- package/script/Deploy.s.sol +0 -124
- package/script/DeployPeriphery.s.sol +0 -354
- package/slither-ci.config.json +0 -10
- package/test/AuditFixes.t.sol +0 -808
- package/test/ComprehensiveInvariant.t.sol +0 -306
- package/test/CoreExploitTests.t.sol +0 -2741
- package/test/EconomicSimulation.t.sol +0 -348
- package/test/EntryPointPermutations.t.sol +0 -684
- package/test/FlashLoanAttacks.t.sol +0 -797
- package/test/PermissionEscalation.t.sol +0 -711
- package/test/PermissionsInvariant.t.sol +0 -403
- package/test/RulesetTransitions.t.sol +0 -713
- package/test/SplitLoopTests.t.sol +0 -752
- package/test/TestAccessToFunds.sol +0 -2683
- package/test/TestAuditResponseDesignProofs.sol +0 -434
- package/test/TestCashOut.sol +0 -198
- package/test/TestCashOutCountFor.sol +0 -271
- package/test/TestCashOutHooks.sol +0 -351
- package/test/TestCashOutTimingEdge.sol +0 -241
- package/test/TestDataHookFuzzing.sol +0 -524
- package/test/TestDurationUnderflow.sol +0 -233
- package/test/TestFeeFreeCashOutBypass.sol +0 -949
- package/test/TestFeeProcessingFailure.sol +0 -218
- package/test/TestFees.sol +0 -619
- package/test/TestForwardedTokenConsumption.sol +0 -425
- package/test/TestInterfaceSupport.sol +0 -81
- package/test/TestJBERC20Inheritance.sol +0 -103
- package/test/TestL2SequencerPriceFeed.sol +0 -292
- package/test/TestLaunchProject.sol +0 -188
- package/test/TestMetaTx.sol +0 -217
- package/test/TestMetadataOffsetOverflow.sol +0 -179
- package/test/TestMetadataParserLib.sol +0 -471
- package/test/TestMigrationHeldFees.sol +0 -255
- package/test/TestMintTokensOf.sol +0 -185
- package/test/TestMultiTerminalSurplus.sol +0 -348
- package/test/TestMultiTokenSurplus.sol +0 -202
- package/test/TestMultipleAccessLimits.sol +0 -664
- package/test/TestPayBurnRedeemFlow.sol +0 -195
- package/test/TestPayHooks.sol +0 -209
- package/test/TestPermissions.sol +0 -324
- package/test/TestPermissionsEdge.sol +0 -290
- package/test/TestPermit2DataHook.t.sol +0 -360
- package/test/TestPermit2Terminal.sol +0 -372
- package/test/TestRulesetQueueing.sol +0 -1025
- package/test/TestRulesetQueuingStress.sol +0 -806
- package/test/TestRulesetWeightCaching.sol +0 -178
- package/test/TestSplits.sol +0 -391
- package/test/TestTerminalMigration.sol +0 -274
- package/test/TestTerminalPreviewParity.sol +0 -208
- package/test/TestTokenFlow.sol +0 -191
- package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
- package/test/WeirdTokenTests.t.sol +0 -817
- package/test/audit/CashOutReenterPay.t.sol +0 -501
- package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
- package/test/audit/CodexMigrationFeeFailure.t.sol +0 -163
- package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
- package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
- package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
- package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
- package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
- package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
- package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
- package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
- package/test/formal/BondingCurveProperties.t.sol +0 -420
- package/test/formal/FeeProperties.t.sol +0 -252
- package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
- package/test/invariants/RulesetsInvariant.t.sol +0 -125
- package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
- package/test/invariants/TokensInvariant.t.sol +0 -195
- package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
- package/test/invariants/handlers/EconomicHandler.sol +0 -377
- package/test/invariants/handlers/Phase3Handler.sol +0 -443
- package/test/invariants/handlers/RulesetsHandler.sol +0 -115
- package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
- package/test/invariants/handlers/TokensHandler.sol +0 -126
- package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
- package/test/regression/WeightCacheBoundary.t.sol +0 -291
- package/test/trees/JBController/burnTokensOf.tree +0 -9
- package/test/trees/JBController/claimTokensFor.tree +0 -5
- package/test/trees/JBController/deployERC20For.tree +0 -5
- package/test/trees/JBController/getRulesetOf.tree +0 -5
- package/test/trees/JBController/launchProjectFor.tree +0 -12
- package/test/trees/JBController/launchRulesetsFor.tree +0 -8
- package/test/trees/JBController/migrateController.tree +0 -12
- package/test/trees/JBController/mintTokensOf.tree +0 -12
- package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
- package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
- package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
- package/test/trees/JBController/setMetadataOf.tree +0 -5
- package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
- package/test/trees/JBController/setTokenFor.tree +0 -5
- package/test/trees/JBController/transferCreditsFrom.tree +0 -8
- package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
- package/test/trees/JBDirectory/setControllerOf.tree +0 -11
- package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
- package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
- package/test/trees/JBERC20/initialize.tree +0 -7
- package/test/trees/JBERC20/name.tree +0 -5
- package/test/trees/JBERC20/nonces.tree +0 -5
- package/test/trees/JBERC20/symbol.tree +0 -5
- package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
- package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
- package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
- package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
- package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
- package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
- package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
- package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
- package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
- package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
- package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
- package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
- package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
- package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
- package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
- package/test/trees/JBMultiTerminal/pay.tree +0 -23
- package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
- package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
- package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
- package/test/trees/JBPermissions/hasPermission.tree +0 -8
- package/test/trees/JBPermissions/hasPermissions.tree +0 -8
- package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
- package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
- package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
- package/test/trees/JBProjects/createFor.tree +0 -11
- package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
- package/test/trees/JBProjects/supportsInterface.tree +0 -9
- package/test/trees/JBProjects/tokenURI.tree +0 -5
- package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
- package/test/trees/JBRulesets/currentOf.tree +0 -12
- package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
- package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
- package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
- package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
- package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
- package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
- package/test/trees/JBSplits/splitsOf.tree +0 -5
- package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
- package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
- package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
- package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
- package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
- package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
- package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
- package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
- package/test/trees/JBTokens/burnFrom.tree +0 -10
- package/test/trees/JBTokens/claimTokensFor.tree +0 -10
- package/test/trees/JBTokens/deployERC20For.tree +0 -12
- package/test/trees/JBTokens/mintFor.tree +0 -10
- package/test/trees/JBTokens/setTokenFor.tree +0 -11
- package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
- package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
- package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
- package/test/trees/mintTokensOf.tree +0 -12
- package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
- package/test/units/static/JBController/JBControllerSetup.sol +0 -50
- package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
- package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
- package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
- package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
- package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
- package/test/units/static/JBController/TestMigrateController.sol +0 -157
- package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
- package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
- package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
- package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
- package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
- package/test/units/static/JBController/TestRulesetViews.sol +0 -225
- package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
- package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
- package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
- package/test/units/static/JBController/TestSetUriOf.sol +0 -57
- package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
- package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
- package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
- package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
- package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
- package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
- package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
- package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
- package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
- package/test/units/static/JBERC20/SigUtils.sol +0 -36
- package/test/units/static/JBERC20/TestInitialize.sol +0 -60
- package/test/units/static/JBERC20/TestName.sol +0 -30
- package/test/units/static/JBERC20/TestNonces.sol +0 -62
- package/test/units/static/JBERC20/TestSymbol.sol +0 -31
- package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
- package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
- package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
- package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
- package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
- package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
- package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
- package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
- package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
- package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
- package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
- package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
- package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
- package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
- package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
- package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
- package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
- package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
- package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
- package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
- package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
- package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
- package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
- package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
- package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
- package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
- package/test/units/static/JBPrices/TestPrices.sol +0 -265
- package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
- package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
- package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
- package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
- package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
- package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
- package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
- package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
- package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
- package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
- package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
- package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
- package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
- package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
- package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
- package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
- package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
- package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
- package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
- package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
- package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
- package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
- package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
- package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
- package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
- package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
- package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
- package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
- package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
- package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
- package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
- package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
- package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
- package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
- package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
- package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
- package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
- package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
- package/test/units/static/JBTokens/TestMintFor.sol +0 -100
- package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
- package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
- package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
- package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
import {Test} from "forge-std/Test.sol";
|
|
5
|
-
import {MetadataResolverHelper} from "./helpers/MetadataResolverHelper.sol";
|
|
6
|
-
import {JBMetadataResolver} from "../src/libraries/JBMetadataResolver.sol";
|
|
7
|
-
|
|
8
|
-
/// @notice Regression test for uint8 overflow in addToMetadata offset increment.
|
|
9
|
-
///
|
|
10
|
-
/// @dev When `addToMetadata` grows the lookup table by one word, it increments every existing
|
|
11
|
-
/// offset byte by 1. If any offset byte is already 255, the old code silently wrapped to 0,
|
|
12
|
-
/// corrupting the lookup table. After the fix it must revert with
|
|
13
|
-
/// `JBMetadataResolver_MetadataTooLong`.
|
|
14
|
-
contract TestMetadataOffsetOverflow is Test {
|
|
15
|
-
MetadataResolverHelper parser;
|
|
16
|
-
|
|
17
|
-
function setUp() external {
|
|
18
|
-
parser = new MetadataResolverHelper();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/// @notice Build metadata whose existing offset byte is 255, then call `addToMetadata` so that
|
|
22
|
-
/// the table must grow by one word. The offset increment (255 + 1) must revert.
|
|
23
|
-
function test_addToMetadata_offsetOverflow_reverts() external {
|
|
24
|
-
// We construct metadata by hand so that an existing offset byte equals 255.
|
|
25
|
-
//
|
|
26
|
-
// Layout:
|
|
27
|
-
// [0..31] 32 bytes reserved (all zeros)
|
|
28
|
-
// [32..36] id1 (4 bytes) + offset1 (1 byte = 255)
|
|
29
|
-
// [37..63] padding (zeros) to fill the first lookup-table word
|
|
30
|
-
//
|
|
31
|
-
// For offset1 = 255, the "data" region notionally starts at byte 255*32 = 8160.
|
|
32
|
-
// We need originalMetadata.length >= 255*32 + 32 = 8192 so the library can compute
|
|
33
|
-
// `numberOfWordslastData` without underflow and the metadata looks structurally valid.
|
|
34
|
-
//
|
|
35
|
-
// The lookup table occupies word 1 (bytes 32..63), so firstOffset = 2 would be
|
|
36
|
-
// the normal case for a single entry fitting in one word. But we're forcing offset1 = 255
|
|
37
|
-
// to trigger the overflow.
|
|
38
|
-
//
|
|
39
|
-
// However, the code path that increments offsets only fires when the new entry does NOT
|
|
40
|
-
// fit in the current last table word (i + TOTAL_ID_SIZE >= firstOffset * WORD_SIZE).
|
|
41
|
-
// With one existing entry (5 bytes at position 32..36) and firstOffset derived from the
|
|
42
|
-
// first entry's offset byte, we need to ensure the table is full enough to trigger growth.
|
|
43
|
-
//
|
|
44
|
-
// Strategy: fill the lookup table so that it occupies exactly `firstOffset - 1` words
|
|
45
|
-
// (i.e. words 1 through firstOffset-1), and the last entry's position is near the end
|
|
46
|
-
// of that region. Then adding one more entry will overflow the table word, triggering
|
|
47
|
-
// the offset increment loop.
|
|
48
|
-
//
|
|
49
|
-
// Simpler approach: pack 6 entries into the table (6 * 5 = 30 bytes, which fills word 1
|
|
50
|
-
// almost completely at bytes 32..61). firstOffset comes from the first entry's offset byte.
|
|
51
|
-
// Set all 6 offset bytes to 255. The table ends at byte 61, and firstOffset = 255 means
|
|
52
|
-
// data starts at 255*32 = 8160. When we add entry 7, position 62 + 5 = 67 >= 255*32
|
|
53
|
-
// is false... so this won't trigger growth.
|
|
54
|
-
//
|
|
55
|
-
// The growth condition is `i + TOTAL_ID_SIZE >= firstOffset * WORD_SIZE` where i is the
|
|
56
|
-
// byte index of the last non-zero byte scanning backward from firstOffset*WORD_SIZE - 1.
|
|
57
|
-
// With firstOffset = 2, data starts at byte 64. 6 entries take bytes 32..61. The 7th
|
|
58
|
-
// entry would start at byte 62, and 62 + 5 = 67 >= 64, triggering growth. But we need
|
|
59
|
-
// offset = 255 to trigger overflow.
|
|
60
|
-
//
|
|
61
|
-
// The key insight: we need firstOffset to be small (so the table is nearly full and growth
|
|
62
|
-
// is triggered), but one of the EXISTING offset bytes to be 255.
|
|
63
|
-
//
|
|
64
|
-
// We can achieve this by:
|
|
65
|
-
// - Having 6 entries in the table (30 bytes, nearly filling one 32-byte word)
|
|
66
|
-
// - firstOffset = 2 (from the first entry, normal for 1 table word)
|
|
67
|
-
// - The last entry has offset byte = 255
|
|
68
|
-
// - We need enough data padding to make the metadata length consistent.
|
|
69
|
-
//
|
|
70
|
-
// Actually, the simplest approach: use createMetadata to build valid metadata with many
|
|
71
|
-
// entries so offsets are high, then manually patch an offset byte to 255. But that's
|
|
72
|
-
// fragile. Instead, let's hand-craft minimal metadata that triggers the exact code path.
|
|
73
|
-
|
|
74
|
-
// Minimal approach: 6 entries in lookup table, first offset = 2.
|
|
75
|
-
// Entry offsets: [2, 3, 4, 5, 6, 255]
|
|
76
|
-
// Data: 5 entries of 1 word each at offsets 2-6, plus a huge gap to offset 255.
|
|
77
|
-
// Total metadata length must be at least 255*32 + 32 = 8192.
|
|
78
|
-
|
|
79
|
-
bytes memory originalMetadata = new bytes(8192);
|
|
80
|
-
|
|
81
|
-
// Word 0 (bytes 0-31): reserved - leave as zeros.
|
|
82
|
-
|
|
83
|
-
// Word 1 (bytes 32-63): lookup table with 6 entries (30 bytes + 2 bytes padding).
|
|
84
|
-
// Entry 1: id=0x11111111, offset=2
|
|
85
|
-
originalMetadata[32] = 0x11;
|
|
86
|
-
originalMetadata[33] = 0x11;
|
|
87
|
-
originalMetadata[34] = 0x11;
|
|
88
|
-
originalMetadata[35] = 0x11;
|
|
89
|
-
originalMetadata[36] = bytes1(uint8(2)); // offset = 2
|
|
90
|
-
|
|
91
|
-
// Entry 2: id=0x22222222, offset=3
|
|
92
|
-
originalMetadata[37] = 0x22;
|
|
93
|
-
originalMetadata[38] = 0x22;
|
|
94
|
-
originalMetadata[39] = 0x22;
|
|
95
|
-
originalMetadata[40] = 0x22;
|
|
96
|
-
originalMetadata[41] = bytes1(uint8(3)); // offset = 3
|
|
97
|
-
|
|
98
|
-
// Entry 3: id=0x33333333, offset=4
|
|
99
|
-
originalMetadata[42] = 0x33;
|
|
100
|
-
originalMetadata[43] = 0x33;
|
|
101
|
-
originalMetadata[44] = 0x33;
|
|
102
|
-
originalMetadata[45] = 0x33;
|
|
103
|
-
originalMetadata[46] = bytes1(uint8(4)); // offset = 4
|
|
104
|
-
|
|
105
|
-
// Entry 4: id=0x44444444, offset=5
|
|
106
|
-
originalMetadata[47] = 0x44;
|
|
107
|
-
originalMetadata[48] = 0x44;
|
|
108
|
-
originalMetadata[49] = 0x44;
|
|
109
|
-
originalMetadata[50] = 0x44;
|
|
110
|
-
originalMetadata[51] = bytes1(uint8(5)); // offset = 5
|
|
111
|
-
|
|
112
|
-
// Entry 5: id=0x55555555, offset=6
|
|
113
|
-
originalMetadata[52] = 0x55;
|
|
114
|
-
originalMetadata[53] = 0x55;
|
|
115
|
-
originalMetadata[54] = 0x55;
|
|
116
|
-
originalMetadata[55] = 0x55;
|
|
117
|
-
originalMetadata[56] = bytes1(uint8(6)); // offset = 6
|
|
118
|
-
|
|
119
|
-
// Entry 6: id=0x66666666, offset=255 -- this is the one that will overflow
|
|
120
|
-
originalMetadata[57] = 0x66;
|
|
121
|
-
originalMetadata[58] = 0x66;
|
|
122
|
-
originalMetadata[59] = 0x66;
|
|
123
|
-
originalMetadata[60] = 0x66;
|
|
124
|
-
originalMetadata[61] = bytes1(uint8(255)); // offset = 255 -- will overflow on increment
|
|
125
|
-
|
|
126
|
-
// Bytes 62-63: padding (zeros) -- already zero.
|
|
127
|
-
|
|
128
|
-
// Fill some data at offset 2 (byte 64) through offset 6 (byte 224) so the structure
|
|
129
|
-
// is valid. Just leave as zeros (already initialized).
|
|
130
|
-
|
|
131
|
-
// Fill one word of data at offset 255 (byte 8160) to make numberOfWordslastData = 1.
|
|
132
|
-
// Just needs to exist in the allocation, which it does since length = 8192.
|
|
133
|
-
originalMetadata[8160] = 0xAB; // Some non-zero data.
|
|
134
|
-
|
|
135
|
-
// The new data to add (must be >= 32 bytes and padded to 32).
|
|
136
|
-
bytes memory dataToAdd = abi.encode(uint256(42));
|
|
137
|
-
|
|
138
|
-
// Now call addToMetadata. The code will:
|
|
139
|
-
// 1. Find firstOffset = 2 (from byte 36)
|
|
140
|
-
// 2. Scan backward from byte 63 to find the last non-zero byte: byte 61 (offset=255)
|
|
141
|
-
// 3. Check if new entry fits: 61 + 5 = 66 >= 2*32 = 64 => YES, table must grow
|
|
142
|
-
// 4. Loop to increment all offset bytes -- byte 61 has value 255, 255+1 overflows!
|
|
143
|
-
//
|
|
144
|
-
// Before the fix: wraps to 0 silently, corrupting the table.
|
|
145
|
-
// After the fix: reverts with JBMetadataResolver_MetadataTooLong.
|
|
146
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_MetadataTooLong.selector);
|
|
147
|
-
parser.addDataToMetadata(originalMetadata, bytes4(0x77777777), dataToAdd);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/// @notice Sanity check: adding to metadata with offset < 255 still works after the fix.
|
|
151
|
-
function test_addToMetadata_offsetNoOverflow_succeeds() external view {
|
|
152
|
-
// Use the library normally: create metadata with a few entries, then add one more.
|
|
153
|
-
bytes4[] memory ids = new bytes4[](2);
|
|
154
|
-
bytes[] memory datas = new bytes[](2);
|
|
155
|
-
|
|
156
|
-
ids[0] = bytes4(0x11111111);
|
|
157
|
-
ids[1] = bytes4(0x22222222);
|
|
158
|
-
datas[0] = abi.encode(uint256(100));
|
|
159
|
-
datas[1] = abi.encode(uint256(200));
|
|
160
|
-
|
|
161
|
-
bytes memory metadata = parser.createMetadata(ids, datas);
|
|
162
|
-
|
|
163
|
-
// Add a third entry -- offsets are small, no overflow.
|
|
164
|
-
bytes memory modified = parser.addDataToMetadata(metadata, bytes4(0x33333333), abi.encode(uint256(300)));
|
|
165
|
-
|
|
166
|
-
// Verify all three entries are retrievable.
|
|
167
|
-
(bool found1, bytes memory data1) = parser.getDataFor(bytes4(0x11111111), modified);
|
|
168
|
-
assertTrue(found1);
|
|
169
|
-
assertEq(abi.decode(data1, (uint256)), 100);
|
|
170
|
-
|
|
171
|
-
(bool found2, bytes memory data2) = parser.getDataFor(bytes4(0x22222222), modified);
|
|
172
|
-
assertTrue(found2);
|
|
173
|
-
assertEq(abi.decode(data2, (uint256)), 200);
|
|
174
|
-
|
|
175
|
-
(bool found3, bytes memory data3) = parser.getDataFor(bytes4(0x33333333), modified);
|
|
176
|
-
assertTrue(found3);
|
|
177
|
-
assertEq(abi.decode(data3, (uint256)), 300);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.28;
|
|
3
|
-
|
|
4
|
-
import {Test} from "forge-std/Test.sol";
|
|
5
|
-
import {MetadataResolverHelper} from "./helpers/MetadataResolverHelper.sol";
|
|
6
|
-
import {JBMetadataResolver} from "../src/libraries/JBMetadataResolver.sol";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @notice Test the `JBDelegateMetadata` library and helper contract.
|
|
10
|
-
*
|
|
11
|
-
* @dev These are a mixed collection of unit and integration tests.
|
|
12
|
-
*/
|
|
13
|
-
contract JBDelegateMetadataLib_Test_Local is Test {
|
|
14
|
-
MetadataResolverHelper parser;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @notice Deploy the helper contract.
|
|
18
|
-
*
|
|
19
|
-
* @dev Helper inherits the lib and add `createMetadata`.
|
|
20
|
-
*/
|
|
21
|
-
function setUp() external {
|
|
22
|
-
parser = new MetadataResolverHelper();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @notice Test the parsing of arbitrary metadata.
|
|
27
|
-
*/
|
|
28
|
-
function test_parse() external view {
|
|
29
|
-
bytes4 _id1 = bytes4(0x11111111);
|
|
30
|
-
bytes4 _id2 = bytes4(0x33333333);
|
|
31
|
-
|
|
32
|
-
uint256 _data1 = 69_696_969;
|
|
33
|
-
bytes memory _data2 = new bytes(50);
|
|
34
|
-
|
|
35
|
-
bytes memory _metadata = abi.encodePacked(
|
|
36
|
-
// -- offset 0 --
|
|
37
|
-
bytes32(uint256(type(uint256).max)), // First 32B reserved
|
|
38
|
-
// -- offset 1 --
|
|
39
|
-
_id1, // First id
|
|
40
|
-
uint8(2), // First data offset == 2
|
|
41
|
-
_id2, // Second id == _id
|
|
42
|
-
uint8(3), // Second data offset == 3
|
|
43
|
-
bytes22(0), // Rest of the word is 0-padded
|
|
44
|
-
// -- offset 2 --
|
|
45
|
-
_data1, // First data
|
|
46
|
-
// -- offset 3 --
|
|
47
|
-
_data2 // Second data
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(_id2, _metadata);
|
|
51
|
-
assertEq(_dataParsed, _data2);
|
|
52
|
-
assertTrue(_found);
|
|
53
|
-
|
|
54
|
-
(_found, _dataParsed) = parser.getDataFor(_id1, _metadata);
|
|
55
|
-
assertEq(abi.decode(_dataParsed, (uint256)), _data1);
|
|
56
|
-
assertTrue(_found);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @notice Test creating and parsing bytes only metadata.
|
|
61
|
-
*/
|
|
62
|
-
function test_createAndParse_bytes() external view {
|
|
63
|
-
bytes4[] memory _ids = new bytes4[](10);
|
|
64
|
-
bytes[] memory _datas = new bytes[](10);
|
|
65
|
-
|
|
66
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
67
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
68
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
69
|
-
_datas[_i] = abi.encode(
|
|
70
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
71
|
-
bytes1(uint8(_i + 1)),
|
|
72
|
-
uint32(69),
|
|
73
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
74
|
-
bytes2(uint16(_i + 69)),
|
|
75
|
-
bytes32(uint256(type(uint256).max))
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
80
|
-
|
|
81
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
82
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(_ids[_i], _metadata);
|
|
83
|
-
(bytes1 _a, uint32 _deadBeef, bytes2 _c, bytes32 _d) =
|
|
84
|
-
abi.decode(_dataParsed, (bytes1, uint32, bytes2, bytes32));
|
|
85
|
-
|
|
86
|
-
assertTrue(_found);
|
|
87
|
-
|
|
88
|
-
assertEq(uint8(_a), _i + 1);
|
|
89
|
-
assertEq(uint256(_deadBeef), uint32(69));
|
|
90
|
-
assertEq(uint16(_c), _i + 69);
|
|
91
|
-
assertEq(_d, bytes32(uint256(type(uint256).max)));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @notice Test creating and parsing `uint`-only metadata.
|
|
97
|
-
*/
|
|
98
|
-
function test_createAndParse_uint(uint256 _numberOfIds) external {
|
|
99
|
-
// Maximum 219 hooks with 1 word data (offset overflow if more).
|
|
100
|
-
_numberOfIds = bound(_numberOfIds, 1, 220);
|
|
101
|
-
|
|
102
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
103
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
104
|
-
|
|
105
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
106
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
107
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
108
|
-
_datas[_i] = abi.encode(type(uint256).max - _i);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (_numberOfIds == 220) vm.expectRevert(JBMetadataResolver.JBMetadataResolver_MetadataTooLong.selector);
|
|
112
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
113
|
-
if (_numberOfIds < 220) {
|
|
114
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
115
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(_ids[_i], _metadata);
|
|
116
|
-
uint256 _data = abi.decode(_dataParsed, (uint256));
|
|
117
|
-
|
|
118
|
-
assertTrue(_found);
|
|
119
|
-
assertEq(_data, type(uint256).max - _i);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @notice Test creating and parsing metadata of varying length.
|
|
126
|
-
*/
|
|
127
|
-
function test_createAndParse_mixed(uint256 _numberOfIds) external view {
|
|
128
|
-
_numberOfIds = bound(_numberOfIds, 1, 15);
|
|
129
|
-
|
|
130
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
131
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
132
|
-
|
|
133
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
134
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
135
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
136
|
-
// forge-lint: disable-next-line(incorrect-shift)
|
|
137
|
-
_datas[_i] = abi.encode(69 << _i * 20);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
141
|
-
|
|
142
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
143
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(_ids[_i], _metadata);
|
|
144
|
-
uint256 _data = abi.decode(_dataParsed, (uint256));
|
|
145
|
-
|
|
146
|
-
assertTrue(_found);
|
|
147
|
-
// forge-lint: disable-next-line(incorrect-shift)
|
|
148
|
-
assertEq(_data, 69 << _i * 20);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @notice Test if `createMetadata` reverts when the offset would overflow.
|
|
154
|
-
*/
|
|
155
|
-
function test_createRevertIfOffsetTooBig(uint256 _numberOfIds) external {
|
|
156
|
-
// Max 1000 for evm memory limit
|
|
157
|
-
_numberOfIds = bound(_numberOfIds, 221, 1000);
|
|
158
|
-
|
|
159
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
160
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
161
|
-
|
|
162
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
163
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
164
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
165
|
-
_datas[_i] = abi.encode(type(uint256).max - _i);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_MetadataTooLong.selector);
|
|
169
|
-
parser.createMetadata(_ids, _datas);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @notice Test adding `uint` to an `uint` metadata.
|
|
174
|
-
*/
|
|
175
|
-
function test_addToMetadata_uint(uint256 _numberOfIds) external view {
|
|
176
|
-
_numberOfIds = bound(_numberOfIds, 1, 219);
|
|
177
|
-
|
|
178
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
179
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
180
|
-
|
|
181
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
182
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
183
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
184
|
-
_datas[_i] = abi.encode(type(uint256).max - _i);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
188
|
-
|
|
189
|
-
bytes memory _modifiedMetadata =
|
|
190
|
-
parser.addDataToMetadata(_metadata, bytes4(uint32(type(uint32).max)), abi.encode(123_456));
|
|
191
|
-
|
|
192
|
-
// Check
|
|
193
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _modifiedMetadata);
|
|
194
|
-
uint256 _data = abi.decode(_dataParsed, (uint256));
|
|
195
|
-
|
|
196
|
-
assertTrue(_found);
|
|
197
|
-
assertEq(_data, 123_456);
|
|
198
|
-
|
|
199
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
200
|
-
(_found, _dataParsed) = parser.getDataFor(_ids[_i], _modifiedMetadata);
|
|
201
|
-
_data = abi.decode(_dataParsed, (uint256));
|
|
202
|
-
|
|
203
|
-
assertTrue(_found);
|
|
204
|
-
assertEq(_data, type(uint256).max - _i);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @notice Test adding `bytes` to a `bytes` metadata.
|
|
210
|
-
*/
|
|
211
|
-
function test_addToMetadata_bytes() public view {
|
|
212
|
-
bytes4[] memory _ids = new bytes4[](2);
|
|
213
|
-
bytes[] memory _datas = new bytes[](2);
|
|
214
|
-
|
|
215
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
216
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
217
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
218
|
-
_datas[_i] = abi.encode(
|
|
219
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
220
|
-
bytes1(uint8(_i + 1)),
|
|
221
|
-
uint32(69),
|
|
222
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
223
|
-
bytes2(uint16(_i + 69)),
|
|
224
|
-
bytes32(uint256(type(uint256).max))
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
229
|
-
|
|
230
|
-
bytes memory _modifiedMetadata = parser.addDataToMetadata(
|
|
231
|
-
_metadata,
|
|
232
|
-
bytes4(uint32(type(uint32).max)),
|
|
233
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
234
|
-
abi.encode(bytes32(uint256(type(uint256).max)), bytes32(hex"123456"))
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _modifiedMetadata);
|
|
238
|
-
(bytes32 _a, bytes32 _b) = abi.decode(_dataParsed, (bytes32, bytes32));
|
|
239
|
-
|
|
240
|
-
assertTrue(_found);
|
|
241
|
-
assertEq(bytes32(uint256(type(uint256).max)), _a);
|
|
242
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
243
|
-
assertEq(bytes32(hex"123456"), _b);
|
|
244
|
-
|
|
245
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
246
|
-
(_found, _dataParsed) = parser.getDataFor(_ids[_i], _modifiedMetadata);
|
|
247
|
-
|
|
248
|
-
(bytes1 _c, uint32 _d, bytes2 _e, bytes32 _f) = abi.decode(_dataParsed, (bytes1, uint32, bytes2, bytes32));
|
|
249
|
-
|
|
250
|
-
assertTrue(_found);
|
|
251
|
-
assertEq(uint8(_c), _i + 1);
|
|
252
|
-
assertEq(_d, uint32(69));
|
|
253
|
-
assertEq(uint16(_e), _i + 69);
|
|
254
|
-
assertEq(_f, bytes32(uint256(type(uint256).max)));
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* @notice Test adding `bytes` to an `uint` metadata.
|
|
260
|
-
*/
|
|
261
|
-
function test_addToMetadata_mixed(uint256 _numberOfIds) external view {
|
|
262
|
-
_numberOfIds = bound(_numberOfIds, 1, 100);
|
|
263
|
-
|
|
264
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
265
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
266
|
-
|
|
267
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
268
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
269
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
270
|
-
_datas[_i] = abi.encode(_i * 4);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
274
|
-
|
|
275
|
-
bytes memory _modifiedMetadata = parser.addDataToMetadata(
|
|
276
|
-
_metadata, bytes4(uint32(type(uint32).max)), abi.encode(uint32(69), bytes32(uint256(type(uint256).max)))
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _modifiedMetadata);
|
|
280
|
-
(uint32 _a, bytes32 _b) = abi.decode(_dataParsed, (uint32, bytes32));
|
|
281
|
-
|
|
282
|
-
assertTrue(_found);
|
|
283
|
-
assertEq(_a, uint32(69));
|
|
284
|
-
assertEq(_b, bytes32(uint256(type(uint256).max)));
|
|
285
|
-
|
|
286
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
287
|
-
(_found, _dataParsed) = parser.getDataFor(_ids[_i], _modifiedMetadata);
|
|
288
|
-
uint256 _data = abi.decode(_dataParsed, (uint256));
|
|
289
|
-
|
|
290
|
-
assertTrue(_found);
|
|
291
|
-
assertEq(_data, _i * 4);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @notice Test adding `bytes32` and `uint` to an empty metadata.
|
|
297
|
-
*/
|
|
298
|
-
function test_addToMetadata_emptyInitialMetadata() external view {
|
|
299
|
-
bytes memory _metadata;
|
|
300
|
-
|
|
301
|
-
bytes memory _modifiedMetadata = parser.addDataToMetadata(
|
|
302
|
-
_metadata, bytes4(uint32(type(uint32).max)), abi.encode(uint32(69), bytes32(uint256(type(uint256).max)))
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _modifiedMetadata);
|
|
306
|
-
(uint32 _a, bytes32 _b) = abi.decode(_dataParsed, (uint32, bytes32));
|
|
307
|
-
|
|
308
|
-
assertTrue(_found);
|
|
309
|
-
assertEq(_a, uint32(69));
|
|
310
|
-
assertEq(_b, bytes32(uint256(type(uint256).max)));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @notice Test adding `bytes32` and `uint` to a metadata which contains something in the first bytes32
|
|
315
|
-
*/
|
|
316
|
-
function test_addToMetadata_preexistingMetadata(uint256 _reserved) external view {
|
|
317
|
-
bytes memory _metadata = abi.encode(_reserved);
|
|
318
|
-
|
|
319
|
-
bytes memory _modifiedMetadata = parser.addDataToMetadata(
|
|
320
|
-
_metadata, bytes4(uint32(type(uint32).max)), abi.encode(uint32(69), bytes32(uint256(type(uint256).max)))
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _modifiedMetadata);
|
|
324
|
-
(uint32 _a, bytes32 _b) = abi.decode(_dataParsed, (uint32, bytes32));
|
|
325
|
-
|
|
326
|
-
assertTrue(_found);
|
|
327
|
-
assertEq(_a, uint32(69));
|
|
328
|
-
assertEq(_b, bytes32(uint256(type(uint256).max)));
|
|
329
|
-
|
|
330
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
331
|
-
assertEq(uint256(bytes32(_modifiedMetadata)), _reserved);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function test_addToMetadata_invalidExistingTable_reverts() public {
|
|
335
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_MetadataTooShort.selector);
|
|
336
|
-
|
|
337
|
-
// Preexisting metadata: 32B + 4B
|
|
338
|
-
parser.addDataToMetadata(
|
|
339
|
-
abi.encodePacked(bytes32(uint256(type(uint256).max)), bytes4(uint32(type(uint32).max))),
|
|
340
|
-
bytes4(uint32(type(uint32).max)),
|
|
341
|
-
bytes("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function test_addToMetadata_shortDataToAdd_reverts() public {
|
|
346
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_DataNotPadded.selector);
|
|
347
|
-
|
|
348
|
-
// Preexisting metadata: 32B + 4B
|
|
349
|
-
parser.addDataToMetadata(
|
|
350
|
-
abi.encodePacked(bytes32(uint256(type(uint256).max)), bytes8(uint64(type(uint64).max))),
|
|
351
|
-
bytes4(uint32(type(uint32).max)),
|
|
352
|
-
bytes("1234")
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* @notice Test behaviour if the ID is not found in the lookup table.
|
|
358
|
-
*/
|
|
359
|
-
function test_idNotFound(uint256 _numberOfIds) public view {
|
|
360
|
-
_numberOfIds = bound(_numberOfIds, 1, 100);
|
|
361
|
-
|
|
362
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
363
|
-
bytes[] memory _datas = new bytes[](_numberOfIds);
|
|
364
|
-
|
|
365
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
366
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
367
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
368
|
-
_datas[_i] = abi.encode(_i * 4);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
bytes memory _metadata = parser.createMetadata(_ids, _datas);
|
|
372
|
-
|
|
373
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _metadata);
|
|
374
|
-
|
|
375
|
-
assertFalse(_found);
|
|
376
|
-
assertEq(_dataParsed, "");
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* @notice Test behaviour if the metadata is empty or less than one ID long.
|
|
381
|
-
*/
|
|
382
|
-
function test_emptyMetadata(uint256 _length) public view {
|
|
383
|
-
_length = bound(_length, 0, 37);
|
|
384
|
-
|
|
385
|
-
bytes memory _metadata;
|
|
386
|
-
|
|
387
|
-
// Fill with hex `F`.
|
|
388
|
-
_metadata = abi.encodePacked(bytes32(uint256(type(uint256).max)), bytes32(uint256(type(uint256).max)));
|
|
389
|
-
|
|
390
|
-
// Downsize to the length.
|
|
391
|
-
assembly {
|
|
392
|
-
mstore(_metadata, _length)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
(bool _found, bytes memory _dataParsed) = parser.getDataFor(bytes4(uint32(type(uint32).max)), _metadata);
|
|
396
|
-
|
|
397
|
-
assertFalse(_found);
|
|
398
|
-
assertEq(_dataParsed, "");
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
function test_differentSizeIdAndMetadataArray_reverts(uint256 _numberOfIds, uint256 _numberOfMetadatas) public {
|
|
402
|
-
_numberOfIds = bound(_numberOfIds, 1, 100);
|
|
403
|
-
_numberOfMetadatas = bound(_numberOfMetadatas, 1, 100);
|
|
404
|
-
|
|
405
|
-
vm.assume(_numberOfIds != _numberOfMetadatas);
|
|
406
|
-
|
|
407
|
-
bytes4[] memory _ids = new bytes4[](_numberOfIds);
|
|
408
|
-
bytes[] memory _datas = new bytes[](_numberOfMetadatas);
|
|
409
|
-
|
|
410
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
411
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
412
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
for (uint256 _i; _i < _datas.length; _i++) {
|
|
416
|
-
_datas[_i] = abi.encode(_i * 4);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Below should revert.
|
|
420
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_LengthMismatch.selector);
|
|
421
|
-
parser.createMetadata(_ids, _datas);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* @notice Test creating and parsing metadata of incorrect length.
|
|
426
|
-
*/
|
|
427
|
-
function test_create__unpadded() external {
|
|
428
|
-
bytes4[] memory _ids = new bytes4[](1);
|
|
429
|
-
bytes[] memory _datas = new bytes[](1);
|
|
430
|
-
|
|
431
|
-
uint8 something = uint8(1);
|
|
432
|
-
bytes memory shortData = abi.encodePacked(something);
|
|
433
|
-
|
|
434
|
-
_ids[0] = bytes4(uint32(1));
|
|
435
|
-
_datas[0] = shortData;
|
|
436
|
-
|
|
437
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_DataNotPadded.selector);
|
|
438
|
-
parser.createMetadata(_ids, _datas);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* @notice Test creating and parsing bytes only metadata.
|
|
443
|
-
*/
|
|
444
|
-
function test_create_incorrect_data_length() external {
|
|
445
|
-
bytes4[] memory _ids = new bytes4[](10);
|
|
446
|
-
bytes[] memory _datas = new bytes[](10);
|
|
447
|
-
|
|
448
|
-
for (uint256 _i; _i < _ids.length; _i++) {
|
|
449
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
450
|
-
_ids[_i] = bytes4(uint32(_i + 1 * 1000));
|
|
451
|
-
|
|
452
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
453
|
-
_datas[_i] = abi.encodePacked(
|
|
454
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
455
|
-
bytes1(uint8(_i + 1)),
|
|
456
|
-
uint32(69),
|
|
457
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
458
|
-
bytes2(uint16(_i + 69)),
|
|
459
|
-
bytes32(uint256(type(uint256).max))
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// Ensure data length is not multiple of word size and is gt word size.
|
|
464
|
-
assertGt(_datas[0].length, 32);
|
|
465
|
-
assertGt(_datas[0].length % 32, 0);
|
|
466
|
-
|
|
467
|
-
// New revert to help integrators.
|
|
468
|
-
vm.expectRevert(JBMetadataResolver.JBMetadataResolver_DataNotPadded.selector);
|
|
469
|
-
parser.createMetadata(_ids, _datas);
|
|
470
|
-
}
|
|
471
|
-
}
|