Basin - tonisives's results

A composable EVM-native decentralized exchange protocol.

General Information

Platform: Code4rena

Start Date: 03/07/2023

Pot Size: $40,000 USDC

Total HM: 14

Participants: 74

Period: 7 days

Judge: alcueca

Total Solo HM: 9

Id: 259

League: ETH

Basin

Findings Distribution

Researcher Performance

Rank: 15/74

Findings: 1

Award: $211.83

🌟 Selected for report: 1

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: tonisives

Also found by: Inspecktor, MohammedRizwan, Qeew, peanuts, sces60107

Labels

bug
2 (Med Risk)
primary issue
satisfactory
selected for report
sponsor confirmed
M-07

Awards

211.8255 USDC - $211.83

External Links

Lines of code

https://github.com/code-423n4/2023-07-basin/blob/c1b72d4e372a6246e0efbd57b47fb4cbb5d77062/src/Aquifer.sol/#L48

Vulnerability details

Impact

The boreWell function in the Aquifer contract is responsible for creating new Wells. However, there are two critical security issues:

  1. Stealing of user's deposit amount: The public readability of the salt parameter allows an attacker to frontrun a user's transaction and capture the deposit amount intended for the user's Well. By creating a Well with the same salt value, the attacker can receive the deposit intended for the user's Well and withdraw the funds.
  2. DoS for boreWell: Another attack vector involves an attacker deploying a Well with the same salt value as the user's intended Well. This causes the user's transaction to be reverted, resulting in a denial-of-service (DoS) attack on the boreWell function. The attacker can repeatedly execute this attack, preventing users from creating new Wells.

Proof of Concept

Stealing of user's deposit amount

If a user intends to create a new Well and deposit funds into it, an attacker can frontrun the user's transactions and capture the deposit amount. Here is how the attack scenario unfolds:

  1. The user broadcasts two transactions: the first to create a Well with a specific salt value, and the second to deposit funds into the newly created Well.
  2. The attacker views these pending transactions and frontruns them by creating a Well for themselves using the same salt value.
  3. The attacker's Well gets created with the same address that the user was expecting for their Well.
  4. As a result, the user's create Well transaction gets reverted, but the deposit transaction successfully executes, depositing the funds into the attacker's Well.
  5. Being the owner of the Well, the attacker can simply withdraw the deposited funds from the Well.

DoS for boreWell

In this attack scenario, an attacker can forcefully revert a user's create Well transaction by deploying a Well for themselves using the user's salt value. Here are the steps of the attack:

  1. The user broadcasts a create Well transaction with a specific salt value.
  2. The attacker frontruns the user's transaction and creates a Well for themselves using the same salt value.
  3. As a result, the user's original create Well transaction gets reverted since the attacker's Well already exists at the predetermined address.
  4. This attack can be repeated multiple times, effectively causing a denial-of-service (DoS) attack on the boreWell function.

Tools Used

vscode

To mitigate the identified security issues, it is recommended to make the upcoming Well address user-specific by combining the salt value with the user's address. This ensures that each user's Well has a unique address and prevents frontrunning attacks and DoS attacks. The following code snippet demonstrates the recommended modification:

well = implementation.cloneDeterministic( keccak256(abi.encode(msg.sender, `salt`)) );

Assessed type

Other

#0 - c4-pre-sort

2023-07-11T14:59:01Z

141345 marked the issue as duplicate of #217

#1 - c4-pre-sort

2023-07-12T16:03:13Z

141345 marked the issue as duplicate of #221

#2 - c4-pre-sort

2023-07-12T16:11:11Z

141345 marked the issue as not a duplicate

#3 - c4-pre-sort

2023-07-12T16:11:15Z

141345 marked the issue as primary issue

#4 - 141345

2023-07-12T16:13:56Z

Stealing of user's intended deposit fund might be the possible path of losing

#5 - c4-sponsor

2023-07-21T14:58:51Z

publiuss marked the issue as sponsor confirmed

#6 - c4-judge

2023-08-04T05:57:08Z

alcueca marked the issue as satisfactory

#7 - c4-judge

2023-08-04T06:01:50Z

alcueca marked the issue as selected for report

#8 - publiuss

2023-08-23T00:44:27Z

This issue has been addressed in the code. The boreWell(...) function now uses a salt consisting of the hash of msg.sender appended to the input salt value. See here: https://github.com/BeanstalkFarms/Basin/blob/91233a22005986aa7c9f3b0c67393842cd8a8e4d/src/Aquifer.sol#L40

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter