Skip to content

Commit

Permalink
ccip cap config contract updates (#1098)
Browse files Browse the repository at this point in the history
## Motivation

The most recent merge introduced breaking changes to the capability
registry contract. This PR fixes them.


## Solution

* capability registry -> capabilities registry rename
* implement IERC165 for the capabilities registry
* update ICapabilitiesRegistry interface
  • Loading branch information
makramkd authored Jun 27, 2024
1 parent 9075d9b commit 88f285b
Show file tree
Hide file tree
Showing 10 changed files with 1,508 additions and 1,513 deletions.
100 changes: 50 additions & 50 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,57 @@ BurnWithFromMintTokenPool_lockOrBurn:test_ChainNotAllowed_Revert() (gas: 28789)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas: 55208)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243659)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24260)
CCIPCapabilityConfigurationSetup:test_getCapabilityConfiguration_Success() (gas: 9561)
CCIPCapabilityConfiguration_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 70645)
CCIPCapabilityConfiguration_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 350565)
CCIPCapabilityConfiguration_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 471510)
CCIPCapabilityConfiguration_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 440232)
CCIPCapabilityConfiguration_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 37027)
CCIPCapabilityConfiguration_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 61043)
CCIPCapabilityConfiguration_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 60963)
CCIPCapabilityConfiguration_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11764)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8897)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 303038)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 49619)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 32253)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 367516)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 120877)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 156973)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 367292)
CCIPCapabilityConfiguration_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 157040)
CCIPCapabilityConfiguration_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9648)
CCIPCapabilityConfiguration__updatePluginConfig:test__updatePluginConfig_InitToRunning_Success() (gas: 1044370)
CCIPCapabilityConfiguration__updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 27539)
CCIPCapabilityConfiguration__updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 23083)
CCIPCapabilityConfiguration__updatePluginConfig:test__updatePluginConfig_RunningToStaging_Success() (gas: 1992245)
CCIPCapabilityConfiguration__updatePluginConfig:test__updatePluginConfig_StagingToRunning_Success() (gas: 2595825)
CCIPCapabilityConfiguration__updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9626)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1833893)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 1055282)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 1055313)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilityRegistryCanCall_Reverts() (gas: 9576)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 16070)
CCIPCapabilityConfiguration_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9626)
CCIPCapabilityConfiguration_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 182909)
CCIPCapabilityConfiguration_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 342472)
CCIPCapabilityConfiguration_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 19116)
CCIPCapabilityConfiguration_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 266071)
CCIPCapabilityConfiguration_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14807)
CCIPCapabilityConfiguration_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9604)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_ChainSelectorNotFound_Reverts() (gas: 285383)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_ChainSelectorNotSet_Reverts() (gas: 282501)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_FMustBePositive_Reverts() (gas: 283422)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_FTooHigh_Reverts() (gas: 283588)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_NodeNotInRegistry_Reverts() (gas: 287815)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_NotEnoughTransmitters_Reverts() (gas: 1068544)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_OfframpAddressCannotBeZero_Reverts() (gas: 282309)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_P2PIdsLengthNotMatching_Reverts() (gas: 284277)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_Success() (gas: 289222)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_TooManyBootstrapP2PIds_Reverts() (gas: 285518)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 1120660)
CCIPCapabilityConfiguration_validateConfig:test__validateConfig_TooManyTransmitters_Reverts() (gas: 1119000)
CCIPCapabilityConfiguration_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9540)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2132891)
CCIPConfigSetup:test_getCapabilityConfiguration_Success() (gas: 9495)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 70755)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 357994)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 481619)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 447731)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 37027)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 61043)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 60963)
CCIPConfig_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11764)
CCIPConfig_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8765)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 307840)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 49663)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 32275)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 372425)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 120943)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 157105)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 372201)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 157172)
CCIPConfig_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9583)
CCIPConfig__updatePluginConfig:test__updatePluginConfig_InitToRunning_Success() (gas: 1051740)
CCIPConfig__updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 27539)
CCIPConfig__updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 23105)
CCIPConfig__updatePluginConfig:test__updatePluginConfig_RunningToStaging_Success() (gas: 2002384)
CCIPConfig__updatePluginConfig:test__updatePluginConfig_StagingToRunning_Success() (gas: 2608050)
CCIPConfig__updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9583)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1844033)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 1062709)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 1062740)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilitiesRegistryCanCall_Reverts() (gas: 9599)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 16070)
CCIPConfig_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9583)
CCIPConfig_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 184703)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 344332)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 20258)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 267558)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14829)
CCIPConfig_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9626)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotFound_Reverts() (gas: 290206)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotSet_Reverts() (gas: 287302)
CCIPConfig_validateConfig:test__validateConfig_FMustBePositive_Reverts() (gas: 288245)
CCIPConfig_validateConfig:test__validateConfig_FTooHigh_Reverts() (gas: 288389)
CCIPConfig_validateConfig:test__validateConfig_NodeNotInRegistry_Reverts() (gas: 293767)
CCIPConfig_validateConfig:test__validateConfig_NotEnoughTransmitters_Reverts() (gas: 1107053)
CCIPConfig_validateConfig:test__validateConfig_OfframpAddressCannotBeZero_Reverts() (gas: 287109)
CCIPConfig_validateConfig:test__validateConfig_P2PIdsLengthNotMatching_Reverts() (gas: 289078)
CCIPConfig_validateConfig:test__validateConfig_Success() (gas: 296533)
CCIPConfig_validateConfig:test__validateConfig_TooManyBootstrapP2PIds_Reverts() (gas: 290321)
CCIPConfig_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 1160583)
CCIPConfig_validateConfig:test__validateConfig_TooManyTransmitters_Reverts() (gas: 1158919)
CCIPConfig_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9562)
CommitStore_constructor:test_Constructor_Success() (gas: 3091440)
CommitStore_isUnpausedAndRMNHealthy:test_RMN_Success() (gas: 75331)
CommitStore_report:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 28784)
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ compileContract ccip/RMN.sol
compileContract ccip/ARMProxy.sol
compileContract ccip/tokenAdminRegistry/TokenAdminRegistry.sol
compileContract ccip/tokenAdminRegistry/RegistryModuleOwnerCustom.sol
compileContract ccip/capability/CCIPCapabilityConfiguration.sol
compileContract ccip/capability/CCIPConfig.sol

