Skip to content

Commit

Permalink
fix: cantina audit findings (#25)
Browse files Browse the repository at this point in the history
* fix: addresses #2 and #3
* fix: addresses #4
* fix: addresses #8
* fix: addresses #1
* fix: addresses #9
* fix: addresses #7
* fix: addresses #5
* fix: addresses #6
* test: impl better workaround to ensure fuzz does not give address with existing code
* test: more assumes
* gas: update snapshot
* test: assumeNotForgeAddress
* gas: update snapshot
* fix: impl fix for attempting to use a composite route as an intermediate route
* test: add case for clearing out second slot when replacing by a shorter route
* gas: update snapshot
* test: add assumptions that addresses do not clash
* gas: update snapshot
  • Loading branch information
xenide authored Dec 16, 2024
1 parent ec72d85 commit c8df956
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 197 deletions.
145 changes: 76 additions & 69 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,79 +1,86 @@
QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 69293044, ~: 77954902)
QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 68012389, ~: 77774179)
QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 69006651, ~: 78950566)
QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 67181426, ~: 77952295)
QueryProcessorTest:testFindNearestSample_NotInitialized() (gas: 1056944146)
QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 80623, ~: 80652)
QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 80622, ~: 80652)
QueryProcessorTest:testGetInstantValue() (gas: 124418)
QueryProcessorTest:testGetInstantValue_NotInitialized(uint256) (runs: 256, μ: 19400, ~: 19400)
QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 69204583, ~: 69204518)
QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 26911, ~: 26984)
QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 72113529, ~: 81319251)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69463960, ~: 78425849)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69493894, ~: 78457616)
QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 67986036, ~: 77745180)
QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 68020346, ~: 77780471)
QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 67977605, ~: 77737553)
QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 67989141, ~: 77747128)
QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 103407330, ~: 109858182)
QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 69204610, ~: 69204518)
QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 26921, ~: 26984)
QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 71299667, ~: 79601317)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69601383, ~: 77006769)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69631465, ~: 77038536)
QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 67155174, ~: 77923691)
QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 67189366, ~: 77958587)
QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 67146760, ~: 77915383)
QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 67158275, ~: 77925299)
QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 100879462, ~: 107747925)
QueryProcessorTest:testGetTimeWeightedAverage_BadSecs() (gas: 10981)
ReservoirPriceOracleTest:testClearRoute() (gas: 52209)
ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 159642)
ReservoirPriceOracleTest:testDesignatePair() (gas: 29089)
ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21129)
ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17515)
ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30670)
ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 33680, ~: 33783)
ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 13019)
ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 401362, ~: 401124)
ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10361941)
ReservoirPriceOracleTest:testGetQuote_ERC4626AssetFails() (gas: 21434)
ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 35858, ~: 36022)
ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 111597)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 111891)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 122213)
ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 20830)
ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 15942)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5316105, ~: 5316096)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10503666, ~: 10503746)
ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 8972, ~: 8972)
ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38232)
ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 36638)
ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 26236, ~: 26339)
ReservoirPriceOracleTest:testName() (gas: 9355)
ReservoirPriceOracleTest:testPriceCache_Inverted() (gas: 22028)
ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 10993)
ReservoirPriceOracleTest:testSetRoute() (gas: 60992)
ReservoirPriceOracleTest:testSetRoute_InvalidDecimals() (gas: 761313)
ReservoirPriceOracleTest:testSetRoute_InvalidRewardThreshold() (gas: 37234)
ReservoirPriceOracleTest:testSetRoute_InvalidRewardThresholdLength() (gas: 18050)
ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 20151)
ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 19209)
ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 201150)
ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 13029)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 169526)
ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 12975)
ReservoirPriceOracleTest:testUndesignatePair() (gas: 30263)
ReservoirPriceOracleTest:testClearRoute() (gas: 52358)
ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 160260)
ReservoirPriceOracleTest:testDesignatePair() (gas: 29133)
ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21174)
ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17537)
ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30736)
ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 33774, ~: 33869)
ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 12952)
ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 401427, ~: 401176)
ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10362427)
ReservoirPriceOracleTest:testGetQuote_ERC4626AssetFails() (gas: 21389)
ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 35952, ~: 36108)
ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 112160)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 112386)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 122794)
ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 20785)
ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 15919)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5229872, ~: 5229880)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10377471, ~: 10377571)
ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 8971, ~: 8971)
ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38209)
ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 36679)
ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 26353, ~: 26448)
ReservoirPriceOracleTest:testName() (gas: 9311)
ReservoirPriceOracleTest:testPriceCache_Inverted() (gas: 22091)
ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 10928)
ReservoirPriceOracleTest:testSetRoute() (gas: 61115)
ReservoirPriceOracleTest:testSetRoute_2ndSlotClearedWhenReplacing3HopByShorterRoute() (gas: 167426)
ReservoirPriceOracleTest:testSetRoute_InvalidDecimals() (gas: 763534)
ReservoirPriceOracleTest:testSetRoute_InvalidRewardThreshold() (gas: 41610)
ReservoirPriceOracleTest:testSetRoute_InvalidRewardThresholdLength() (gas: 18129)
ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 20221)
ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 19356)
ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 201780)
ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 13074)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 173710)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting_UsingCompositeAsIntermediate() (gas: 114782)
ReservoirPriceOracleTest:testSetRoute_ReplaceExistingCompositeWithSimple() (gas: 182717)
ReservoirPriceOracleTest:testSetRoute_ReplaceExistingSimpleWithComposite() (gas: 103503)
ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 13020)
ReservoirPriceOracleTest:testUndesignatePair() (gas: 30285)
ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 15315)
ReservoirPriceOracleTest:testUpdatePrice_AboveThresholdBelowMaxReward(uint256) (runs: 256, μ: 164770, ~: 164790)
ReservoirPriceOracleTest:testUpdatePrice_BelowThreshold(uint256) (runs: 256, μ: 149645, ~: 149316)
ReservoirPriceOracleTest:testUpdatePrice_BeyondMaxReward(uint256) (runs: 256, μ: 162201, ~: 162226)
ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 153384)
ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 11080585)
ReservoirPriceOracleTest:testUpdatePrice_NoPath() (gas: 15986)
ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5374104)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ContractNoReceive() (gas: 152500)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_InsufficientReward(uint256) (runs: 256, μ: 210828, ~: 211040)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ZeroRecipient() (gas: 146179)
ReservoirPriceOracleTest:testUpdatePrice_WriteToNonSimpleRoute() (gas: 498183)
ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 19038)
ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 10953)
ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21613, ~: 21687)
ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17688, ~: 17994)
ReservoirPriceOracleTest:testValidatePair_NoDesignatedPair() (gas: 119204)
ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30001, ~: 29763)
ReservoirPriceOracleTest:testUpdatePrice_AboveThresholdBelowMaxReward(uint256) (runs: 256, μ: 162400, ~: 162426)
ReservoirPriceOracleTest:testUpdatePrice_BelowThreshold(uint256) (runs: 256, μ: 149819, ~: 149851)
ReservoirPriceOracleTest:testUpdatePrice_BeyondMaxReward(uint256) (runs: 256, μ: 159761, ~: 159835)
ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 153341)
ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 11082572)
ReservoirPriceOracleTest:testUpdatePrice_NoPath() (gas: 15942)
ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5374118)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ContractNoReceive() (gas: 150542)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_InsufficientReward(uint256) (runs: 256, μ: 208872, ~: 209191)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ZeroRecipient() (gas: 144199)
ReservoirPriceOracleTest:testUpdatePrice_WriteToNonSimpleRoute() (gas: 502364)
ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 19117)
ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 10987)
ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21699, ~: 21778)
ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17869, ~: 18066)
ReservoirPriceOracleTest:testValidatePair_NoDesignatedPair() (gas: 119160)
ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30089, ~: 29838)
RoutesLibTest:testGetDecimalDifference() (gas: 3966)
RoutesLibTest:testIsCompositeRoute() (gas: 4332)
RoutesLibTest:testPackSimplePrice(int8,uint256) (runs: 256, μ: 8083, ~: 7862)
RoutesLibTest:testPackSimplePrice(int8,uint64,uint256) (runs: 256, μ: 8159, ~: 7915)
SamplesTest:testAccumulator() (gas: 3930)
SamplesTest:testAccumulator_BadVariableRequest() (gas: 3355)
SamplesTest:testInstant() (gas: 3880)
SamplesTest:testInstant_BadVariableRequest() (gas: 3376)
SamplesTest:testInstant_BadVariableRequest() (gas: 3376)
UtilsTest:testCalcPercentageDiff_Double(uint256) (runs: 256, μ: 7055, ~: 6836)
UtilsTest:testCalcPercentageDiff_Half(uint256) (runs: 256, μ: 7235, ~: 7432)
UtilsTest:testCalcPercentageDiff_NoDiff(uint256) (runs: 256, μ: 6838, ~: 6622)
Loading

0 comments on commit c8df956

Please sign in to comment.