Skip to content

Commit

Permalink
set more correct gas overheads (#1319)
Browse files Browse the repository at this point in the history
Cleanup & more realistic values for gas overheads
  • Loading branch information
RensR authored Aug 19, 2024
1 parent f1f63fd commit 11c2759
Show file tree
Hide file tree
Showing 36 changed files with 726 additions and 775 deletions.
48 changes: 24 additions & 24 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,30 @@ CommitStore_verify:test_Paused_Revert() (gas: 18496)
CommitStore_verify:test_TooManyLeaves_Revert() (gas: 36785)
DefensiveExampleTest:test_HappyPath_Success() (gas: 200018)
DefensiveExampleTest:test_Recovery() (gas: 424256)
E2E:test_E2E_3MessagesSuccess_gas() (gas: 1104304)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_NotACompatiblePool_Revert() (gas: 38416)
E2E:test_E2E_3MessagesSuccess_gas() (gas: 1104303)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_NotACompatiblePool_Revert() (gas: 38408)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_Success() (gas: 106250)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_TokenHandlingError_transfer_Revert() (gas: 87421)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_InvalidDataLength_Revert() (gas: 38958)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_ReleaseOrMintBalanceMismatch_Revert() (gas: 96515)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_TokenHandlingError_BalanceOf_Revert() (gas: 41964)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_TokenHandlingError_transfer_Revert() (gas: 87409)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_InvalidDataLength_Revert() (gas: 38954)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_ReleaseOrMintBalanceMismatch_Revert() (gas: 96511)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_TokenHandlingError_BalanceOf_Revert() (gas: 41956)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_skip_ReleaseOrMintBalanceMismatch_if_pool_Revert() (gas: 88684)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddMultipleChains_Success() (gas: 468131)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddNewChain_Success() (gas: 99235)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ApplyZeroUpdates_Success() (gas: 12399)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChainOnRamp_Revert() (gas: 93193)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChain_Success() (gas: 109906)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_RouterAddress_Revert() (gas: 13267)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroOnRampAddress_Revert() (gas: 17992)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroSourceChainSelector_Revert() (gas: 15347)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddMultipleChains_Success() (gas: 468115)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddNewChain_Success() (gas: 99227)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ApplyZeroUpdates_Success() (gas: 12395)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChainOnRamp_Revert() (gas: 93181)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChain_Success() (gas: 109890)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_RouterAddress_Revert() (gas: 13263)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroOnRampAddress_Revert() (gas: 17988)
EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroSourceChainSelector_Revert() (gas: 15343)
EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsDifferentChains_Success() (gas: 313594)
EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsSameChain_Success() (gas: 254984)
EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsSkipDuplicate_Success() (gas: 166123)
EVM2EVMMultiOffRamp_batchExecute:test_OutOfBoundsGasLimitsAccess_Revert() (gas: 187729)
EVM2EVMMultiOffRamp_batchExecute:test_SingleReport_Success() (gas: 153140)
EVM2EVMMultiOffRamp_batchExecute:test_Unhealthy_Revert() (gas: 518887)
EVM2EVMMultiOffRamp_batchExecute:test_ZeroReports_Revert() (gas: 10439)
EVM2EVMMultiOffRamp_ccipReceive:test_Reverts() (gas: 15688)
EVM2EVMMultiOffRamp_ccipReceive:test_Reverts() (gas: 15684)
EVM2EVMMultiOffRamp_commit:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 67458)
EVM2EVMMultiOffRamp_commit:test_InvalidInterval_Revert() (gas: 59734)
EVM2EVMMultiOffRamp_commit:test_InvalidRootRevert() (gas: 58814)
Expand All @@ -166,7 +166,7 @@ EVM2EVMMultiOffRamp_commit:test_Unhealthy_Revert() (gas: 77608)
EVM2EVMMultiOffRamp_commit:test_ValidPriceUpdateThenStaleReportWithRoot_Success() (gas: 205117)
EVM2EVMMultiOffRamp_commit:test_WrongConfigWithoutSigners_Revert() (gas: 6532473)
EVM2EVMMultiOffRamp_commit:test_ZeroEpochAndRound_Revert() (gas: 47788)
EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6125452)
EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6125436)
EVM2EVMMultiOffRamp_constructor:test_SourceChainSelector_Revert() (gas: 137067)
EVM2EVMMultiOffRamp_constructor:test_ZeroChainSelector_Revert() (gas: 103784)
EVM2EVMMultiOffRamp_constructor:test_ZeroNonceManager_Revert() (gas: 101677)
Expand Down Expand Up @@ -221,9 +221,9 @@ EVM2EVMMultiOffRamp_executeSingleReport:test_Unhealthy_Revert() (gas: 515089)
EVM2EVMMultiOffRamp_executeSingleReport:test_WithCurseOnAnotherSourceChain_Success() (gas: 485207)
EVM2EVMMultiOffRamp_executeSingleReport:test__execute_SkippedAlreadyExecutedMessageUnordered_Success() (gas: 133513)
EVM2EVMMultiOffRamp_executeSingleReport:test__execute_SkippedAlreadyExecutedMessage_Success() (gas: 162713)
EVM2EVMMultiOffRamp_getExecutionState:test_FillExecutionState_Success() (gas: 3677612)
EVM2EVMMultiOffRamp_getExecutionState:test_GetDifferentChainExecutionState_Success() (gas: 118399)
EVM2EVMMultiOffRamp_getExecutionState:test_GetExecutionState_Success() (gas: 87606)
EVM2EVMMultiOffRamp_getExecutionState:test_FillExecutionState_Success() (gas: 3674540)
EVM2EVMMultiOffRamp_getExecutionState:test_GetDifferentChainExecutionState_Success() (gas: 118375)
EVM2EVMMultiOffRamp_getExecutionState:test_GetExecutionState_Success() (gas: 87586)
EVM2EVMMultiOffRamp_manuallyExecute:test_ManualExecGasLimitMismatchSingleReport_Revert() (gas: 75635)
EVM2EVMMultiOffRamp_manuallyExecute:test_ManualExecInvalidGasLimit_Revert() (gas: 26471)
EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_DoesNotRevertIfUntouched_Success() (gas: 168604)
Expand All @@ -236,10 +236,10 @@ EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_Success() (gas: 208322)
EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithGasOverride_Success() (gas: 208944)
EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithMultiReportGasOverride_Success() (gas: 662979)
EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithPartialMessages_Success() (gas: 301931)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 164054)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 23740)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() (gas: 64488)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidEVMAddress_Revert() (gas: 39524)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 164042)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 23736)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() (gas: 64484)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidEVMAddress_Revert() (gas: 39516)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_PoolDoesNotSupportDest_Reverts() (gas: 81512)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_Success() (gas: 176140)
EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_destDenominatedDecimals_Success() (gas: 189342)
Expand Down Expand Up @@ -861,7 +861,7 @@ Router_ccipSend:test_NonLinkFeeToken_Success() (gas: 242732)
Router_ccipSend:test_UnsupportedDestinationChain_Revert() (gas: 24749)
Router_ccipSend:test_WhenNotHealthy_Revert() (gas: 44724)
Router_ccipSend:test_WrappedNativeFeeToken_Success() (gas: 174440)
Router_ccipSend:test_ZeroFeeAndGasPrice_Success() (gas: 245146)
Router_ccipSend:test_ZeroFeeAndGasPrice_Success() (gas: 244856)
Router_constructor:test_Constructor_Success() (gas: 13074)
Router_getArmProxy:test_getArmProxy() (gas: 10561)
Router_getFee:test_GetFeeSupportedChain_Success() (gas: 46464)
Expand Down
15 changes: 12 additions & 3 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,37 @@
},
"files": [
"src/v0.8/ccip/**/*.sol",
"!src/v0.8/ccip/test/**/*",
"src/v0.8/ccip/test/mocks/**/*",
"src/v0.8/shared/access/ConfirmedOwner.sol",
"src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol",
"src/v0.8/shared/access/OwnerIsCreator.sol",
"src/v0.8/shared/access/AuthorizedCallers.sol",
"src/v0.8/shared/call/CallWithExactGas.sol",
"src/v0.8/shared/enumerable/EnumerableMapBytes32.sol",
"src/v0.8/shared/enumerable/EnumerableMapAddresses.sol",
"src/v0.8/shared/interfaces/IOwnable.sol",
"src/v0.8/shared/interfaces/ITypeAndVersion.sol",
"src/v0.8/shared/interfaces/IERC677Receiver.sol",
"src/v0.8/shared/interfaces/AggregatorV3Interface.sol",
"src/v0.8/shared/token/ERC20/IBurnMintERC20.sol",
"src/v0.8/shared/token/ERC677/IERC677.sol",
"src/v0.8/shared/token/ERC677/IERC677Receiver.sol",
"src/v0.8/shared/token/ERC677/ERC677.sol",
"src/v0.8/shared/token/ERC677/BurnMintERC677.sol",
"src/v0.8/shared/util/SortedSetValidationUtil.sol",
"src/v0.8/liquiditymanager/interfaces/ILiquidityContainer.sol",
"src/v0.8/keystone/interfaces/ICapabilityConfiguration.sol",
"src/v0.8/vendor/openzeppelin-solidity",
"src/v0.8/vendor/Context.sol",
"src/v0.8/vendor/Pausable.sol",
"abi/v0.8/",
"src/v0.8/ccip/LICENSE.md",
"src/v0.8/ccip/LICENSE-MIT.md",
"src/v0.8/ccip/v1.5-CCIP-License-grants.md"
"src/v0.8/ccip/v1.5-CCIP-License-grants.md",
"!src/v0.8/ccip/test/**/*",
"src/v0.8/ccip/test/mocks/**/*",
"!src/v0.8/ccip/test/mocks/test/*",
"!src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol",
"!src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol"
],
"pnpm": {
"_comment": "See https://github.com/ethers-io/ethers.js/discussions/2849#discussioncomment-2696454",
Expand Down
23 changes: 5 additions & 18 deletions contracts/src/v0.8/ccip/test/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ contract BaseTest is Test {
// Onramp
uint96 internal constant MAX_NOP_FEES_JUELS = 1e27;
uint96 internal constant MAX_MSG_FEES_JUELS = 1e18;
uint32 internal constant DEST_GAS_OVERHEAD = 350_000;
uint32 internal constant DEST_GAS_OVERHEAD = 300_000;
uint16 internal constant DEST_GAS_PER_PAYLOAD_BYTE = 16;

uint16 internal constant DEFAULT_TOKEN_FEE_USD_CENTS = 50;
uint32 internal constant DEFAULT_TOKEN_DEST_GAS_OVERHEAD = 85_000;
uint32 internal constant DEFAULT_TOKEN_DEST_GAS_OVERHEAD = 90_000;
uint32 internal constant DEFAULT_TOKEN_BYTES_OVERHEAD = 32;

bool private s_baseTestInitialized;
Expand Down Expand Up @@ -87,15 +87,15 @@ contract BaseTest is Test {
s_mockRMN = new MockRMN();
}

function getOutboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) {
function _getOutboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: true, capacity: 100e28, rate: 1e15});
}

function getInboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) {
function _getInboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: true, capacity: 222e30, rate: 1e18});
}

function getSingleTokenPriceUpdateStruct(
function _getSingleTokenPriceUpdateStruct(
address token,
uint224 price
) internal pure returns (Internal.PriceUpdates memory) {
Expand All @@ -107,17 +107,4 @@ contract BaseTest is Test {

return priceUpdates;
}

function getSingleGasPriceUpdateStruct(
uint64 chainSelector,
uint224 usdPerUnitGas
) internal pure returns (Internal.PriceUpdates memory) {
Internal.GasPriceUpdate[] memory gasPriceUpdates = new Internal.GasPriceUpdate[](1);
gasPriceUpdates[0] = Internal.GasPriceUpdate({destChainSelector: chainSelector, usdPerUnitGas: usdPerUnitGas});

Internal.PriceUpdates memory priceUpdates =
Internal.PriceUpdates({tokenPriceUpdates: new Internal.TokenPriceUpdate[](0), gasPriceUpdates: gasPriceUpdates});

return priceUpdates;
}
}
3 changes: 1 addition & 2 deletions contracts/src/v0.8/ccip/test/NonceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {EVM2EVMMultiOnRamp} from "../onRamp/EVM2EVMMultiOnRamp.sol";
import {EVM2EVMOnRamp} from "../onRamp/EVM2EVMOnRamp.sol";

import {BaseTest} from "./BaseTest.t.sol";
import {EVM2EVMMultiOnRampHelper} from "./helpers/EVM2EVMMultiOnRampHelper.sol";
import {EVM2EVMOffRampHelper} from "./helpers/EVM2EVMOffRampHelper.sol";
import {EVM2EVMOnRampHelper} from "./helpers/EVM2EVMOnRampHelper.sol";
import {MockCommitStore} from "./mocks/MockCommitStore.sol";
Expand Down Expand Up @@ -214,7 +213,7 @@ contract NonceManager_OnRampUpgrade is EVM2EVMMultiOnRampSetup {
minFeeUSDCents: 1_00, // 1 USD
maxFeeUSDCents: 1000_00, // 1,000 USD
deciBps: 2_5, // 2.5 bps, or 0.025%
destGasOverhead: 40_000,
destGasOverhead: 140_000,
destBytesOverhead: uint32(Pool.CCIP_LOCK_OR_BURN_V1_RET_BYTES),
aggregateRateLimitEnabled: true
});
Expand Down
9 changes: 4 additions & 5 deletions contracts/src/v0.8/ccip/test/TokenSetup.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {IPoolV1} from "../interfaces/IPool.sol";

