Wallet deployment is vulnerable to cross-chain frontrunning #143
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-460
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2023-01-biconomy/blob/53c8c3823175aeb26dee5529eeefa81240a406ba/scw-contracts/contracts/smart-contract-wallet/SmartAccountFactory.sol#L57
https://github.com/code-423n4/2023-01-biconomy/blob/53c8c3823175aeb26dee5529eeefa81240a406ba/scw-contracts/contracts/smart-contract-wallet/SmartAccountFactory.sol#L34
https://github.com/code-423n4/2023-01-biconomy/blob/53c8c3823175aeb26dee5529eeefa81240a406ba/scw-contracts/contracts/smart-contract-wallet/SmartAccountFactory.sol#L38
Vulnerability details
Impact
Wallet deployment is vulnerable to cross-chain frontrun and front-run
Proof of Concept
We need to look into the wallet deployment function.
the deploy wallet use create opcode to create smart contract, the deployCountFactualWallet uses create2 to create smart contract.
An important difference lies in how the address of the new contract is determined. With CREATE the address is determined by the factory contract's nonce. Everytime CREATE is called in the factory, its nonce is increased by 1. With CREATE2, the address is determined by an arbitrary salt value and the init_code.
The wallet deployment is vulnerable to cross-chain front-run.
For example, a user use deployWallet to deploy a wallet in chain A,
The user assume he also controls the wallet in chain B so he sent the asset to chain B's wallet address that has not been deployed yet.
A hacker detects his transaction and frunt-run the wallet deployment in chain B.
A hacker can know the nonce of factory contract by seeing how many transaction is deployed via the factory contract.
The hacker can then copy the deploymentData and front-run the user in chain B and become owner of the wallet.
Precisely what happen in the wintermute hack back last year.
https://rekt.news/wintermute-rekt/
For the wallet that use create2, a malicious user can extract salt because he know the salt is computed below
and he can copy the deploymentData and deploy a wallet in chain B and call BaseSmartAccount(proxy).init to become the owner of the smart account.
Tools Used
Manual Review
Recommended Mitigation Steps
We recommend the protocol add chain id when generating salt and not use create opcode when deployment the proxy and when the wallet address is pre-computed in getAddressForCounterfactualWallet in Factory contract.
The text was updated successfully, but these errors were encountered: