Skip to content

Commit

Permalink
formalize comment and formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub committed Sep 9, 2024
1 parent e01e113 commit cb2849c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 64 deletions.
64 changes: 47 additions & 17 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ BurnWithFromMintTokenPool_lockOrBurn:test_ChainNotAllowed_Revert() (gas: 28773)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas: 55115)
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243556)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 23951)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2132690)
CCIPClientTest:test_HappyPath_Success() (gas: 192136)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andDestTokens_Success() (gas: 326581)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andNoDestTokens_Success() (gas: 218713)
CCIPClientTest:test_ccipSend_with_NativeFeeToken_andDestTokens_Success() (gas: 380248)
CCIPClientTest:test_modifyFeeToken_Success() (gas: 74415)
CCIPClientWithACKTest:test_ccipReceiveAndSendAck_Success() (gas: 331013)
CCIPClientWithACKTest:test_ccipReceiver_ack_with_invalidAckMessageHeaderBytes_Revert() (gas: 415370)
CCIPClientWithACKTest:test_ccipSendAndReceiveAck_in_return_Success() (gas: 346114)
CCIPClientWithACKTest:test_ccipSend_withNonNativeFeetoken_andNoDestTokens_Success() (gas: 242924)
CCIPClientWithACKTest:test_ccipSend_with_NativeFeeToken_andNoDestTokens_Success() (gas: 403065)
CCIPClientWithACKTest:test_send_tokens_that_are_not_feeToken_Success() (gas: 552379)
CCIPConfigSetup:test_getCapabilityConfiguration_Success() (gas: 9539)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 66088)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 357846)
Expand Down Expand Up @@ -87,6 +97,26 @@ CCIPConfig_validateConfig:test__validateConfig_P2PIdsLengthNotMatching_Reverts()
CCIPConfig_validateConfig:test__validateConfig_Success() (gas: 299419)
CCIPConfig_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 492913)
CCIPConfig_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9606)
CCIPReceiverTest:test_HappyPath_Success() (gas: 193787)
CCIPReceiverTest:test_Recovery_from_invalid_sender_Success() (gas: 408960)
CCIPReceiverTest:test_Recovery_with_intentional_Revert() (gas: 414462)
CCIPReceiverTest:test_abandonFailedMessage_which_has_not_already_failed_Revert() (gas: 13388)
CCIPReceiverTest:test_apply_InvalidChainUpdate_Revert() (gas: 13841)
CCIPReceiverTest:test_disableChain_andRevert_onccipReceive_Revert() (gas: 200263)
CCIPReceiverTest:test_modifyRouter_Success() (gas: 26455)
CCIPReceiverTest:test_removeSender_from_approvedList_and_revert_Success() (gas: 405377)
CCIPReceiverTest:test_retryFailedMessage_Success() (gas: 423637)
CCIPReceiverTest:test_retryFailedMessage_which_has_not_already_failed_Revert() (gas: 11168)
CCIPReceiverTest:test_withdraw_nativeToken_to_owner_Success() (gas: 20876)
CCIPReceiverWithAckTest:test_attemptACK_message_which_has_already_been_acknowledged_Revert() (gas: 406869)
CCIPReceiverWithAckTest:test_ccipReceive_ack_message_Success() (gas: 53229)
CCIPReceiverWithAckTest:test_ccipReceive_and_respond_with_ack_Success() (gas: 330692)
CCIPReceiverWithAckTest:test_ccipReceiver_ack_with_invalidAckMessageHeaderBytes_Revert() (gas: 415299)
CCIPReceiverWithAckTest:test_feeTokenApproval_in_constructor_Success() (gas: 2831885)
CCIPReceiverWithAckTest:test_modifyFeeToken_Success() (gas: 74830)
CCIPSenderTest:test_ccipSend_withNonNativeFeetoken_andDestTokens_Success() (gas: 340076)
CCIPSenderTest:test_ccipSend_withNonNativeFeetoken_andNoDestTokens_Success() (gas: 224347)
CCIPSenderTest:test_ccipSend_with_NativeFeeToken_andDestTokens_Success() (gas: 371349)
CommitStore_constructor:test_Constructor_Success() (gas: 3091326)
CommitStore_isUnpausedAndRMNHealthy:test_RMN_Success() (gas: 73420)
CommitStore_report:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 28670)
Expand Down Expand Up @@ -115,8 +145,6 @@ CommitStore_verify:test_Blessed_Success() (gas: 96389)
CommitStore_verify:test_NotBlessed_Success() (gas: 61374)
CommitStore_verify:test_Paused_Revert() (gas: 18496)
CommitStore_verify:test_TooManyLeaves_Revert() (gas: 36785)
DefensiveExampleTest:test_HappyPath_Success() (gas: 200018)
DefensiveExampleTest:test_Recovery() (gas: 424256)
E2E:test_E2E_3MessagesSuccess_gas() (gas: 1100023)
EVM2EVMOffRamp__releaseOrMintToken:test__releaseOrMintToken_NotACompatiblePool_Revert() (gas: 37782)
EVM2EVMOffRamp__releaseOrMintToken:test__releaseOrMintToken_Success() (gas: 103730)
Expand Down Expand Up @@ -168,7 +196,7 @@ EVM2EVMOffRamp_execute:test_Unhealthy_Revert() (gas: 544641)
EVM2EVMOffRamp_execute:test_UnsupportedNumberOfTokens_Revert() (gas: 64323)
EVM2EVMOffRamp_execute:test__execute_SkippedAlreadyExecutedMessageUnordered_Success() (gas: 122322)
EVM2EVMOffRamp_execute:test__execute_SkippedAlreadyExecutedMessage_Success() (gas: 142532)
EVM2EVMOffRamp_execute:test_execute_RouterYULCall_Success() (gas: 427328)
EVM2EVMOffRamp_execute:test_execute_RouterYULCall_Success() (gas: 1583346)
EVM2EVMOffRamp_executeSingleMessage:test_MessageSender_Revert() (gas: 18502)
EVM2EVMOffRamp_executeSingleMessage:test_NonContractWithTokens_Success() (gas: 278106)
EVM2EVMOffRamp_executeSingleMessage:test_NonContract_Success() (gas: 18668)
Expand All @@ -192,11 +220,11 @@ EVM2EVMOffRamp_manuallyExecute:test_ManualExecInvalidGasLimit_Revert() (gas: 274
EVM2EVMOffRamp_manuallyExecute:test_ManualExecWithMultipleMessagesAndSourceTokens_Success() (gas: 530151)
EVM2EVMOffRamp_manuallyExecute:test_ManualExecWithSourceTokens_Success() (gas: 345758)
EVM2EVMOffRamp_manuallyExecute:test_ManualExec_Success() (gas: 187324)
EVM2EVMOffRamp_manuallyExecute:test_ReentrancyManualExecuteFails_Success() (gas: 2321912)
EVM2EVMOffRamp_manuallyExecute:test_ReentrancyManualExecuteFails_Success() (gas: 3381693)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_DestinationGasAmountCountMismatch_Revert() (gas: 362965)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_DoesNotRevertIfUntouched_Success() (gas: 143900)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_InvalidTokenGasOverride_Revert() (gas: 366104)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_LowGasLimitManualExec_Success() (gas: 482682)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_LowGasLimitManualExec_Success() (gas: 1638915)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_WithGasOverride_Success() (gas: 189727)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_WithInvalidReceiverExecutionGasOverride_Revert() (gas: 153641)
EVM2EVMOffRamp_manuallyExecute:test_manuallyExecute_WithInvalidSourceTokenDataCount_Revert() (gas: 59894)
Expand Down Expand Up @@ -690,7 +718,7 @@ OffRamp_executeSingleReport:test_NonExistingSourceChain_Revert() (gas: 28459)
OffRamp_executeSingleReport:test_ReceiverError_Success() (gas: 187534)
OffRamp_executeSingleReport:test_RetryFailedMessageWithoutManualExecution_Revert() (gas: 198006)
OffRamp_executeSingleReport:test_RootNotCommitted_Revert() (gas: 40129)
OffRamp_executeSingleReport:test_RouterYULCall_Revert() (gas: 447379)
OffRamp_executeSingleReport:test_RouterYULCall_Revert() (gas: 1603224)
OffRamp_executeSingleReport:test_SingleMessageNoTokensOtherChain_Success() (gas: 247824)
OffRamp_executeSingleReport:test_SingleMessageNoTokensUnordered_Success() (gas: 192091)
OffRamp_executeSingleReport:test_SingleMessageNoTokens_Success() (gas: 211684)
Expand All @@ -716,9 +744,9 @@ OffRamp_manuallyExecute:test_manuallyExecute_DoesNotRevertIfUntouched_Success()
OffRamp_manuallyExecute:test_manuallyExecute_FailedTx_Revert() (gas: 211065)
OffRamp_manuallyExecute:test_manuallyExecute_ForkedChain_Revert() (gas: 26057)
OffRamp_manuallyExecute:test_manuallyExecute_GasLimitMismatchMultipleReports_Revert() (gas: 152806)
OffRamp_manuallyExecute:test_manuallyExecute_LowGasLimit_Success() (gas: 529785)
OffRamp_manuallyExecute:test_manuallyExecute_LowGasLimit_Success() (gas: 1685436)
OffRamp_manuallyExecute:test_manuallyExecute_MultipleReportsWithSingleCursedLane_Revert() (gas: 310294)
OffRamp_manuallyExecute:test_manuallyExecute_ReentrancyFails_Success() (gas: 2389687)
OffRamp_manuallyExecute:test_manuallyExecute_ReentrancyFails_Success() (gas: 3441495)
OffRamp_manuallyExecute:test_manuallyExecute_SourceChainSelectorMismatch_Revert() (gas: 162168)
OffRamp_manuallyExecute:test_manuallyExecute_Success() (gas: 223992)
OffRamp_manuallyExecute:test_manuallyExecute_WithGasOverride_Success() (gas: 224567)
Expand Down Expand Up @@ -786,11 +814,13 @@ OnRamp_setDynamicConfig:test_SetConfigInvalidConfig_Revert() (gas: 11359)
OnRamp_setDynamicConfig:test_SetConfigOnlyOwner_Revert() (gas: 16385)
OnRamp_setDynamicConfig:test_SetDynamicConfig_Success() (gas: 55321)
OnRamp_withdrawFeeTokens:test_WithdrawFeeTokens_Success() (gas: 97095)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 152669)
PingPong_plumbing:test_OutOfOrderExecution_Success() (gas: 20277)
PingPong_plumbing:test_Pausing_Success() (gas: 17777)
PingPong_startPingPong:test_StartPingPong_With_OOO_Success() (gas: 163187)
PingPong_startPingPong:test_StartPingPong_With_Sequenced_Ordered_Success() (gas: 182599)
PingPong_example_ccipReceive:test_CcipReceive_Success() (gas: 180083)
PingPong_example_startPingPong:test_StartPingPong_Success() (gas: 209814)
PingPong_example_startPingPong:test_StartPingPong_With_OOO_Success() (gas: 279194)
PingPong_example_startPingPong:test_StartPingPong_With_Sequenced_Ordered_Success() (gas: 204537)
PingPong_plumbing:test_OutOfOrderExecution_Success() (gas: 124484)
PingPong_plumbing:test_Pausing_Success() (gas: 17917)
PingPong_plumbing:test_typeAndVersion() (gas: 9741)
RMNHome:test() (gas: 186)
RMN_constructor:test_Constructor_Success() (gas: 48838)
RMN_getRecordedCurseRelatedOps:test_OpsPostDeployment() (gas: 19666)
Expand Down Expand Up @@ -902,9 +932,9 @@ Router_routeMessage:test_ManualExec_Success() (gas: 35381)
Router_routeMessage:test_OnlyOffRamp_Revert() (gas: 25116)
Router_routeMessage:test_WhenNotHealthy_Revert() (gas: 44724)
Router_setWrappedNative:test_OnlyOwner_Revert() (gas: 10986)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 55531)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 419466)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20151)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 271268)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 447066)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20161)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_OnlyPendingAdministrator_Revert() (gas: 51085)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_Success() (gas: 43947)
TokenAdminRegistry_addRegistryModule:test_addRegistryModule_OnlyOwner_Revert() (gas: 12629)
Expand Down
18 changes: 6 additions & 12 deletions contracts/src/v0.8/ccip/applications/external/CCIPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ contract CCIPReceiver is CCIPBase {
/// not revert, all errors should be handled internally in this contract.
/// @param message The message to process.
/// @dev Extremely important to ensure only router calls this.
function ccipReceive(Client.Any2EVMMessage calldata message)
external
virtual
onlyRouter
isValidChain(message.sourceChainSelector)
{
function ccipReceive(
Client.Any2EVMMessage calldata message
) external virtual onlyRouter isValidChain(message.sourceChainSelector) {
try this.processMessage(message) {}
catch (bytes memory err) {
// If custom retry logic is desired, plus granting the owner the ability to extract tokens as a last resort for
Expand All @@ -68,12 +65,9 @@ contract CCIPReceiver is CCIPBase {

/// @notice Contains arbitrary application-logic for incoming CCIP messages.
/// @dev It has to be external because of the try/catch of ccipReceive() which invokes it
function processMessage(Client.Any2EVMMessage calldata message)
external
virtual
onlySelf
isValidSender(message.sourceChainSelector, message.sender)
{}
function processMessage(
Client.Any2EVMMessage calldata message
) external virtual onlySelf isValidSender(message.sourceChainSelector, message.sender) {}

// ================================================================
// │ Failed Message Processing |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ contract CCIPReceiverWithACK is CCIPReceiver {
/// @notice Application-specific logic for incoming ccip messages.
/// @dev Function does NOT require the status of an incoming ACK be "sent" because this implementation does not send, only receives
/// Any MessageType encoding is implemented by the sender contract, and is not natively part of CCIP messages.
function processMessage(Client.Any2EVMMessage calldata message)
external
virtual
override
onlySelf
isValidSender(message.sourceChainSelector, message.sender)
{
function processMessage(
Client.Any2EVMMessage calldata message
) external virtual override onlySelf isValidSender(message.sourceChainSelector, message.sender) {
(MessagePayload memory payload) = abi.decode(message.data, (MessagePayload));

// message type is a concept with ClientWithACK
Expand Down
26 changes: 11 additions & 15 deletions contracts/src/v0.8/ccip/applications/internal/PingPongDemo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ pragma solidity ^0.8.0;
import {Client} from "../../libraries/Client.sol";
import {CCIPClient} from "../external/CCIPClient.sol";

import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol";
import {IRouter} from "../../interfaces/IRouter.sol";
import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol";

import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/// @title PingPongDemo - A simple ping-pong contract for demonstrating cross-chain communication
contract PingPongDemo is CCIPClient {

event Ping(uint256 pingPongCount);
event Pong(uint256 pingPongCount);
event OutOfOrderExecutionChange(bool isOutOfOrder);
Expand Down Expand Up @@ -58,12 +57,9 @@ contract PingPongDemo is CCIPClient {
/// @dev This example just sends the tokens to the owner of this contracts. More
/// interesting functions could be implemented.
/// @dev It has to be external because of the try/catch.
function processMessage(Client.Any2EVMMessage calldata message)
external
override
onlySelf
isValidSender(message.sourceChainSelector, message.sender)
{
function processMessage(
Client.Any2EVMMessage calldata message
) external override onlySelf isValidSender(message.sourceChainSelector, message.sender) {
if (!s_isPaused) {
_respond(abi.decode(message.data, (uint256)) + 1);
}
Expand Down Expand Up @@ -106,26 +102,26 @@ contract PingPongDemo is CCIPClient {
return s_isPaused;
}

function getOutOfOrderExecution() external view returns (bool) {
function getOutOfOrderExecution() external view virtual returns (bool) {
return s_allowOutOfOrderExecution;
}

function setOutOfOrderExecution(bool outOfOrderExecution) external onlyOwner {
// It adds gas having the extra storage slot, but the alternative is a bunch of very messy assembly code
// to slice it out of the extra args.
function setOutOfOrderExecution(bool outOfOrderExecution) external virtual onlyOwner {
// An additional storage slot is used for code simplicity. The current storage value can be
// retrieved by parsing the extraArgsBytes field of the chain configuration, but this is not recommended
// as it is more expensive and error-prone by requiring additional parsing logic in raw assembly.
s_allowOutOfOrderExecution = outOfOrderExecution;

address onRamp = IRouter(s_ccipRouter).getOnRamp(s_counterpartChainSelector);
EVM2EVMOnRamp.StaticConfig memory staticConfig = EVM2EVMOnRamp(onRamp).getStaticConfig();

// Enabling out of order execution also requires setting a manual gas limit, therefore the on-ramp default
// gas limit is used to ensure consistency, but can be overwritten manually by the contract owner using
// gas limit is used to ensure consistency, but can be overwritten manually by the contract owner using
// the applyChainUpdates function.
s_chainConfigs[s_counterpartChainSelector].extraArgsBytes = Client._argsToBytes(
Client.EVMExtraArgsV2({gasLimit: staticConfig.defaultTxGasLimit, allowOutOfOrderExecution: outOfOrderExecution})
);

emit OutOfOrderExecutionChange(outOfOrderExecution);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ contract PingPongDappSetup is EVM2EVMOnRampSetup {
}

contract PingPong_example_startPingPong is PingPongDappSetup {
uint256 pingPongNumber = 1;
bytes data = abi.encode(pingPongNumber);
uint256 pingPongNumber = 1;
bytes data = abi.encode(pingPongNumber);

function test_StartPingPong_Success() public {
function test_StartPingPong_Success() public {
Client.EVM2AnyMessage memory sentMessage = Client.EVM2AnyMessage({
receiver: abi.encode(i_pongContract),
data: data,
Expand Down Expand Up @@ -170,7 +170,7 @@ contract PingPong_example_ccipReceive is PingPongDappSetup {
contract PingPong_plumbing is PingPongDappSetup {
function test_Fuzz_CounterPartChainSelector_Success(uint64 chainSelector) public {
vm.assume(chainSelector != 0);

s_pingPong.setCounterpart(chainSelector, address(0x1234));

assertEq(s_pingPong.getCounterpartChainSelector(), chainSelector);
Expand Down Expand Up @@ -205,7 +205,7 @@ contract PingPong_plumbing is PingPongDappSetup {
function test_typeAndVersion() public view {
assertEq(s_pingPong.typeAndVersion(), "PingPongDemo 1.6.0-dev");
}

function test_OutOfOrderExecution_Success() public {
assertFalse(s_pingPong.getOutOfOrderExecution());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ contract CCIPReceiverReverting is CCIPReceiver {
/// @dev This example just sends the tokens to the owner of this contracts. More
/// interesting functions could be implemented.
/// @dev It has to be external because of the try/catch.
function processMessage(Client.Any2EVMMessage calldata message)
external
view
override
onlySelf
isValidSender(message.sourceChainSelector, message.sender)
{
function processMessage(
Client.Any2EVMMessage calldata message
) external view override onlySelf isValidSender(message.sourceChainSelector, message.sender) {
// Meant to help simulate a failed-message
if (s_simRevert) revert ErrorCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pragma solidity ^0.8.19;
import {Client} from "../../../libraries/Client.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {EVM2EVMOffRamp} from "../../../offRamp/EVM2EVMOffRamp.sol";
import {CCIPReceiverBasic} from "./CCIPReceiverBasic.sol";

import {OffRamp} from "../../../offRamp/OffRamp.sol";
import {CCIPReceiverBasic} from "./CCIPReceiverBasic.sol";

contract ReentrancyAbuserMultiRamp is CCIPReceiverBasic {
event ReentrancySucceeded();
Expand Down

0 comments on commit cb2849c

Please sign in to comment.