Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CCIPConfig, adding exhaustive checks for p2pIds and bootstrapP2PIds #1178

Merged
merged 7 commits into from
Jul 11, 2024

Conversation

0xsuryansh
Copy link
Member

Motivation

In CCIPConfig._validateConfig we try to do an exhaustive amount of validations,
the following validations remained

  1. Check whether a duplicate bootstrap P2P id, P2P id, signer, or transmitter was passed in.
  2. Check that p2p ids in cfg.bootstrapP2PIds are included in cfg.p2pIds

Ticket CCIP-2595

Solution

Created a library SortedSetValidationUtil in chainlink main-repo smartcontractkit/chainlink#13774 to support these sort, duplicate and subset check in CCIPConfig.
These changes are cherry-picked
This library can also be used in the optimisation of CCIPConfigArraysValidation._ensureInRegistry

Regarding 1 : Since each p2pId at index i corresponds to the signer at index i both arrays can't be sorted at the same time.
Hence, we are going the enforce that p2pIds and bootstrapP2PIds are sent sorted on function calls to in CCIPConfig contract. This means that these exhaustive checks for bytes[] signers and bytes[] transmitters needs to be done in off-chain tooling.

Signed-off-by: 0xsuryansh <[email protected]>
@0xsuryansh 0xsuryansh requested a review from a team as a code owner July 10, 2024 09:52
Copy link
Contributor

github-actions bot commented Jul 10, 2024

LCOV of commit cc47bfa during Solidity Foundry #6423

Summary coverage rate:
  lines......: 98.7% (1828 of 1853 lines)
  functions..: 96.3% (340 of 353 functions)
  branches...: 90.4% (752 of 832 branches)

Files changed coverage rate: n/a

@@ -146,6 +147,16 @@ func P2pIDsFromInts(ints []int64) [][32]byte {
p2pID := p2pkey.MustNewV2XXXTestingOnly(big.NewInt(i)).PeerID()
p2pIDs = append(p2pIDs, p2pID)
}
sort.Slice(p2pIDs, func(i, j int) bool {
for k := 0; k < 32; k++ {
if p2pIDs[i][k] < p2pIDs[j][k] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow does this work as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm I thought you were comparing arrays.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this basically the same as converting to a uint256 and comparing? I think it is but not 100% sure. If it is, it might be easier to grok this sort that way instead of this.

@@ -0,0 +1,5 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the changeset, we do not use them in ccip

@@ -536,6 +557,130 @@ contract CCIPConfig_validateConfig is CCIPConfigSetup {
vm.expectRevert(abi.encodeWithSelector(CCIPConfig.NodeNotInRegistry.selector, nonExistentP2PId));
s_ccipCC.validateConfig(config);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: are we still planning the fuzz test for validateConfig?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a ticket for this, will pick this up ref : https://smartcontract-it.atlassian.net/browse/CCIP-2004

@0xsuryansh 0xsuryansh merged commit 2bb582b into ccip-develop Jul 11, 2024
107 checks passed
@0xsuryansh 0xsuryansh deleted the feat/CCIP-2595 branch July 11, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants