28938 - [SC - Medium] Attacker can invalidate users supplyWithPermit ...

Submitted on Mar 2nd 2024 at 12:59:17 UTC by @Norah for Boost | ZeroLend

Report ID: #28938

Report type: Smart Contract

Report severity: Medium

Target: https://pacific-explorer.manta.network/address/0x8676e39B5D2f0d6E0d78a4208a0cCBc50504972e

Impacts:

  • Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)

Description

Brief/Intro

  • Where:

    • [supplyWithPermit()]

    • [repayWithPermit()]

    • (https://pacific-explorer.manta.network/address/0x8676e39B5D2f0d6E0d78a4208a0cCBc50504972e?tab=contract)

  • Expected behavior:

    • The supplyWithPermit() and repayWithPermit() functions utilises the permit function so that approve and pull operations can happen in a single transaction instead of two consecutive transactions.

Vulnerability Details

  • Attack:

    • ERC20Permit uses the nonces mapping for replay protection. Once a signature is verified and approved, the nonce increases, invalidating the same signature being replayed.

    • supplyWithPermit() expects the holder to sign their tokens and provide the signature in function parameter.

    • When a supplyWithPermit() transaction is in the mempool, an attacker can take this signature, call the permit function on the token themselves.

    • Since this is a valid signature, the token accepts it and increases the nonce.

    • As a result victim transaction will revert, whenever it gets mined becuase the nonce has been already use.

    • Check POC for more detail.

Impact Details

  • Attacker can invalidate users supplyWithPermit() and repayWithPermit() transactions.

  • While Attacker does not profit from this, it harms users (gas fee and opportunity cost) and protocols reputation.

Recommendation

  • In repayWithPermit and supplyWithPermit function, check if it has the approval it needs. If not, then only submit the permit signature.

  • Given the fix is simple, I would suggest to implement it as there is also possibility that sophisticated attacker might uses this to delay users repay() transaction and gain advantage.

References

Add any relevant links to documentation or code

Proof of Concept

  • Following is POCs demonstrating the attack vector on Manta-Pacific fork in foundry..

  • To recreate please enter your RPC, and then run "forge test"

Last updated

Was this helpful?