Skip to content

Commit

Permalink
Merge branch 'ccip-develop' into fix/onramp-allowlist-race-condition
Browse files Browse the repository at this point in the history
# Conflicts:
#	contracts/gas-snapshots/ccip.gas-snapshot
#	core/gethwrappers/ccip/generation/generated-wrapper-dependency-versions-do-not-edit.txt
  • Loading branch information
0xsuryansh committed Oct 7, 2024
2 parents 52162b4 + f77ff21 commit 4ddff04
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 219 deletions.
18 changes: 5 additions & 13 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ gomod: ## Ensure chainlink's go dependencies are installed.
go mod download

.PHONY: gomodtidy
gomodtidy: ## Run go mod tidy on all modules.
go mod tidy
cd ./core/scripts && go mod tidy
cd ./integration-tests && go mod tidy
cd ./integration-tests/load && go mod tidy
cd ./dashboard-lib && go mod tidy
gomodtidy: gomods ## Run go mod tidy on all modules.
gomods tidy

.PHONY: docs
docs: ## Install and run pkgsite to view Go docs
Expand Down Expand Up @@ -93,12 +89,8 @@ abigen: ## Build & install abigen.
./tools/bin/build_abigen

.PHONY: generate
generate: pnpmdep abigen codecgen mockery protoc ## Execute all go:generate commands.
go generate -x ./...
cd ./core/scripts && go generate -x ./...
cd ./integration-tests && go generate -x ./...
cd ./integration-tests/load && go generate -x ./...
cd ./dashboard-lib && go generate -x ./...
generate: pnpmdep abigen codecgen mockery protoc gomods ## Execute all go:generate commands.
gomods -w go generate -x ./...
mockery

.PHONY: rm-mocked
Expand Down Expand Up @@ -140,7 +132,7 @@ presubmit: ## Format go files and imports.

.PHONY: gomods
gomods: ## Install gomods
go install github.com/jmank88/[email protected].1
go install github.com/jmank88/[email protected].5

.PHONY: mockery
mockery: $(mockery) ## Install mockery.
Expand Down
256 changes: 128 additions & 128 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions contracts/src/v0.8/ccip/capability/CCIPHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
s_configs;

/// @notice The total number of configs ever set, used for generating the version of the configs.
/// @dev Used to ensure unique digests across all configurations.
uint32 private s_currentVersion = 0;
/// @notice The index of the active config.
uint32 private s_activeConfigIndex = 0;
/// @notice The index of the active config on a per-don and per-plugin basis.
mapping(uint32 donId => mapping(Internal.OCRPluginType pluginType => uint32)) private s_activeConfigIndexes;

/// @notice Constructor for the CCIPHome contract takes in the address of the capabilities registry. This address
/// is the only allowed caller to mutate the configuration through beforeCapabilityConfigSet.
Expand Down Expand Up @@ -263,21 +264,21 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
Internal.OCRPluginType pluginType
) public view returns (bytes32 activeConfigDigest, bytes32 candidateConfigDigest) {
return (
s_configs[donId][pluginType][_getActiveIndex()].configDigest,
s_configs[donId][pluginType][_getCandidateIndex()].configDigest
s_configs[donId][pluginType][_getActiveIndex(donId, pluginType)].configDigest,
s_configs[donId][pluginType][_getCandidateIndex(donId, pluginType)].configDigest
);
}

/// @notice Returns the active config digest for for a given key.
/// @param donId The key of the plugin to get the config digests for.
function getActiveDigest(uint32 donId, Internal.OCRPluginType pluginType) public view returns (bytes32) {
return s_configs[donId][pluginType][_getActiveIndex()].configDigest;
return s_configs[donId][pluginType][_getActiveIndex(donId, pluginType)].configDigest;
}

