Skip to content

Commit

Permalink
pass destChainSelector to onRamp
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Oct 17, 2023
1 parent a17a78c commit caece7c
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 145 deletions.
167 changes: 84 additions & 83 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract Router is IRouter, IRouterClient, ITypeAndVersion, OwnerIsCreator {
);
}

return IEVM2AnyOnRamp(onRamp).forwardFromRouter(message, feeTokenAmount, msg.sender);
return IEVM2AnyOnRamp(onRamp).forwardFromRouter(message, feeTokenAmount, msg.sender, destinationChainSelector);
}

// ================================================================
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/v0.8/ccip/interfaces/IEVM2AnyOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ interface IEVM2AnyOnRamp {
/// @dev if the contract is paused, this function will revert.
/// @param message Message struct to send
/// @param originalSender The original initiator of the CCIP request
/// @param destChainSelector The destination chain selector
function forwardFromRouter(
Client.EVM2AnyMessage memory message,
uint256 feeTokenAmount,
address originalSender
address originalSender,
uint64 destChainSelector
) external returns (bytes32);
}
5 changes: 4 additions & 1 deletion contracts/src/v0.8/ccip/onRamp/EVM2EVMOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ contract EVM2EVMOnRamp is IEVM2AnyOnRamp, ILinkAvailable, AggregateRateLimiter,
error NotAFeeToken(address token);
error CannotSendZeroTokens();
error SourceTokenDataTooLarge(address token);
error InvalidChainSelector(uint64 chainSelector);

event ConfigSet(StaticConfig staticConfig, DynamicConfig dynamicConfig);
event NopPaid(address indexed nop, uint256 amount);
Expand Down Expand Up @@ -256,12 +257,14 @@ contract EVM2EVMOnRamp is IEVM2AnyOnRamp, ILinkAvailable, AggregateRateLimiter,
function forwardFromRouter(
Client.EVM2AnyMessage calldata message,
uint256 feeTokenAmount,
address originalSender
address originalSender,
uint64 destChainSelector
) external whenHealthy returns (bytes32) {
// Validate message sender is set and allowed. Not validated in `getFee` since it is not user-driven.
if (originalSender == address(0)) revert RouterMustSetOriginalSender();
// Router address may be zero intentionally to pause.
if (msg.sender != s_dynamicConfig.router) revert MustBeCalledByRouter();
if (destChainSelector != i_destChainSelector) revert InvalidChainSelector(destChainSelector);

// EVM destination addresses should be abi encoded and therefore always 32 bytes long
// Not duplicately validated in `getFee`. Invalid address is uncommon, gas cost outweighs UX gain.
Expand Down
88 changes: 50 additions & 38 deletions contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ contract EVM2EVMOnRamp_payNops_fuzz is EVM2EVMOnRampSetup {
// Set Nop fee juels
deal(s_sourceFeeToken, address(s_onRamp), nopFeesJuels);
changePrank(address(s_sourceRouter));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER, DEST_CHAIN_ID);

changePrank(OWNER);

Expand Down Expand Up @@ -109,7 +109,7 @@ contract EVM2EVMNopsFeeSetup is EVM2EVMOnRampSetup {
// Send a bunch of messages, increasing the juels in the contract
for (uint256 i = 0; i < numberOfMessages; ++i) {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), feeAmount, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), feeAmount, OWNER, DEST_CHAIN_ID);
}

assertEq(s_onRamp.getNopFeesJuels(), feeAmount * numberOfMessages);
Expand Down Expand Up @@ -169,7 +169,7 @@ contract EVM2EVMOnRamp_payNops is EVM2EVMNopsFeeSetup {
changePrank(address(s_sourceRouter));
uint256 feeAmount = 1234567890;
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), feeAmount, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), feeAmount, OWNER, DEST_CHAIN_ID);

changePrank(newNop);
uint256 prevNopBalance = IERC20(s_sourceFeeToken).balanceOf(prevNop);
Expand Down Expand Up @@ -271,7 +271,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 1, 1, feeAmount, OWNER));

s_onRamp.forwardFromRouter(message, feeAmount, OWNER);
s_onRamp.forwardFromRouter(message, feeAmount, OWNER, DEST_CHAIN_ID);
}

