DisputeGameFactory.findLatestGames function code can be modified to improve efficiency
Low/Info issue submitted by Shield
Summary
Vulnerability Detail
In the DisputeGameFactory.findLatestGames function the follwoing if statement is used to break the for loop in the event required number of _n latest games are retrieved from the _disputeGameList array as shown below:
if (games_.length >= _n) break;
But the _game.length start from 0 (before getting incremented) and will always equal n value before it exceeds the n value.
Impact
The >= check is unnecessary and makes the code inefficient.
The >= can be updated as == to make the code more efficient since the _game.length start from 0 (before getting incremented) and will always equal n value before it exceeds the n value.
DisputeGameFactory.findLatestGames
function code can be modified to improve efficiencyLow/Info issue submitted by Shield
Summary
Vulnerability Detail
In the
DisputeGameFactory.findLatestGames
function the follwoingif
statement is used to break thefor
loop in the event required number of_n
latest games are retrieved from the_disputeGameList
array as shown below:But the
_game.length
start from0
(before getting incremented) and will always equaln
value before it exceeds then
value.Impact
The
>=
check is unnecessary and makes the code inefficient.Code Snippet
https://github.com/sherlock-audit/2024-02-optimism-2024/blob/main/optimism/packages/contracts-bedrock/src/dispute/DisputeGameFactory.sol#L179
Tool used
Manual Review
Recommendation
The
>=
can be updated as==
to make the code more efficient since the_game.length
start from0
(before getting incremented) and will always equaln
value before it exceeds then
value.