/// @notice Returns the candidate config digest for for a given key.
/// @param donId The key of the plugin to get the config digests for.
function getCandidateDigest(uint32 donId, Internal.OCRPluginType pluginType) public view returns (bytes32) {
return s_configs[donId][pluginType][_getCandidateIndex()].configDigest;
return s_configs[donId][pluginType][_getCandidateIndex(donId, pluginType)].configDigest;
}

/// @notice The offchain code can use this to fetch an old config which might still be in use by some remotes. Use
Expand Down Expand Up @@ -310,12 +311,12 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
uint32 donId,
Internal.OCRPluginType pluginType
) external view returns (VersionedConfig memory activeConfig, VersionedConfig memory candidateConfig) {
VersionedConfig memory storedActiveConfig = s_configs[donId][pluginType][_getActiveIndex()];
VersionedConfig memory storedActiveConfig = s_configs[donId][pluginType][_getActiveIndex(donId, pluginType)];
if (storedActiveConfig.configDigest != ZERO_DIGEST) {
activeConfig = storedActiveConfig;
}

VersionedConfig memory storedCandidateConfig = s_configs[donId][pluginType][_getCandidateIndex()];
VersionedConfig memory storedCandidateConfig = s_configs[donId][pluginType][_getCandidateIndex(donId, pluginType)];
if (storedCandidateConfig.configDigest != ZERO_DIGEST) {
candidateConfig = storedCandidateConfig;
}
Expand Down Expand Up @@ -353,7 +354,7 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
uint32 newVersion = ++s_currentVersion;
newConfigDigest = _calculateConfigDigest(donId, pluginType, abi.encode(config), newVersion);

VersionedConfig storage existingConfig = s_configs[donId][pluginType][_getCandidateIndex()];
VersionedConfig storage existingConfig = s_configs[donId][pluginType][_getCandidateIndex(donId, pluginType)];
existingConfig.configDigest = newConfigDigest;
existingConfig.version = newVersion;
existingConfig.config = config;
Expand All @@ -373,7 +374,7 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
revert RevokingZeroDigestNotAllowed();
}

uint256 candidateConfigIndex = _getCandidateIndex();
uint256 candidateConfigIndex = _getCandidateIndex(donId, pluginType);
if (s_configs[donId][pluginType][candidateConfigIndex].configDigest != configDigest) {
revert ConfigDigestMismatch(s_configs[donId][pluginType][candidateConfigIndex].configDigest, configDigest);
}
Expand All @@ -400,19 +401,19 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
revert NoOpStateTransitionNotAllowed();
}

uint256 candidateConfigIndex = _getCandidateIndex();
uint256 candidateConfigIndex = _getCandidateIndex(donId, pluginType);
if (s_configs[donId][pluginType][candidateConfigIndex].configDigest != digestToPromote) {
revert ConfigDigestMismatch(s_configs[donId][pluginType][candidateConfigIndex].configDigest, digestToPromote);
}

VersionedConfig storage activeConfig = s_configs[donId][pluginType][_getActiveIndex()];
VersionedConfig storage activeConfig = s_configs[donId][pluginType][_getActiveIndex(donId, pluginType)];
if (activeConfig.configDigest != digestToRevoke) {
revert ConfigDigestMismatch(activeConfig.configDigest, digestToRevoke);
}

delete activeConfig.configDigest;

s_activeConfigIndex ^= 1;
s_activeConfigIndexes[donId][pluginType] ^= 1;
if (digestToRevoke != ZERO_DIGEST) {
emit ActiveConfigRevoked(digestToRevoke);
}
Expand Down Expand Up @@ -444,12 +445,12 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
);
}

