Skip to content

Commit

Permalink
LM-20-add-zero-value-checks-in-setter-functions-in-rebalancer (#806)
Browse files Browse the repository at this point in the history
## Motivation
Add zero checks to setter functions to avoid misconfiguration


## Solution
Zero checks in setter functions :)
  • Loading branch information
RyanRHall authored May 6, 2024
1 parent 6b98596 commit e666420
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions contracts/.changeset/rich-emus-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts-ccip": patch
---

add zero checks for setters in LM
13 changes: 7 additions & 6 deletions contracts/gas-snapshots/liquiditymanager.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ LiquidityManager__report:test_EmptyReportReverts() (gas: 11161)
LiquidityManager_addLiquidity:test_addLiquiditySuccess() (gas: 284740)
LiquidityManager_rebalanceLiquidity:test_InsufficientLiquidityReverts() (gas: 19585)
LiquidityManager_rebalanceLiquidity:test_InvalidRemoteChainReverts() (gas: 197560)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess() (gas: 8766133)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess_AlreadyFinalized() (gas: 8575758)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPools_MultiStageFinalization() (gas: 8570966)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPools_NativeRewrap() (gas: 8488731)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess() (gas: 8797105)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess_AlreadyFinalized() (gas: 8591256)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPools_MultiStageFinalization() (gas: 8586464)
LiquidityManager_rebalanceLiquidity:test_rebalanceBetweenPools_NativeRewrap() (gas: 8504229)
LiquidityManager_rebalanceLiquidity:test_rebalanceLiquiditySuccess() (gas: 384964)
LiquidityManager_removeLiquidity:test_InsufficientLiquidityReverts() (gas: 191737)
LiquidityManager_removeLiquidity:test_OnlyOwnerReverts() (gas: 10967)
Expand All @@ -14,8 +14,9 @@ LiquidityManager_setCrossChainRebalancer:test_OnlyOwnerReverts() (gas: 17027)
LiquidityManager_setCrossChainRebalancer:test_ZeroAddressReverts() (gas: 21630)
LiquidityManager_setCrossChainRebalancer:test_ZeroChainSelectorReverts() (gas: 13105)
LiquidityManager_setCrossChainRebalancer:test_setCrossChainRebalancerSuccess() (gas: 162333)
LiquidityManager_setLocalLiquidityContainer:test_OnlyOwnerReverts() (gas: 11008)
LiquidityManager_setLocalLiquidityContainer:test_setLocalLiquidityContainerSuccess() (gas: 3288832)
LiquidityManager_setLocalLiquidityContainer:test_OnlyOwnerReverts() (gas: 11030)
LiquidityManager_setLocalLiquidityContainer:test_ReverstWhen_CalledWithTheZeroAddress() (gas: 10621)
LiquidityManager_setLocalLiquidityContainer:test_setLocalLiquidityContainerSuccess() (gas: 3288855)
LiquidityManager_setMinimumLiquidity:test_OnlyOwnerReverts() (gas: 10925)
LiquidityManager_setMinimumLiquidity:test_setMinimumLiquiditySuccess() (gas: 36434)
LiquidityManager_withdrawNative:test_OnlyOwnerReverts() (gas: 13115)
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/v0.8/liquiditymanager/LiquidityManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ contract LiquidityManager is ILiquidityManager, OCR3Base {
revert ZeroChainSelector();
}

if (address(token) == address(0)) {
if (address(token) == address(0) || address(localLiquidityContainer) == address(0)) {
revert ZeroAddress();
}
i_localToken = token;
Expand Down Expand Up @@ -515,6 +515,9 @@ contract LiquidityManager is ILiquidityManager, OCR3Base {
/// @notice Sets the local liquidity container.
/// @dev Only the owner can call this function.
function setLocalLiquidityContainer(ILiquidityContainer localLiquidityContainer) external onlyOwner {
if (address(localLiquidityContainer) == address(0)) {
revert ZeroAddress();
}
s_localLiquidityContainer = localLiquidityContainer;

emit LiquidityContainerSet(address(localLiquidityContainer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,11 @@ contract LiquidityManager_setLocalLiquidityContainer is LiquidityManagerSetup {

s_liquidityManager.setLocalLiquidityContainer(LockReleaseTokenPool(address(1)));
}

function test_ReverstWhen_CalledWithTheZeroAddress() external {
vm.expectRevert(LiquidityManager.ZeroAddress.selector);
s_liquidityManager.setLocalLiquidityContainer(LockReleaseTokenPool(address(0)));
}
}

contract LiquidityManager_setMinimumLiquidity is LiquidityManagerSetup {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ arbitrum_token_gateway: ../../../contracts/solc/v0.8.19/IArbitrumTokenGateway/IA
arbsys: ../../../contracts/solc/v0.8.19/IArbSys/IArbSys.abi ../../../contracts/solc/v0.8.19/IArbSys/IArbSys.bin 70adb49f157d8e077485d1a5c87ddf64b214822aef736bb68e122a77bab78a16
l2_arbitrum_gateway: ../../../contracts/solc/v0.8.19/IL2ArbitrumGateway/IL2ArbitrumGateway.abi ../../../contracts/solc/v0.8.19/IL2ArbitrumGateway/IL2ArbitrumGateway.bin 4d1af2bdb0aeb0b15e3cbc4ed2158f9bcba4925f68ed3669e0ecfde14115c893
l2_arbitrum_messenger: ../../../contracts/solc/v0.8.19/IL2ArbitrumMessenger/IL2ArbitrumMessenger.abi ../../../contracts/solc/v0.8.19/IL2ArbitrumMessenger/IL2ArbitrumMessenger.bin 84d4bfedf16e92e3fb15880832fa54a3a21808dffea8a7c0946cde3b5e17a0c3
liquiditymanager: ../../../contracts/solc/v0.8.19/LiquidityManager/LiquidityManager.abi ../../../contracts/solc/v0.8.19/LiquidityManager/LiquidityManager.bin e14db5ac9b211cd23766da0fa1766276d26885e46175bc9dcd764f2ad56b986b
liquiditymanager: ../../../contracts/solc/v0.8.19/LiquidityManager/LiquidityManager.abi ../../../contracts/solc/v0.8.19/LiquidityManager/LiquidityManager.bin 3d1958af21fd4b1f481fd46b30cc8ff79b06ad6539332d620072f41c2b053421
mock_l1_bridge_adapter: ../../../contracts/solc/v0.8.19/MockBridgeAdapter/MockL1BridgeAdapter.abi ../../../contracts/solc/v0.8.19/MockBridgeAdapter/MockL1BridgeAdapter.bin bdf2dcc0dff76de9aa8eb3eee8cce23c426577aa511b581c30b95ed0178c4041
mock_l2_bridge_adapter: ../../../contracts/solc/v0.8.19/MockBridgeAdapter/MockL2BridgeAdapter.abi ../../../contracts/solc/v0.8.19/MockBridgeAdapter/MockL2BridgeAdapter.bin ae85dc829dcd8fbe37f7b439c4c7c6f462fedb14254c86beafa30ba28f7b5ac6
no_op_ocr3: ../../../contracts/solc/v0.8.19/NoOpOCR3/NoOpOCR3.abi ../../../contracts/solc/v0.8.19/NoOpOCR3/NoOpOCR3.bin 3a5ef6a7a6502339d7965b44debb5536ee9b6d2181985e52d905307315c0a853
Expand Down

0 comments on commit e666420

Please sign in to comment.