Skip to content

Commit

Permalink
assert fees can be set to zero (#1380)
Browse files Browse the repository at this point in the history
Assert we would have the option to set any of the fee components to zero
if we would want.

---------

Co-authored-by: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 181302f commit 7c70148
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 35 deletions.
56 changes: 27 additions & 29 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ EVM2EVMOnRamp_forwardFromRouter_upgrade:test_V2_Success() (gas: 95349)
EVM2EVMOnRamp_getDataAvailabilityCost:test_EmptyMessageCalculatesDataAvailabilityCost_Success() (gas: 20544)
EVM2EVMOnRamp_getDataAvailabilityCost:test_SimpleMessageCalculatesDataAvailabilityCost_Success() (gas: 20912)
EVM2EVMOnRamp_getFee:test_EmptyMessage_Success() (gas: 78230)
EVM2EVMOnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 81762)
EVM2EVMOnRamp_getFee:test_HighGasMessage_Success() (gas: 234078)
EVM2EVMOnRamp_getFee:test_MessageGasLimitTooHigh_Revert() (gas: 16715)
EVM2EVMOnRamp_getFee:test_MessageTooLarge_Revert() (gas: 95271)
Expand Down Expand Up @@ -343,10 +344,10 @@ FeeQuoter_applyTokenTransferFeeConfigUpdates:test_ApplyTokenTransferFeeConfig_Su
FeeQuoter_applyTokenTransferFeeConfigUpdates:test_ApplyTokenTransferFeeZeroInput() (gas: 13089)
FeeQuoter_applyTokenTransferFeeConfigUpdates:test_InvalidDestBytesOverhead_Revert() (gas: 17071)
FeeQuoter_applyTokenTransferFeeConfigUpdates:test_OnlyCallableByOwnerOrAdmin_Revert() (gas: 12240)
FeeQuoter_constructor:test_InvalidLinkTokenEqZeroAddress_Revert() (gas: 107016)
FeeQuoter_constructor:test_InvalidMaxFeeJuelsPerMsg_Revert() (gas: 111366)
FeeQuoter_constructor:test_InvalidStalenessThreshold_Revert() (gas: 111419)
FeeQuoter_constructor:test_Setup_Success() (gas: 5336824)
FeeQuoter_constructor:test_InvalidLinkTokenEqZeroAddress_Revert() (gas: 107046)
FeeQuoter_constructor:test_InvalidMaxFeeJuelsPerMsg_Revert() (gas: 111396)
FeeQuoter_constructor:test_InvalidStalenessThreshold_Revert() (gas: 111449)
FeeQuoter_constructor:test_Setup_Success() (gas: 5358690)
FeeQuoter_convertTokenAmount:test_ConvertTokenAmount_Success() (gas: 72739)
FeeQuoter_convertTokenAmount:test_LinkTokenNotSupported_Revert() (gas: 30963)
FeeQuoter_getDataAvailabilityCost:test_EmptyMessageCalculatesDataAvailabilityCost_Success() (gas: 94303)
Expand All @@ -368,17 +369,17 @@ FeeQuoter_getTokenTransferCost:test_ZeroAmountTokenTransferChargesMinFeeAndGas_S
FeeQuoter_getTokenTransferCost:test_ZeroFeeConfigChargesMinFee_Success() (gas: 40013)
FeeQuoter_getTokenTransferCost:test_getTokenTransferCost_selfServeUsesDefaults_Success() (gas: 29299)
FeeQuoter_getValidatedFee:test_DestinationChainNotEnabled_Revert() (gas: 18180)
FeeQuoter_getValidatedFee:test_EmptyMessage_Success() (gas: 81054)
FeeQuoter_getValidatedFee:test_EnforceOutOfOrder_Revert() (gas: 54294)
FeeQuoter_getValidatedFee:test_HighGasMessage_Success() (gas: 237472)
FeeQuoter_getValidatedFee:test_InvalidEVMAddress_Revert() (gas: 19949)
FeeQuoter_getValidatedFee:test_MessageGasLimitTooHigh_Revert() (gas: 31746)
FeeQuoter_getValidatedFee:test_MessageTooLarge_Revert() (gas: 97692)
FeeQuoter_getValidatedFee:test_MessageWithDataAndTokenTransfer_Success() (gas: 142833)
FeeQuoter_getValidatedFee:test_NotAFeeToken_Revert() (gas: 29407)
FeeQuoter_getValidatedFee:test_SingleTokenMessage_Success() (gas: 111861)
FeeQuoter_getValidatedFee:test_TooManyTokens_Revert() (gas: 20085)
FeeQuoter_getValidatedFee:test_ZeroDataAvailabilityMultiplier_Success() (gas: 61933)
FeeQuoter_getValidatedFee:test_EmptyMessage_Success() (gas: 85936)
FeeQuoter_getValidatedFee:test_EnforceOutOfOrder_Revert() (gas: 56735)
FeeQuoter_getValidatedFee:test_HighGasMessage_Success() (gas: 242354)
FeeQuoter_getValidatedFee:test_InvalidEVMAddress_Revert() (gas: 22390)
FeeQuoter_getValidatedFee:test_MessageGasLimitTooHigh_Revert() (gas: 34187)
FeeQuoter_getValidatedFee:test_MessageTooLarge_Revert() (gas: 100133)
FeeQuoter_getValidatedFee:test_MessageWithDataAndTokenTransfer_Success() (gas: 147715)
FeeQuoter_getValidatedFee:test_NotAFeeToken_Revert() (gas: 21043)
FeeQuoter_getValidatedFee:test_SingleTokenMessage_Success() (gas: 116743)
FeeQuoter_getValidatedFee:test_TooManyTokens_Revert() (gas: 22526)
FeeQuoter_getValidatedFee:test_ZeroDataAvailabilityMultiplier_Success() (gas: 64374)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedErc20Above18Decimals_Success() (gas: 2094539)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedErc20Below18Decimals_Success() (gas: 2094497)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedFeedAt0Decimals_Success() (gas: 2074616)
Expand Down Expand Up @@ -564,8 +565,8 @@ MultiOCR3Base_transmit:test_UnAuthorizedTransmitter_Revert() (gas: 24191)
MultiOCR3Base_transmit:test_UnauthorizedSigner_Revert() (gas: 61409)
MultiOCR3Base_transmit:test_UnconfiguredPlugin_Revert() (gas: 39890)
MultiOCR3Base_transmit:test_ZeroSignatures_Revert() (gas: 32973)
MultiOnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 410978)
MultiRampsE2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1504783)
MultiOnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 414301)
MultiRampsE2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1506106)
NonceManager_NonceIncrementation:test_getIncrementedOutboundNonce_Success() (gas: 37907)
NonceManager_NonceIncrementation:test_incrementInboundNonce_Skip() (gas: 23694)
NonceManager_NonceIncrementation:test_incrementInboundNonce_Success() (gas: 38763)
Expand Down Expand Up @@ -747,19 +748,15 @@ OffRamp_verify:test_NotBlessedWrongChainSelector_Success() (gas: 178754)
OffRamp_verify:test_NotBlessed_Success() (gas: 141593)
OffRamp_verify:test_TooManyLeaves_Revert() (gas: 51510)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 390336)
OnRamp_allowListConfigUpdates:test_applyAllowList_Success() (gas: 323566)
OnRamp_allowListConfigUpdates:test_applyAllowList_Revert() (gas: 66509)
OnRamp_allowListConfigUpdates:test_setAllowListAdmin_ByNonOwner_Revert() (gas: 11833)
OnRamp_allowListConfigUpdates:test_setAllowListAdmin_Success() (gas: 36159)
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_WithInvalidChainSelector_Revert() (gas: 13242)
OnRamp_allowListConfigUpdates:test_applyAllowList_Success() (gas: 323566)
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_Success() (gas: 64501)
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_WithInalidChainSelector_Revert() (gas: 13308)
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_WithInvalidChainSelector_Revert() (gas: 13242)
OnRamp_constructor:test_Constructor_InvalidConfigChainSelectorEqZero_Revert() (gas: 94878)
OnRamp_constructor:test_Constructor_InvalidConfigNonceManagerEqAddressZero_Revert() (gas: 92812)
OnRamp_constructor:test_Constructor_InvalidConfigRMNProxyEqAddressZero_Revert() (gas: 97827)
OnRamp_constructor:test_Constructor_InvalidConfigTokenAdminRegistryEqAddressZero_Revert() (gas: 92870)
OnRamp_constructor:test_Constructor_Success() (gas: 2866937)
OnRamp_forwardFromRouter:test_CannotSendZeroTokens_Revert() (gas: 72097)
OnRamp_forwardFromRouter:test_ForwardFromRouterExtraArgsV2AllowOutOfOrderTrue_Success() (gas: 115250)
OnRamp_forwardFromRouter:test_ForwardFromRouterExtraArgsV2_Success() (gas: 146019)
OnRamp_forwardFromRouter:test_ForwardFromRouterSuccessCustomExtraArgs() (gas: 145615)
Expand All @@ -770,6 +767,7 @@ OnRamp_forwardFromRouter:test_ForwardFromRouter_Success_ConfigurableSourceRouter
OnRamp_forwardFromRouter:test_InvalidExtraArgsTag_Revert() (gas: 28810)
OnRamp_forwardFromRouter:test_MessageValidationError_Revert() (gas: 138683)
OnRamp_forwardFromRouter:test_MesssageFeeTooHigh_Revert() (gas: 26910)
OnRamp_forwardFromRouter:test_MultiCannotSendZeroTokens_Revert() (gas: 74456)
OnRamp_forwardFromRouter:test_OriginalSender_Revert() (gas: 12918)
OnRamp_forwardFromRouter:test_Paused_Revert() (gas: 37224)
OnRamp_forwardFromRouter:test_Permissions_Revert() (gas: 18179)
Expand All @@ -782,19 +780,19 @@ OnRamp_forwardFromRouter:test_UnAllowedOriginalSender_Revert() (gas: 18609)
OnRamp_forwardFromRouter:test_UnsupportedToken_Revert() (gas: 111118)
OnRamp_forwardFromRouter:test_forwardFromRouter_UnsupportedToken_Revert() (gas: 76545)
OnRamp_forwardFromRouter:test_forwardFromRouter_WithValidation_Success() (gas: 278740)
OnRamp_forwardFromRouter:test_MultiCannotSendZeroTokens_Revert() (gas: 74456)
OnRamp_getFee:test_EmptyMessage_Success() (gas: 104331)
OnRamp_getFee:test_EnforceOutOfOrder_Revert() (gas: 73163)
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 119655)
OnRamp_getFee:test_EmptyMessage_Success() (gas: 110107)
OnRamp_getFee:test_EnforceOutOfOrder_Revert() (gas: 75610)
OnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 95456)
OnRamp_getFee:test_NotAFeeTokenButPricedToken_Revert() (gas: 41814)
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 125476)
OnRamp_getFee:test_Unhealthy_Revert() (gas: 43669)
OnRamp_getSupportedTokens:test_GetSupportedTokens_Revert() (gas: 10438)
OnRamp_getTokenPool:test_GetTokenPool_Success() (gas: 35204)
OnRamp_setDynamicConfig:test_SetConfigInvalidConfigFeeAggregatorEqAddressZero_Revert() (gas: 11402)
OnRamp_setDynamicConfig:test_SetConfigInvalidConfigPriceRegistryEqAddressZero_Revert() (gas: 12978)
OnRamp_setDynamicConfig:test_SetConfigInvalidConfigFeeQuoterEqAddressZero_Revert() (gas: 13001)
OnRamp_setDynamicConfig:test_SetConfigInvalidConfig_Revert() (gas: 11359)
OnRamp_setDynamicConfig:test_SetConfigOnlyOwner_Revert() (gas: 16385)
OnRamp_setDynamicConfig:test_SetDynamicConfig_Success() (gas: 55321)
OnRamp_setDynamicConfig:test_SetConfigInvalidConfigFeeQuoterEqAddressZero_Revert() (gas: 13001)
OnRamp_withdrawFeeTokens:test_WithdrawFeeTokens_Success() (gas: 97107)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 150169)
PingPong_plumbing:test_OutOfOrderExecution_Success() (gas: 20277)
Expand Down
5 changes: 3 additions & 2 deletions contracts/src/v0.8/ccip/FeeQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
using KeystoneFeedDefaultMetadataLib for bytes;