# Test helpers
compileContract ccip/test/helpers/BurnMintERC677Helper.sol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ pragma solidity 0.8.24;

import {ICapabilityConfiguration} from "../../keystone/interfaces/ICapabilityConfiguration.sol";
import {ITypeAndVersion} from "../../shared/interfaces/ITypeAndVersion.sol";
import {ICapabilityRegistry} from "./interfaces/ICapabilityRegistry.sol";
import {ICapabilitiesRegistry} from "./interfaces/ICapabilitiesRegistry.sol";

import {OwnerIsCreator} from "../../shared/access/OwnerIsCreator.sol";

import {IERC165} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/interfaces/IERC165.sol";
import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableSet.sol";

/// @notice CCIPCapabilityConfiguration stores the configuration for the CCIP capability.
/// We have two classes of configuration: chain configuration and DON (in the CapabilityRegistry sense) configuration.
/// @notice CCIPConfig stores the configuration for the CCIP capability.
/// We have two classes of configuration: chain configuration and DON (in the CapabilitiesRegistry sense) configuration.
/// Each chain will have a single configuration which includes information like the router address.
/// Each CR DON will have up to four configurations: for each of (commit, exec), one blue and one green configuration.
/// This is done in order to achieve "blue-green" deployments.
contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator {
contract CCIPConfig is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator, IERC165 {
using EnumerableSet for EnumerableSet.UintSet;

/// @notice Emitted when a chain's configuration is set.
Expand All @@ -28,7 +29,7 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio

error ChainConfigNotSetForChain(uint64 chainSelector);
error NodeNotInRegistry(bytes32 p2pId);
error OnlyCapabilityRegistryCanCall();
error OnlyCapabilitiesRegistryCanCall();
error ChainSelectorNotFound(uint64 chainSelector);
error ChainSelectorNotSet();
error TooManyOCR3Configs();
Expand Down Expand Up @@ -72,7 +73,7 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
/// @notice Chain configuration.
/// Changes to chain configuration are detected out-of-band in plugins and decoded offchain.
struct ChainConfig {
bytes32[] readers; // The P2P IDs of the readers for the chain. These IDs must be registered in the capability registry.
bytes32[] readers; // The P2P IDs of the readers for the chain. These IDs must be registered in the capabilities registry.
uint8 fChain; // The fault tolerance parameter of the chain.
bytes config; // The chain configuration. This is kept intentionally opaque so as to add fields in the future if needed.
}
Expand Down Expand Up @@ -108,10 +109,10 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
}

/// @notice Type and version override.
string public constant override typeAndVersion = "CCIPCapabilityConfiguration 1.6.0-dev";
string public constant override typeAndVersion = "CCIPConfig 1.6.0-dev";

/// @notice The canonical capability registry address.
address internal immutable i_capabilityRegistry;
/// @notice The canonical capabilities registry address.
address internal immutable i_capabilitiesRegistry;

/// @notice chain configuration for each chain that CCIP is deployed on.
mapping(uint64 chainSelector => ChainConfig chainConfig) internal s_chainConfigurations;
Expand All @@ -131,9 +132,14 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
uint8 internal constant MAX_OCR3_CONFIGS_PER_DON = 4;
uint8 internal constant MAX_NUM_ORACLES = 31;

/// @param capabilityRegistry the canonical capability registry address.
constructor(address capabilityRegistry) {
i_capabilityRegistry = capabilityRegistry;
/// @param capabilitiesRegistry the canonical capabilities registry address.
constructor(address capabilitiesRegistry) {
i_capabilitiesRegistry = capabilitiesRegistry;
}

/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
return interfaceId == type(ICapabilityConfiguration).interfaceId || interfaceId == type(IERC165).interfaceId;
}

// ================================================================
Expand Down Expand Up @@ -180,8 +186,8 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
uint64, /* configCount */
uint32 donId
) external override {
if (msg.sender != i_capabilityRegistry) {
revert OnlyCapabilityRegistryCanCall();
if (msg.sender != i_capabilitiesRegistry) {
revert OnlyCapabilitiesRegistryCanCall();
}

OCR3Config[] memory ocr3Configs = abi.decode(config, (OCR3Config[]));
Expand Down Expand Up @@ -398,7 +404,7 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
}
if (cfg.bootstrapP2PIds.length > cfg.p2pIds.length) revert TooManyBootstrapP2PIds();

// Check that the readers are in the capability registry.
// Check that the readers are in the capabilities registry.
// TODO: check for duplicate signers, duplicate p2p ids, etc.
// TODO: check that p2p ids in cfg.bootstrapP2PIds are included in cfg.p2pIds.
for (uint256 i = 0; i < cfg.signers.length; ++i) {
Expand Down Expand Up @@ -473,7 +479,7 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
bytes32[] memory readers = chainConfig.readers;
uint64 chainSelector = chainConfigAdds[i].chainSelector;

// Verify that the provided readers are present in the capability registry.
// Verify that the provided readers are present in the capabilities registry.
for (uint256 j = 0; j < readers.length; j++) {
_ensureInRegistry(readers[j]);
}
Expand All @@ -490,10 +496,10 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
}
}