function testForwardFromRouterSuccessLegacyExtraArgs() public {
Expand All @@ -287,7 +287,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
// We expect the message to be emitted with strict = false.
emit CCIPSendRequested(_messageToEvent(message, 1, 1, feeAmount, OWNER));

s_onRamp.forwardFromRouter(message, feeAmount, OWNER);
s_onRamp.forwardFromRouter(message, feeAmount, OWNER, DEST_CHAIN_ID);
}

function testForwardFromRouterSuccess() public {
Expand All @@ -299,7 +299,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 1, 1, feeAmount, OWNER));

s_onRamp.forwardFromRouter(message, feeAmount, OWNER);
s_onRamp.forwardFromRouter(message, feeAmount, OWNER, DEST_CHAIN_ID);
}

function testShouldIncrementSeqNumAndNonceSuccess() public {
Expand All @@ -311,7 +311,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, i, i, 0, OWNER));

s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);

uint64 nonceAfter = s_onRamp.getSenderNonce(OWNER);
assertEq(nonceAfter, nonceBefore + 1);
Expand All @@ -326,7 +326,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
uint256 feeAmount = 1234567890;
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

s_onRamp.forwardFromRouter(message, feeAmount, OWNER);
s_onRamp.forwardFromRouter(message, feeAmount, OWNER, DEST_CHAIN_ID);

assertEq(IERC20(s_sourceFeeToken).balanceOf(address(s_onRamp)), feeAmount);
assertEq(s_onRamp.getNopFeesJuels(), feeAmount);
Expand All @@ -339,7 +339,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
uint256 feeAmount = 1234567890;
IERC20(s_sourceTokens[1]).transferFrom(OWNER, address(s_onRamp), feeAmount);

s_onRamp.forwardFromRouter(message, feeAmount, OWNER);
s_onRamp.forwardFromRouter(message, feeAmount, OWNER, DEST_CHAIN_ID);

assertEq(IERC20(s_sourceTokens[1]).balanceOf(address(s_onRamp)), feeAmount);

Expand Down Expand Up @@ -375,7 +375,10 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
emit CCIPSendRequested(expectedEvent);

// Assert the message Id is correct
assertEq(expectedEvent.messageId, s_onRamp.forwardFromRouter(message, feeTokenAmount, originalSender));
assertEq(
expectedEvent.messageId,
s_onRamp.forwardFromRouter(message, feeTokenAmount, originalSender, DEST_CHAIN_ID)
);
// Assert the fee token amount is correctly assigned to the nop fee pool
assertEq(feeTokenAmount, s_onRamp.getNopFeesJuels());
}
Expand All @@ -388,7 +391,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
address router = address(0);
s_onRamp.setDynamicConfig(generateDynamicOnRampConfig(router, address(2)));
vm.expectRevert(EVM2EVMOnRamp.MustBeCalledByRouter.selector);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER, DEST_CHAIN_ID);
}

function testInvalidExtraArgsTagReverts() public {
Expand All @@ -397,40 +400,40 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(EVM2EVMOnRamp.InvalidExtraArgsTag.selector);

s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}

function testUnhealthyReverts() public {
s_mockARM.voteToCurse(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
vm.expectRevert(EVM2EVMOnRamp.BadARMSignal.selector);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER, DEST_CHAIN_ID);
}

function testPermissionsReverts() public {
changePrank(OWNER);
vm.expectRevert(EVM2EVMOnRamp.MustBeCalledByRouter.selector);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, OWNER, DEST_CHAIN_ID);
}

function testOriginalSenderReverts() public {
vm.expectRevert(EVM2EVMOnRamp.RouterMustSetOriginalSender.selector);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, address(0));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), 0, address(0), DEST_CHAIN_ID);
}

function testMessageTooLargeReverts() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.data = new bytes(MAX_DATA_SIZE + 1);
vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.MessageTooLarge.selector, MAX_DATA_SIZE, message.data.length));

s_onRamp.forwardFromRouter(message, 0, STRANGER);
s_onRamp.forwardFromRouter(message, 0, STRANGER, DEST_CHAIN_ID);
}