error TokenNotSupported(address token);
error FeeTokenNotSupported(address token);
error ChainNotSupported(uint64 chain);
error StaleGasPrice(uint64 destChainSelector, uint256 threshold, uint256 timePassed);
error StaleKeystoneUpdate(address token, uint256 feedTimestamp, uint256 storedTimeStamp);
Expand Down Expand Up @@ -147,7 +148,7 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
/// applyPremiumMultiplierWeiPerEthUpdates to set the mapping
struct PremiumMultiplierWeiPerEthArgs {
address token; // // ───────────────────╮ Token address
uint64 premiumMultiplierWeiPerEth; // ──╯ Multiplier for destination chain specific premiums. Should never be 0 so can be used as an isEnabled flag
uint64 premiumMultiplierWeiPerEth; // ──╯ Multiplier for destination chain specific premiums.
}

string public constant override typeAndVersion = "FeeQuoter 1.6.0-dev";
Expand All @@ -174,7 +175,6 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
mapping(address token => IFeeQuoter.TokenPriceFeedConfig dataFeedAddress) private s_usdPriceFeedsPerToken;

/// @dev The multiplier for destination chain specific premiums that can be set by the owner or fee admin
/// This should never be 0 once set, so it can be used as an isEnabled flag
mapping(address token => uint64 premiumMultiplierWeiPerEth) internal s_premiumMultiplierWeiPerEth;

