diff --git a/src/NTokenStrategy.sol b/src/NTokenStrategy.sol index 3e4e89cc..281dab90 100644 --- a/src/NTokenStrategy.sol +++ b/src/NTokenStrategy.sol @@ -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 @@ -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) = @@ -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