Skip to content

Commit

Permalink
CCIP-4075 misc. gas optimizations and redundancy checks (#15006)
Browse files Browse the repository at this point in the history
* misc. gas optimizations and redundancy checks

* remove check around event emission that was previously added

* changeset

* Update gethwrappers

* [Bot] Update changeset file with jira issues

* remove superfluous comment

---------

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 27aabcb commit 33dba89
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
10 changes: 10 additions & 0 deletions contracts/.changeset/proud-brooms-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainlink/contracts': patch
---

minor gas optimizations and input sanity checks for CCIPHome #bugfix


PR issue: CCIP-4075

Solidity Review issue: CCIP-3966
21 changes: 11 additions & 10 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ CCIPHome__validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 773
CCIPHome__validateConfig:test__validateConfig_ZeroP2PId_Reverts() (gas: 293455)
CCIPHome__validateConfig:test__validateConfig_ZeroSignerKey_Reverts() (gas: 293503)
CCIPHome_applyChainConfigUpdates:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 187738)
CCIPHome_applyChainConfigUpdates:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 349752)
CCIPHome_applyChainConfigUpdates:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 349623)
CCIPHome_applyChainConfigUpdates:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 18065)
CCIPHome_applyChainConfigUpdates:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 272742)
CCIPHome_applyChainConfigUpdates:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14952)
CCIPHome_applyChainConfigUpdates:test_getPaginatedCCIPHomes_Success() (gas: 373741)
CCIPHome_applyChainConfigUpdates:test_getPaginatedCCIPHomes_Success() (gas: 372561)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_DONIdMismatch_reverts() (gas: 38098)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_InnerCallReverts_reverts() (gas: 11827)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_InvalidSelector_reverts() (gas: 11015)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilitiesRegistryCanCall_reverts() (gas: 37072)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_success() (gas: 1455716)
CCIPHome_constructor:test_constructor_CapabilitiesRegistryAddressZero_reverts() (gas: 63876)
CCIPHome_constructor:test_constructor_success() (gas: 3499586)
CCIPHome_constructor:test_constructor_CapabilitiesRegistryAddressZero_reverts() (gas: 63859)
CCIPHome_constructor:test_constructor_success() (gas: 3484144)
CCIPHome_constructor:test_getCapabilityConfiguration_success() (gas: 9150)
CCIPHome_constructor:test_supportsInterface_success() (gas: 9907)
CCIPHome_getAllConfigs:test_getAllConfigs_success() (gas: 2773000)
Expand Down Expand Up @@ -606,23 +606,24 @@ RMNHome_setDynamicConfig:test_setDynamicConfig_MinObserversTooHigh_reverts() (ga
RMNHome_setDynamicConfig:test_setDynamicConfig_OnlyOwner_reverts() (gas: 14099)
RMNHome_setDynamicConfig:test_setDynamicConfig_success() (gas: 104862)
RMNRemote_constructor:test_constructor_success() (gas: 8334)
RMNRemote_constructor:test_constructor_zeroChainSelector_reverts() (gas: 59238)
RMNRemote_constructor:test_constructor_zeroChainSelector_reverts() (gas: 59245)
RMNRemote_curse:test_curse_AlreadyCursed_duplicateSubject_reverts() (gas: 154479)
RMNRemote_curse:test_curse_calledByNonOwner_reverts() (gas: 18802)
RMNRemote_curse:test_curse_success() (gas: 149431)
RMNRemote_global_and_legacy_curses:test_global_and_legacy_curses_success() (gas: 133512)
RMNRemote_setConfig:test_setConfig_addSigner_removeSigner_success() (gas: 993400)
RMNRemote_setConfig:test_setConfig_duplicateOnChainPublicKey_reverts() (gas: 323497)
RMNRemote_setConfig:test_setConfig_invalidSignerOrder_reverts() (gas: 80115)
RMNRemote_setConfig:test_setConfig_notEnoughSigners_reverts() (gas: 54212)
RMNRemote_setConfig:test_setConfig_ZeroValueNotAllowed_revert() (gas: 37971)
RMNRemote_setConfig:test_setConfig_addSigner_removeSigner_success() (gas: 993448)
RMNRemote_setConfig:test_setConfig_duplicateOnChainPublicKey_reverts() (gas: 323540)
RMNRemote_setConfig:test_setConfig_invalidSignerOrder_reverts() (gas: 80201)
RMNRemote_setConfig:test_setConfig_notEnoughSigners_reverts() (gas: 54232)
RMNRemote_uncurse:test_uncurse_NotCursed_duplicatedUncurseSubject_reverts() (gas: 51993)
RMNRemote_uncurse:test_uncurse_calledByNonOwner_reverts() (gas: 18772)
RMNRemote_uncurse:test_uncurse_success() (gas: 40171)
RMNRemote_verify_withConfigNotSet:test_verify_reverts() (gas: 13578)
RMNRemote_verify_withConfigSet:test_verify_InvalidSignature_reverts() (gas: 96449)
RMNRemote_verify_withConfigSet:test_verify_OutOfOrderSignatures_duplicateSignature_reverts() (gas: 94267)
RMNRemote_verify_withConfigSet:test_verify_OutOfOrderSignatures_not_sorted_reverts() (gas: 101330)
RMNRemote_verify_withConfigSet:test_verify_ThresholdNotMet_reverts() (gas: 303846)
RMNRemote_verify_withConfigSet:test_verify_ThresholdNotMet_reverts() (gas: 303866)
RMNRemote_verify_withConfigSet:test_verify_UnexpectedSigner_reverts() (gas: 427512)
RMNRemote_verify_withConfigSet:test_verify_success() (gas: 86159)
RateLimiter_constructor:test_Constructor_Success() (gas: 19806)
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/v0.8/ccip/capability/CCIPHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
if (digestToRevoke != ZERO_DIGEST) {
emit ActiveConfigRevoked(digestToRevoke);
}

emit ConfigPromoted(digestToPromote);
}

