Skip to content

Commit f772bcf

Browse files
authored
Fix/onramp allowlist race condition (#1480)
1 parent c4907f3 commit f772bcf

File tree

6 files changed

+85
-32
lines changed

6 files changed

+85
-32
lines changed

contracts/gas-snapshots/ccip.gas-snapshot

+21-20
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ MultiOCR3Base_transmit:test_UnAuthorizedTransmitter_Revert() (gas: 24234)
564564
MultiOCR3Base_transmit:test_UnauthorizedSigner_Revert() (gas: 61275)
565565
MultiOCR3Base_transmit:test_UnconfiguredPlugin_Revert() (gas: 39933)
566566
MultiOCR3Base_transmit:test_ZeroSignatures_Revert() (gas: 33049)
567-
MultiOnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 233701)
568-
MultiRampsE2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1501791)
567+
MultiOnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 233635)
568+
MultiRampsE2E:test_E2E_3MessagesMMultiOffRampSuccess_gas() (gas: 1501725)
569569
NonceManager_NonceIncrementation:test_getIncrementedOutboundNonce_Success() (gas: 37934)
570570
NonceManager_NonceIncrementation:test_incrementInboundNonce_Skip() (gas: 23706)
571571
NonceManager_NonceIncrementation:test_incrementInboundNonce_Success() (gas: 38778)
@@ -748,23 +748,24 @@ OffRamp_trialExecute:test_TokenHandlingErrorIsCaught_Success() (gas: 227999)
748748
OffRamp_trialExecute:test_TokenPoolIsNotAContract_Success() (gas: 295396)
749749
OffRamp_trialExecute:test_trialExecute_Success() (gas: 277896)
750750
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 390842)
751-
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 18030)
752-
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_Revert() (gas: 67426)
753-
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_Success() (gas: 325083)
754-
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_Success() (gas: 65095)
755-
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_WithInvalidChainSelector_Revert() (gas: 13422)
756-
OnRamp_constructor:test_Constructor_InvalidConfigChainSelectorEqZero_Revert() (gas: 94996)
757-
OnRamp_constructor:test_Constructor_InvalidConfigNonceManagerEqAddressZero_Revert() (gas: 92938)
758-
OnRamp_constructor:test_Constructor_InvalidConfigRMNProxyEqAddressZero_Revert() (gas: 97971)
759-
OnRamp_constructor:test_Constructor_InvalidConfigTokenAdminRegistryEqAddressZero_Revert() (gas: 92972)
760-
OnRamp_constructor:test_Constructor_Success() (gas: 2736399)
751+
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 18018)
752+
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_Revert() (gas: 67797)
753+
OnRamp_applyAllowListUpdates:test_applyAllowListUpdates_Success() (gas: 325198)
754+
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_Success() (gas: 65878)
755+
OnRamp_applyDestChainConfigUpdates:test_ApplyDestChainConfigUpdates_WithInvalidChainSelector_Revert() (gas: 13631)
756+
OnRamp_constructor:test_Constructor_EnableAllowList_ForwardFromRouter_Reverts() (gas: 2673564)
757+
OnRamp_constructor:test_Constructor_InvalidConfigChainSelectorEqZero_Revert() (gas: 95249)
758+
OnRamp_constructor:test_Constructor_InvalidConfigNonceManagerEqAddressZero_Revert() (gas: 93191)
759+
OnRamp_constructor:test_Constructor_InvalidConfigRMNProxyEqAddressZero_Revert() (gas: 98224)
760+
OnRamp_constructor:test_Constructor_InvalidConfigTokenAdminRegistryEqAddressZero_Revert() (gas: 93247)
761+
OnRamp_constructor:test_Constructor_Success() (gas: 2753286)
761762
OnRamp_forwardFromRouter:test_ForwardFromRouterExtraArgsV2AllowOutOfOrderTrue_Success() (gas: 115307)
762763
OnRamp_forwardFromRouter:test_ForwardFromRouterExtraArgsV2_Success() (gas: 146108)
763764
OnRamp_forwardFromRouter:test_ForwardFromRouterSuccessCustomExtraArgs() (gas: 145705)
764765
OnRamp_forwardFromRouter:test_ForwardFromRouterSuccessEmptyExtraArgs() (gas: 143866)
765766
OnRamp_forwardFromRouter:test_ForwardFromRouterSuccessLegacyExtraArgs() (gas: 145902)
766767
OnRamp_forwardFromRouter:test_ForwardFromRouter_Success() (gas: 145300)
767-
OnRamp_forwardFromRouter:test_ForwardFromRouter_Success_ConfigurableSourceRouter() (gas: 145006)
768+
OnRamp_forwardFromRouter:test_ForwardFromRouter_Success_ConfigurableSourceRouter() (gas: 140701)
768769
OnRamp_forwardFromRouter:test_InvalidExtraArgsTag_Revert() (gas: 38554)
769770
OnRamp_forwardFromRouter:test_MessageInterceptionError_Revert() (gas: 143051)
770771
OnRamp_forwardFromRouter:test_MesssageFeeTooHigh_Revert() (gas: 36596)
@@ -781,20 +782,20 @@ OnRamp_forwardFromRouter:test_UnAllowedOriginalSender_Revert() (gas: 24010)
781782
OnRamp_forwardFromRouter:test_UnsupportedToken_Revert() (gas: 75866)
782783
OnRamp_forwardFromRouter:test_forwardFromRouter_UnsupportedToken_Revert() (gas: 38599)
783784
OnRamp_forwardFromRouter:test_forwardFromRouter_WithInterception_Success() (gas: 280170)
784-
OnRamp_getFee:test_EmptyMessage_Success() (gas: 98513)
785-
OnRamp_getFee:test_EnforceOutOfOrder_Revert() (gas: 64645)
786-
OnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 86177)
787-
OnRamp_getFee:test_NotAFeeTokenButPricedToken_Revert() (gas: 35097)
788-
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 113639)
789-
OnRamp_getFee:test_Unhealthy_Revert() (gas: 17061)
785+
OnRamp_getFee:test_EmptyMessage_Success() (gas: 98469)
786+
OnRamp_getFee:test_EnforceOutOfOrder_Revert() (gas: 64623)
787+
OnRamp_getFee:test_GetFeeOfZeroForTokenMessage_Success() (gas: 86133)
788+
OnRamp_getFee:test_NotAFeeTokenButPricedToken_Revert() (gas: 35075)
789+
OnRamp_getFee:test_SingleTokenMessage_Success() (gas: 113595)
790+
OnRamp_getFee:test_Unhealthy_Revert() (gas: 17039)
790791
OnRamp_getSupportedTokens:test_GetSupportedTokens_Revert() (gas: 10474)
791792
OnRamp_getTokenPool:test_GetTokenPool_Success() (gas: 35348)
792793
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigFeeAggregatorEqAddressZero_Revert() (gas: 11536)
793794
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigFeeQuoterEqAddressZero_Revert() (gas: 13195)
794795
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigInvalidConfig_Revert() (gas: 11522)
795796
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigOnlyOwner_Revert() (gas: 16850)
796797
OnRamp_setDynamicConfig:test_setDynamicConfig_InvalidConfigReentrancyGuardEnteredEqTrue_Revert() (gas: 13265)
797-
OnRamp_setDynamicConfig:test_setDynamicConfig_Success() (gas: 56369)
798+
OnRamp_setDynamicConfig:test_setDynamicConfig_Success() (gas: 56347)
798799
OnRamp_withdrawFeeTokens:test_WithdrawFeeTokens_Success() (gas: 97302)
799800
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 151349)
800801
PingPong_plumbing:test_OutOfOrderExecution_Success() (gas: 20310)

