Skip to content

Commit e10eb67

Browse files
committed
implement finality config in BaseVerifier
1 parent be8c0e8 commit e10eb67

2 files changed

Lines changed: 33 additions & 17 deletions

File tree

chains/evm/contracts/ccvs/components/BaseVerifier.sol

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {ITypeAndVersion} from "@chainlink/contracts/src/v0.8/shared/interfaces/I
88

99
import {Client} from "../../libraries/Client.sol";
1010

11+
import {FinalityCodec} from "../../libraries/FinalityCodec.sol";
1112
import {IERC165} from "@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol";
1213
import {EnumerableSet} from "@openzeppelin/contracts@5.3.0/utils/structs/EnumerableSet.sol";
1314

@@ -33,7 +34,8 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
3334
IRouter router; // ──────────╮ Local router to use for messages to/fom this chain.
3435
uint16 feeUSDCents; // │ The fee in US dollar cents for messages to this remote chain. [0, $655.35]
3536
uint32 gasForVerification; //│ The gas to reserve for verification of messages on the remote chain.
36-
uint32 payloadSizeBytes; // │ The size of the verification payload on the remote chain.
37+
uint16 payloadSizeBytes; // │ The size of the verification payload on the remote chain.
38+
bytes2 finalityConfig; // │ The finality configuration for the local chain for messages to the remote chain.
3739
bool allowlistEnabled; // ───╯ True if the allowlist is enabled.
3840
EnumerableSet.AddressSet allowedSendersList; // The list of addresses allowed to send messages.
3941
}
@@ -44,7 +46,8 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
4446
bool allowlistEnabled; // │ True if the allowlist is enabled.
4547
uint16 feeUSDCents; // ────────╯ The fee in US dollar cents for messages to this remote chain.
4648
uint32 gasForVerification; // ─╮ The gas to reserve for verification of messages on the remote chain.
47-
uint32 payloadSizeBytes; // ───╯ The size of the verification payload on the remote chain.
49+
uint16 payloadSizeBytes; // │ The size of the verification payload on the remote chain.
50+
bytes2 finalityConfig; // ─────╯ The finality configuration for the local chain for messages to the remote chain.
4851
}
4952

5053
/// @dev Struct to hold the allowlist configuration args per dest chain.
@@ -108,17 +111,29 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
108111

109112
/// @notice get ChainConfig configured for the remoteChainSelector.
110113
/// @param remoteChainSelector The remote chain selector.
111-
/// @return allowlistEnabled boolean indicator to specify if allowlist check is enabled.
112-
/// @return router address of the local router.
114+
/// @return remoteChainConfig The struct containing the remote chain settings.
113115
/// @return allowedSendersList list of addresses that are allowed to send messages to the remote chain.
114116
function getRemoteChainConfig(
115117
uint64 remoteChainSelector
116-
) external view virtual returns (bool allowlistEnabled, address router, address[] memory allowedSendersList) {
118+
)
119+
external
120+
view
121+
virtual
122+
returns (RemoteChainConfigArgs memory remoteChainConfig, address[] memory allowedSendersList)
123+
{
117124
RemoteChainConfig storage config = _getRemoteChainConfig(remoteChainSelector);
118-
allowlistEnabled = config.allowlistEnabled;
119-
router = address(config.router);
120-
allowedSendersList = config.allowedSendersList.values();
121-
return (allowlistEnabled, router, allowedSendersList);
125+
return (
126+
RemoteChainConfigArgs({
127+
router: config.router,
128+
remoteChainSelector: remoteChainSelector,
129+
allowlistEnabled: config.allowlistEnabled,
130+
feeUSDCents: config.feeUSDCents,
131+
gasForVerification: config.gasForVerification,
132+
payloadSizeBytes: config.payloadSizeBytes,
133+
finalityConfig: config.finalityConfig
134+
}),
135+
config.allowedSendersList.values()
136+
);
122137
}
123138

124139
function _getRemoteChainConfig(
@@ -152,6 +167,7 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
152167
remoteChainConfig.gasForVerification = remoteChainConfigArg.gasForVerification;
153168
// The payload could be zero bytes if no offchain data is required.
154169
remoteChainConfig.payloadSizeBytes = remoteChainConfigArg.payloadSizeBytes;
170+
remoteChainConfig.finalityConfig = remoteChainConfigArg.finalityConfig;
155171

156172
emit RemoteChainConfigSet(
157173
remoteChainSelector, address(remoteChainConfigArg.router), remoteChainConfig.allowlistEnabled
@@ -241,16 +257,16 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
241257
uint64 destChainSelector,
242258
Client.EVM2AnyMessage memory, // message
243259
bytes memory, // extraArgs
244-
bytes2 // finalityConfig
260+
bytes2 requestedFinality
245261
) external view virtual returns (uint16 feeUSDCents, uint32 gasForVerification, uint32 payloadSizeBytes) {
246-
if (s_remoteChainConfigs[destChainSelector].router == IRouter(address(0))) {
262+
RemoteChainConfig storage config = _getRemoteChainConfig(destChainSelector);
263+
264+
if (config.router == IRouter(address(0))) {
247265
revert RemoteChainNotSupported(destChainSelector);
248266
}
249-
return (
250-
s_remoteChainConfigs[destChainSelector].feeUSDCents,
251-
s_remoteChainConfigs[destChainSelector].gasForVerification,
252-
s_remoteChainConfigs[destChainSelector].payloadSizeBytes
253-
);
267+
FinalityCodec._ensureRequestedFinalityAllowed(requestedFinality, config.finalityConfig);
268+
269+
return (config.feeUSDCents, config.gasForVerification, config.payloadSizeBytes);
254270
}
255271

256272
function _assertNotCursedByRMN(

chains/evm/contracts/libraries/FinalityCodec.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ library FinalityCodec {
122122
// Otherwise, it must be block-depth based.
123123
uint16 requestedBlockDepth = uint16(requestedFinality & BLOCK_DEPTH_MASK);
124124
uint16 allowedBlockDepth = uint16(allowedFinality & BLOCK_DEPTH_MASK);
125-
if (allowedBlockDepth == 0 || requestedBlockDepth > allowedBlockDepth) {
125+
if (allowedBlockDepth == 0 || requestedBlockDepth < allowedBlockDepth) {
126126
revert InvalidBlockDepth(requestedBlockDepth, allowedBlockDepth);
127127
}
128128
}

0 commit comments

Comments
 (0)