/// @notice Helper function to ensure that a node is in the capability registry.
/// @notice Helper function to ensure that a node is in the capabilities registry.
/// @param p2pId The P2P ID of the node to check.
function _ensureInRegistry(bytes32 p2pId) internal view {
(ICapabilityRegistry.NodeInfo memory node,) = ICapabilityRegistry(i_capabilityRegistry).getNode(p2pId);
ICapabilitiesRegistry.NodeInfo memory node = ICapabilitiesRegistry(i_capabilitiesRegistry).getNode(p2pId);
if (node.p2pId == bytes32("")) {
revert NodeNotInRegistry(p2pId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface ICapabilityRegistry {
interface ICapabilitiesRegistry {
struct NodeInfo {
/// @notice The id of the node operator that manages this node
uint32 nodeOperatorId;
/// @notice The number of times the node's configuration has been updated
uint32 configCount;
/// @notice The ID of the Workflow DON that the node belongs to. A node can
/// only belong to one DON that accepts Workflows.
uint32 workflowDONId;
/// @notice The signer address for application-layer message verification.
bytes32 signer;
/// @notice This is an Ed25519 public key that is used to identify a node.
/// This key is guaranteed to be unique in the CapabilityRegistry. It is
/// This key is guaranteed to be unique in the CapabilitiesRegistry. It is
/// used to identify a node in the the P2P network.
bytes32 p2pId;
/// @notice The list of hashed capability IDs supported by the node
bytes32[] hashedCapabilityIds;
/// @notice The list of capabilities DON Ids supported by the node. A node
/// can belong to multiple capabilities DONs. This list does not include a
/// Workflow DON id if the node belongs to one.
uint256[] capabilitiesDONIds;
}

/// @notice Gets a node's data
/// @param p2pId The P2P ID of the node to query for
/// @return NodeInfo The node data
/// @return configCount The number of times the node has been configured
function getNode(bytes32 p2pId) external view returns (NodeInfo memory, uint32 configCount);
function getNode(bytes32 p2pId) external view returns (NodeInfo memory);
}
Loading

0 comments on commit 88f285b

Please sign in to comment.