Skip to content

Commit

Permalink
feat(its): prevent invalid flow limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy committed Nov 4, 2024
1 parent 588f79c commit e23ef80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/interfaces/IFlowLimit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand Down
2 changes: 2 additions & 0 deletions contracts/utils/FlowLimit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
}
Expand Down
9 changes: 9 additions & 0 deletions test/InterchainTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e23ef80

Please sign in to comment.