/// @dev The destination chain specific fee configs
Expand Down Expand Up @@ -473,6 +473,7 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
) external view returns (uint256 feeTokenAmount) {
DestChainConfig memory destChainConfig = s_destChainConfigs[destChainSelector];
if (!destChainConfig.isEnabled) revert DestinationChainNotEnabled(destChainSelector);
if (!s_feeTokens.contains(message.feeToken)) revert FeeTokenNotSupported(message.feeToken);

uint256 numberOfTokens = message.tokenAmounts.length;
_validateMessage(destChainConfig, message.data.length, numberOfTokens, message.receiver);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ contract FeeQuoter_getValidatedFee is FeeQuoterFeeSetup {
Client.EVM2AnyMessage memory message = _generateSingleTokenMessage(notAFeeToken, 1);
message.feeToken = notAFeeToken;

vm.expectRevert(abi.encodeWithSelector(FeeQuoter.TokenNotSupported.selector, notAFeeToken));
vm.expectRevert(abi.encodeWithSelector(FeeQuoter.FeeTokenNotSupported.selector, notAFeeToken));

s_feeQuoter.getValidatedFee(DEST_CHAIN_SELECTOR, message);
}
Expand Down
26 changes: 26 additions & 0 deletions contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,32 @@ contract EVM2EVMOnRamp_getFee is EVM2EVMOnRamp_getFeeSetup {
}
}

