Boost _ Folks Finance 33609 - [Smart Contract - Medium] Account creation can be frontrun making the users unable to create an account
Submitted on Wed Jul 24 2024 14:15:37 GMT-0400 (Atlantic Standard Time) by @Kalogerone for Boost | Folks Finance
Report ID: #33609
Report type: Smart Contract
Report severity: Medium
Target: https://testnet.snowtrace.io/address/0x3324B5BF2b5C85999C6DAf2f77b5a29aB74197cc
Impacts:
Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Description
Brief/Intro
A user who tries to create an account for the protocol has to choose his accountId
. Any user can frontrun this transaction with the same accountId
, making the initial user's transaction to revert because his selected accountId
is taken.
Vulnerability Details
Each account has a unique bytes32
identifier named accountId
. During the account creation, each user is asked to provide the accountId
that his account will have.
This arbitrary accountId
value is sent through a bridge to the Hub.sol
contract which in turn calls the createAccount
function is AccountManager.sol
.
At this point, if there is already an account with the desired accountId
, the transaction reverts. An attacker can take advantage of this and frontrun all the account creation transactions (on the chains with a public mempool, like the Ethereum mainnet
) and prevent all the users from creating an account, which is essential for someone to use the protocol.
Impact Details
This is a griefing attack which prevents any new users from using the protocol, since they can't create an account. Every transaction will fail because the attacker can frontrun it with the same accountId
.
References
https://github.com/Folks-Finance/folks-finance-xchain-contracts/blob/main/contracts/spoke/SpokeCommon.sol#L27
https://github.com/Folks-Finance/folks-finance-xchain-contracts/blob/main/contracts/hub/Hub.sol#L163
https://github.com/Folks-Finance/folks-finance-xchain-contracts/blob/main/contracts/hub/AccountManager.sol#L42
Recommendation
Don't allow for the users to select their desired accountId
. Use a counter internally and increment it with every account creation and use it as the accountId
.
Proof of concept
Proof of Concept
Let's follow this scenario:
Bob tries to create an account with
accountId = "BOB_ACCOUNT_ID"
Alice (the attacker) sees this transaction in the mempool and frontruns bob transaction with
accountId = "BOB_ACCOUNT_ID"
Alice's transaction goes through
Bob's transaction gets reverted
Repeat
Add the following test in the test/AccountManager.test.ts
file under the describe("Create Account", () => {
tab.
Last updated