Skip to content

Commit

Permalink
don't pass in derivable values
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Sep 20, 2024
1 parent 4533ed6 commit 08f2d35
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 94 deletions.
63 changes: 31 additions & 32 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,42 @@ BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 244050)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24170)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2052431)
CCIPHomeSetup:test_getCapabilityConfiguration_Success() (gas: 9551)
CCIPHomeSetup:test_getCapabilityConfiguration_Success() (gas: 9485)
CCIPHome_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 83249)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 354619)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 466942)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 433238)
CCIPHome_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11646)
CCIPHome_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8761)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 305971)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 46117)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 25018)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 362446)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 109995)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 141578)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 362163)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 141645)
CCIPHome_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9740)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1698388)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 990917)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 990951)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 354552)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 466897)
CCIPHome_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 433263)
CCIPHome_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8670)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 305949)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 46160)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 24996)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 362424)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 109973)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 141534)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 362141)
CCIPHome_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 141601)
CCIPHome_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9652)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1696904)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 990175)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 990209)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilitiesRegistryCanCall_Reverts() (gas: 9665)
CCIPHome_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 15592)
CCIPHome_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9639)
CCIPHome_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9573)
CCIPHome_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 185182)
CCIPHome_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 347148)
CCIPHome_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 347214)
CCIPHome_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 20599)
CCIPHome_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 270814)
CCIPHome_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 270849)
CCIPHome_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14921)
CCIPHome_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9660)
CCIPHome_chainConfig:test_getPaginatedCCIPHomes_Success() (gas: 370770)
CCIPHome_constructor:test_constructor_Success() (gas: 3016066)
CCIPHome_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 61051)
CCIPHome_updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 22183)
CCIPHome_updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 19514)
CCIPHome_updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9697)
CCIPHome_updatePluginConfig:test_updatePluginConfig_InitToRunning_Success() (gas: 1039323)
CCIPHome_updatePluginConfig:test_updatePluginConfig_RunningToStaging_Success() (gas: 1923495)
CCIPHome_updatePluginConfig:test_updatePluginConfig_StagingToRunning_Success() (gas: 1923529)
CCIPHome_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9594)
CCIPHome_chainConfig:test_getPaginatedCCIPHomes_Success() (gas: 370990)
CCIPHome_constructor:test_constructor_Success() (gas: 2957125)
CCIPHome_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 60980)
CCIPHome_updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 19611)
CCIPHome_updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 19418)
CCIPHome_updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9631)
CCIPHome_updatePluginConfig:test_updatePluginConfig_InitToRunning_Success() (gas: 1038558)
CCIPHome_updatePluginConfig:test_updatePluginConfig_RunningToStaging_Success() (gas: 1921768)
CCIPHome_updatePluginConfig:test_updatePluginConfig_StagingToRunning_Success() (gas: 1921802)
CCIPHome_validateConfig:test__validateConfigLessTransmittersThanSigners_Success() (gas: 333177)
CCIPHome_validateConfig:test__validateConfigSmallerFChain_Success() (gas: 464532)
CCIPHome_validateConfig:test__validateConfig_ABIEncodedAddress_OfframpAddressCannotBeZero_Reverts() (gas: 288463)
Expand All @@ -88,7 +87,7 @@ CCIPHome_validateConfig:test__validateConfig_Success() (gas: 299119)
CCIPHome_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 788872)
CCIPHome_validateConfig:test__validateConfig_ZeroP2PId_Reverts() (gas: 292418)
CCIPHome_validateConfig:test__validateConfig_ZeroSignerKey_Reverts() (gas: 292467)
CCIPHome_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9639)
CCIPHome_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9573)
CommitStore_constructor:test_Constructor_Success() (gas: 2855567)
CommitStore_isUnpausedAndRMNHealthy:test_RMN_Success() (gas: 73954)
CommitStore_report:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 28739)
Expand Down
35 changes: 12 additions & 23 deletions contracts/src/v0.8/ccip/capability/CCIPHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,14 @@ contract CCIPHome is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator {
/// @param pluginType The plugin type.
/// @param newConfig The new configuration.
function _updatePluginConfig(uint32 donId, Internal.OCRPluginType pluginType, OCR3Config[] memory newConfig) internal {
// There can be at most MAX_OCR3_CONFIGS_PER_PLUGIN configurations per plugin type.
if (newConfig.length > MAX_OCR3_CONFIGS_PER_PLUGIN) {
revert InvalidConfigLength(newConfig.length);
}
OCR3ConfigWithMeta[] memory currentConfig = s_ocr3Configs[donId][pluginType];

// Validate the state transition being proposed, which is implicitly defined by the combination
// of lengths of the current and new configurations.
ConfigState currentState = _stateFromConfigLength(currentConfig.length);
ConfigState proposedState = _stateFromConfigLength(newConfig.length);
_validateConfigStateTransition(currentState, proposedState);

// Build the new configuration with metadata and validate that the transition is valid.
OCR3ConfigWithMeta[] memory newConfigWithMeta =
_computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, proposedState);
OCR3ConfigWithMeta[] memory newConfigWithMeta = _computeNewConfigWithMeta(donId, currentConfig, newConfig);

_validateConfigTransition(currentConfig, newConfigWithMeta);

Expand Down Expand Up @@ -295,16 +292,6 @@ contract CCIPHome is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator {
// │ Config State Machine │
// ================================================================

/// @notice Determine the config state of the configuration from the length of the config.
/// @param configLen The length of the configuration.
/// @return The config state.
function _stateFromConfigLength(uint256 configLen) internal pure returns (ConfigState) {
if (configLen > 2) {
revert InvalidConfigLength(configLen);
}
return ConfigState(configLen);
}

/// @notice Validates the state transition between two config states.
/// The only valid state transitions are the following:
/// Init -> Running (first ever config)
Expand Down Expand Up @@ -373,16 +360,18 @@ contract CCIPHome is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator {
/// @param donId The DON ID.
/// @param currentConfig The current configuration, including metadata.
/// @param newConfig The new configuration, without metadata.
/// @param currentState The current state of the configuration.
/// @param newState The new state of the configuration.
/// @return The new configuration with metadata.
function _computeNewConfigWithMeta(
uint32 donId,
OCR3ConfigWithMeta[] memory currentConfig,
OCR3Config[] memory newConfig,
ConfigState currentState,
ConfigState newState
OCR3Config[] memory newConfig
) internal view returns (OCR3ConfigWithMeta[] memory) {
ConfigState currentState = ConfigState(currentConfig.length);
ConfigState newState = ConfigState(newConfig.length);
// Validate the state transition being proposed, which is implicitly defined by the combination
// of lengths of the current and new configurations.
_validateConfigStateTransition(currentState, newState);

uint64[] memory configCounts = new uint64[](newConfig.length);

// Set config counts based on the only valid state transitions.
Expand Down
35 changes: 4 additions & 31 deletions contracts/src/v0.8/ccip/test/capability/CCIPHome.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -550,20 +550,6 @@ contract CCIPHome_validateConfig is CCIPHomeSetup {
}

contract CCIPHome_ConfigStateMachine is CCIPHomeSetup {
function test__stateFromConfigLength_Success() public view {
uint256 configLen = 0;
CCIPHome.ConfigState state = s_ccipCC.stateFromConfigLength(configLen);
assertEq(uint256(state), uint256(CCIPHome.ConfigState.Init));

configLen = 1;
state = s_ccipCC.stateFromConfigLength(configLen);
assertEq(uint256(state), uint256(CCIPHome.ConfigState.Running));

configLen = 2;
state = s_ccipCC.stateFromConfigLength(configLen);
assertEq(uint256(state), uint256(CCIPHome.ConfigState.Staging));
}

function test__validateConfigStateTransition_Success() public view {
s_ccipCC.validateConfigStateTransition(CCIPHome.ConfigState.Init, CCIPHome.ConfigState.Running);

Expand Down Expand Up @@ -633,10 +619,9 @@ contract CCIPHome_ConfigStateMachine is CCIPHomeSetup {
offchainConfigVersion: 30,
offchainConfig: bytes("commit")
});
CCIPHome.ConfigState currentState = CCIPHome.ConfigState.Init;
CCIPHome.ConfigState newState = CCIPHome.ConfigState.Running;

CCIPHome.OCR3ConfigWithMeta[] memory newConfigWithMeta =
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, newState);
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig);
assertEq(newConfigWithMeta.length, 1, "new config with meta length must be 1");
assertEq(newConfigWithMeta[0].version, uint64(1), "config count must be 1");
assertEq(uint8(newConfigWithMeta[0].config.pluginType), uint8(newConfig[0].pluginType), "plugin type must match");
Expand Down Expand Up @@ -686,11 +671,8 @@ contract CCIPHome_ConfigStateMachine is CCIPHomeSetup {
// green config next.
newConfig[1] = greenConfig;

CCIPHome.ConfigState currentState = CCIPHome.ConfigState.Running;
CCIPHome.ConfigState newState = CCIPHome.ConfigState.Staging;

CCIPHome.OCR3ConfigWithMeta[] memory newConfigWithMeta =
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, newState);
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig);
assertEq(newConfigWithMeta.length, 2, "new config with meta length must be 2");

assertEq(newConfigWithMeta[0].version, uint64(1), "config count of blue must be 1");
Expand Down Expand Up @@ -759,11 +741,8 @@ contract CCIPHome_ConfigStateMachine is CCIPHomeSetup {
CCIPHome.OCR3Config[] memory newConfig = new CCIPHome.OCR3Config[](1);
newConfig[0] = greenConfig;

CCIPHome.ConfigState currentState = CCIPHome.ConfigState.Staging;
CCIPHome.ConfigState newState = CCIPHome.ConfigState.Running;

CCIPHome.OCR3ConfigWithMeta[] memory newConfigWithMeta =
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, newState);
s_ccipCC.computeNewConfigWithMeta(donId, currentConfig, newConfig);

assertEq(newConfigWithMeta.length, 1, "new config with meta length must be 1");
assertEq(newConfigWithMeta[0].version, uint64(2), "config count must be 2");
Expand Down Expand Up @@ -891,12 +870,6 @@ contract CCIPHome_ConfigStateMachine is CCIPHomeSetup {

// Reverts.

function test_Fuzz__stateFromConfigLength_Reverts(uint256 configLen) public {
vm.assume(configLen > 2);
vm.expectRevert(abi.encodeWithSelector(CCIPHome.InvalidConfigLength.selector, configLen));
s_ccipCC.stateFromConfigLength(configLen);
}

function test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() public {
uint32 donId = 1;
CCIPHome.OCR3Config memory blueConfig = CCIPHome.OCR3Config({
Expand Down
10 changes: 2 additions & 8 deletions contracts/src/v0.8/ccip/test/helpers/CCIPHomeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {Internal} from "../../libraries/Internal.sol";
contract CCIPHomeHelper is CCIPHome {
constructor(address capabilitiesRegistry) CCIPHome(capabilitiesRegistry) {}

function stateFromConfigLength(uint256 configLength) public pure returns (CCIPHome.ConfigState) {
return _stateFromConfigLength(configLength);
}

function validateConfigStateTransition(CCIPHome.ConfigState currentState, CCIPHome.ConfigState newState) public pure {
_validateConfigStateTransition(currentState, newState);
}
Expand All @@ -25,11 +21,9 @@ contract CCIPHomeHelper is CCIPHome {
function computeNewConfigWithMeta(
uint32 donId,
CCIPHome.OCR3ConfigWithMeta[] memory currentConfig,
CCIPHome.OCR3Config[] memory newConfig,
CCIPHome.ConfigState currentState,
CCIPHome.ConfigState newState
CCIPHome.OCR3Config[] memory newConfig
) public view returns (CCIPHome.OCR3ConfigWithMeta[] memory) {
return _computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, newState);
return _computeNewConfigWithMeta(donId, currentConfig, newConfig);
}

function computeConfigDigest(
Expand Down

0 comments on commit 08f2d35

Please sign in to comment.