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

TOB-AJNA-8: Array lengths are not checked in LP allowance functions #725

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/interfaces/pool/commons/IPoolErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ interface IPoolErrors {
*/
error InsufficientLiquidity();

/**
* @notice When increasing / decreasing LPs allowances indexes and amounts arrays parameters should have same length.
*/
error InvalidAllowancesInput();

/**
* @notice When transferring LPs between indices, the new index must be a valid index.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/libraries/external/LenderActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ library LenderActions {
error CannotMergeToHigherPrice();
error DustAmountNotExceeded();
error NoAllowance();
error InvalidAllowancesInput();
error InvalidIndex();
error InvalidAmount();
error LUPBelowHTP();
Expand Down Expand Up @@ -579,6 +580,8 @@ library LenderActions {
* @notice See `IPoolLenderActions` for descriptions
* @dev write state:
* - increment LPs allowances
* @dev reverts on:
* - invalid indexes and amounts input InvalidAllowancesInput()
* @dev emit events:
* - IncreaseLPsAllowance
*/
Expand All @@ -589,8 +592,10 @@ library LenderActions {
uint256[] calldata amounts_
) external {
uint256 indexesLength = indexes_.length;
uint256 index;

if (indexesLength != amounts_.length) revert InvalidAllowancesInput();

uint256 index;
for (uint256 i = 0; i < indexesLength; ) {
index = indexes_[i];

Expand All @@ -611,6 +616,8 @@ library LenderActions {
* @notice See `IPoolLenderActions` for descriptions
* @dev write state:
* - decrement LPs allowances
* @dev reverts on:
* - invalid indexes and amounts input InvalidAllowancesInput()
* @dev emit events:
* - DecreaseLPsAllowance
*/
Expand All @@ -621,6 +628,9 @@ library LenderActions {
uint256[] calldata amounts_
) external {
uint256 indexesLength = indexes_.length;

if (indexesLength != amounts_.length) revert InvalidAllowancesInput();

uint256 index;

for (uint256 i = 0; i < indexesLength; ) {
Expand Down
19 changes: 19 additions & 0 deletions tests/forge/ERC20Pool/ERC20PoolTransferLPs.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ contract ERC20PoolTransferLPsTest is ERC20HelperContract {
});
}

function testIncreaseDecreaseLPsWithInvalidInput() external tearDown {
uint256[] memory indexes = new uint256[](3);
indexes[0] = 2550;
indexes[1] = 2551;
indexes[2] = 2552;

uint256[] memory amounts = new uint256[](2);
amounts[0] = 10_000 * 1e18;
amounts[1] = 30_000 * 1e18;

// increase allowance should revert for invalid input
vm.expectRevert(IPoolErrors.InvalidAllowancesInput.selector);
_pool.increaseLPsAllowance(_lender2, indexes, amounts);

// decrease allowance should revert for invalid input
vm.expectRevert(IPoolErrors.InvalidAllowancesInput.selector);
_pool.decreaseLPsAllowance(_lender2, indexes, amounts);
}

function testTransferLPsForAllIndexes() external tearDown {
uint256[] memory indexes = new uint256[](3);
indexes[0] = 2550;
Expand Down