import {BurnMintERC677} from "../../shared/token/ERC677/BurnMintERC677.sol";
import {Client} from "../libraries/Client.sol";
import {BurnMintTokenPool} from "../pools/BurnMintTokenPool.sol";
Expand Down Expand Up @@ -138,7 +136,7 @@ contract TokenSetup is RouterSetup {
}
}

function getCastedSourceEVMTokenAmountsWithZeroAmounts()
function _getCastedSourceEVMTokenAmountsWithZeroAmounts()
internal
view
returns (Client.EVMTokenAmount[] memory tokenAmounts)
Expand All @@ -147,6 +145,7 @@ contract TokenSetup is RouterSetup {
for (uint256 i = 0; i < tokenAmounts.length; ++i) {
tokenAmounts[i].token = s_sourceTokens[i];
}
return tokenAmounts;
}

function _setPool(
Expand All @@ -170,8 +169,8 @@ contract TokenSetup is RouterSetup {
remotePoolAddress: abi.encode(remotePoolAddress),
remoteTokenAddress: abi.encode(remoteToken),
allowed: true,
outboundRateLimiterConfig: getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: getInboundRateLimiterConfig()
outboundRateLimiterConfig: _getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: _getInboundRateLimiterConfig()
});

TokenPool(pool).applyChainUpdates(chainUpdates);
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/v0.8/ccip/test/arm/ARMProxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ pragma solidity 0.8.24;
import {IRMN} from "../../interfaces/IRMN.sol";

