-
Notifications
You must be signed in to change notification settings - Fork 21
[CCIP-7723] Define & Implement ICrossChainVerifierResolver #1330
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4781b61
[CCIP-7723] Define & Implement ICrossChainVerifierResolver
kylesmartin ed45056
Rm event emission
kylesmartin 3099172
Lint fixes
kylesmartin b8e02cb
Merge main
kylesmartin 136af18
fix tests with hacks
kylesmartin 71d37db
Fix tests
kylesmartin f76ae67
Import cleanup
kylesmartin b32893e
Fix imports
kylesmartin beb5518
Comments
kylesmartin 69adf06
More tests
kylesmartin ca440f5
Merge dev
kylesmartin 9e16385
Lint
kylesmartin 895c788
Add versioned_verifier_resolver gobindings
kylesmartin eebe683
Add typeAndVersion
kylesmartin fa39409
Update deployment code
kylesmartin 1d835e4
Merge dev
kylesmartin 8edcb5f
Comments
kylesmartin 302b6d3
Add extraArgs
kylesmartin b80bbd2
Update deployment code
kylesmartin 7a3126b
Merge
kylesmartin e28e606
Bump versions
kylesmartin c2afcdc
Comments
kylesmartin 2acc758
Bump deployment
kylesmartin 0413073
Fix
kylesmartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
chains/evm/contracts/ccvs/VersionedVerifierResolver.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.24; | ||
|
|
||
| import {ICrossChainVerifierResolver} from "../interfaces/ICrossChainVerifierResolver.sol"; | ||
| import {IVersionedVerifier} from "../interfaces/IVersionedVerifier.sol"; | ||
|
|
||
| import {Ownable2StepMsgSender} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2StepMsgSender.sol"; | ||
|
|
||
| /// @notice Resolves and returns the appropriate verifier contract for the given outbound / inbound traffic. | ||
| /// @dev On source, the destChainSelector of a message is used to determine the verifier implementation to apply. | ||
| /// On destination, we must use the verifier version was applied on source, parsing this version from the ccvData. | ||
| contract VersionedVerifierResolver is ICrossChainVerifierResolver, Ownable2StepMsgSender { | ||
| error InvalidCCVDataLength(); | ||
| error InvalidDestChainSelector(uint64 destChainSelector); | ||
| error VersionMismatch(address verifier, bytes4 expected, bytes4 got); | ||
|
|
||
| event InboundImplementationRemoved(bytes4 version); | ||
| event OutboundImplementationRemoved(uint64 destChainSelector); | ||
| event InboundImplementationUpdated(bytes4 version, address prevImpl, address newImpl); | ||
| event OutboundImplementationUpdated(uint64 destChainSelector, address prevImpl, address newImpl); | ||
|
|
||
| struct InboundImplementationArgs { | ||
| bytes4 version; // ────╮ Verifier version. | ||
| address verifier; // ──╯ Address of the verifier contract. | ||
| } | ||
|
|
||
| struct OutboundImplementationArgs { | ||
| uint64 destChainSelector; // ──╮ Destination chain selector. | ||
| address verifier; // ──────────╯ Address of the verifier contract. | ||
| } | ||
|
|
||
| /// @notice maps verifier versions to their implementation addresses, applied to inbound traffic. | ||
| mapping(bytes4 version => address verifier) private s_inboundImplementations; | ||
| /// @notice maps destination chain selectors to their implementation addresses, applied to outbound traffic. | ||
| mapping(uint64 destChainSelector => address version) private s_outboundImplementations; | ||
|
|
||
| /// @inheritdoc ICrossChainVerifierResolver | ||
| function getInboundImplementation( | ||
kylesmartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bytes calldata ccvData | ||
| ) external view returns (address) { | ||
| if (ccvData.length < 4) { | ||
| revert InvalidCCVDataLength(); | ||
| } | ||
| return s_inboundImplementations[bytes4(ccvData[:4])]; | ||
| } | ||
|
|
||
| /// @notice Returns the verifier contract for a given version. | ||
| /// @param version The version of the verifier contract. | ||
| /// @return verifierAddress The address of the verifier contract. | ||
| function getInboundImplementationForVersion( | ||
| bytes4 version | ||
kylesmartin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) external view returns (address) { | ||
| return s_inboundImplementations[version]; | ||
| } | ||
|
|
||
| /// @inheritdoc ICrossChainVerifierResolver | ||
| function getOutboundImplementation( | ||
| uint64 destChainSelector | ||
| ) external view returns (address) { | ||
| return s_outboundImplementations[destChainSelector]; | ||
| } | ||
|
|
||
| /// @notice Updates inbound implementations. | ||
| /// @param implementations Verifier versions and their corresponding contracts. | ||
| function applyInboundImplementationUpdates( | ||
| InboundImplementationArgs[] calldata implementations | ||
| ) external onlyOwner { | ||
| for (uint256 i = 0; i < implementations.length; ++i) { | ||
| InboundImplementationArgs memory implementation = implementations[i]; | ||
| if (implementation.verifier == address(0)) { | ||
| // If the verifier address is zero, we clear the implementation for this version. | ||
| delete s_inboundImplementations[implementation.version]; | ||
| emit InboundImplementationRemoved(implementation.version); | ||
| continue; | ||
| } | ||
| bytes4 expectedVersion = IVersionedVerifier(implementation.verifier).VERSION_TAG(); | ||
kylesmartin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (expectedVersion != implementation.version) { | ||
| revert VersionMismatch(implementation.verifier, expectedVersion, implementation.version); | ||
| } | ||
| address previous = s_inboundImplementations[implementation.version]; | ||
| s_inboundImplementations[implementation.version] = implementation.verifier; | ||
| emit InboundImplementationUpdated(implementation.version, previous, implementation.verifier); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Updates outbound implementations. | ||
| /// @param implementations Destination chain selectors and their corresponding verifier contracts. | ||
| function applyOutboundImplementationUpdates( | ||
kylesmartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| OutboundImplementationArgs[] calldata implementations | ||
| ) external onlyOwner { | ||
| for (uint256 i = 0; i < implementations.length; ++i) { | ||
| OutboundImplementationArgs memory implementation = implementations[i]; | ||
| if (implementation.verifier == address(0)) { | ||
| // If the verifier address is zero, we clear the implementation for this destination chain. | ||
| delete s_outboundImplementations[implementation.destChainSelector]; | ||
| emit OutboundImplementationRemoved(implementation.destChainSelector); | ||
| continue; | ||
| } | ||
| if (implementation.destChainSelector == 0) { | ||
| revert InvalidDestChainSelector(implementation.destChainSelector); | ||
| } | ||
| address previous = s_outboundImplementations[implementation.destChainSelector]; | ||
| s_outboundImplementations[implementation.destChainSelector] = implementation.verifier; | ||
| emit OutboundImplementationUpdated(implementation.destChainSelector, previous, implementation.verifier); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.