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.
OptimismPortal2.checkWithdrawal
can be modified to make the code more efficientLow/Info issue submitted by Shield
Summary
The check to verify whether the
withdrawalHash
is already finalized, is placed inefficiently in theOptimismPortal2.checkWithdrawal
function.Vulnerability Detail
In the
OptimismPortal2.checkWithdrawal
function the check to verify whether thewithdrawalHash
is already finalized, is performed right at the end as shown below:Impact
Hence if the
withdrawal is already finalized it will revert at the end of the
checkWithdrawal` 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.