function testTooManyTokensReverts() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
uint256 tooMany = MAX_TOKENS_LENGTH + 1;
message.tokenAmounts = new Client.EVMTokenAmount[](tooMany);
vm.expectRevert(EVM2EVMOnRamp.UnsupportedNumberOfTokens.selector);
s_onRamp.forwardFromRouter(message, 0, STRANGER);
s_onRamp.forwardFromRouter(message, 0, STRANGER, DEST_CHAIN_ID);
}

function testCannotSendZeroTokensReverts() public {
Expand All @@ -439,7 +442,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
message.tokenAmounts[0].amount = 0;
message.tokenAmounts[0].token = s_sourceTokens[0];
vm.expectRevert(EVM2EVMOnRamp.CannotSendZeroTokens.selector);
s_onRamp.forwardFromRouter(message, 0, STRANGER);
s_onRamp.forwardFromRouter(message, 0, STRANGER, DEST_CHAIN_ID);
}

function testUnsupportedTokenReverts() public {
Expand All @@ -461,7 +464,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
changePrank(address(s_sourceRouter));
vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.UnsupportedToken.selector, wrongToken));

s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}

function testMaxCapacityExceededReverts() public {
Expand All @@ -480,7 +483,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
)
);

s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}

function testPriceNotFoundForTokenReverts() public {
Expand All @@ -493,15 +496,15 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(abi.encodeWithSelector(AggregateRateLimiter.PriceNotFoundForToken.selector, fakeToken));

s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}

// Asserts gasLimit must be <=maxGasLimit
function testMessageGasLimitTooHighReverts() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.extraArgs = Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: MAX_GAS_LIMIT + 1}));
vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.MessageGasLimitTooHigh.selector));
s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}

function testInvalidAddressEncodePackedReverts() public {
Expand All @@ -510,7 +513,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.InvalidAddress.selector, message.receiver));

s_onRamp.forwardFromRouter(message, 1, OWNER);
s_onRamp.forwardFromRouter(message, 1, OWNER, DEST_CHAIN_ID);
}

function testInvalidAddressReverts() public {
Expand All @@ -519,7 +522,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.InvalidAddress.selector, message.receiver));

s_onRamp.forwardFromRouter(message, 1, OWNER);
s_onRamp.forwardFromRouter(message, 1, OWNER, DEST_CHAIN_ID);
}

// We disallow sending to addresses 0-9.
Expand All @@ -531,7 +534,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.InvalidAddress.selector, message.receiver));

s_onRamp.forwardFromRouter(message, 1, OWNER);
s_onRamp.forwardFromRouter(message, 1, OWNER, DEST_CHAIN_ID);
}
}

Expand All @@ -540,7 +543,16 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {

vm.expectRevert(EVM2EVMOnRamp.MaxFeeBalanceReached.selector);

s_onRamp.forwardFromRouter(message, MAX_NOP_FEES_JUELS + 1, OWNER);
s_onRamp.forwardFromRouter(message, MAX_NOP_FEES_JUELS + 1, OWNER, DEST_CHAIN_ID);
}

function testInvalidChainSelectorReverts() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();

uint64 wrongChainId = DEST_CHAIN_ID + 1;
vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.InvalidChainSelector.selector, wrongChainId));

s_onRamp.forwardFromRouter(message, 1, OWNER, wrongChainId);
}

function testSourceTokenDataTooLargeReverts() public {
Expand Down Expand Up @@ -589,7 +601,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup {
changePrank(address(s_sourceRouter));

vm.expectRevert(abi.encodeWithSelector(EVM2EVMOnRamp.SourceTokenDataTooLarge.selector, sourceETH));
s_onRamp.forwardFromRouter(message, 0, OWNER);
s_onRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);
}
}

Expand Down Expand Up @@ -638,15 +650,15 @@ contract EVM2EVMOnRamp_forwardFromRouter_upgrade is EVM2EVMOnRampSetup {

vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 1, 1, FEE_AMOUNT, OWNER));
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER);
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER, DEST_CHAIN_ID);
}

