Skip to content

Commit a0c09fa

Browse files
committed
fix naming, comments, errors
1 parent 9b2adcb commit a0c09fa

12 files changed

Lines changed: 37 additions & 25 deletions

File tree

chains/evm/contracts/ccvs/VersionedVerifierResolver.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
pragma solidity ^0.8.24;
33

44
import {ICrossChainVerifierResolver} from "../interfaces/ICrossChainVerifierResolver.sol";
5-
import {FeeTokenHandler} from "../libraries/FeeTokenHandler.sol";
65
import {ITypeAndVersion} from "@chainlink/contracts/src/v0.8/shared/interfaces/ITypeAndVersion.sol";
76

7+
import {FeeTokenHandler} from "../libraries/FeeTokenHandler.sol";
88
import {Ownable2StepMsgSender} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2StepMsgSender.sol";
99

1010
import {EnumerableSet} from "@openzeppelin/contracts@5.3.0/utils/structs/EnumerableSet.sol";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract contract BaseVerifier is ICrossChainVerifierV1, ITypeAndVersion {
3232

3333
// solhint-disable-next-line gas-struct-packing
3434
struct RemoteChainConfig {
35-
IRouter router; // ──────────╮ Local router to use for messages to/fom this chain.
35+
IRouter router; // ──────────╮ Local router to use for messages to/from this chain.
3636
uint16 feeUSDCents; // │ The fee in US dollar cents for messages to this remote chain. [0, $655.35]
3737
uint32 gasForVerification; //│ The gas to reserve for verification of messages on the remote chain.
3838
uint16 payloadSizeBytes; // │ The size of the verification payload on the remote chain.

chains/evm/contracts/libraries/FinalityCodec.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ library FinalityCodec {
100100
}
101101
}
102102

103-
/// @notice Ensures `requestedFinality` is permitted by `allowedFinality`. When matching on flags, the request must not
104-
/// carry a block depth (lower bits zero aside from the all-zero finality case, which is handled earlier).
105-
/// @param requestedFinality The requested finality params to check. This value must already be validated by
106-
/// `_validateRequestedFinality` to ensure it is well-formed.
103+
/// @notice Validates that `requestedFinality` is well-formed and permitted by `allowedFinality`.
104+
/// @param requestedFinality The requested finality params to check.
107105
/// @param allowedFinality The allowed finality params to check against.
108106
function _ensureRequestedFinalityAllowed(
109107
bytes2 requestedFinality,
@@ -113,6 +111,10 @@ library FinalityCodec {
113111
if (requestedFinality == WAIT_FOR_FINALITY_FLAG) {
114112
return;
115113
}
114+
115+
// Validate the structural shape of the requested finality, as it is only allowed to signal one mode.
116+
_validateRequestedFinality(requestedFinality);
117+
116118
// If any of the flags match, the request is allowed only when it has no depth field (flag-only request).
117119
if ((requestedFinality >> BLOCK_DEPTH_BITS) & (allowedFinality >> BLOCK_DEPTH_BITS) != 0) {
118120
if (uint16(requestedFinality & BLOCK_DEPTH_MASK) != 0) {

chains/evm/contracts/libraries/MessageV1Codec.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ library MessageV1Codec {
136136
// Configurable per-message finality value.
137137
bytes2 finality;
138138
// A hash of the verifiers and executor addresses. This is used by the offchain systems to validate the list of CCVs
139-
// and executor that should be used for this message. This has no meaning on the destination chain ans is not
139+
// and executor that should be used for this message. This has no meaning on the destination chain and is not
140140
// checked against anything.
141141
bytes32 ccvAndExecutorHash;
142142
// Variable length fields - must match wire format order.

chains/evm/contracts/offRamp/OffRamp.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,13 @@ contract OffRamp is ITypeAndVersion, Ownable2StepMsgSender {
499499
address[] memory requiredReceiverCCVs;
500500
if (isTokenOnlyTransfer) {
501501
if (tokenTransfer.length > 0) {
502-
// For token-only transfers, we skip querying the receiver for CCVs, and don't add the defaults. This enables
503-
// pure token transfers to only require the pool CCVs, as the token issuer is the only party that takes any risk.
502+
// For token-only transfers with tokens, we skip querying the receiver for CCVs, and don't add the defaults.
503+
// This enables pure token transfers to only require the pool CCVs, as the token issuer is the only party that
504+
// takes any risk. As a consequence, the receiver's finality policy (getCCVsAndFinalityConfig) is intentionally
505+
// NOT checked against message.finality for this path — finality enforcement is delegated entirely to the pool
506+
// (which validates finality in _validateReleaseOrMint). If a receiver wants to enforce its own finality policy
507+
// for token transfers it must NOT qualify as a token-only transfer (i.e. it must have a non-zero data payload
508+
// or a non-zero ccipReceiveGasLimit).
504509
requiredReceiverCCVs = new address[](0);
505510
optionalCCVs = new address[](0);
506511
optionalThreshold = 0;

chains/evm/contracts/onRamp/OnRamp.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, Ownable2StepMsgSender
565565
resolvedArgs.executor = destChainConfig.defaultExecutor;
566566
}
567567

568+
// Validate the wire shape of the requested finality. Note: the receiver's finality policy
569+
// (getCCVsAndFinalityConfig) is checked on delivery by the OffRamp, not here. A sender using a non-zero
570+
// finalityConfig targeting a receiver that only accepts bytes2(0) will succeed at send time but fail on
571+
// execution. Senders should consult the receiver's policy off-chain before choosing a finalityConfig.
568572
FinalityCodec._validateRequestedFinality(resolvedArgs.finalityConfig);
569573

570574
return resolvedArgs;

chains/evm/contracts/pools/TokenPool.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {IRMN} from "../interfaces/IRMN.sol";
99
import {IRouter} from "../interfaces/IRouter.sol";
1010

1111
import {FeeTokenHandler} from "../libraries/FeeTokenHandler.sol";
12+
import {FinalityCodec} from "../libraries/FinalityCodec.sol";
1213
import {Pool} from "../libraries/Pool.sol";
1314
import {RateLimiter} from "../libraries/RateLimiter.sol";
1415
import {Ownable2StepMsgSender} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2StepMsgSender.sol";
1516

16-
import {FinalityCodec} from "../libraries/FinalityCodec.sol";
1717
import {IERC20} from "@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol";
1818
import {IERC20Metadata} from "@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol";
1919
import {SafeERC20} from "@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol";
@@ -43,8 +43,6 @@ abstract contract TokenPool is IPoolV1V2, Ownable2StepMsgSender {
4343
using RateLimiter for RateLimiter.TokenBucket;
4444
using SafeERC20 for IERC20;
4545

46-
error InvalidFinalityConfig(uint16 requested, uint16 minFinality);
47-
error FastFinalityNotEnabled();
4846
error InvalidTransferFeeBps(uint256 bps);
4947
error InvalidTokenTransferFeeConfig(uint64 destChainSelector);
5048
error CallerIsNotARampOnRouter(address caller);
@@ -89,7 +87,7 @@ abstract contract TokenPool is IPoolV1V2, Ownable2StepMsgSender {
8987
RateLimiter.Config outboundRateLimiterConfig,
9088
RateLimiter.Config inboundRateLimiterConfig
9189
);
92-
event FinalityConfigSet(bytes2 minFinality);
90+
event FinalityConfigSet(bytes2 allowedFinality);
9391
event AdvancedPoolHooksUpdated(IAdvancedPoolHooks oldHook, IAdvancedPoolHooks newHook);
9492

9593
struct ChainUpdate {
@@ -253,7 +251,8 @@ abstract contract TokenPool is IPoolV1V2, Ownable2StepMsgSender {
253251
function setFinalityConfig(
254252
bytes2 allowedFinality
255253
) public virtual onlyOwner {
256-
// Every value
254+
// Any bytes2 value is accepted as allowedFinality; the FinalityCodec semantics are enforced when requests are
255+
// checked against this value via FinalityCodec._ensureRequestedFinalityAllowed.
257256
s_finalityConfig = allowedFinality;
258257

259258
emit FinalityConfigSet(allowedFinality);
@@ -485,6 +484,10 @@ abstract contract TokenPool is IPoolV1V2, Ownable2StepMsgSender {
485484
revert InvalidSourcePoolAddress(releaseOrMintIn.sourcePoolAddress);
486485
}
487486
if (finalityConfig != WAIT_FOR_FINALITY) {
487+
// Validate that the finality carried in the inbound message is permitted by this pool's config. This mirrors
488+
// the outbound check in _validateLockOrBurn and ensures the FTF inbound rate-limit bucket is only consumed for
489+
// modes the pool has explicitly enabled, even if a future OffRamp skips this check.
490+
FinalityCodec._ensureRequestedFinalityAllowed(finalityConfig, s_finalityConfig);
488491
_consumeFastFinalityInboundRateLimit(releaseOrMintIn.localToken, releaseOrMintIn.remoteChainSelector, localAmount);
489492
} else {
490493
_consumeInboundRateLimit(releaseOrMintIn.localToken, releaseOrMintIn.remoteChainSelector, localAmount);
@@ -1066,8 +1069,7 @@ abstract contract TokenPool is IPoolV1V2, Ownable2StepMsgSender {
10661069
virtual
10671070
returns (uint256 feeUSDCents, uint32 destGasOverhead, uint32 destBytesOverhead, uint16 tokenFeeBps, bool isEnabled)
10681071
{
1069-
// Use the codec to validate that the requested finality is allowed by the pool's configuration. This will revert
1070-
// if the requested finality is not allowed.
1072+
// Validate that the requested finality is well-formed and permitted by this pool's config.
10711073
FinalityCodec._ensureRequestedFinalityAllowed(finalityConfig, s_finalityConfig);
10721074

10731075
TokenTransferFeeConfig memory feeConfig = s_tokenTransferFeeConfig[destChainSelector];

chains/evm/contracts/pools/USDC/CCTPThroughCCVTokenPool.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.24;
33

4+
import {ICrossChainVerifierResolver} from "../../interfaces/ICrossChainVerifierResolver.sol";
45
import {IPoolV1} from "../../interfaces/IPool.sol";
56
import {IPoolV2} from "../../interfaces/IPoolV2.sol";
67
import {ITypeAndVersion} from "@chainlink/contracts/src/v0.8/shared/interfaces/ITypeAndVersion.sol";
78

89
import {CCTPVerifier} from "../../ccvs/CCTPVerifier.sol";
9-
import {ICrossChainVerifierResolver} from "../../interfaces/ICrossChainVerifierResolver.sol";
1010
import {Pool} from "../../libraries/Pool.sol";
1111
import {USDCSourcePoolDataCodec} from "../../libraries/USDCSourcePoolDataCodec.sol";
1212
import {TokenPool} from "../TokenPool.sol";

chains/evm/contracts/test/Router/Router.recoverTokens.t.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.24;
33

4-
import {IERC20} from "@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol";
5-
64
import {Router} from "../../Router.sol";
7-
85
import {MaybeRevertMessageReceiver} from "../helpers/receivers/MaybeRevertMessageReceiver.sol";
96
import {RouterSetup} from "./RouterSetup.t.sol";
107

8+
import {IERC20} from "@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol";
9+
1110
contract Router_recoverTokens is RouterSetup {
1211
function test_RecoverTokens() public {
1312
// Assert we can recover sourceToken

chains/evm/contracts/test/ccvs/components/BaseVerifier/BaseVerifier.getFee.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract BaseVerifier_getFee is BaseVerifierSetup {
3737
s_baseVerifier.applyRemoteChainConfigUpdates(configs);
3838

3939
Client.EVM2AnyMessage memory message;
40-
// Request 10 blocks — meets the minimum of 5 (request more security than required is fine).
40+
// Request 10 blocks — meets the minimum of 10 (requesting at least the minimum is allowed).
4141
(uint256 feeUSDCents,,) =
4242
s_baseVerifier.getFee(DEST_CHAIN_SELECTOR, message, "", FinalityCodec._encodeBlockDepth(10));
4343
assertEq(feeUSDCents, DEFAULT_CCV_FEE_USD_CENTS);

0 commit comments

Comments
 (0)