Skip to content

Commit

Permalink
CCIP-4646 account for token transfer bytes overhead in execution cost (
Browse files Browse the repository at this point in the history
…#15737)

* CCIP-4646 Account for tokenTransferBytesOverhead in exec cost

* add changeset

* [Bot] Update changeset file with jira issues

---------

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 45fcad7 commit 631cd8f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
9 changes: 9 additions & 0 deletions contracts/.changeset/early-cups-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@chainlink/contracts': minor
---

#internal Account for tokenTransferBytesOverhead in exec cost

PR issue: CCIP-4646

Solidity Review issue: CCIP-3966
54 changes: 27 additions & 27 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BurnWithFromMintTokenPool_lockOrBurn:test_ChainNotAllowed_Revert() (gas: 27346)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas: 54878)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 244496)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24223)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2077779)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2078199)
CCIPHome__validateConfig:test__validateConfigLessTransmittersThanSigners_Success() (gas: 332619)
CCIPHome__validateConfig:test__validateConfigSmallerFChain_Success() (gas: 458568)
CCIPHome__validateConfig:test__validateConfig_ABIEncodedAddress_OfframpAddressCannotBeZero_Reverts() (gas: 289191)
Expand Down Expand Up @@ -68,7 +68,7 @@ CCIPHome_setCandidate:test_setCandidate_success() (gas: 1365439)
CCIPHome_supportsInterface:test_supportsInterface_success() (gas: 9885)
DefensiveExampleTest:test_HappyPath_Success() (gas: 200540)
DefensiveExampleTest:test_Recovery() (gas: 425013)
E2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1512391)
E2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1512665)
EtherSenderReceiverTest_ccipReceive:test_ccipReceive_fallbackToWethTransfer() (gas: 96980)
EtherSenderReceiverTest_ccipReceive:test_ccipReceive_happyPath() (gas: 49812)
EtherSenderReceiverTest_ccipReceive:test_ccipReceive_wrongToken() (gas: 17479)
Expand Down Expand Up @@ -138,7 +138,7 @@ FeeQuoter_applyTokenTransferFeeConfigUpdates:test_OnlyCallableByOwnerOrAdmin_Rev
FeeQuoter_constructor:test_InvalidLinkTokenEqZeroAddress_Revert() (gas: 106632)
FeeQuoter_constructor:test_InvalidMaxFeeJuelsPerMsg_Revert() (gas: 110982)
FeeQuoter_constructor:test_InvalidStalenessThreshold_Revert() (gas: 111057)
FeeQuoter_constructor:test_Setup_Success() (gas: 5011219)
FeeQuoter_constructor:test_Setup_Success() (gas: 5014619)
FeeQuoter_convertTokenAmount:test_ConvertTokenAmount_Success() (gas: 68416)
FeeQuoter_convertTokenAmount:test_LinkTokenNotSupported_Revert() (gas: 29300)
FeeQuoter_getDataAvailabilityCost:test_EmptyMessageCalculatesDataAvailabilityCost_Success() (gas: 96433)
Expand All @@ -162,17 +162,17 @@ FeeQuoter_getTokenTransferCost:test_ZeroAmountTokenTransferChargesMinFeeAndGas_S
FeeQuoter_getTokenTransferCost:test_ZeroFeeConfigChargesMinFee_Success() (gas: 40822)
FeeQuoter_getTokenTransferCost:test_getTokenTransferCost_selfServeUsesDefaults_Success() (gas: 29736)
FeeQuoter_getValidatedFee:test_DestinationChainNotEnabled_Revert() (gas: 18465)
FeeQuoter_getValidatedFee:test_EmptyMessage_Success() (gas: 83340)
FeeQuoter_getValidatedFee:test_EmptyMessage_Success() (gas: 83484)
FeeQuoter_getValidatedFee:test_EnforceOutOfOrder_Revert() (gas: 53570)
FeeQuoter_getValidatedFee:test_HighGasMessage_Success() (gas: 239736)
FeeQuoter_getValidatedFee:test_HighGasMessage_Success() (gas: 239880)
FeeQuoter_getValidatedFee:test_InvalidEVMAddress_Revert() (gas: 22668)
FeeQuoter_getValidatedFee:test_MessageGasLimitTooHigh_Revert() (gas: 29966)
FeeQuoter_getValidatedFee:test_MessageTooLarge_Revert() (gas: 100417)
FeeQuoter_getValidatedFee:test_MessageWithDataAndTokenTransfer_Success() (gas: 143246)
FeeQuoter_getValidatedFee:test_MessageWithDataAndTokenTransfer_Success() (gas: 143562)
FeeQuoter_getValidatedFee:test_NotAFeeToken_Revert() (gas: 21280)
FeeQuoter_getValidatedFee:test_SingleTokenMessage_Success() (gas: 114510)
FeeQuoter_getValidatedFee:test_SingleTokenMessage_Success() (gas: 115060)
FeeQuoter_getValidatedFee:test_TooManyTokens_Revert() (gas: 23495)
FeeQuoter_getValidatedFee:test_ZeroDataAvailabilityMultiplier_Success() (gas: 63909)
FeeQuoter_getValidatedFee:test_ZeroDataAvailabilityMultiplier_Success() (gas: 63981)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedErc20Above18Decimals_Success() (gas: 1897852)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedErc20Below18Decimals_Success() (gas: 1897810)
FeeQuoter_getValidatedTokenPrice:test_GetValidatedTokenPriceFromFeedFeedAt0Decimals_Success() (gas: 1877929)
Expand Down Expand Up @@ -491,7 +491,7 @@ OffRamp_trialExecute:test_trialExecute() (gas: 271859)
OffRamp_trialExecute:test_trialExecute_RateLimitError() (gas: 127545)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 138855)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 289500)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 251641)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 251893)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 17227)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_Revert() (gas: 67101)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_Success() (gas: 325983)
Expand Down Expand Up @@ -526,11 +526,11 @@ OnRamp_forwardFromRouter:test_UnAllowedOriginalSender_Revert() (gas: 24015)
OnRamp_forwardFromRouter:test_UnsupportedToken_Revert() (gas: 75854)
OnRamp_forwardFromRouter:test_forwardFromRouter_UnsupportedToken_Revert() (gas: 38588)
OnRamp_forwardFromRouter:test_forwardFromRouter_WithInterception_Success() (gas: 281529)
OnRamp_getFee:test_EmptyMessage_Success() (gas: 98692)
OnRamp_getFee:test_EmptyMessage_Success() (gas: 99028)
OnRamp_getFee:test_EnforceOutOfOrder_Revert() (gas: 65475)
OnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 87119)
OnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 87287)
OnRamp_getFee:test_NotAFeeTokenButPricedToken_Revert() (gas: 35166)
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 113865)
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 114201)
OnRamp_getFee:test_Unhealthy_Revert() (gas: 17040)
OnRamp_getSupportedTokens:test_GetSupportedTokens_Revert() (gas: 10565)
OnRamp_getTokenPool:test_GetTokenPool_Success() (gas: 35405)
Expand All @@ -541,11 +541,11 @@ OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigOnlyOwner_Revert() (g
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigReentrancyGuardEnteredEqTrue_Revert() (gas: 13264)
OnRamp_setDynamicConfig:test_setDynamicConfig_Success() (gas: 56440)
OnRamp_withdrawFeeTokens:test_WithdrawFeeTokens_Success() (gas: 125901)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 172880)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 172964)
PingPong_setOutOfOrderExecution:test_OutOfOrderExecution_Success() (gas: 20283)
PingPong_setPaused:test_Pausing_Success() (gas: 17738)
PingPong_startPingPong:test_StartPingPong_With_OOO_Success() (gas: 151993)
PingPong_startPingPong:test_StartPingPong_With_Sequenced_Ordered_Success() (gas: 177608)
PingPong_startPingPong:test_StartPingPong_With_OOO_Success() (gas: 152077)
PingPong_startPingPong:test_StartPingPong_With_Sequenced_Ordered_Success() (gas: 177692)
RMNHome_getConfigDigests:test_getConfigDigests_success() (gas: 1079685)
RMNHome_promoteCandidateAndRevokeActive:test_promoteCandidateAndRevokeActive_ConfigDigestMismatch_reverts() (gas: 23879)
RMNHome_promoteCandidateAndRevokeActive:test_promoteCandidateAndRevokeActive_NoOpStateTransitionNotAllowed_reverts() (gas: 10597)
Expand Down Expand Up @@ -612,23 +612,23 @@ RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Rever
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Success() (gas: 129930)
Router_applyRampUpdates:test_applyRampUpdates_OffRampUpdatesWithRouting() (gas: 10749731)
Router_applyRampUpdates:test_applyRampUpdates_OnRampDisable() (gas: 56422)
Router_ccipSend:test_CCIPSendLinkFeeNoTokenSuccess_gas() (gas: 131447)
Router_ccipSend:test_CCIPSendLinkFeeOneTokenSuccess_gas() (gas: 221710)
Router_ccipSend:test_FeeTokenAmountTooLow_Revert() (gas: 71858)
Router_ccipSend:test_CCIPSendLinkFeeNoTokenSuccess_gas() (gas: 131531)
Router_ccipSend:test_CCIPSendLinkFeeOneTokenSuccess_gas() (gas: 221794)
Router_ccipSend:test_FeeTokenAmountTooLow_Revert() (gas: 71942)
Router_ccipSend:test_InvalidMsgValue() (gas: 32411)
Router_ccipSend:test_NativeFeeTokenInsufficientValue() (gas: 69524)
Router_ccipSend:test_NativeFeeTokenOverpay_Success() (gas: 193318)
Router_ccipSend:test_NativeFeeTokenZeroValue() (gas: 61550)
Router_ccipSend:test_NativeFeeToken_Success() (gas: 191922)
Router_ccipSend:test_NonLinkFeeToken_Success() (gas: 226583)
Router_ccipSend:test_NativeFeeTokenInsufficientValue() (gas: 69608)
Router_ccipSend:test_NativeFeeTokenOverpay_Success() (gas: 193486)
Router_ccipSend:test_NativeFeeTokenZeroValue() (gas: 61634)
Router_ccipSend:test_NativeFeeToken_Success() (gas: 192090)
Router_ccipSend:test_NonLinkFeeToken_Success() (gas: 226667)
Router_ccipSend:test_UnsupportedDestinationChain_Revert() (gas: 25056)
Router_ccipSend:test_WhenNotHealthy_Revert() (gas: 45056)
Router_ccipSend:test_WrappedNativeFeeToken_Success() (gas: 194231)
Router_ccipSend:test_ccipSend_nativeFeeNoTokenSuccess_gas() (gas: 140696)
Router_ccipSend:test_ccipSend_nativeFeeOneTokenSuccess_gas() (gas: 230894)
Router_ccipSend:test_WrappedNativeFeeToken_Success() (gas: 194399)
Router_ccipSend:test_ccipSend_nativeFeeNoTokenSuccess_gas() (gas: 140780)
Router_ccipSend:test_ccipSend_nativeFeeOneTokenSuccess_gas() (gas: 230978)
Router_constructor:test_Constructor_Success() (gas: 13222)
Router_getArmProxy:test_getArmProxy() (gas: 10573)
Router_getFee:test_GetFeeSupportedChain_Success() (gas: 51934)
Router_getFee:test_GetFeeSupportedChain_Success() (gas: 52018)
Router_getFee:test_UnsupportedDestinationChain_Revert() (gas: 17385)
Router_getSupportedTokens:test_GetSupportedTokens_Revert() (gas: 10565)
Router_recoverTokens:test_RecoverTokensInvalidRecipient_Revert() (gas: 11410)
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v0.8/ccip/FeeQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
// fee logic for other chains should be implemented in the future.
uint256 executionCost = uint112(packedGasPrice)
* (
destChainConfig.destGasOverhead + (message.data.length * destChainConfig.destGasPerPayloadByte) + tokenTransferGas
destChainConfig.destGasOverhead
+ ((message.data.length + tokenTransferBytesOverhead) * destChainConfig.destGasPerPayloadByte) + tokenTransferGas
+ _parseEVMExtraArgsFromBytes(message.extraArgs, destChainConfig).gasLimit
) * destChainConfig.gasMultiplierWeiPerEth;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract FeeQuoter_getValidatedFee is FeeQuoterFeeSetup {

uint256 feeAmount = s_feeQuoter.getValidatedFee(DEST_CHAIN_SELECTOR, message);

uint256 gasUsed = GAS_LIMIT + DEST_GAS_OVERHEAD
uint256 gasUsed = GAS_LIMIT + DEST_GAS_OVERHEAD + tokenBytesOverhead * DEST_GAS_PER_PAYLOAD_BYTE
+ s_feeQuoter.getTokenTransferFeeConfig(DEST_CHAIN_SELECTOR, message.tokenAmounts[0].token).destGasOverhead;
uint256 gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS);
(uint256 transferFeeUSD,,) =
Expand Down Expand Up @@ -152,12 +152,20 @@ contract FeeQuoter_getValidatedFee is FeeQuoterFeeSetup {
tokenBytesOverhead += destBytesOverhead == 0 ? uint32(Pool.CCIP_LOCK_OR_BURN_V1_RET_BYTES) : destBytesOverhead;
}

