Skip to content

Commit

Permalink
Changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkaseman committed Apr 12, 2024
1 parent c9de21c commit 0704b11
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 229 deletions.
155 changes: 80 additions & 75 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ ARM_voteToCurse:testEvenIfAlreadyCursedSuccess() (gas: 275945)
ARM_voteToCurse:testInvalidVoterReverts() (gas: 13660)
ARM_voteToCurse:testOwnerCanCurseAndUncurse() (gas: 200805)
ARM_voteToCurse:testVoteToCurseSuccess_gas() (gas: 70262)
AggregateTokenLimiter__rateLimitValue:testAggregateValueMaxCapacityExceededReverts() (gas: 16389)
AggregateTokenLimiter__rateLimitValue:testRateLimitValueSuccess_gas() (gas: 18361)
AggregateTokenLimiter_constructor:testConstructorSuccess() (gas: 26734)
AggregateTokenLimiter_getTokenBucket:testGetTokenBucketSuccess() (gas: 19686)
AggregateTokenLimiter_getTokenBucket:testRefillSuccess() (gas: 40876)
AggregateTokenLimiter_getTokenBucket:testTimeUnderflowReverts() (gas: 15285)
AggregateTokenLimiter_getTokenLimitAdmin:testGetTokenLimitAdminSuccess() (gas: 10443)
AggregateTokenLimiter_setAdmin:testOnlyOwnerOrAdminReverts() (gas: 12961)
AggregateTokenLimiter_setAdmin:testOwnerSuccess() (gas: 18877)
AggregateTokenLimiter__getTokenValue:testGetTokenValueSuccess() (gas: 17198)
AggregateTokenLimiter__getTokenValue:testNoTokenPriceReverts() (gas: 18817)
AggregateTokenLimiter__rateLimitValue:testAggregateValueMaxCapacityExceededReverts() (gas: 16411)
AggregateTokenLimiter__rateLimitValue:testRateLimitValueSuccess_gas() (gas: 18354)
AggregateTokenLimiter_constructor:testConstructorSuccess() (gas: 26823)
AggregateTokenLimiter_getTokenBucket:testGetTokenBucketSuccess() (gas: 19708)
AggregateTokenLimiter_getTokenBucket:testRefillSuccess() (gas: 40935)
AggregateTokenLimiter_getTokenBucket:testTimeUnderflowReverts() (gas: 15307)
AggregateTokenLimiter_getTokenLimitAdmin:testGetTokenLimitAdminSuccess() (gas: 10465)
AggregateTokenLimiter_setAdmin:testOnlyOwnerOrAdminReverts() (gas: 13012)
AggregateTokenLimiter_setAdmin:testOwnerSuccess() (gas: 18950)
AggregateTokenLimiter_setRateLimiterConfig:testOnlyOnlyCallableByAdminOrOwnerReverts() (gas: 17434)
AggregateTokenLimiter_setRateLimiterConfig:testOwnerSuccess() (gas: 30020)
AggregateTokenLimiter_setRateLimiterConfig:testTokenLimitAdminSuccess() (gas: 32003)
AggregateTokenLimiter_setRateLimiterConfig:testOwnerSuccess() (gas: 30050)
AggregateTokenLimiter_setRateLimiterConfig:testTokenLimitAdminSuccess() (gas: 32032)
BurnFromMintTokenPool_lockOrBurn:testChainNotAllowedReverts() (gas: 22860)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 63723)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 248751)
Expand Down Expand Up @@ -97,94 +99,97 @@ CommitStore_verify:testPausedReverts() (gas: 18438)
CommitStore_verify:testTooManyLeavesReverts() (gas: 36830)
DefensiveExampleTest:testHappyPathSuccess() (gas: 207184)
DefensiveExampleTest:testRecovery() (gas: 431320)
E2E:testE2E_3MessagesSuccess_gas() (gas: 991841)
EVM2EVMOffRamp__releaseOrMintTokens:test_RateLimitErrors_Reverts() (gas: 625164)
EVM2EVMOffRamp__releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 143685)
EVM2EVMOffRamp__releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAContract_Reverts() (gas: 27261)
EVM2EVMOffRamp__releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 31714)
EVM2EVMOffRamp__releaseOrMintTokens:test_fuzz__releaseOrMintTokens_AnyRevertIsCaught_Success(uint256) (runs: 256, μ: 23177, ~: 23903)
EVM2EVMOffRamp__releaseOrMintTokens:test_releaseOrMintTokens_Success() (gas: 157516)
EVM2EVMOffRamp__report:testReportSuccess() (gas: 127460)
E2E:testE2E_3MessagesSuccess_gas() (gas: 991819)
EVM2EVMOffRamp__releaseOrMintTokens:test_RateLimitErrors_Reverts() (gas: 625054)
EVM2EVMOffRamp__releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 143663)
EVM2EVMOffRamp__releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAContract_Reverts() (gas: 27239)
EVM2EVMOffRamp__releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 31692)
EVM2EVMOffRamp__releaseOrMintTokens:test_fuzz__releaseOrMintTokens_AnyRevertIsCaught_Success(uint256) (runs: 256, μ: 23127, ~: 23881)
EVM2EVMOffRamp__releaseOrMintTokens:test_releaseOrMintTokens_Success() (gas: 157494)
EVM2EVMOffRamp__report:testReportSuccess() (gas: 127438)
EVM2EVMOffRamp__trialExecute:testRateLimitErrorSuccess() (gas: 195843)
EVM2EVMOffRamp__trialExecute:testTokenHandlingErrorIsCaughtSuccess() (gas: 204499)
EVM2EVMOffRamp__trialExecute:test_trialExecuteSuccess() (gas: 259973)
EVM2EVMOffRamp__updateRateLimitTokens:testNonOwnerReverts() (gas: 12160)
EVM2EVMOffRamp__updateRateLimitTokens:test_updateRateLimitTokensSuccess() (gas: 156261)
EVM2EVMOffRamp_ccipReceive:testReverts() (gas: 17043)
EVM2EVMOffRamp_constructor:testCommitStoreAlreadyInUseReverts() (gas: 158125)
EVM2EVMOffRamp_constructor:testConstructorSuccess() (gas: 5178349)
EVM2EVMOffRamp_constructor:testConstructorSuccess() (gas: 5189210)
EVM2EVMOffRamp_constructor:testZeroOnRampAddressReverts() (gas: 148872)
EVM2EVMOffRamp_execute:testAlreadyExecutedReverts() (gas: 137483)
EVM2EVMOffRamp_execute:testEmptyReportReverts() (gas: 19038)
EVM2EVMOffRamp_execute:testInvalidMessageIdReverts() (gas: 34134)
EVM2EVMOffRamp_execute:testInvalidSourceChainReverts() (gas: 49417)
EVM2EVMOffRamp_execute:testInvalidSourcePoolAddressSuccess() (gas: 409903)
EVM2EVMOffRamp_execute:testManualExecutionNotYetEnabledReverts() (gas: 44164)
EVM2EVMOffRamp_execute:testMessageTooLargeReverts() (gas: 150204)
EVM2EVMOffRamp_execute:testPausedReverts() (gas: 99235)
EVM2EVMOffRamp_execute:testReceiverErrorSuccess() (gas: 164545)
EVM2EVMOffRamp_execute:testRootNotCommittedReverts() (gas: 39062)
EVM2EVMOffRamp_execute:testRouterYULCallReverts() (gas: 413890)
EVM2EVMOffRamp_execute:testSingleMessageNoTokensSuccess() (gas: 174116)
EVM2EVMOffRamp_execute:testSingleMessageToNonCCIPReceiverSuccess() (gas: 246354)
EVM2EVMOffRamp_execute:testSingleMessagesNoTokensSuccess_gas() (gas: 114745)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceStillExecutesSuccess() (gas: 354522)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceSuccess() (gas: 51950)
EVM2EVMOffRamp_execute:testStrictUntouchedToSuccessSuccess() (gas: 131724)
EVM2EVMOffRamp_execute:testTokenDataMismatchReverts() (gas: 49773)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensAndGESuccess() (gas: 480492)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensSuccess_gas() (gas: 419323)
EVM2EVMOffRamp_execute:testUnexpectedTokenDataReverts() (gas: 33092)
EVM2EVMOffRamp_execute:testUnhealthyReverts() (gas: 468475)
EVM2EVMOffRamp_execute:testUnsupportedNumberOfTokensReverts() (gas: 61498)
EVM2EVMOffRamp_execute:testAlreadyExecutedReverts() (gas: 137439)
EVM2EVMOffRamp_execute:testEmptyReportReverts() (gas: 19016)
EVM2EVMOffRamp_execute:testInvalidMessageIdReverts() (gas: 34112)
EVM2EVMOffRamp_execute:testInvalidSourceChainReverts() (gas: 49373)
EVM2EVMOffRamp_execute:testInvalidSourcePoolAddressSuccess() (gas: 409837)
EVM2EVMOffRamp_execute:testManualExecutionNotYetEnabledReverts() (gas: 44142)
EVM2EVMOffRamp_execute:testMessageTooLargeReverts() (gas: 150160)
EVM2EVMOffRamp_execute:testPausedReverts() (gas: 99213)
EVM2EVMOffRamp_execute:testReceiverErrorSuccess() (gas: 164501)
EVM2EVMOffRamp_execute:testRootNotCommittedReverts() (gas: 39040)
EVM2EVMOffRamp_execute:testRouterYULCallReverts() (gas: 413846)
EVM2EVMOffRamp_execute:testSingleMessageNoTokensSuccess() (gas: 174050)
EVM2EVMOffRamp_execute:testSingleMessageToNonCCIPReceiverSuccess() (gas: 246310)
EVM2EVMOffRamp_execute:testSingleMessagesNoTokensSuccess_gas() (gas: 114723)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceStillExecutesSuccess() (gas: 354478)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceSuccess() (gas: 51906)
EVM2EVMOffRamp_execute:testStrictUntouchedToSuccessSuccess() (gas: 131680)
EVM2EVMOffRamp_execute:testTokenDataMismatchReverts() (gas: 49751)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensAndGESuccess() (gas: 480448)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensSuccess_gas() (gas: 419301)
EVM2EVMOffRamp_execute:testUnexpectedTokenDataReverts() (gas: 33070)
EVM2EVMOffRamp_execute:testUnhealthyReverts() (gas: 468431)
EVM2EVMOffRamp_execute:testUnsupportedNumberOfTokensReverts() (gas: 61454)
EVM2EVMOffRamp_executeSingleMessage:testMessageSenderReverts() (gas: 20583)
EVM2EVMOffRamp_executeSingleMessage:testNonContractSuccess() (gas: 20121)
EVM2EVMOffRamp_executeSingleMessage:testNonContractWithTokensSuccess() (gas: 227589)
EVM2EVMOffRamp_executeSingleMessage:testTokenHandlingErrorReverts() (gas: 180163)
EVM2EVMOffRamp_executeSingleMessage:testZeroGasDONExecutionReverts() (gas: 48637)
EVM2EVMOffRamp_executeSingleMessage:test_executeSingleMessage_NoTokens_Success() (gas: 48110)
EVM2EVMOffRamp_executeSingleMessage:test_executeSingleMessage_WithTokens_Success() (gas: 262006)
EVM2EVMOffRamp_execute_upgrade:testV2NonceNewSenderStartsAtZeroSuccess() (gas: 233029)
EVM2EVMOffRamp_execute_upgrade:testV2NonceStartsAtV1NonceSuccess() (gas: 281429)
EVM2EVMOffRamp_execute_upgrade:testV2OffRampNonceSkipsIfMsgInFlightSuccess() (gas: 262582)
EVM2EVMOffRamp_execute_upgrade:testV2SenderNoncesReadsPreviousRampSuccess() (gas: 229263)
EVM2EVMOffRamp_execute_upgrade:testV2Success() (gas: 131524)
EVM2EVMOffRamp_getExecutionState:testFillExecutionStateSuccess() (gas: 3343429)
EVM2EVMOffRamp_getExecutionState:test_GetExecutionStateSuccess() (gas: 82666)
EVM2EVMOffRamp_manuallyExecute:testLowGasLimitManualExecSuccess() (gas: 497153)
EVM2EVMOffRamp_manuallyExecute:testManualExecFailedTxReverts() (gas: 188051)
EVM2EVMOffRamp_manuallyExecute:testManualExecForkedChainReverts() (gas: 25984)
EVM2EVMOffRamp_manuallyExecute:testManualExecGasLimitMismatchReverts() (gas: 43480)
EVM2EVMOffRamp_manuallyExecute:testManualExecInvalidGasLimitReverts() (gas: 26003)
EVM2EVMOffRamp_manuallyExecute:testManualExecSuccess() (gas: 189749)
EVM2EVMOffRamp_manuallyExecute:testManualExecWithGasOverrideSuccess() (gas: 190420)
EVM2EVMOffRamp_manuallyExecute:testReentrancyManualExecuteFails() (gas: 2042576)
EVM2EVMOffRamp_metadataHash:testMetadataHashSuccess() (gas: 8960)
EVM2EVMOffRamp_setDynamicConfig:testNonOwnerReverts() (gas: 40310)
EVM2EVMOffRamp_setDynamicConfig:testRouterZeroAddressReverts() (gas: 38520)
EVM2EVMOffRamp_execute_upgrade:testV2NonceNewSenderStartsAtZeroSuccess() (gas: 232963)
EVM2EVMOffRamp_execute_upgrade:testV2NonceStartsAtV1NonceSuccess() (gas: 281319)
EVM2EVMOffRamp_execute_upgrade:testV2OffRampNonceSkipsIfMsgInFlightSuccess() (gas: 262450)
EVM2EVMOffRamp_execute_upgrade:testV2SenderNoncesReadsPreviousRampSuccess() (gas: 229131)
EVM2EVMOffRamp_execute_upgrade:testV2Success() (gas: 131502)
EVM2EVMOffRamp_getExecutionState:testFillExecutionStateSuccess() (gas: 3360325)
EVM2EVMOffRamp_getExecutionState:test_GetExecutionStateSuccess() (gas: 82776)
EVM2EVMOffRamp_manuallyExecute:testLowGasLimitManualExecSuccess() (gas: 497174)
EVM2EVMOffRamp_manuallyExecute:testManualExecFailedTxReverts() (gas: 188072)
EVM2EVMOffRamp_manuallyExecute:testManualExecForkedChainReverts() (gas: 26049)
EVM2EVMOffRamp_manuallyExecute:testManualExecGasLimitMismatchReverts() (gas: 43675)
EVM2EVMOffRamp_manuallyExecute:testManualExecInvalidGasLimitReverts() (gas: 26068)
EVM2EVMOffRamp_manuallyExecute:testManualExecSuccess() (gas: 189770)
EVM2EVMOffRamp_manuallyExecute:testManualExecWithGasOverrideSuccess() (gas: 190441)
EVM2EVMOffRamp_manuallyExecute:testReentrancyManualExecuteFails() (gas: 2042684)
EVM2EVMOffRamp_metadataHash:testMetadataHashSuccess() (gas: 8938)
EVM2EVMOffRamp_setDynamicConfig:testNonOwnerReverts() (gas: 40332)
EVM2EVMOffRamp_setDynamicConfig:testRouterZeroAddressReverts() (gas: 38542)
EVM2EVMOffRamp_setDynamicConfig:testSetDynamicConfigSuccess() (gas: 144167)
EVM2EVMOnRamp_constructor:testConstructorSuccess() (gas: 5516252)
EVM2EVMOnRamp_forwardFromRouter:testCannotSendZeroTokensReverts() (gas: 31723)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccess() (gas: 126926)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccessCustomExtraArgs() (gas: 127250)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccessLegacyExtraArgs() (gas: 137765)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccess() (gas: 126983)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccessCustomExtraArgs() (gas: 127285)
EVM2EVMOnRamp_forwardFromRouter:testForwardFromRouterSuccessLegacyExtraArgs() (gas: 137822)
EVM2EVMOnRamp_forwardFromRouter:testHighCapacityARLOffSuccess() (gas: 213319)
EVM2EVMOnRamp_forwardFromRouter:testInvalidAddressEncodePackedReverts() (gas: 24143)
EVM2EVMOnRamp_forwardFromRouter:testInvalidAddressReverts() (gas: 24442)
EVM2EVMOnRamp_forwardFromRouter:testInvalidAddressReverts() (gas: 24464)
EVM2EVMOnRamp_forwardFromRouter:testInvalidChainSelectorReverts() (gas: 23186)
EVM2EVMOnRamp_forwardFromRouter:testInvalidExtraArgsTagReverts() (gas: 23473)
EVM2EVMOnRamp_forwardFromRouter:testMaxCapacityExceededReverts() (gas: 79450)
EVM2EVMOnRamp_forwardFromRouter:testMaxCapacityExceededReverts() (gas: 79485)
EVM2EVMOnRamp_forwardFromRouter:testMaxFeeBalanceReachedReverts() (gas: 32398)
EVM2EVMOnRamp_forwardFromRouter:testMessageGasLimitTooHighReverts() (gas: 27161)
EVM2EVMOnRamp_forwardFromRouter:testMessageGasLimitTooHighReverts() (gas: 27117)
EVM2EVMOnRamp_forwardFromRouter:testMessageTooLargeReverts() (gas: 105650)
EVM2EVMOnRamp_forwardFromRouter:testOriginalSenderReverts() (gas: 20332)
EVM2EVMOnRamp_forwardFromRouter:testPausedReverts() (gas: 50983)
EVM2EVMOnRamp_forwardFromRouter:testPermissionsReverts() (gas: 23183)
EVM2EVMOnRamp_forwardFromRouter:testPriceNotFoundForTokenReverts() (gas: 52685)
EVM2EVMOnRamp_forwardFromRouter:testPausedReverts() (gas: 50989)
EVM2EVMOnRamp_forwardFromRouter:testPermissionsReverts() (gas: 23189)
EVM2EVMOnRamp_forwardFromRouter:testPriceNotFoundForTokenReverts() (gas: 52697)
EVM2EVMOnRamp_forwardFromRouter:testShouldIncrementSeqNumAndNonceSuccess() (gas: 170340)
EVM2EVMOnRamp_forwardFromRouter:testShouldStoreLinkFees() (gas: 107733)
EVM2EVMOnRamp_forwardFromRouter:testShouldStoreNonLinkFees() (gas: 127011)
EVM2EVMOnRamp_forwardFromRouter:testSourceTokenDataTooLargeReverts() (gas: 3572353)
EVM2EVMOnRamp_forwardFromRouter:testShouldStoreLinkFees() (gas: 107768)
EVM2EVMOnRamp_forwardFromRouter:testShouldStoreNonLinkFees() (gas: 127116)
EVM2EVMOnRamp_forwardFromRouter:testSourceTokenDataTooLargeReverts() (gas: 3572365)
EVM2EVMOnRamp_forwardFromRouter:testTooManyTokensReverts() (gas: 28283)
EVM2EVMOnRamp_forwardFromRouter:testUnhealthyReverts() (gas: 43114)
EVM2EVMOnRamp_forwardFromRouter:testUnsupportedTokenReverts() (gas: 106457)
EVM2EVMOnRamp_forwardFromRouter:testUnsupportedTokenReverts() (gas: 106426)
EVM2EVMOnRamp_forwardFromRouter:testZeroAddressReceiverReverts() (gas: 173989)
EVM2EVMOnRamp_forwardFromRouter_upgrade:testV2NonceNewSenderStartsAtZeroSuccess() (gas: 142371)
EVM2EVMOnRamp_forwardFromRouter_upgrade:testV2NonceStartsAtV1NonceSuccess() (gas: 186548)
Expand Down Expand Up @@ -240,7 +245,7 @@ EVM2EVMOnRamp_setNops:testTooManyNopsReverts() (gas: 190427)
EVM2EVMOnRamp_setNops:testZeroAddressCannotBeNopReverts() (gas: 53616)
EVM2EVMOnRamp_setTokenTransferFeeConfig:testOnlyCallableByOwnerOrAdminReverts() (gas: 13536)
EVM2EVMOnRamp_setTokenTransferFeeConfig:testSetFeeTokenConfigByAdminSuccess() (gas: 16445)
EVM2EVMOnRamp_setTokenTransferFeeConfig:testSetTokenTransferFeeSuccess() (gas: 80076)
EVM2EVMOnRamp_setTokenTransferFeeConfig:testSetTokenTransferFeeSuccess() (gas: 80913)
EVM2EVMOnRamp_withdrawNonLinkFees:testLinkBalanceNotSettledReverts() (gas: 78604)
EVM2EVMOnRamp_withdrawNonLinkFees:testNonOwnerOrAdminReverts() (gas: 15306)
EVM2EVMOnRamp_withdrawNonLinkFees:testSettlingBalanceSuccess() (gas: 275745)
Expand Down
18 changes: 18 additions & 0 deletions contracts/src/v0.8/ccip/AggregateRateLimiter.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import {IPriceRegistry} from "./interfaces/IPriceRegistry.sol";