Expand All @@ -431,7 +432,7 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,
uint32 version
) internal view returns (bytes32) {
return bytes32(
(PREFIX & PREFIX_MASK)
PREFIX
| (
uint256(
keccak256(
Expand Down Expand Up @@ -551,9 +552,8 @@ contract CCIPHome is OwnerIsCreator, ITypeAndVersion, ICapabilityConfiguration,

ChainConfigArgs[] memory paginatedChainConfigs = new ChainConfigArgs[](endIndex - startIndex);

uint256[] memory chainSelectors = s_remoteChainSelectors.values();
for (uint256 i = startIndex; i < endIndex; ++i) {
uint64 chainSelector = uint64(chainSelectors[i]);
uint64 chainSelector = uint64(s_remoteChainSelectors.at(i));
paginatedChainConfigs[i - startIndex] =
ChainConfigArgs({chainSelector: chainSelector, chainConfig: s_chainConfigurations[chainSelector]});
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v0.8/ccip/rmn/RMNHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ contract RMNHome is OwnerIsCreator, ITypeAndVersion {
if (digestToRevoke != ZERO_DIGEST) {
emit ActiveConfigRevoked(digestToRevoke);
}

emit ConfigPromoted(digestToPromote);
}

Expand Down Expand Up @@ -311,7 +312,7 @@ contract RMNHome is OwnerIsCreator, ITypeAndVersion {
/// @return The calculated config digest.
function _calculateConfigDigest(bytes memory staticConfig, uint32 version) internal view returns (bytes32) {
return bytes32(
(PREFIX & PREFIX_MASK)
PREFIX
| (
uint256(
keccak256(bytes.concat(abi.encode(bytes32("EVM"), block.chainid, address(this), version), staticConfig))
Expand Down
4 changes: 4 additions & 0 deletions contracts/src/v0.8/ccip/rmn/RMNRemote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ contract RMNRemote is OwnerIsCreator, ITypeAndVersion, IRMNRemote {
function setConfig(
Config calldata newConfig
) external onlyOwner {
if (newConfig.rmnHomeContractConfigDigest == bytes32(0)) {
revert ZeroValueNotAllowed();
}

// signers are in ascending order of nodeIndex
for (uint256 i = 1; i < newConfig.signers.length; ++i) {
if (!(newConfig.signers[i - 1].nodeIndex < newConfig.signers[i].nodeIndex)) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/v0.8/ccip/test/rmn/RMNRemote.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ contract RMNRemote_constructor is RMNRemoteSetup {
}

contract RMNRemote_setConfig is RMNRemoteSetup {
function test_setConfig_ZeroValueNotAllowed_revert() public {
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: bytes32(0), signers: s_signers, f: 1});

vm.expectRevert(RMNRemote.ZeroValueNotAllowed.selector);

s_rmnRemote.setConfig(config);
}

function test_setConfig_addSigner_removeSigner_success() public {
uint32 currentConfigVersion = 0;
uint256 numSigners = s_signers.length;
Expand Down
2 changes: 1 addition & 1 deletion core/gethwrappers/ccip/generated/ccip_home/ccip_home.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/gethwrappers/ccip/generated/rmn_remote/rmn_remote.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ burn_from_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnFromMintTokenPool
burn_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnMintTokenPool/BurnMintTokenPool.abi ../../../contracts/solc/v0.8.24/BurnMintTokenPool/BurnMintTokenPool.bin 3e8e3358f0bb520af069a7d37ea625940a88461a54418b1d5925eabced8c74df
burn_with_from_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.abi ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.bin 734c2a0ea8f1224b5f01ed849410209e74b4e3427e8bfddb8ff5dd8ead5f2d8d
ccip_encoding_utils: ../../../contracts/solc/v0.8.24/ICCIPEncodingUtils/ICCIPEncodingUtils.abi ../../../contracts/solc/v0.8.24/ICCIPEncodingUtils/ICCIPEncodingUtils.bin 9971fc93c34442a0989570d3dab90a125de31e6e60754ad972807ce6ad4dfba0
ccip_home: ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.abi ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.bin 76e5647a4574b1f09d9ee22ce1242f7c48d85412069a03e505b8000a7e3c7701
ccip_home: ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.abi ../../../contracts/solc/v0.8.24/CCIPHome/CCIPHome.bin 540cec5df4dbd8474975ed4b6d60baf8119cd57e610f33342912957a4a4bcc20
ccip_reader_tester: ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.abi ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.bin 893c9930e874fe5235db24e28a22650c37f562da94fac93618566bcd84839fdc
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 0db599eee25f7269cb90a4701b00eac7709dd6287697e1a85c0f3e98f792e3a0
Expand All @@ -23,7 +23,7 @@ registry_module_owner_custom: ../../../contracts/solc/v0.8.24/RegistryModuleOwne
report_codec: ../../../contracts/solc/v0.8.24/ReportCodec/ReportCodec.abi ../../../contracts/solc/v0.8.24/ReportCodec/ReportCodec.bin 6c943b39f003aa67c3cefa19a8ff99e846236a058e1ceae77569c3a065ffd5c7
rmn_home: ../../../contracts/solc/v0.8.24/RMNHome/RMNHome.abi ../../../contracts/solc/v0.8.24/RMNHome/RMNHome.bin fa6f66001bb8de061f9c4672e83fdf3f57ab751a7de519a459908c96b077ce74
rmn_proxy_contract: ../../../contracts/solc/v0.8.24/ARMProxy/ARMProxy.abi ../../../contracts/solc/v0.8.24/ARMProxy/ARMProxy.bin b048d8e752e3c41113ebb305c1efa06737ad36b4907b93e627fb0a3113023454
rmn_remote: ../../../contracts/solc/v0.8.24/RMNRemote/RMNRemote.abi ../../../contracts/solc/v0.8.24/RMNRemote/RMNRemote.bin 637a7adc456c1d08409a15b617bb9c7a709bf71d2a5f88022fafb4ccd445df83
rmn_remote: ../../../contracts/solc/v0.8.24/RMNRemote/RMNRemote.abi ../../../contracts/solc/v0.8.24/RMNRemote/RMNRemote.bin 82102dd2a7b5cc0b2a774cccea3b4c3a2e9c5e37b6faa3358cc49d3ad6fcd7c9
router: ../../../contracts/solc/v0.8.24/Router/Router.abi ../../../contracts/solc/v0.8.24/Router/Router.bin 2e4f0a7826c8abb49d882bb49fc5ff20a186dbd3137624b9097ffed903ae4888
token_admin_registry: ../../../contracts/solc/v0.8.24/TokenAdminRegistry/TokenAdminRegistry.abi ../../../contracts/solc/v0.8.24/TokenAdminRegistry/TokenAdminRegistry.bin 942be7d1681ac102e0615bee13f76838ebb0b261697cf1270d2bf82c12e57aeb
token_pool: ../../../contracts/solc/v0.8.24/TokenPool/TokenPool.abi ../../../contracts/solc/v0.8.24/TokenPool/TokenPool.bin 7c01fd89f5153baa4d7409d14beabb3f861abfbf8880d3c6d06802cc398570f9
Expand Down

0 comments on commit 33dba89

Please sign in to comment.