From e23ef80f9b6d362308ddc1ce903244fd8427f93a Mon Sep 17 00:00:00 2001 From: ahramy Date: Mon, 4 Nov 2024 12:04:19 -0800 Subject: [PATCH] feat(its): prevent invalid flow limit --- contracts/interfaces/IFlowLimit.sol | 1 + contracts/utils/FlowLimit.sol | 2 ++ test/InterchainTokenService.js | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/contracts/interfaces/IFlowLimit.sol b/contracts/interfaces/IFlowLimit.sol index 978c8176..796b4597 100644 --- a/contracts/interfaces/IFlowLimit.sol +++ b/contracts/interfaces/IFlowLimit.sol @@ -8,6 +8,7 @@ pragma solidity ^0.8.0; */ interface IFlowLimit { error FlowLimitExceeded(uint256 limit, uint256 flowAmount, address tokenManager); + error InvalidFlowLimit(uint256 flowLimit, bytes32 tokenId); event FlowLimitSet(bytes32 indexed tokenId, address operator, uint256 flowLimit_); diff --git a/contracts/utils/FlowLimit.sol b/contracts/utils/FlowLimit.sol index 9598a925..296cf3bc 100644 --- a/contracts/utils/FlowLimit.sol +++ b/contracts/utils/FlowLimit.sol @@ -33,6 +33,8 @@ contract FlowLimit is IFlowLimit { * @param tokenId The id of the token to set the flow limit for. */ function _setFlowLimit(uint256 flowLimit_, bytes32 tokenId) internal { + if (flowLimit_ == type(uint256).max) revert InvalidFlowLimit(flowLimit_, tokenId); + assembly { sstore(FLOW_LIMIT_SLOT, flowLimit_) } diff --git a/test/InterchainTokenService.js b/test/InterchainTokenService.js index f12ecc7e..b9d66099 100644 --- a/test/InterchainTokenService.js +++ b/test/InterchainTokenService.js @@ -2721,6 +2721,15 @@ describe('Interchain Token Service', () => { await tokenManager.setFlowLimit(flowLimit).then((tx) => tx.wait); }); + it('Should be reverted setting invalid flow limit', async () => { + const invalidFlowLimit = MaxUint256; + + await expectRevert((gasOptions) => tokenManager.setFlowLimit(invalidFlowLimit, gasOptions), tokenManager, 'InvalidFlowLimit', [ + invalidFlowLimit, + tokenId, + ]); + }); + it('Should be able to send token only if it does not trigger the mint limit', async () => { await service.interchainTransfer(tokenId, destinationChain, destinationAddress, sendAmount, '0x', 0).then((tx) => tx.wait);