import {OwnerIsCreator} from "./../shared/access/OwnerIsCreator.sol";
import {Client} from "./libraries/Client.sol";
import {RateLimiter} from "./libraries/RateLimiter.sol";
import {USDPriceWith18Decimals} from "./libraries/USDPriceWith18Decimals.sol";

/// @notice The aggregate rate limiter is a wrapper of the token bucket rate limiter
/// which permits rate limiting based on the aggregate value of a group of
/// token transfers, using a price registry to convert to a numeraire asset (e.g. USD).
contract AggregateRateLimiter is OwnerIsCreator {
using RateLimiter for RateLimiter.TokenBucket;
using USDPriceWith18Decimals for uint224;

error PriceNotFoundForToken(address token);

event AdminSet(address newAdmin);

Expand All @@ -35,6 +42,17 @@ contract AggregateRateLimiter is OwnerIsCreator {
s_rateLimiter._consume(value, address(0));
}

function _getTokenValue(
Client.EVMTokenAmount memory tokenAmount,
IPriceRegistry priceRegistry
) internal view returns (uint256) {
// not fetching validated price, as price staleness is not important for value-based rate limiting
// we only need to verify the price is not 0
uint224 pricePerToken = priceRegistry.getTokenPrice(tokenAmount.token).value;
if (pricePerToken == 0) revert PriceNotFoundForToken(tokenAmount.token);
return pricePerToken._calcUSDValueFromTokenAmount(tokenAmount.amount);
}

/// @notice Gets the token bucket with its values for the block it was requested at.
/// @return The token bucket.
function currentRateLimiterState() external view returns (RateLimiter.TokenBucket memory) {
Expand Down
Loading

0 comments on commit 0704b11

Please sign in to comment.