Destruction of the SmartAccount implementation
The SmartAccount implementation contract could be left uninitialised, allowing an attacker to initialise it and then destroy it via a delegatecall to a selfdestruct contract. This would freeze all wallets that point to that implementation, including their funds.
Submitted by V_B, also found by gogo, gogo, adriro, smit_rajput, Koolex, hihen, spacelord47, 0xdeadbeef0x, Matin, chaduke, jonatascm, ro, taek, HE1M, and kankodu
contracts/smart-contract-wallet/SmartAccount.sol#L166 contracts/smart-contract-wallet/SmartAccount.sol#L192 contracts/smart-contract-wallet/SmartAccount.sol#L229 contracts/smart-contract-wallet/base/Executor.sol#L23
If the SmartAccount implementation contract is not initialized, it can be destroyed using the following attack scenario:
- Initialize the
SmartAccountimplementation contract using theinitfunction. - Execute a transaction that contains a single
delegatecallto a contract that executes theselfdestructopcode on any incoming call, such as:
contract Destructor {
fallback() external {
selfdestruct(payable(0));
}
}
The destruction of the implementation contract would result in the freezing of all functionality of the wallets that point to such an implementation. It would also be impossible to change the implementation address, as the Singleton functionality and the entire contract would be destroyed, leaving only the functionality from the Proxy contract accessible.
In the deploy script there is the following logic:
const SmartWallet = await ethers.getContractFactory("SmartAccount");
const baseImpl = await SmartWallet.deploy();
await baseImpl.deployed();
console.log("base wallet impl deployed at: ", baseImpl.address);
So, in the deploy script there is no enforce that the SmartAccount contract implementation was initialized.
The same situation in scw-contracts/scripts/wallet-factory.deploy.ts script.
Please note, that in case only the possibility of initialization of the SmartAccount implementation will be banned it will be possible to use this attack. This is so because in such a case owner variable will be equal to zero and it will be easy to pass a check inside of checkSignatures function using the fact that for incorrect input parameters ecrecover returns a zero address.
Impact
Complete freezing of all functionality of all wallets (including complete funds freezing).
Recommended Mitigation Steps
Add to the deploy script initialization of the SmartAccount implementation, or add to the SmartAccount contract the following constructor that will prevent implementation contract from the initialization:
// Constructor ensures that this implementation contract can not be initialized
constructor() public {
owner = address(1);
}
#14also notes that if owner is left to address(0) some validation can be bypassed.
livingrockrises (Biconomy) confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the implementation contract was deployed without initialisation or a constructor guard, leaving it open to initialisation and subsequent destruction.
Impact
The destruction would completely freeze all functionality of all wallets pointing to that implementation, including their funds.
What the attacker needed
Implementation contract left uninitialised; attacker can call init on implementation
The fix
The deploy script should initialise the implementation, or the contract should include a constructor that sets the owner to a non-zero address to prevent initialisation.
How it was found
- Initialise the SmartAccount implementation contract using the init function.
- Execute a transaction containing a single delegatecall to a contract that runs selfdestruct on any incoming call.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract implementation is a template that many wallets copy. If the template itself is left unprotected, an attacker can take it over and then delete it. Deleting the template breaks every wallet that relies on it, locking users out of their funds.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.