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: add deltas array length check in NTokenStrategy #99

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
14 changes: 13 additions & 1 deletion src/NTokenStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ pragma solidity ^0.8.13;

import { IStrategy, Pool } from "src/interfaces/IStrategy.sol";

/**
* @dev Thrown when the length of the deltas array is not the
* same as the length of the reserves array.
*/
error InvalidTokenDeltas();

/**
* @title N-token strategy base contract for DFMM.
* @notice This abstract contract defines the basic behavior of
Expand Down Expand Up @@ -46,6 +52,9 @@ abstract contract NTokenStrategy is IStrategy {
// we cannot assign to `deltaLiquidity` directly.
(uint256[] memory maxTokenDeltas, uint256 deltaL) =
abi.decode(data, (uint256[], uint256));
if (maxTokenDeltas.length != pool.reserves.length) {
revert InvalidTokenDeltas();
}
deltaLiquidity = deltaL;

(uint256[] memory deltas, uint256[] memory nextReserves) =
Expand Down Expand Up @@ -82,8 +91,11 @@ abstract contract NTokenStrategy is IStrategy {
{
(uint256[] memory minTokenDeltas, uint256 deltaL) =
abi.decode(data, (uint256[], uint256));

if (minTokenDeltas.length != pool.reserves.length) {
revert InvalidTokenDeltas();
}
deltaLiquidity = deltaL;

(uint256[] memory deltas, uint256[] memory nextReserves) =
_computeDeallocateDeltasAndReservesGivenDeltaL(
deltaLiquidity, minTokenDeltas, pool
Expand Down
Loading