import {ARMProxy} from "../../ARMProxy.sol";
import {RMN} from "../../RMN.sol";
import {MockRMN} from "../mocks/MockRMN.sol";
import {RMNSetup, makeSubjects} from "./RMNSetup.t.sol";
import {RMNSetup} from "./RMNSetup.t.sol";

contract ARMProxyTest is RMNSetup {
MockRMN internal s_mockRMN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {ReentrantMaliciousTokenPool} from "./ReentrantMaliciousTokenPool.sol";

import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

import {console} from "forge-std/console.sol";

/// @title MultiOnRampTokenPoolReentrancy
/// Attempts to perform a reentrancy exploit on Onramp with a malicious TokenPool
contract MultiOnRampTokenPoolReentrancy is EVM2EVMMultiOnRampSetup {
Expand Down Expand Up @@ -41,8 +39,8 @@ contract MultiOnRampTokenPoolReentrancy is EVM2EVMMultiOnRampSetup {
remotePoolAddress: abi.encode(s_destPoolBySourceToken[s_sourceTokens[0]]),
remoteTokenAddress: abi.encode(s_destTokens[0]),
allowed: true,
outboundRateLimiterConfig: getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: getInboundRateLimiterConfig()
outboundRateLimiterConfig: _getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: _getInboundRateLimiterConfig()
});
s_maliciousTokenPool.applyChainUpdates(chainUpdates);
s_sourcePoolByToken[address(s_sourceToken)] = address(s_maliciousTokenPool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ contract OnRampTokenPoolReentrancy is EVM2EVMOnRampSetup {
remotePoolAddress: abi.encode(s_destPoolBySourceToken[s_sourceTokens[0]]),
remoteTokenAddress: abi.encode(s_destTokens[0]),
allowed: true,
outboundRateLimiterConfig: getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: getInboundRateLimiterConfig()
outboundRateLimiterConfig: _getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: _getInboundRateLimiterConfig()
});
s_maliciousTokenPool.applyChainUpdates(chainUpdates);
s_sourcePoolByToken[address(s_sourceToken)] = address(s_maliciousTokenPool);
Expand Down
Loading

0 comments on commit 11c2759

Please sign in to comment.