sherlock-audit / 2024-02-optimism-2024-judging

6 stars 4 forks source link

`OptimismPortal2.checkWithdrawal` can be modified to make the code more efficient #249

Closed sherlock-admin3 closed 7 months ago

sherlock-admin3 commented 7 months ago

OptimismPortal2.checkWithdrawal can be modified to make the code more efficient

Low/Info issue submitted by Shield

Summary

The check to verify whether the withdrawalHash is already finalized, is placed inefficiently in the OptimismPortal2.checkWithdrawal function.

Vulnerability Detail

In the OptimismPortal2.checkWithdrawal function the check to verify whether the withdrawalHash is already finalized, is performed right at the end as shown below:

     require(!finalizedWithdrawals[_withdrawalHash], "OptimismPortal: withdrawal has already been finalized");

Impact

Hence if the withdrawal is already finalized it will revert at the end of thecheckWithdrawal` function exeuction which is inefficient.

Code Snippet

https://github.com/sherlock-audit/2024-02-optimism-2024/blob/main/optimism/packages/contracts-bedrock/src/L1/OptimismPortal2.sol#L518

Tool used

Manual Review

Recommendation

Above check can be placed right at the start of the OptimismPortal2.checkWithdrawal function to make the code execution more efficient.