Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flow-limit): handle large flow limit values #294

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
*/
ahramy marked this conversation as resolved.
Show resolved Hide resolved
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
6 changes: 5 additions & 1 deletion contracts/utils/FlowLimit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ contract FlowLimit is IFlowLimit {

/**
* @notice Internal function to set the flow limit.
* @param flowLimit_ The value to set the flow limit to.
* @param flowLimit_ The value to set the flow limit to. Must not be set to `uint256.max`.
* Only the operator can set the flow limit for their own token; however, an incorrect setting
* may result in a denial of service due to potential arithmetic underflow or overflow.
* @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);
ahramy marked this conversation as resolved.
Show resolved Hide resolved

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
Loading