sherlock-audit / 2023-01-optimism-judging

24 stars 10 forks source link

shw - Incorrect encoding of deposit transactions that creates a new contract #267

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

shw

low

Incorrect encoding of deposit transactions that creates a new contract

Summary

Incorrect encoding of deposit transactions that creates a new contract

Vulnerability Detail

The encodeDepositTransaction() function in the libraries/Encoding.sol contract does not correctly encode the _tx.isCreation field of a deposit transaction. At L35, the encoded isCreation field is always set to false.

Impact

The encoding of a deposit transaction is incorrect when _tx.isCreation is true. As a result, the deposit transaction's hash calculated from the hashDepositTransaction() function of libraries/Hashing.sol is incorrect either.

Code Snippet

https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/libraries/Encoding.sol#L35 https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/libraries/Hashing.sol#L21-L27

Tool used

Manual Review

Recommendation

Fix RLPWriter.writeBool(false) on L35 to RLPWriter.writeBool(_tx.isCreation).

Duplicate of #89