Open code423n4 opened 1 year ago
gzeon-c4 marked the issue as primary issue
https://github.com/code-423n4/2023-01-biconomy-findings/issues/278 also described a way to make the user tx not revert by self destructing with another call. i.e.
livingrockrises marked the issue as sponsor confirmed
gzeon-c4 marked the issue as satisfactory
gzeon-c4 marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2023-01-biconomy/blob/main/scw-contracts/contracts/smart-contract-wallet/SmartAccountFactory.sol#L33-L45
Vulnerability details
A counterfactual wallet can be used by pre-generating its address using the
SmartAccountFactory.getAddressForCounterfactualWallet
function. This address can then be securely used (for example, sending funds to this address) knowing in advance that the user will later be able to deploy it at the same address to gain control.However, an attacker can deploy the counterfactual wallet on behalf of the owner and use an arbitrary entrypoint:
https://github.com/code-423n4/2023-01-biconomy/blob/main/scw-contracts/contracts/smart-contract-wallet/SmartAccountFactory.sol#L33-L45
As the entrypoint address doesn't take any role in the address generation (it isn't part of the salt or the init hash), then the attacker is able to use any arbitrary entrypoint while keeping the address the same as the pre-generated address.
Impact
After the attacker has deployed the wallet with its own entrypoint, this contract can be used to execute any arbitrary call or code (using
delegatecall
) using theexecFromEntryPoint
function:https://github.com/code-423n4/2023-01-biconomy/blob/main/scw-contracts/contracts/smart-contract-wallet/SmartAccount.sol#L489-L492
This means the attacker has total control over the wallet, it can be used to steal any pre-existing funds in the wallet, change the owner, etc.
PoC
In the following test, the attacker deploys the counterfactual wallet using the
StealEntryPoint
contract as the entrypoint, which is then used to steal any funds present in the wallet.Recommendation
This may need further discussion, but an easy fix would be to include the entrypoint as part of the salt. Note that the entrypoint used to generate the address must be kept the same and be used during the deployment of the counterfactual wallet.