Skip to content

Commit d5dabce

Browse files
committed
change data types
1 parent d572faa commit d5dabce

69 files changed

Lines changed: 424 additions & 366 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chains/evm/contracts/ccvs/CCTPVerifier.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ contract CCTPVerifier is Ownable2StepMsgSender, BaseVerifier {
242242
}
243243

244244
DepositForBurnParams memory params = DepositForBurnParams({
245-
messageId: messageId, finality: message.finality, finalityThreshold: CCTP_STANDARD_FINALITY_THRESHOLD
245+
messageId: messageId,
246+
finality: uint32(uint16(message.finality)),
247+
finalityThreshold: CCTP_STANDARD_FINALITY_THRESHOLD
246248
});
247249

248250
// The maximum fee, taken on destination, is a portion of the total amount transferred.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
241241
uint64 destChainSelector,
242242
Client.EVM2AnyMessage memory, // message
243243
bytes memory, // extraArgs
244-
uint16 // blockConfirmations
244+
bytes2 // finalityConfig
245245
) external view virtual returns (uint16 feeUSDCents, uint32 gasForVerification, uint32 payloadSizeBytes) {
246246
if (s_remoteChainConfigs[destChainSelector].router == IRouter(address(0))) {
247247
revert RemoteChainNotSupported(destChainSelector);

chains/evm/contracts/executor/Executor.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ contract Executor is IExecutor, Ownable2StepMsgSender {
196196

197197
/// @notice Validates whether or not the executor can process the message and returns the fee required to do so.
198198
/// @param destChainSelector The destination chain selector.
199-
/// @param blockConfirmationsRequested The requested block confirmations for the message. `0` indicates waiting for finality.
199+
/// @param finalityConfig The requested finality encoding for the message. `bytes2(0)` indicates waiting for finality.
200200
/// @param ccvs The CCVs that are requested on source.
201201
/// @return usdCentsFee The USD denominated fee for the executor.
202202
function getFee(
203203
uint64 destChainSelector,
204-
uint16 blockConfirmationsRequested,
204+
bytes2 finalityConfig,
205205
address[] calldata ccvs,
206206
bytes calldata, // extraArgs
207207
address // feeToken
@@ -210,8 +210,9 @@ contract Executor is IExecutor, Ownable2StepMsgSender {
210210
if (!remoteChainConfig.enabled) {
211211
revert InvalidDestChain(destChainSelector);
212212
}
213-
if (blockConfirmationsRequested != 0 && blockConfirmationsRequested < s_dynamicConfig.minBlockConfirmations) {
214-
revert Executor__RequestedBlockDepthTooLow(blockConfirmationsRequested, s_dynamicConfig.minBlockConfirmations);
213+
uint16 requested = uint16(finalityConfig);
214+
if (requested != 0 && requested < s_dynamicConfig.minBlockConfirmations) {
215+
revert Executor__RequestedBlockDepthTooLow(requested, s_dynamicConfig.minBlockConfirmations);
215216
}
216217

217218
if (s_dynamicConfig.ccvAllowlistEnabled) {

chains/evm/contracts/interfaces/IAdvancedPoolHooks.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ import {IPoolV2} from "./IPoolV2.sol";
88
interface IAdvancedPoolHooks {
99
/// @notice Preflight check before lock or burn operation.
1010
/// @param lockOrBurnIn The lock or burn input parameters.
11-
/// @param blockConfirmationsRequested The block confirmations requested.
11+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
1212
/// @param tokenArgs Additional token arguments.
1313
/// @param amountPostFee The amount after token pool bps-based fees have been deducted.
1414
/// @dev This function may revert if the preflight check fails. This means the transaction is rolled back on source.
1515
function preflightCheck(
1616
Pool.LockOrBurnInV1 calldata lockOrBurnIn,
17-
uint16 blockConfirmationsRequested,
17+
bytes2 finalityConfig,
1818
bytes calldata tokenArgs,
1919
uint256 amountPostFee
2020
) external;
2121

2222
/// @notice Postflight check before releasing or minting tokens.
2323
/// @param releaseOrMintIn The release or mint output parameters.
2424
/// @param localAmount The local amount to be released or minted.
25-
/// @param blockConfirmationsRequested The block confirmations requested.
25+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
2626
/// @dev This function may revert if the postflight check fails. This means the transaction is unexecutable until
2727
/// the issue is resolved.
2828
function postflightCheck(
2929
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn,
3030
uint256 localAmount,
31-
uint16 blockConfirmationsRequested
31+
bytes2 finalityConfig
3232
) external;
3333

3434
/// @notice Returns the set of required CCVs for transfers in a specific direction.
3535
/// @param localToken The address of the local token.
3636
/// @param remoteChainSelector The remote chain selector for this transfer.
3737
/// @param amount The amount being transferred.
38-
/// @param blockConfirmationsRequested Requested block confirmations.
38+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
3939
/// @param extraData Direction-specific payload forwarded by the caller (e.g. token args or source pool data).
4040
/// @param direction The direction of the transfer (Inbound or Outbound).
4141
/// @return requiredCCVs Set of required CCV addresses.
4242
function getRequiredCCVs(
4343
address localToken,
4444
uint64 remoteChainSelector,
4545
uint256 amount,
46-
uint16 blockConfirmationsRequested,
46+
bytes2 finalityConfig,
4747
bytes calldata extraData,
4848
IPoolV2.MessageDirection direction
4949
) external view returns (address[] memory requiredCCVs);

chains/evm/contracts/interfaces/ICrossChainVerifierV1.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ interface ICrossChainVerifierV1 is IERC165 {
3838
/// @param destChainSelector The destination chain selector of the message.
3939
/// @param message The message to be sent.
4040
/// @param extraArgs Opaque extra args that can be used by the fee quoter,
41-
/// @param blockConfirmations The user requested number of block confirmations.
41+
/// @param finalityConfig The user requested finality encoding (see `FinalityCodec`).
4242
function getFee(
4343
uint64 destChainSelector,
4444
Client.EVM2AnyMessage memory message,
4545
bytes memory extraArgs,
46-
uint16 blockConfirmations
46+
bytes2 finalityConfig
4747
) external view returns (uint16 feeUSDCents, uint32 gasForVerification, uint32 payloadSizeBytes);
4848

4949
/// @notice Message sending, verifier hook.

chains/evm/contracts/interfaces/IExecutor.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ interface IExecutor {
99

1010
/// @notice Validates whether or not the executor can process the message and returns the fee required to do so.
1111
/// @param destChainSelector The destination chain selector.
12-
/// @param blockConfirmationsRequested The requested block confirmations for finality.
12+
/// @param finalityConfig The requested finality encoding for the message (see `FinalityCodec`).
1313
/// @param ccvAddresses Array of CCV addresses that will be used for the message.
1414
/// @param extraArgs Extra arguments for the executor.
1515
function getFee(
1616
uint64 destChainSelector,
17-
uint16 blockConfirmationsRequested,
17+
bytes2 finalityConfig,
1818
address[] memory ccvAddresses,
1919
bytes memory extraArgs,
2020
address feeToken

chains/evm/contracts/interfaces/IPoolV2.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,52 @@ interface IPoolV2 is IERC165 {
2626

2727
/// @notice Lock tokens into the pool or burn the tokens.
2828
/// @param lockOrBurnIn Encoded data fields for the processing of tokens on the source chain.
29-
/// @param blockConfirmationsRequested Requested block confirmations.
29+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
3030
/// @param tokenArgs Additional token arguments.
3131
/// @return lockOrBurnOut Encoded data fields for the processing of tokens on the destination chain.
3232
/// @return destTokenAmount The amount of tokens that will be set in TokenTransferV1.amount to be released/mint on destination.
3333
function lockOrBurn(
3434
Pool.LockOrBurnInV1 calldata lockOrBurnIn,
35-
uint16 blockConfirmationsRequested,
35+
bytes2 finalityConfig,
3636
bytes calldata tokenArgs
3737
) external returns (Pool.LockOrBurnOutV1 memory lockOrBurnOut, uint256 destTokenAmount);
3838

3939
/// @notice Releases or mints tokens on the destination chain.
4040
/// @param releaseOrMintIn Encoded data fields for the processing of tokens on the destination chain.
41-
/// @param blockConfirmationsRequested Requested block confirmations.
41+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
4242
/// @return releaseOrMintOut Encoded data fields describing the result of the release or mint.
4343
function releaseOrMint(
4444
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn,
45-
uint16 blockConfirmationsRequested
45+
bytes2 finalityConfig
4646
) external returns (Pool.ReleaseOrMintOutV1 memory releaseOrMintOut);
4747

4848
/// @notice Returns the set of required CCVs for transfers in a given direction.
4949
/// @param localToken The address of the local token.
5050
/// @param remoteChainSelector The chain selector of the remote chain.
5151
/// @param sourceAmount The source-denominated amount of tokens to be transferred.
52-
/// @param blockConfirmationsRequested Requested block confirmations.
52+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
5353
/// @param extraData Direction-specific payload forwarded by the caller (e.g. token args or source pool data).
5454
/// @param direction Whether CCVs are required for outbound (source -> remote) or inbound (remote -> destination) transfers.
5555
/// @return requiredCCVs A set of addresses representing the required CCVs.
5656
function getRequiredCCVs(
5757
address localToken,
5858
uint64 remoteChainSelector,
5959
uint256 sourceAmount,
60-
uint16 blockConfirmationsRequested,
60+
bytes2 finalityConfig,
6161
bytes calldata extraData,
6262
MessageDirection direction
6363
) external view returns (address[] memory requiredCCVs);
6464

6565
/// @notice Returns the fee overrides for transferring the pool's token to a destination chain.
6666
/// @param localToken The address of the local token.
6767
/// @param destChainSelector The chain selector of the destination chain.
68-
/// @param blockConfirmationsRequested Requested block confirmations.
68+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
6969
/// @param tokenArgs Additional token argument from the CCIP message.
7070
/// @return feeConfig the fee configuration for transferring the token to the destination chain.
7171
function getTokenTransferFeeConfig(
7272
address localToken,
7373
uint64 destChainSelector,
74-
uint16 blockConfirmationsRequested,
74+
bytes2 finalityConfig,
7575
bytes calldata tokenArgs
7676
) external view returns (TokenTransferFeeConfig memory feeConfig);
7777

@@ -80,7 +80,7 @@ interface IPoolV2 is IERC165 {
8080
/// @param destChainSelector The destination lane selector.
8181
/// @param amount The amount of tokens being bridged on this lane.
8282
/// @param feeToken The token used to pay feeUSDCents.
83-
/// @param blockConfirmationsRequested Requested block confirmations.
83+
/// @param finalityConfig Requested finality encoding (see `FinalityCodec`).
8484
/// @param tokenArgs Opaque token arguments supplied by the caller.
8585
/// @return feeUSDCents Flat fee charged in USD cents (crumbs) for this transfer.
8686
/// @return destGasOverhead Destination gas charged for accounting in the cost model.
@@ -92,7 +92,7 @@ interface IPoolV2 is IERC165 {
9292
uint64 destChainSelector,
9393
uint256 amount,
9494
address feeToken,
95-
uint16 blockConfirmationsRequested,
95+
bytes2 finalityConfig,
9696
bytes calldata tokenArgs
9797
)
9898
external

chains/evm/contracts/libraries/ExtraArgsCodec.sol

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4+
import {FinalityCodec} from "./FinalityCodec.sol";
5+
46
/// @notice Gas-optimized assembly version of ExtraArgsCodec library.
57
library ExtraArgsCodec {
68
error InvalidDataLength(EncodingErrorLocation location, uint256 offset);
@@ -14,7 +16,7 @@ library ExtraArgsCodec {
1416

1517
// Base size excludes all variable-length fields (CCV addresses/args, executor address, executorArgs, tokenReceiver,
1618
// tokenArgs).
17-
// Encoding order: tag(4) + gasLimit(4) + blockConfirmations(2) + ccvsLength(1) + executorLength(1) +
19+
// Encoding order: tag(4) + gasLimit(4) + finalityConfig(2) + ccvsLength(1) + executorLength(1) +
1820
// executorArgsLength(2) + tokenReceiverLength(1) + tokenArgsLength(2) = 17 bytes.
1921
uint256 public constant GENERIC_EXTRA_ARGS_V3_BASE_SIZE = 4 + 4 + 2 + 1 + 1 + 2 + 1 + 2;
2022
uint256 public constant GENERIC_EXTRA_ARGS_V3_STATIC_LENGTH_SIZE = 4 + 4 + 2 + 1;
@@ -49,7 +51,7 @@ library ExtraArgsCodec {
4951
/// Static length fields.
5052
/// bytes4 tag; Version tag.
5153
/// uint32 gasLimit; Gas limit for the callback on the destination chain.
52-
/// uint16 blockConfirmations; Number of block confirmations to wait for (0 = default finality).
54+
/// bytes2 finalityConfig; Finality config (see `FinalityCodec`): block depth and/or flags.
5355
/// uint8 ccvsLength; Number of cross-chain verifiers.
5456
///
5557
/// Variable length fields (per CCV, repeated ccvsLength times).
@@ -78,12 +80,9 @@ library ExtraArgsCodec {
7880
/// There are various ways to estimate the gas required for a callback on the destination chain, depending on the
7981
/// chain family. Please refer to the documentation for each chain for more details.
8082
uint32 gasLimit;
81-
/// @notice The number of block confirmations to wait for. 0 means the default finality that the CCV considers
82-
/// final. Any non-zero value means a block depth. CCVs, Pools and the executor may all reject this value by
83-
/// reverting the transaction on the source chain if they do not want to take on the risk of the block confirmations
84-
/// specified.
83+
/// @notice The finality config, see FinalityCodec for encoding details.
8584
/// @dev May be zero to indicate waiting for finality is desired.
86-
uint16 blockConfirmations;
85+
bytes2 finalityConfig;
8786
/// @notice An array of CCV addresses representing the cross-chain verifiers to be used for the message.
8887
/// @dev May be empty to specify the default verifier(s) should be used.
8988
address[] ccvs;
@@ -116,15 +115,15 @@ library ExtraArgsCodec {
116115
bytes tokenArgs;
117116
}
118117

119-
/// @notice Creates a basic encoded GenericExtraArgsV3 with only gasLimit and blockConfirmations set.
118+
/// @notice Creates a basic encoded GenericExtraArgsV3 with only gasLimit and block-depth finality set.
120119
/// @param gasLimit The gas limit for the callback on the destination chain.
121-
/// @param blockConfirmations The user requested number of block confirmations.
120+
/// @param blockDepth Block depth encoded via `FinalityCodec._encodeBlockDepth` (no upper flag bits).
122121
/// @return encoded The encoded extra args as bytes. These are ready to be passed into CCIP functions.
123122
function _getBasicEncodedExtraArgsV3(
124123
uint32 gasLimit,
125-
uint16 blockConfirmations
124+
uint16 blockDepth
126125
) internal pure returns (bytes memory) {
127-
return abi.encodePacked(GENERIC_EXTRA_ARGS_V3_TAG, gasLimit, blockConfirmations, bytes7(0));
126+
return abi.encodePacked(GENERIC_EXTRA_ARGS_V3_TAG, gasLimit, FinalityCodec._encodeBlockDepth(blockDepth), bytes7(0));
128127
}
129128

130129
enum SVMTokenReceiverUsage {
@@ -395,7 +394,7 @@ library ExtraArgsCodec {
395394
);
396395

397396
bytes memory staticFields =
398-
abi.encodePacked(GENERIC_EXTRA_ARGS_V3_TAG, extraArgs.gasLimit, extraArgs.blockConfirmations, uint8(ccvsLength));
397+
abi.encodePacked(GENERIC_EXTRA_ARGS_V3_TAG, extraArgs.gasLimit, extraArgs.finalityConfig, uint8(ccvsLength));
399398

400399
uint256 ptr;
401400
// This block is memory safe because it only writes to the allocated `encoded` bytes.
@@ -462,15 +461,17 @@ library ExtraArgsCodec {
462461
let gasLimit := calldataload(add(encoded.offset, 4))
463462
mstore(extraArgs, and(shr(224, gasLimit), 0xFFFFFFFF))
464463

465-
// Read block confirmations (2 bytes).
466-
let blockConfirmations := calldataload(add(encoded.offset, 8))
467-
mstore(add(extraArgs, 32), and(shr(240, blockConfirmations), 0xFFFF))
464+
// Read finalityConfig (2 bytes).
465+
// bytes2 is left-aligned in memory, so mask the top 2 bytes of the loaded word directly
466+
// instead of shifting right (which would produce a right-aligned uint that reads back as zero).
467+
let finalityWord := calldataload(add(encoded.offset, 8))
468+
mstore(add(extraArgs, 32), and(finalityWord, shl(240, 0xFFFF)))
468469

469470
// Read ccvs length (1 byte).
470471
ccvsLength := byte(0, calldataload(add(encoded.offset, 10)))
471472
}
472473

473-
uint256 offset = GENERIC_EXTRA_ARGS_V3_STATIC_LENGTH_SIZE; // Skip tag, gasLimit, blockConfirmations, ccvsLength.
474+
uint256 offset = GENERIC_EXTRA_ARGS_V3_STATIC_LENGTH_SIZE; // Skip tag, gasLimit, finalityConfig, ccvsLength.
474475

475476
// Allocate arrays for CCVs.
476477
extraArgs.ccvs = new address[](ccvsLength);

chains/evm/contracts/libraries/FinalityCodec.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ library FinalityCodec {
4949
return _encodeBlockDepth(blockDepth) | WAIT_FOR_SAFE_FLAG;
5050
}
5151

52-
/// @notice Validates requested finality: either `bytes2(0)`, exactly `WAIT_FOR_SAFE_FLAG`, or a pure block depth
53-
/// (no flag bits, depth in `1..MAX_BLOCK_DEPTH`). Never a flag combined with a non-zero depth.
52+
/// @notice Validates requested finality: either `bytes2(0)`, exactly one set bit among the upper flag bits, or a pure
53+
/// block depth (no flag bits, depth in `1..MAX_BLOCK_DEPTH`). Never a flag combined with a non-zero depth. Unknown
54+
/// flags are accepted here for wire compatibility; pools/CCVs reject modes they do not implement.
5455
/// @param encodedFinality The encoded finality params to validate.
5556
function _validateRequestedFinality(
5657
bytes2 encodedFinality

chains/evm/contracts/libraries/MessageV1Codec.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ library MessageV1Codec {
9090
/// uint64 messageNumber; Auto-incrementing number for the message.
9191
/// uint32 executionGasLimit; Gas limit for message execution on the destination chain.
9292
/// uint32 ccipReceiveGasLimit; Gas limit for the user callback on the destination chain.
93-
/// uint16 finality; Configurable per-message finality value.
93+
/// bytes2 finality; Configurable per-message finality value (see `FinalityCodec`).
9494
/// bytes32 ccvAndExecutorHash; Hash of the verifiers and executor addresses.
9595
///
9696
/// Variable length fields.
@@ -134,7 +134,7 @@ library MessageV1Codec {
134134
// Gas limit for the user callback on the destination chain.
135135
uint32 ccipReceiveGasLimit;
136136
// Configurable per-message finality value.
137-
uint16 finality;
137+
bytes2 finality;
138138
// A hash of the verifiers and executor addresses. This is used by the offchain systems to validate the list of CCVs
139139
// and executor that should be used for this message. This has no meaning on the destination chain ans is not
140140
// checked against anything.
@@ -428,7 +428,7 @@ library MessageV1Codec {
428428
message.ccipReceiveGasLimit = uint32(bytes4(encoded[29:33]));
429429

430430
// finality (2 bytes, big endian).
431-
message.finality = uint16(bytes2(encoded[33:35]));
431+
message.finality = bytes2(encoded[33:35]);
432432

433433
message.ccvAndExecutorHash = bytes32(encoded[35:67]);
434434

0 commit comments

Comments
 (0)