Fallback handlers can trick users into calling functions of the AmbireAccount contract
A malicious fallback handler can contain a function whose selector matches a function in the base AmbireAccount contract, so calling the innocent-looking fallback function actually triggers the base function, such as setAddrPrivilege, allowing the attacker to gain control of the wallet.
Submitted by adriro
Selector clashing can be used to trick users into calling base functions of the wallet.
Fallback handlers provide extensibility to the Ambire wallet. The main idea here is that functions not present in the wallet implementation are delegated to the fallback handler by using the fallback() function.
Function dispatch in Solidity is done using function selectors. Selectors are represented by the first 4 bytes of the keccak hash of the function signature (name + argument types). It is possible (and not computationally difficult) to find different functions that have the same selector.
This means that a malicious actor can craft a fallback handler with a function signature carefully selected to match one of the functions present in the base AmbireAccount contract, and with an innocent looking implementation. While the fallback implementation may seem harmless, this function, when called, will actually trigger the function in the base AmbireAccount contract. This can be used, for example, to hide a call to setAddrPrivilege() which could be used to grant control of the wallet to the malicious actor.
This is similar to the exploit reported on proxies in this article, which caused the proposal of the transparent proxy pattern.
As further reference, another similar issue can be found in the DebtDAO audit that could lead to unnoticed calls due to selector clashing (disclaimer: the linked report is authored by me).
Recommendation
It is difficult to provide a recommendation based on the current design of contracts. Any whitelisting or validation around the selector won’t work as the main entry point of the wallet is the AmbireAccount contract itself. The solution would need to be based on something similar to what was proposed for transparent proxies, which involves segmenting the calls to avoid clashing, but this could cripple the functionality and simplicity of the wallet.
I’m not sure if this is applicable: the use case of this is the Ambire team pushing out fallback handlers and allowing users to opt into them. While this does leave an opportunity for us to be that malicious actor, I’m not sure there’s a better trade off here.
The scenario is convincing; provided the attacker manages to have its malicious implementation of
fallbackHandlerused by Ambire wallet users, which seems unlikely, but doable. Furthermore, as there are no admin roles here, the possibility of this attack by the Ambire team is worth stating.Overall, I think Medium severity is appropriate. I agree with the previous comments that there is no clear mitigation though, aside from warning users about this.
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 design allows arbitrary fallback handlers and relies on function selectors for dispatch, so selector collisions between the handler and the base contract cause unintended base functions to be executed.
Impact
If a user opts into a malicious fallback handler, the attacker could trigger a base wallet function such as setAddrPrivilege and gain control of the wallet; the judge considered this unlikely but doable and rated it Medium.
What the attacker needed
User opts into a malicious fallback handler
The fix
There is no clear mitigation; the report suggests segmenting calls similarly to the transparent proxy pattern, and the judge suggests warning users.
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 wallet contract can hand off unknown function calls to a separate 'fallback handler' contract. Each function is identified by a short code (selector) derived from its name and arguments, and different functions can share the same code. An attacker could publish a handler with a harmless-looking function that has the same code as a sensitive wallet function, so a user calling the harmless one actually runs the sensitive one.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.