Skip to content

fix: Add return value checks for ERC20 transfers in L2Staking#704

Merged
SegueII merged 1 commit intomorph-l2:mainfrom
mulukenmenberu:mulefix
Jan 15, 2025
Merged

fix: Add return value checks for ERC20 transfers in L2Staking#704
SegueII merged 1 commit intomorph-l2:mainfrom
mulukenmenberu:mulefix

Conversation

@mulukenmenberu
Copy link
Copy Markdown
Contributor

I've found a potential security vulnerability in the L2Staking contract's _transfer and _transferFrom functions:
The issue is in both transfer functions where they check the balance difference after the transfer. While they verify that the balance increased by the expected amount, they don't check if the initial transfer operation was successful.

This commit adds explicit checks for the return values of ERC20 transfer and transferFrom operations in the L2Staking contract. While the contract already verified balance changes, it didn't check if the initial transfer succeeded.

  • Add require statement to check transfer() return value
  • Add require statement to check transferFrom() return value
  • Improve error messages to be more specific
  • Maintain existing balance difference checks as additional safety

This change follows ERC20 best practices and prevents potential issues with tokens that don't revert on failed transfers.

This commit adds explicit checks for the return values of ERC20 transfer and
transferFrom operations in the L2Staking contract. While the contract already
verified balance changes, it didn't check if the initial transfer succeeded.

- Add require statement to check transfer() return value
- Add require statement to check transferFrom() return value
- Improve error messages to be more specific
- Maintain existing balance difference checks as additional safety

This change follows ERC20 best practices and prevents potential issues with
tokens that don't revert on failed transfers.
@mulukenmenberu mulukenmenberu requested a review from a team as a code owner January 6, 2025 07:18
@mulukenmenberu mulukenmenberu requested review from yunxu1 and removed request for a team January 6, 2025 07:18
@chengwenxi chengwenxi requested a review from SegueII January 7, 2025 08:48
@SegueII
Copy link
Copy Markdown
Contributor

SegueII commented Jan 7, 2025

MorphToken is our system-level contract, when the transfer fails, it will directly revert and will not return false. At present, there is no vulnerability.
And as you said, this change can improve error messages to be more specific, and follows the ERC20 best practices.

@SegueII SegueII merged commit 6361197 into morph-l2:main Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants