HardhatFoundry
30,000 USDC
View results
Submission Details
Severity: low
Invalid

Logic for creating accounts is not rightly implemented

Summary

Initialising accounts can be griefed

Vulnerability Details

Would be key to note that creating account around all three factories (K1ValidatorFactory, NexusAccountFactory & RegistryFactory) are done in a similar way.

Now take a look at https://github.com/Cyfrin/2024-07-biconomy/blob/9590f25cd63f7ad2c54feb618036984774f3879d/contracts/factory/NexusAccountFactory.sol#L44-L64

function createAccount(bytes calldata initData, bytes32 salt) external payable override returns (address payable) {
// Compute the actual salt for deterministic deployment
bytes32 actualSalt;
assembly {
let ptr := mload(0x40)
let calldataLength := sub(calldatasize(), 0x04)
mstore(0x40, add(ptr, calldataLength))
calldatacopy(ptr, 0x04, calldataLength)
actualSalt := keccak256(ptr, calldataLength)
}
// Deploy the account using the deterministic address
(bool alreadyDeployed, address account) = LibClone.createDeterministicERC1967(msg.value, ACCOUNT_IMPLEMENTATION, actualSalt);
if (!alreadyDeployed) {
INexus(account).initializeAccount(initData);
emit AccountCreated(account, initData, salt);
}
return payable(account);
}

This function creates a new Nexus account with the provided initialization data, issue however is that in the case where the account is already deployed the account never gets initialised. Whereas this shouldn't happen in the normal intended flow, this is very possible cause an attacker can just frontrun the attempt at creating the account with deterministically creating an account, considering the salt is not unique to the caller.

That would mean that the attacker can grief valid attempts of creating account, since they would never be initialised.

Impact

As hinted under Vulnerability Details, valid attempts of creating account can easily be faulted by an attacker since by frontrunning this the attacker ensures the accounts they would never be initialised.

As hinted earlier on in the report, this bug case is applicable to all three factories hinted below:

  • https://github.com/Cyfrin/2024-07-biconomy/blob/9590f25cd63f7ad2c54feb618036984774f3879d/contracts/factory/NexusAccountFactory.sol#L43-L64

  • https://github.com/Cyfrin/2024-07-biconomy/blob/9590f25cd63f7ad2c54feb618036984774f3879d/contracts/factory/RegistryFactory.sol#L111-L130

  • https://github.com/Cyfrin/2024-07-biconomy/blob/9590f25cd63f7ad2c54feb618036984774f3879d/contracts/factory/K1ValidatorFactory.sol#L75-L105

Tools Used

Manual review

Recommendations

Consider either making the salt value unique down to the msg.sender value or, even if the account is already deployed still try to initialize the account.

Updates

Lead Judging Commences

0xnevi Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

finding-createAccount-frontrun-salt

Invalid if a new Nexus proxy is already deployed, [`createDeterministicERC1967` will not revert](https://github.com/Vectorized/solady/blob/main/src/utils/LibClone.sol#L745), but simply return, so there is no DoS here. Users should carefully select a unique salt and initData when creating a new Nexus Proxy instance as noted in documentation [here](https://github.com/bcnmy/nexus/wiki/NexusAccountFactory#createaccount)

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.