function _getActiveIndex() private view returns (uint32) {
return s_activeConfigIndex;
function _getActiveIndex(uint32 donId, Internal.OCRPluginType pluginType) private view returns (uint32) {
return s_activeConfigIndexes[donId][pluginType];
}

function _getCandidateIndex() private view returns (uint32) {
return s_activeConfigIndex ^ 1;
function _getCandidateIndex(uint32 donId, Internal.OCRPluginType pluginType) private view returns (uint32) {
return s_activeConfigIndexes[donId][pluginType] ^ 1;
}

// ================================================================
Expand Down
20 changes: 20 additions & 0 deletions contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {MultiOCR3Base} from "../ocr/MultiOCR3Base.sol";

import {IERC20} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/token/ERC20/IERC20.sol";
import {ERC165Checker} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/introspection/ERC165Checker.sol";
import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/structs/EnumerableSet.sol";

/// @notice OffRamp enables OCR networks to execute multiple messages
/// in an OffRamp in a single transaction.
Expand All @@ -32,6 +33,7 @@ import {ERC165Checker} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts
contract OffRamp is ITypeAndVersion, MultiOCR3Base {
using ERC165Checker for address;
using EnumerableMapAddresses for EnumerableMapAddresses.AddressToAddressMap;
using EnumerableSet for EnumerableSet.UintSet;

error ZeroChainSelectorNotAllowed();
error ExecutionError(bytes32 messageId, bytes err);
Expand Down Expand Up @@ -156,6 +158,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
// DYNAMIC CONFIG
DynamicConfig internal s_dynamicConfig;

/// @notice Set of source chain selectors
EnumerableSet.UintSet internal s_sourceChainSelectors;

/// @notice SourceChainConfig per chain
/// (forms lane configurations from sourceChainSelector => StaticConfig.chainSelector)
mapping(uint64 sourceChainSelector => SourceChainConfig sourceChainConfig) private s_sourceChainConfigs;
Expand Down Expand Up @@ -919,6 +924,18 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
return s_sourceChainConfigs[sourceChainSelector];
}

/// @notice Returns all source chain configs
/// @return sourceChainConfigs The source chain configs corresponding to all the supported chain selectors
function getAllSourceChainConfigs() external view returns (uint64[] memory, SourceChainConfig[] memory) {
SourceChainConfig[] memory sourceChainConfigs = new SourceChainConfig[](s_sourceChainSelectors.length());
uint64[] memory sourceChainSelectors = new uint64[](s_sourceChainSelectors.length());
for (uint256 i = 0; i < s_sourceChainSelectors.length(); ++i) {
sourceChainSelectors[i] = uint64(s_sourceChainSelectors.at(i));
sourceChainConfigs[i] = s_sourceChainConfigs[sourceChainSelectors[i]];
}
return (sourceChainSelectors, sourceChainConfigs);
}

/// @notice Updates source configs
/// @param sourceChainConfigUpdates Source chain configs
function applySourceChainConfigUpdates(SourceChainConfigArgs[] memory sourceChainConfigUpdates) external onlyOwner {
Expand Down Expand Up @@ -962,6 +979,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
currentConfig.isEnabled = sourceConfigUpdate.isEnabled;
currentConfig.router = sourceConfigUpdate.router;

// We don't need to check the return value, as inserting the item twice has no effect.
s_sourceChainSelectors.add(sourceChainSelector);

emit SourceChainConfigSet(sourceChainSelector, currentConfig);
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/pools/TokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract contract TokenPool is IPoolV1, OwnerIsCreator {
struct ChainUpdate {
uint64 remoteChainSelector; // ──╮ Remote chain selector
bool allowed; // ────────────────╯ Whether the chain should be enabled
bytes remotePoolAddress; // Address of the remote pool, ABI encoded in the case of a remove EVM chain.
bytes remotePoolAddress; // Address of the remote pool, ABI encoded in the case of a remote EVM chain.
bytes remoteTokenAddress; // Address of the remote token, ABI encoded in the case of a remote EVM chain.
RateLimiter.Config outboundRateLimiterConfig; // Outbound rate limited config, meaning the rate limits for all of the onRamps for the given chain
RateLimiter.Config inboundRateLimiterConfig; // Inbound rate limited config, meaning the rate limits for all of the offRamps for the given chain
Expand Down
Loading

0 comments on commit 4ddff04

Please sign in to comment.