Skip to content

Commit

Permalink
forge fmt and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Jan 9, 2025
1 parent 05f3201 commit 74e2f05
Show file tree
Hide file tree
Showing 8 changed files with 931 additions and 234 deletions.
977 changes: 835 additions & 142 deletions contracts/.gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/interfaces/IMessageTransformer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ interface IMessageTransformer {
function transformOutboundMessage(
Internal.EVM2AnyRampMessage memory message
) external returns (Internal.EVM2AnyRampMessage memory);
}
}
7 changes: 3 additions & 4 deletions contracts/src/v0.8/ccip/offRamp/MessageTransformerOffRamp.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {OffRamp} from "./OffRamp.sol";
import {IMessageTransformer} from "../interfaces/IMessageTransformer.sol";
import {Internal} from "../libraries/Internal.sol";
import {OffRamp} from "./OffRamp.sol";

contract MessageTransformerOffRamp is OffRamp {

address internal s_messageTransformer;

constructor(
StaticConfig memory staticConfig,
DynamicConfig memory dynamicConfig,
Expand Down Expand Up @@ -37,4 +36,4 @@ contract MessageTransformerOffRamp is OffRamp {
}
return transformedMessage;
}
}
}
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
/// @return transformedMessage modified message
function _beforeExecuteSingleMessage(
Internal.Any2EVMRampMessage memory message
) internal virtual returns (Internal.Any2EVMRampMessage memory transformedMessage) {
) internal virtual returns (Internal.Any2EVMRampMessage memory transformedMessage) {
return message;
}

Expand Down
13 changes: 6 additions & 7 deletions contracts/src/v0.8/ccip/onRamp/MessageTransformerOnRamp.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {OnRamp} from "./OnRamp.sol";
import {IMessageTransformer} from "../interfaces/IMessageTransformer.sol";
import {Internal} from "../libraries/Internal.sol";
import {OnRamp} from "./OnRamp.sol";