function testV2SenderNoncesReadsPreviousRampSuccess() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
uint64 startNonce = s_onRamp.getSenderNonce(OWNER);

for (uint64 i = 1; i < 4; ++i) {
s_prevOnRamp.forwardFromRouter(message, 0, OWNER);
s_prevOnRamp.forwardFromRouter(message, 0, OWNER, DEST_CHAIN_ID);

assertEq(startNonce + i, s_onRamp.getSenderNonce(OWNER));
}
Expand All @@ -658,21 +670,21 @@ contract EVM2EVMOnRamp_forwardFromRouter_upgrade is EVM2EVMOnRampSetup {
uint64 startNonce = s_onRamp.getSenderNonce(OWNER);

// send 1 message from previous onramp
s_prevOnRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER);
s_prevOnRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER, DEST_CHAIN_ID);

assertEq(startNonce + 1, s_onRamp.getSenderNonce(OWNER));

// new onramp nonce should start from 2, while sequence number start from 1
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 1, startNonce + 2, FEE_AMOUNT, OWNER));
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER);
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER, DEST_CHAIN_ID);

assertEq(startNonce + 2, s_onRamp.getSenderNonce(OWNER));

// after another send, nonce should be 3, and sequence number be 2
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 2, startNonce + 3, FEE_AMOUNT, OWNER));
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER);
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER, DEST_CHAIN_ID);

assertEq(startNonce + 3, s_onRamp.getSenderNonce(OWNER));
}
Expand All @@ -681,13 +693,13 @@ contract EVM2EVMOnRamp_forwardFromRouter_upgrade is EVM2EVMOnRampSetup {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();

// send 1 message from previous onramp from OWNER
s_prevOnRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER);
s_prevOnRamp.forwardFromRouter(message, FEE_AMOUNT, OWNER, DEST_CHAIN_ID);

address newSender = address(1234567);
// new onramp nonce should start from 1 for new sender
vm.expectEmit();
emit CCIPSendRequested(_messageToEvent(message, 1, 1, FEE_AMOUNT, newSender));
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, newSender);
s_onRamp.forwardFromRouter(message, FEE_AMOUNT, newSender, DEST_CHAIN_ID);
}
}

Expand Down Expand Up @@ -1393,7 +1405,7 @@ contract EVM2EVMOnRamp_setNops is EVM2EVMOnRampSetup {
// Set Nop fee juels
deal(s_sourceFeeToken, address(s_onRamp), nopFeesJuels);
changePrank(address(s_sourceRouter));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER, DEST_CHAIN_ID);
changePrank(OWNER);

// We don't care about the fee calculation logic in this test
Expand Down Expand Up @@ -1435,7 +1447,7 @@ contract EVM2EVMOnRamp_setNops is EVM2EVMOnRampSetup {
// Set Nop fee juels but don't transfer LINK. This can happen when users
// pay in non-link tokens.
changePrank(address(s_sourceRouter));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER, DEST_CHAIN_ID);
changePrank(OWNER);

vm.expectRevert(EVM2EVMOnRamp.InsufficientBalance.selector);
Expand Down Expand Up @@ -1499,7 +1511,7 @@ contract EVM2EVMOnRamp_withdrawNonLinkFees is EVM2EVMOnRampSetup {
// Set Nop fee juels
uint96 nopFeesJuels = 10000000;
changePrank(address(s_sourceRouter));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER, DEST_CHAIN_ID);
changePrank(OWNER);

vm.expectRevert(EVM2EVMOnRamp.LinkBalanceNotSettled.selector);
Expand All @@ -1519,7 +1531,7 @@ contract EVM2EVMOnRamp_withdrawNonLinkFees is EVM2EVMOnRampSetup {
// Set Nop fee juels
uint96 nopFeesJuels = 10000000;
changePrank(address(s_sourceRouter));
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER);
s_onRamp.forwardFromRouter(_generateEmptyMessage(), nopFeesJuels, OWNER, DEST_CHAIN_ID);
changePrank(OWNER);

vm.expectRevert(EVM2EVMOnRamp.LinkBalanceNotSettled.selector);
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit caece7c

Please sign in to comment.