contracts/src/v0.8/ccip/onRamp/OnRamp.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCreator {
9191
/// can be passed in the constructor and the applyDestChainConfigUpdates function
9292
//solhint-disable gas-struct-packing
9393
struct DestChainConfigArgs {
94-
uint64 destChainSelector; // Destination chain selector
95-
IRouter router; // Source router address
94+
uint64 destChainSelector; // ─╮ Destination chain selector
95+
IRouter router; // │ Source router address
96+
bool allowListEnabled; //─────╯ Boolean indicator to specify if allowList check is enabled
9697
}
9798

9899
/// @dev Struct used to apply AllowList Senders for multiple destChainSelectors
@@ -377,6 +378,7 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCreator {
377378

378379
DestChainConfig storage destChainConfig = s_destChainConfigs[destChainSelector];
379380
destChainConfig.router = destChainConfigArg.router;
381+
destChainConfig.allowListEnabled = destChainConfigArg.allowListEnabled;
380382

381383
emit DestChainConfigSet(
382384
destChainSelector, destChainConfig.sequenceNumber, destChainConfigArg.router, destChainConfig.allowListEnabled

contracts/src/v0.8/ccip/test/onRamp/OnRamp.t.sol

+54-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ contract OnRamp_constructor is OnRampSetup {
4848
assertEq(address(s_sourceRouter), address(s_onRamp.getRouter(DEST_CHAIN_SELECTOR)));
4949
}
5050

51+
function test_Constructor_EnableAllowList_ForwardFromRouter_Reverts() public {
52+
OnRamp.StaticConfig memory staticConfig = OnRamp.StaticConfig({
53+
chainSelector: SOURCE_CHAIN_SELECTOR,
54+
rmnRemote: s_mockRMNRemote,
55+
nonceManager: address(s_outboundNonceManager),
56+
tokenAdminRegistry: address(s_tokenAdminRegistry)
57+
});
58+
59+
OnRamp.DynamicConfig memory dynamicConfig = _generateDynamicOnRampConfig(address(s_feeQuoter));
60+
61+
// Creating a DestChainConfig and setting allowListEnabled : true
62+
OnRamp.DestChainConfigArgs[] memory destChainConfigs = new OnRamp.DestChainConfigArgs[](1);
63+
destChainConfigs[0] = OnRamp.DestChainConfigArgs({
64+
destChainSelector: DEST_CHAIN_SELECTOR,
65+
router: s_sourceRouter,
66+
allowListEnabled: true
67+
});
68+
69+
vm.expectEmit();
70+
emit OnRamp.ConfigSet(staticConfig, dynamicConfig);
71+
72+
vm.expectEmit();
73+
emit OnRamp.DestChainConfigSet(DEST_CHAIN_SELECTOR, 0, s_sourceRouter, true);
74+
75+
OnRampHelper tempOnRamp = new OnRampHelper(staticConfig, dynamicConfig, destChainConfigs);
76+
77+
// Sending a message and expecting revert as allowList is enabled with no address in allowlist
78+
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
79+
vm.startPrank(address(s_sourceRouter));
80+
vm.expectRevert(abi.encodeWithSelector(OnRamp.SenderNotAllowed.selector, OWNER));
81+
tempOnRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, 0, OWNER);
82+
}
83+
5184
function test_Constructor_InvalidConfigChainSelectorEqZero_Revert() public {
5285
vm.expectRevert(OnRamp.InvalidConfig.selector);
5386
new OnRampHelper(
@@ -844,8 +877,13 @@ contract OnRamp_applyDestChainConfigUpdates is OnRampSetup {
844877

845878
// supports updating and adding lanes simultaneously
846879
configArgs = new OnRamp.DestChainConfigArgs[](2);
847-
configArgs[0] = OnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: s_sourceRouter});
848-
configArgs[1] = OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999))});
880+
configArgs[0] = OnRamp.DestChainConfigArgs({
881+
destChainSelector: DEST_CHAIN_SELECTOR,
882+
router: s_sourceRouter,
883+
allowListEnabled: false
884+
});
885+
configArgs[1] =
886+
OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999)), allowListEnabled: false});
849887
vm.expectEmit();
850888
emit OnRamp.DestChainConfigSet(DEST_CHAIN_SELECTOR, 0, s_sourceRouter, false);
851889
vm.expectEmit();
@@ -877,8 +915,13 @@ contract OnRamp_applyAllowListUpdates is OnRampSetup {
877915
vm.startPrank(OWNER);
878916

879917
OnRamp.DestChainConfigArgs[] memory configArgs = new OnRamp.DestChainConfigArgs[](2);
880-
configArgs[0] = OnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: s_sourceRouter});
881-
configArgs[1] = OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999))});
918+
configArgs[0] = OnRamp.DestChainConfigArgs({
919+
destChainSelector: DEST_CHAIN_SELECTOR,
920+
router: s_sourceRouter,
921+
allowListEnabled: false
922+
});
923+
configArgs[1] =
924+
OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999)), allowListEnabled: false});
882925
vm.expectEmit();
883926
emit OnRamp.DestChainConfigSet(DEST_CHAIN_SELECTOR, 0, s_sourceRouter, false);
884927
vm.expectEmit();
@@ -968,8 +1011,13 @@ contract OnRamp_applyAllowListUpdates is OnRampSetup {
9681011
vm.startPrank(OWNER);
9691012

9701013
OnRamp.DestChainConfigArgs[] memory configArgs = new OnRamp.DestChainConfigArgs[](2);
971-
configArgs[0] = OnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: s_sourceRouter});
972-
configArgs[1] = OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999))});
1014+
configArgs[0] = OnRamp.DestChainConfigArgs({
1015+
destChainSelector: DEST_CHAIN_SELECTOR,
1016+
router: s_sourceRouter,
1017+
allowListEnabled: false
1018+
});
1019+
configArgs[1] =
1020+
OnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999)), allowListEnabled: false});
9731021
vm.expectEmit();
9741022
emit OnRamp.DestChainConfigSet(DEST_CHAIN_SELECTOR, 0, s_sourceRouter, false);
9751023
vm.expectEmit();

contracts/src/v0.8/ccip/test/onRamp/OnRampSetup.t.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ contract OnRampSetup is FeeQuoterFeeSetup {
126126

127127
function _generateDestChainConfigArgs(IRouter router) internal pure returns (OnRamp.DestChainConfigArgs[] memory) {
128128
OnRamp.DestChainConfigArgs[] memory destChainConfigs = new OnRamp.DestChainConfigArgs[](1);
129-
destChainConfigs[0] = OnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: router});
129+
destChainConfigs[0] =
130+
OnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: router, allowListEnabled: false});
130131
return destChainConfigs;
131132
}
132133

0 commit comments

Comments
 (0)