function test_GetFeeOfZeroForTokenMessage_Success() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();

uint256 feeAmount = s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);
assertTrue(feeAmount > 0);

EVM2EVMOnRamp.FeeTokenConfigArgs[] memory feeTokenConfigArgs = new EVM2EVMOnRamp.FeeTokenConfigArgs[](1);
feeTokenConfigArgs[0] = EVM2EVMOnRamp.FeeTokenConfigArgs({
token: message.feeToken,
networkFeeUSDCents: 0,
gasMultiplierWeiPerEth: 0,
premiumMultiplierWeiPerEth: 0,
enabled: true
});

s_onRamp.setFeeTokenConfig(feeTokenConfigArgs);
EVM2EVMOnRamp.DynamicConfig memory config =
generateDynamicOnRampConfig(address(s_sourceRouter), address(s_feeQuoter));
config.destDataAvailabilityMultiplierBps = 0;

s_onRamp.setDynamicConfig(config);

feeAmount = s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);
assertEq(0, feeAmount);
}

function test_ZeroDataAvailabilityMultiplier_Success() public {
EVM2EVMOnRamp.DynamicConfig memory dynamicConfig = s_onRamp.getDynamicConfig();
dynamicConfig.destDataAvailabilityMultiplierBps = 0;
Expand Down
29 changes: 29 additions & 0 deletions contracts/src/v0.8/ccip/test/onRamp/OnRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,26 @@ contract OnRamp_getFee is OnRampSetup {
}
}

