Invalid check to make sure Minter is already in
The Minter contract's initialize function contains a check that compares msg.sender to the zero address, which can never be true, so the intended 'already initialized' error is never thrown. An attacker cannot exploit this to gain value, but the contract fails to deliver the promised error message.
- Disclosed after under an hour
30584 - [SC - Insight] Invalid check to make sure Minter is already in...
Submitted on May 1st 2024 at 13:08:37 UTC by @kankodu for Boost | Alchemix
Report ID: #30584
Report type: Smart Contract
Report severity: Insight
Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Minter.sol
Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
- A meaningless check
Vulnerability Details
- In
Minter.initializefunction, there is this checkrequire(msg.sender != address(0), "already initialized");that is supposed to make sure it throws an error Minter is already initialized. This check is meaningless. - msg.sender won't ever be equal to address(0). There is no circumstance where this error will be thrown.
- If the error is moved before
require(initializer == msg.sender, "not initializer");and updated withrequire(initializer != address(0), "already initialized");in that case it makes sense. It will now throw an error that Minter is already initialized if someone (including the previous initializer) tries to initialise it again.
function initialize() external {
require(initializer != address(0), "already initialized");
require(initializer == msg.sender, "not initializer");
initializer = address(0);
}
Impact Details
- Contract fails to deliver promised returns, but doesn't lose value
- A useful error won't ever be thrown if it is left as it is.
References
Proof of Concept
- Take a look at this test.
- It has to impersonate the address(0) for the error to be thrown. In real environment this won't be possible.
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 check uses msg.sender instead of the initializer state variable, so it can never trigger.
Impact
The contract fails to deliver the promised error message, but no value is lost and the issue is not exploitable.
What the attacker needed
None
The fix
The check should be changed to compare the initializer state variable to the zero address and moved before the caller check.
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 has a function to set itself up, called initialize. It tries to stop someone from setting it up twice by checking if the caller is the zero address, which is a special address that no real user can have. Because no real user can be the zero address, that check never stops anyone, so the error message meant to warn about double setup never appears.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.