uint256 gasUsed =
customGasLimit + DEST_GAS_OVERHEAD + message.data.length * DEST_GAS_PER_PAYLOAD_BYTE + tokenGasOverhead;
uint256 gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS);
(uint256 transferFeeUSD,,) =
(uint256 transferFeeUSD,, uint256 tokenTransferBytesOverhead) =
s_feeQuoter.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, feeTokenPrices[i], message.tokenAmounts);

uint256 gasFeeUSD;

{
uint256 gasUsed = customGasLimit + DEST_GAS_OVERHEAD
+ (message.data.length + tokenTransferBytesOverhead) * DEST_GAS_PER_PAYLOAD_BYTE + tokenGasOverhead;

gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS);
}

uint256 messageFeeUSD = (transferFeeUSD * premiumMultiplierWeiPerEth);

uint256 dataAvailabilityFeeUSD = s_feeQuoter.getDataAvailabilityCost(
DEST_CHAIN_SELECTOR,
USD_PER_DATA_AVAILABILITY_GAS,
Expand Down
2 changes: 1 addition & 1 deletion 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 @@ -6,7 +6,7 @@ ccip_encoding_utils: ../../../contracts/solc/v0.8.24/ICCIPEncodingUtils/ICCIPEnc
ccip_home: ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.abi ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.bin 865bc25c54cf346e5f519dc3fb625260a12c80983b5ba2dcea63519a7befc660
ccip_reader_tester: ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.abi ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.bin b368699ae7dbee7c21d049a641642837f18ce2cc8d4ece69509f205de673108e
ether_sender_receiver: ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.abi ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.bin 09510a3f773f108a3c231e8d202835c845ded862d071ec54c4f89c12d868b8de
fee_quoter: ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.abi ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.bin aee49c9246d5903e68b175516b3cdfdec5df23e25d53d604cd382b6bc0bf34f7
fee_quoter: ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.abi ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.bin 95cf64cb4e2f7110469db455218aefea7b8cf1b5deab1a6f07745a4e657fad8c
lock_release_token_pool: ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.bin 04b40584830294fb603cc2a250af7d831d05a04650a8c2fc9e3af5a78c471be6
maybe_revert_message_receiver: ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin d73956c26232ebcc4a5444429fa99cbefed960e323be9b5a24925885c2e477d5
message_hasher: ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.abi ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.bin ec2d3a92348d8e7b8f0d359b62a45157b9d2c750c01fbcf991826c4392f6e218
Expand Down

0 comments on commit 631cd8f

Please sign in to comment.