function test_GetFeeOfZeroForTokenMessage_Success() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();

uint256 feeAmount = s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);
assertTrue(feeAmount > 0);

FeeQuoter.PremiumMultiplierWeiPerEthArgs[] memory tokenMults = new FeeQuoter.PremiumMultiplierWeiPerEthArgs[](1);
tokenMults[0] = FeeQuoter.PremiumMultiplierWeiPerEthArgs({token: message.feeToken, premiumMultiplierWeiPerEth: 0});
s_feeQuoter.applyPremiumMultiplierWeiPerEthUpdates(tokenMults);

FeeQuoter.DestChainConfigArgs[] memory destChainConfigArgs = _generateFeeQuoterDestChainConfigArgs();
destChainConfigArgs[0].destChainConfig.destDataAvailabilityMultiplierBps = 0;
destChainConfigArgs[0].destChainConfig.gasMultiplierWeiPerEth = 0;
s_feeQuoter.applyDestChainConfigUpdates(destChainConfigArgs);

feeAmount = s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);

assertEq(0, feeAmount);
}

// Reverts

function test_Unhealthy_Revert() public {
Expand All @@ -634,6 +654,15 @@ contract OnRamp_getFee is OnRampSetup {
vm.expectRevert(FeeQuoter.ExtraArgOutOfOrderExecutionMustBeTrue.selector);
s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);
}

function test_NotAFeeTokenButPricedToken_Revert() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.feeToken = s_sourceTokens[1];

vm.expectRevert(abi.encodeWithSelector(FeeQuoter.FeeTokenNotSupported.selector, message.feeToken));

s_onRamp.getFee(DEST_CHAIN_SELECTOR, message);
}
}

contract OnRamp_setDynamicConfig is OnRampSetup {
Expand Down
4 changes: 2 additions & 2 deletions core/gethwrappers/ccip/generated/fee_quoter/fee_quoter.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ commit_store_helper: ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitSto
ether_sender_receiver: ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.abi ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.bin 09510a3f773f108a3c231e8d202835c845ded862d071ec54c4f89c12d868b8de
evm_2_evm_offramp: ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.bin b0d77babbe635cd6ba04c2af049badc9e9d28a4b6ed6bb75f830ad902a618beb
evm_2_evm_onramp: ../../../contracts/solc/v0.8.24/EVM2EVMOnRamp/EVM2EVMOnRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMOnRamp/EVM2EVMOnRamp.bin 5c02c2b167946b3467636ff2bb58594cb4652fc63d8bdfee2488ed562e2a3e50
fee_quoter: ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.abi ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.bin 95cdd54835272004bbe4a469b8529aa6f92ece2f903d914615010f1bf80a16c8
fee_quoter: ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.abi ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.bin 920b7a293165fe8306fbed0cafd866bafc5943e8759486f7803bfbbd40309b6b
lock_release_token_pool: ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.bin e6a8ec9e8faccb1da7d90e0f702ed72975964f97dc3222b54cfcca0a0ba3fea2
lock_release_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.bin e632b08be0fbd1d013e8b3a9d75293d0d532b83071c531ff2be1deec1fa48ec1
maybe_revert_message_receiver: ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin d73956c26232ebcc4a5444429fa99cbefed960e323be9b5a24925885c2e477d5
Expand Down

0 comments on commit 7c70148

Please sign in to comment.