Skip to content

Commit

Permalink
feat: fix add missing min check (#547)
Browse files Browse the repository at this point in the history
### Description

Fixes the audit finding
https://audits.sherlock.xyz/contests/598/voting/44?dashboard_id=14327c9c7bc843a43c46c4efd899f4c1


### Other changes

no

### Tested

Unit test

### Related issues

- Fixes
[#597](mento-protocol/mento-general#597)
  • Loading branch information
baroooo authored Nov 22, 2024
1 parent c9e2d5e commit 84d9d42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/libraries/TradingLimits.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ library TradingLimits {
uint8 private constant L1 = 2; // 0b010 Limit1
uint8 private constant LG = 4; // 0b100 LimitGlobal
int48 private constant MAX_INT48 = type(int48).max;
int48 private constant MIN_INT48 = type(int48).min;

/**
* @notice Validate a trading limit configuration.
Expand Down Expand Up @@ -129,6 +130,7 @@ library TradingLimits {
) internal view returns (ITradingLimits.State memory) {
int256 _deltaFlowUnits = _deltaFlow / int256((10 ** uint256(decimals)));
require(_deltaFlowUnits <= MAX_INT48, "dFlow too large");
require(_deltaFlowUnits >= MIN_INT48, "dFlow too small");

int48 deltaFlowUnits = int48(_deltaFlowUnits);
if (deltaFlowUnits == 0) {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/libraries/TradingLimits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ contract TradingLimitsTest is Test {
state = harness.update(state, configLG(500000), 3 * 10e32, 18);
}

function test_update_withTooSmallAmount_reverts() public {
int256 tooSmall = (type(int48).min - int256(1)) * 1e18;
vm.expectRevert(bytes("dFlow too small"));
state = harness.update(state, configLG(500000), tooSmall, 18);
}

function test_update_withOverflowOnAdd_reverts() public {
ITradingLimits.Config memory config = configLG(int48(uint48(2 ** 47)));
int256 maxFlow = int256(uint256(type(uint48).max / 2));
Expand Down

0 comments on commit 84d9d42

Please sign in to comment.