Validate Array Length Matching Before Execution to Avoid Reverts
The Socket system not only aggregates different solutions via its routes and controllers but also allows to batch calls between them into one transaction. For example, a user may call swaps between several DEXs and then perform a bridge transfer.\\nAs a result, the `SocketGateway` contract has many functions that accept multiple arrays that contain the necessary data for execution in their respective routes. However, these arrays need to be of the same length because individual elements in the arrays are intended to be matched at the same indices:\\n```\\nfunction executeRoutes(\\n    uint32[] calldata routeIds,\\n    bytes[] calldata dataItems,\\n    bytes[] calldata eventDataItems\\n) external payable {\\n    uint256 routeIdslength = routeIds.length;\\n    for (uint256 index = 0; index < routeIdslength; ) {\\n        (bool success, bytes memory result) = addressAt(routeIds[index])\\n            .delegatecall(dataItems[index]);\\n\\n        if (!success) {\\n            assembly {\\n                revert(add(result, 32), mload(result))\\n            }\\n        }\\n\\n        emit SocketRouteExecuted(routeIds[index], eventDataItems[index]);\\n\\n        unchecked {\\n            ++index;\\n        }\\n    }\\n}\\n```\\n\\nNote that in the above example function, all 3 different calldata arrays `routeIds`, `dataItems`, and `eventDataItems` were utilizing the same `index` to retrieve the correct element. A common practice in such cases is to confirm that the sizes of the arrays match before continuing with the execution of the rest of the transaction to avoid costly reverts that could happen due to “Index out of bounds” error.\\nDue to the aggregating and batching nature of the Socket system that may have its users rely on 3rd party offchain APIs to construct these array payloads, such as from APIs of the systems that Socket is integrating, a mishap in just any one of them could cause this issue.
Implement a check on the array lengths so they match.
```\\nfunction executeRoutes(\\n    uint32[] calldata routeIds,\\n    bytes[] calldata dataItems,\\n    bytes[] calldata eventDataItems\\n) external payable {\\n    uint256 routeIdslength = routeIds.length;\\n    for (uint256 index = 0; index < routeIdslength; ) {\\n        (bool success, bytes memory result) = addressAt(routeIds[index])\\n            .delegatecall(dataItems[index]);\\n\\n        if (!success) {\\n            assembly {\\n                revert(add(result, 32), mload(result))\\n            }\\n        }\\n\\n        emit SocketRouteExecuted(routeIds[index], eventDataItems[index]);\\n\\n        unchecked {\\n            ++index;\\n        }\\n    }\\n}\\n```\\n