contract MessageTransformerOnRamp is OnRamp {

address internal s_messageTransformer;

error ZeroAddressNotAllowed();
Expand All @@ -25,18 +24,18 @@ contract MessageTransformerOnRamp is OnRamp {

function getMessageTransformerAddress() external view returns (address) {
return s_messageTransformer;
}
}

function _postProcessMessage(
Internal.EVM2AnyRampMessage memory message
) internal override returns (Internal.EVM2AnyRampMessage memory transformedMessage) {
try IMessageTransformer(s_messageTransformer).transformOutboundMessage(
message
) returns (Internal.EVM2AnyRampMessage memory m) {
try IMessageTransformer(s_messageTransformer).transformOutboundMessage(message) returns (
Internal.EVM2AnyRampMessage memory m
) {
transformedMessage = m;
} catch (bytes memory err) {
revert IMessageTransformer.MessageTransformError(err);
}
return transformedMessage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ contract MessageTransformerHelper is IMessageTransformer {
}
return message;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {OffRamp} from "../../../offRamp/OffRamp.sol";
import {MessageTransformerOffRamp} from "../../../offRamp/MessageTransformerOffRamp.sol";
import {OffRampSetup} from "./OffRampSetup.t.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {Router} from "../../../Router.sol";
import {IMessageTransformer} from "../../../interfaces/IMessageTransformer.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {MessageTransformerOffRamp} from "../../../offRamp/MessageTransformerOffRamp.sol";
import {OffRamp} from "../../../offRamp/OffRamp.sol";

import {MessageTransformerHelper} from "../../helpers/MessageTransformerHelper.sol";
import {Router} from "../../../Router.sol";
import {OffRampSetup} from "./OffRampSetup.t.sol";

contract MessageTransformerOffRamp_executeSingleMessage is OffRampSetup {

MessageTransformerOffRamp internal s_messageTransformerOffRamp;


function setUp() public virtual override {
super.setUp();
s_messageTransformerOffRamp = new MessageTransformerOffRamp(
Expand All @@ -22,7 +21,7 @@ contract MessageTransformerOffRamp_executeSingleMessage is OffRampSetup {
new OffRamp.SourceChainConfigArgs[](0),
address(s_inboundMessageTransformer)
);

OffRamp.SourceChainConfigArgs[] memory sourceChainConfigs = new OffRamp.SourceChainConfigArgs[](1);
sourceChainConfigs[0] = OffRamp.SourceChainConfigArgs({
router: s_destRouter,
Expand All @@ -38,7 +37,8 @@ contract MessageTransformerOffRamp_executeSingleMessage is OffRampSetup {
for (uint256 i = 0; i < sourceChainConfigs.length; ++i) {
uint64 sourceChainSelector = sourceChainConfigs[i].sourceChainSelector;

offRampUpdates[2 * i] = Router.OffRamp({sourceChainSelector: sourceChainSelector, offRamp: address(s_messageTransformerOffRamp)});
offRampUpdates[2 * i] =
Router.OffRamp({sourceChainSelector: sourceChainSelector, offRamp: address(s_messageTransformerOffRamp)});
offRampUpdates[2 * i + 1] = Router.OffRamp({
sourceChainSelector: sourceChainSelector,
offRamp: s_inboundNonceManager.getPreviousRamps(sourceChainSelector).prevOffRamp
Expand All @@ -51,14 +51,16 @@ contract MessageTransformerOffRamp_executeSingleMessage is OffRampSetup {
function test_executeSingleMessage_WithMessageTransformer() public {
vm.stopPrank();
vm.startPrank(address(s_messageTransformerOffRamp));
Internal.Any2EVMRampMessage memory message = _generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);
s_messageTransformerOffRamp.executeSingleMessage(message, new bytes[](message.tokenAmounts.length), new uint32[](0));
}

function test_executeSingleMessage_WithMessageTransformer_RevertWhen_UnknownChain() public {
vm.stopPrank();
vm.startPrank(address(s_messageTransformerOffRamp));
Internal.Any2EVMRampMessage memory message = _generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);
// Fail with any error (UnknownChain in this case) to check if OffRamp wraps the error with MessageTransformError during the revert
s_inboundMessageTransformer.setShouldRevert(true);
vm.expectRevert(
Expand All @@ -69,4 +71,4 @@ contract MessageTransformerOffRamp_executeSingleMessage is OffRampSetup {
);
s_messageTransformerOffRamp.executeSingleMessage(message, new bytes[](message.tokenAmounts.length), new uint32[](0));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {OnRampSetup} from "./OnRampSetup.t.sol";
import {OnRamp} from "../../../onRamp/OnRamp.sol";
import {MessageTransformerOnRamp} from "../../../onRamp/MessageTransformerOnRamp.sol";
import {MessageTransformerHelper} from "../../helpers/MessageTransformerHelper.sol";
import {Client} from "../../../libraries/Client.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {AuthorizedCallers} from "../../../../shared/access/AuthorizedCallers.sol";
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/interfaces/IERC20.sol";
import {IMessageTransformer} from "../../../interfaces/IMessageTransformer.sol";
import {Router} from "../../../Router.sol";
import {NonceManager} from "../../../NonceManager.sol";
import {AuthorizedCallers} from "../../../../shared/access/AuthorizedCallers.sol";
import {Router} from "../../../Router.sol";
import {IMessageTransformer} from "../../../interfaces/IMessageTransformer.sol";
import {Client} from "../../../libraries/Client.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {MessageTransformerOnRamp} from "../../../onRamp/MessageTransformerOnRamp.sol";
import {OnRamp} from "../../../onRamp/OnRamp.sol";
import {MessageTransformerHelper} from "../../helpers/MessageTransformerHelper.sol";
import {OnRampSetup} from "./OnRampSetup.t.sol";

contract MessageTransformerOnRamp_forwardFromRouter is OnRampSetup {
MessageTransformerOnRamp internal s_messageTransformerOnRamp;
MessageTransformerHelper internal s_messageTransformer;

MessageTransformerOnRamp internal s_messageTransformerOnRamp;
MessageTransformerHelper internal s_messageTransformer;

function setUp() public virtual override {
super.setUp();
s_messageTransformer = new MessageTransformerHelper();
s_messageTransformerOnRamp = new MessageTransformerOnRamp(
s_onRamp.getStaticConfig(),
s_onRamp.getDynamicConfig(),
_generateDestChainConfigArgs(s_sourceRouter),
address(s_messageTransformer)
);
s_metadataHash = keccak256(abi.encode(Internal.EVM_2_ANY_MESSAGE_HASH, SOURCE_CHAIN_SELECTOR, DEST_CHAIN_SELECTOR, address(s_messageTransformerOnRamp)));
address[] memory authorizedCallers = new address[](1);
authorizedCallers[0] = address(s_messageTransformerOnRamp);
function setUp() public virtual override {
super.setUp();
s_messageTransformer = new MessageTransformerHelper();
s_messageTransformerOnRamp = new MessageTransformerOnRamp(
s_onRamp.getStaticConfig(),
s_onRamp.getDynamicConfig(),
_generateDestChainConfigArgs(s_sourceRouter),
address(s_messageTransformer)
);
s_metadataHash = keccak256(
abi.encode(
Internal.EVM_2_ANY_MESSAGE_HASH, SOURCE_CHAIN_SELECTOR, DEST_CHAIN_SELECTOR, address(s_messageTransformerOnRamp)
)
);
address[] memory authorizedCallers = new address[](1);
authorizedCallers[0] = address(s_messageTransformerOnRamp);

NonceManager(s_outboundNonceManager).applyAuthorizedCallerUpdates(
AuthorizedCallers.AuthorizedCallerArgs({addedCallers: authorizedCallers, removedCallers: new address[](0)})
);
NonceManager(s_outboundNonceManager).applyAuthorizedCallerUpdates(
AuthorizedCallers.AuthorizedCallerArgs({addedCallers: authorizedCallers, removedCallers: new address[](0)})
);

Router.OnRamp[] memory onRampUpdates = new Router.OnRamp[](1);
onRampUpdates[0] = Router.OnRamp({destChainSelector: DEST_CHAIN_SELECTOR, onRamp: address(s_messageTransformerOnRamp)});
Router.OnRamp[] memory onRampUpdates = new Router.OnRamp[](1);
onRampUpdates[0] =
Router.OnRamp({destChainSelector: DEST_CHAIN_SELECTOR, onRamp: address(s_messageTransformerOnRamp)});

Router.OffRamp[] memory offRampUpdates = new Router.OffRamp[](2);
offRampUpdates[0] = Router.OffRamp({sourceChainSelector: SOURCE_CHAIN_SELECTOR, offRamp: makeAddr("offRamp0")});
offRampUpdates[1] = Router.OffRamp({sourceChainSelector: SOURCE_CHAIN_SELECTOR, offRamp: makeAddr("offRamp1")});
s_sourceRouter.applyRampUpdates(onRampUpdates, new Router.OffRamp[](0), offRampUpdates);
vm.startPrank(address(s_sourceRouter));
}
Router.OffRamp[] memory offRampUpdates = new Router.OffRamp[](2);
offRampUpdates[0] = Router.OffRamp({sourceChainSelector: SOURCE_CHAIN_SELECTOR, offRamp: makeAddr("offRamp0")});
offRampUpdates[1] = Router.OffRamp({sourceChainSelector: SOURCE_CHAIN_SELECTOR, offRamp: makeAddr("offRamp1")});
s_sourceRouter.applyRampUpdates(onRampUpdates, new Router.OffRamp[](0), offRampUpdates);
vm.startPrank(address(s_sourceRouter));
}

function test_forwardFromRouter_WithMessageTransformer_Success() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.extraArgs = Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT * 2}));
uint256 feeAmount = 1234567890;
message.tokenAmounts = new Client.EVMTokenAmount[](1);
message.tokenAmounts[0].amount = 1e18;
message.tokenAmounts[0].token = s_sourceTokens[0];
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_messageTransformerOnRamp), feeAmount);
vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, 1, _messageToEvent(message, 1, 1, feeAmount, OWNER));
s_messageTransformerOnRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
function test_forwardFromRouter_WithMessageTransformer_Success() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.extraArgs = Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT * 2}));
uint256 feeAmount = 1234567890;
message.tokenAmounts = new Client.EVMTokenAmount[](1);
message.tokenAmounts[0].amount = 1e18;
message.tokenAmounts[0].token = s_sourceTokens[0];
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_messageTransformerOnRamp), feeAmount);
vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, 1, _messageToEvent(message, 1, 1, feeAmount, OWNER));
s_messageTransformerOnRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}

function test_MessageTransformerError_Revert() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.extraArgs = Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT * 2}));
uint256 feeAmount = 1234567890;
message.tokenAmounts = new Client.EVMTokenAmount[](1);
message.tokenAmounts[0].amount = 1e18;
message.tokenAmounts[0].token = s_sourceTokens[0];
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_messageTransformerOnRamp), feeAmount);
function test_MessageTransformerError_Revert() public {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();
message.extraArgs = Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT * 2}));
uint256 feeAmount = 1234567890;
message.tokenAmounts = new Client.EVMTokenAmount[](1);
message.tokenAmounts[0].amount = 1e18;
message.tokenAmounts[0].token = s_sourceTokens[0];
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_messageTransformerOnRamp), feeAmount);

// Fail with any error (UnknownChain in this case) to check if OnRamp wraps the error with MessageTransformError during the revert
s_messageTransformer.setShouldRevert(true);
vm.expectRevert(
abi.encodeWithSelector(
IMessageTransformer.MessageTransformError.selector,
abi.encodeWithSelector(MessageTransformerHelper.UnknownChain.selector)
)
);
s_messageTransformerOnRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
}
// Fail with any error (UnknownChain in this case) to check if OnRamp wraps the error with MessageTransformError during the revert
s_messageTransformer.setShouldRevert(true);
vm.expectRevert(
abi.encodeWithSelector(
IMessageTransformer.MessageTransformError.selector,
abi.encodeWithSelector(MessageTransformerHelper.UnknownChain.selector)
)
);
s_messageTransformerOnRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
}

0 comments on commit 74e2f05

Please sign in to comment.