Skip to content

Commit

Permalink
make external, rm empty funcs, add events (#1059)
Browse files Browse the repository at this point in the history
Static analysis results
  • Loading branch information
RensR authored Jun 20, 2024
1 parent cf39242 commit 745a035
Show file tree
Hide file tree
Showing 25 changed files with 908 additions and 54 deletions.
36 changes: 18 additions & 18 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243659)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24260)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2133850)
CommitStore_constructor:test_Constructor_Success() (gas: 3068979)
CommitStore_constructor:test_Constructor_Success() (gas: 3091440)
CommitStore_isUnpausedAndRMNHealthy:test_RMN_Success() (gas: 75331)
CommitStore_report:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 28784)
CommitStore_report:test_InvalidInterval_Revert() (gas: 28724)
Expand All @@ -55,9 +55,9 @@ CommitStore_resetUnblessedRoots:test_OnlyOwner_Revert() (gas: 11325)
CommitStore_resetUnblessedRoots:test_ResetUnblessedRoots_Success() (gas: 140460)
CommitStore_setDynamicConfig:test_InvalidCommitStoreConfig_Revert() (gas: 37263)
CommitStore_setDynamicConfig:test_OnlyOwner_Revert() (gas: 37399)
CommitStore_setDynamicConfig:test_PriceEpochCleared_Success() (gas: 127733)
CommitStore_setDynamicConfig:test_PriceEpochCleared_Success() (gas: 129098)
CommitStore_setLatestPriceEpochAndRound:test_OnlyOwner_Revert() (gas: 11047)
CommitStore_setLatestPriceEpochAndRound:test_SetLatestPriceEpochAndRound_Success() (gas: 16626)
CommitStore_setLatestPriceEpochAndRound:test_SetLatestPriceEpochAndRound_Success() (gas: 20642)
CommitStore_setMinSeqNr:test_OnlyOwner_Revert() (gas: 11046)
CommitStore_verify:test_Blessed_Success() (gas: 96279)
CommitStore_verify:test_NotBlessed_Success() (gas: 58800)
Expand All @@ -83,22 +83,22 @@ EVM2EVMMultiOffRamp_batchExecute:test_SingleReport_Success() (gas: 136157)
EVM2EVMMultiOffRamp_batchExecute:test_Unhealthy_Revert() (gas: 520361)
EVM2EVMMultiOffRamp_batchExecute:test_ZeroReports_Revert() (gas: 10441)
EVM2EVMMultiOffRamp_ccipReceive:test_Reverts() (gas: 17112)
EVM2EVMMultiOffRamp_commit:test_NoConfigWithOtherConfigPresent_Revert() (gas: 7030444)
EVM2EVMMultiOffRamp_commit:test_NoConfig_Revert() (gas: 6613367)
EVM2EVMMultiOffRamp_commit:test_NoConfigWithOtherConfigPresent_Revert() (gas: 7043083)
EVM2EVMMultiOffRamp_commit:test_NoConfig_Revert() (gas: 6626006)
EVM2EVMMultiOffRamp_commit:test_SingleReport_Success() (gas: 161050)
EVM2EVMMultiOffRamp_commit:test_UnauthorizedTransmitter_Revert() (gas: 120903)
EVM2EVMMultiOffRamp_commit:test_WrongConfigWithoutSigners_Revert() (gas: 7049219)
EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6699198)
EVM2EVMMultiOffRamp_constructor:test_SourceChainSelector_Revert() (gas: 100010)
EVM2EVMMultiOffRamp_constructor:test_ZeroChainSelector_Revert() (gas: 98591)
EVM2EVMMultiOffRamp_constructor:test_ZeroOnRampAddress_Revert() (gas: 100043)
EVM2EVMMultiOffRamp_constructor:test_ZeroRMNProxy_Revert() (gas: 96348)
EVM2EVMMultiOffRamp_constructor:test_ZeroTokenAdminRegistry_Revert() (gas: 96438)
EVM2EVMMultiOffRamp_execute:test_NoConfigWithOtherConfigPresent_Revert() (gas: 7079961)
EVM2EVMMultiOffRamp_execute:test_NoConfig_Revert() (gas: 6662627)
EVM2EVMMultiOffRamp_commit:test_WrongConfigWithoutSigners_Revert() (gas: 7061858)
EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6711837)
EVM2EVMMultiOffRamp_constructor:test_SourceChainSelector_Revert() (gas: 100030)
EVM2EVMMultiOffRamp_constructor:test_ZeroChainSelector_Revert() (gas: 98610)
EVM2EVMMultiOffRamp_constructor:test_ZeroOnRampAddress_Revert() (gas: 100063)
EVM2EVMMultiOffRamp_constructor:test_ZeroRMNProxy_Revert() (gas: 96367)
EVM2EVMMultiOffRamp_constructor:test_ZeroTokenAdminRegistry_Revert() (gas: 96457)
EVM2EVMMultiOffRamp_execute:test_NoConfigWithOtherConfigPresent_Revert() (gas: 7092600)
EVM2EVMMultiOffRamp_execute:test_NoConfig_Revert() (gas: 6675266)
EVM2EVMMultiOffRamp_execute:test_SingleReport_Success() (gas: 156875)
EVM2EVMMultiOffRamp_execute:test_UnauthorizedTransmitter_Revert() (gas: 140719)
EVM2EVMMultiOffRamp_execute:test_WrongConfigWithSigners_Revert() (gas: 7442269)
EVM2EVMMultiOffRamp_execute:test_WrongConfigWithSigners_Revert() (gas: 7454908)
EVM2EVMMultiOffRamp_executeSingleMessage:test_MessageSender_Revert() (gas: 20642)
EVM2EVMMultiOffRamp_executeSingleMessage:test_NonContractWithTokens_Success() (gas: 255841)
EVM2EVMMultiOffRamp_executeSingleMessage:test_NonContract_Success() (gas: 22871)
Expand Down Expand Up @@ -143,7 +143,7 @@ EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedNonceStartsAtV1Nonce_Success()
EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedOffRampNonceSkipsIfMsgInFlight_Success() (gas: 270581)
EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedSenderNoncesReadsPreviousRampTransitive_Success() (gas: 247819)
EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedSenderNoncesReadsPreviousRamp_Success() (gas: 235794)
EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedWithMultiRamp_Revert() (gas: 7615107)
EVM2EVMMultiOffRamp_execute_upgrade:test_UpgradedWithMultiRamp_Revert() (gas: 7627747)
EVM2EVMMultiOffRamp_execute_upgrade:test_Upgraded_Success() (gas: 136510)
EVM2EVMMultiOffRamp_getExecutionState:test_FillExecutionState_Success() (gas: 3590746)
EVM2EVMMultiOffRamp_getExecutionState:test_GetDifferentChainExecutionState_Success() (gas: 117760)
Expand Down Expand Up @@ -201,8 +201,8 @@ EVM2EVMMultiOffRamp_setDynamicConfig:test_RouterZeroAddress_Revert() (gas: 14413
EVM2EVMMultiOffRamp_setDynamicConfig:test_SetDynamicConfigWithValidator_Success() (gas: 45435)
EVM2EVMMultiOffRamp_setDynamicConfig:test_SetDynamicConfig_Success() (gas: 40479)
EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound:test_OnlyOwner_Revert() (gas: 11043)
EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound:test_PriceEpochCleared_Success() (gas: 241566)
EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound:test_SetLatestPriceEpochAndRound_Success() (gas: 16555)
EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound:test_PriceEpochCleared_Success() (gas: 242916)
EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound:test_SetLatestPriceEpochAndRound_Success() (gas: 20502)
EVM2EVMMultiOffRamp_trialExecute:test_RateLimitError_Success() (gas: 243932)
EVM2EVMMultiOffRamp_trialExecute:test_TokenHandlingErrorIsCaught_Success() (gas: 252523)
EVM2EVMMultiOffRamp_trialExecute:test_TokenPoolIsNotAContract_Success() (gas: 306347)
Expand Down
12 changes: 11 additions & 1 deletion contracts/src/v0.8/ccip/CommitStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract CommitStore is ICommitStore, ITypeAndVersion, OCR2Base {
event ReportAccepted(CommitReport report);
event ConfigSet(StaticConfig staticConfig, DynamicConfig dynamicConfig);
event RootRemoved(bytes32 root);
event SequenceNumberSet(uint64 oldSeqNum, uint64 newSeqNum);
event LatestPriceEpochAndRoundSet(uint40 oldEpochAndRound, uint40 newEpochAndRound);

/// @notice Static commit store config
/// @dev RMN depends on this struct, if changing, please notify the RMN maintainers.
Expand Down Expand Up @@ -112,19 +114,27 @@ contract CommitStore is ICommitStore, ITypeAndVersion, OCR2Base {
/// @notice Sets the minimum sequence number.
/// @param minSeqNr The new minimum sequence number.
function setMinSeqNr(uint64 minSeqNr) external onlyOwner {
uint64 oldSeqNum = s_minSeqNr;

s_minSeqNr = minSeqNr;

emit SequenceNumberSet(oldSeqNum, minSeqNr);
}

/// @notice Returns the epoch and round of the last price update.
/// @return the latest price epoch and round.
function getLatestPriceEpochAndRound() public view returns (uint64) {
function getLatestPriceEpochAndRound() external view returns (uint64) {
return s_latestPriceEpochAndRound;
}

/// @notice Sets the latest epoch and round for price update.
/// @param latestPriceEpochAndRound The new epoch and round for prices.
function setLatestPriceEpochAndRound(uint40 latestPriceEpochAndRound) external onlyOwner {
uint40 oldEpochAndRound = s_latestPriceEpochAndRound;

s_latestPriceEpochAndRound = latestPriceEpochAndRound;

emit LatestPriceEpochAndRoundSet(oldEpochAndRound, latestPriceEpochAndRound);
}

/// @notice Returns the timestamp of a potentially previously committed merkle root.
Expand Down
1 change: 0 additions & 1 deletion contracts/src/v0.8/ccip/MultiAggregateRateLimiter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ contract MultiAggregateRateLimiter is IMessageInterceptor, OwnerIsCreator {

error UnauthorizedCaller(address caller);
error PriceNotFoundForToken(address token);
error UpdateLengthMismatch();
error ZeroAddressNotAllowed();
error ZeroChainSelectorNotAllowed();

Expand Down
3 changes: 1 addition & 2 deletions contracts/src/v0.8/ccip/applications/CCIPClientExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import {IERC20} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/
// change if you introduce upgradeability. An immutable dapp building on top of CCIP
// like the example below will inherit the trust properties of CCIP (i.e. the oracle network).
// @dev The receiver's are encoded offchain and passed as direct arguments to permit supporting
// new chain family receivers (e.g. a solana encoded receiver address) without upgrading.
// new chain family receivers (e.g. a Solana encoded receiver address) without upgrading.
contract CCIPClientExample is CCIPReceiver, OwnerIsCreator {
error InvalidConfig();
error InvalidChain(uint64 chainSelector);

event MessageSent(bytes32 messageId);
Expand Down
3 changes: 0 additions & 3 deletions contracts/src/v0.8/ccip/applications/EtherSenderReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ contract EtherSenderReceiver is CCIPReceiver, ITypeAndVersion {
error InvalidTokenAmounts(uint256 gotAmounts);
error InvalidToken(address gotToken, address expectedToken);
error TokenAmountNotEqualToMsgValue(uint256 gotAmount, uint256 msgValue);
error InsufficientMsgValue(uint256 gotAmount, uint256 msgValue);
error InsufficientFee(uint256 gotFee, uint256 fee);
error GasLimitTooLow(uint256 minLimit, uint256 gotLimit);

string public constant override typeAndVersion = "EtherSenderReceiver 1.5.0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract SelfFundedPingPong is PingPongDemo {
return s_countIncrBeforeFunding;
}

function setCountIncrBeforeFunding(uint8 countIncrBeforeFunding) public onlyOwner {
function setCountIncrBeforeFunding(uint8 countIncrBeforeFunding) external onlyOwner {
s_countIncrBeforeFunding = countIncrBeforeFunding;
emit CountIncrBeforeFundingSet(countIncrBeforeFunding);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/ocr/MultiOCR3Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract contract MultiOCR3Base is ITypeAndVersion, OwnerIsCreator {

/// @notice Hook that is called after a plugin's OCR3 config changes
/// @param ocrPluginType Plugin type for which the config changed
function _afterOCR3ConfigSet(uint8 ocrPluginType) internal virtual {}
function _afterOCR3ConfigSet(uint8 ocrPluginType) internal virtual;

/// @notice Clears oracle roles for the provided oracle addresses
/// @param ocrPluginType OCR plugin type to clear roles for
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/ocr/OCR2Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract contract OCR2Base is OwnerIsCreator, OCR2Abstract {

/// @dev Hook that is run from setOCR2Config() right after validating configuration.
/// Empty by default, please provide an implementation in a child contract if you need additional configuration processing
function _beforeSetConfig(bytes memory _onchainConfig) internal virtual {}
function _beforeSetConfig(bytes memory _onchainConfig) internal virtual;

/// @return list of addresses permitted to transmit reports to this contract
/// @dev The list will match the order used to specify the transmitter during setConfig
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/ocr/OCR2BaseNoChecks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ abstract contract OCR2BaseNoChecks is OwnerIsCreator, OCR2Abstract {

/// @dev Hook that is run from setOCR2Config() right after validating configuration.
/// Empty by default, please provide an implementation in a child contract if you need additional configuration processing
function _beforeSetConfig(bytes memory _onchainConfig) internal virtual {}
function _beforeSetConfig(bytes memory _onchainConfig) internal virtual;

/// @return list of addresses permitted to transmit reports to this contract
/// @dev The list will match the order used to specify the transmitter during setConfig
Expand Down
9 changes: 7 additions & 2 deletions contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ contract EVM2EVMMultiOffRamp is IAny2EVMMultiOffRamp, ITypeAndVersion, MultiOCR3
/// @dev RMN depends on this event, if changing, please notify the RMN maintainers.
event CommitReportAccepted(CommitReport report);
event RootRemoved(bytes32 root);
event LatestPriceEpochAndRoundSet(uint40 oldEpochAndRound, uint40 newEpochAndRound);

/// @notice Static offRamp config
/// @dev RMN depends on this struct, if changing, please notify the RMN maintainers.
Expand All @@ -97,7 +98,7 @@ contract EVM2EVMMultiOffRamp is IAny2EVMMultiOffRamp, ITypeAndVersion, MultiOCR3
struct SourceChainConfig {
bool isEnabled; // ─────────╮ Flag whether the source chain is enabled or not
uint64 minSeqNr; // | The min sequence number expected for future messages
address prevOffRamp; // ────╯ Address of previous-version per-lane OffRamp. Used to be able to provide seequencing continuity during a zero downtime upgrade.
address prevOffRamp; // ────╯ Address of previous-version per-lane OffRamp. Used to be able to provide sequencing continuity during a zero downtime upgrade.
address onRamp; // OnRamp address on the source chain
/// @dev Ensures that 2 identical messages sent to 2 different lanes will have a distinct hash.
/// Must match the metadataHash used in computing leaf hashes offchain for the root committed in
Expand Down Expand Up @@ -727,14 +728,18 @@ contract EVM2EVMMultiOffRamp is IAny2EVMMultiOffRamp, ITypeAndVersion, MultiOCR3

/// @notice Returns the epoch and round of the last price update.
/// @return the latest price epoch and round.
function getLatestPriceEpochAndRound() public view returns (uint64) {
function getLatestPriceEpochAndRound() external view returns (uint64) {
return s_latestPriceEpochAndRound;
}

/// @notice Sets the latest epoch and round for price update.
/// @param latestPriceEpochAndRound The new epoch and round for prices.
function setLatestPriceEpochAndRound(uint40 latestPriceEpochAndRound) external onlyOwner {
uint40 oldEpochAndRound = s_latestPriceEpochAndRound;

s_latestPriceEpochAndRound = latestPriceEpochAndRound;

emit LatestPriceEpochAndRoundSet(oldEpochAndRound, latestPriceEpochAndRound);
}

/// @notice Returns the timestamp of a potentially previously committed merkle root.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/offRamp/EVM2EVMOffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
}

/// @inheritdoc IAny2EVMOffRamp
function getSenderNonce(address sender) public view returns (uint64 nonce) {
function getSenderNonce(address sender) external view returns (uint64 nonce) {
uint256 senderNonce = s_senderNonce[sender];

if (senderNonce == 0 && i_prevOffRamp != address(0)) {
Expand Down
5 changes: 0 additions & 5 deletions contracts/src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyMultiOnRamp, AggregateRateLimiter, ITypeA

error InvalidExtraArgsTag();
error OnlyCallableByOwnerOrAdmin();
error InvalidWithdrawParams();
error NoFeesToPay();
error MaxFeeBalanceReached();
error MessageTooLarge(uint256 maxSize, uint256 actualSize);
error MessageGasLimitTooHigh();
error MessageFeeTooHigh(uint256 msgFeeJuels, uint256 maxFeeJuelsPerMsg);
Expand All @@ -41,11 +38,9 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyMultiOnRamp, AggregateRateLimiter, ITypeA
error RouterMustSetOriginalSender();
error InvalidConfig();
error CursedByRMN(uint64 sourceChainSelector);
error LinkBalanceNotSettled();
error NotAFeeToken(address token);
error CannotSendZeroTokens();
error SourceTokenDataTooLarge(address token);
error InvalidChainSelector(uint64 chainSelector);
error GetSupportedTokensFunctionalityRemovedCheckAdminRegistry();
error InvalidDestChainConfig(uint64 destChainSelector);
error DestinationChainNotEnabled(uint64 destChainSelector);
Expand Down
11 changes: 10 additions & 1 deletion contracts/src/v0.8/ccip/test/commitStore/CommitStore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ contract CommitStore_constructor is PriceRegistrySetup, OCR2BaseSetup {

contract CommitStore_setMinSeqNr is CommitStoreSetup {
function test_Fuzz_SetMinSeqNr_Success(uint64 minSeqNr) public {
vm.expectEmit();
emit CommitStore.SequenceNumberSet(s_commitStore.getExpectedNextSequenceNumber(), minSeqNr);

s_commitStore.setMinSeqNr(minSeqNr);

assertEq(s_commitStore.getExpectedNextSequenceNumber(), minSeqNr);
Expand Down Expand Up @@ -597,9 +600,15 @@ contract CommitStore_isUnpausedAndRMNHealthy is CommitStoreSetup {
contract CommitStore_setLatestPriceEpochAndRound is CommitStoreSetup {
function test_SetLatestPriceEpochAndRound_Success() public {
uint40 latestRoundAndEpoch = 1782155;

vm.expectEmit();
emit CommitStore.LatestPriceEpochAndRoundSet(
uint40(s_commitStore.getLatestPriceEpochAndRound()), latestRoundAndEpoch
);

s_commitStore.setLatestPriceEpochAndRound(latestRoundAndEpoch);

assertEq(s_commitStore.getLatestPriceEpochAndRound(), latestRoundAndEpoch);
assertEq(uint40(s_commitStore.getLatestPriceEpochAndRound()), latestRoundAndEpoch);
}

// Reverts
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/v0.8/ccip/test/helpers/OCR2Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ contract OCR2Helper is OCR2Base(false) {
function typeAndVersion() public pure override returns (string memory) {
return "OCR2BaseHelper 1.0.0";
}

function _beforeSetConfig(bytes memory _onchainConfig) internal override {}
}
2 changes: 2 additions & 0 deletions contracts/src/v0.8/ccip/test/helpers/OCR2NoChecksHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ contract OCR2NoChecksHelper is OCR2BaseNoChecks {
function typeAndVersion() public pure override returns (string memory) {
return "OCR2BaseHelper 1.0.0";
}

function _beforeSetConfig(bytes memory _onchainConfig) internal override {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,12 @@ contract EVM2EVMMultiOffRamp_isUnpausedAndRMNHealthy is EVM2EVMMultiOffRampSetup
contract EVM2EVMMultiOffRamp_setLatestPriceEpochAndRound is EVM2EVMMultiOffRampSetup {
function test_SetLatestPriceEpochAndRound_Success() public {
uint40 latestRoundAndEpoch = 1782155;

vm.expectEmit();
emit EVM2EVMMultiOffRamp.LatestPriceEpochAndRoundSet(
uint40(s_offRamp.getLatestPriceEpochAndRound()), latestRoundAndEpoch
);

s_offRamp.setLatestPriceEpochAndRound(latestRoundAndEpoch);
assertEq(s_offRamp.getLatestPriceEpochAndRound(), latestRoundAndEpoch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract TokenAdminRegistry is ITokenAdminRegistry, ITypeAndVersion, OwnerIsCrea
// ================================================================

/// @notice Public getter to check for permissions of an administrator
function isAdministrator(address localToken, address administrator) public view returns (bool) {
function isAdministrator(address localToken, address administrator) external view returns (bool) {
return s_tokenConfig[localToken].administrator == administrator;
}

Expand Down
Loading

0 comments on commit 745a035

Please sign in to comment.