WETH.sol computes the wrong totalSupply()
The WETH contract's totalSupply() function reads the contract's own token balance instead of its native currency balance, so it always returns zero. An attacker could not gain funds, but the reported total supply is wrong, breaking a core function of the contract.
Submitted by p4st13r4, also found by hansfriese, Ruhum, TerrierLover, WatchPug, and zzzitron
Affected code:
WETH.sol is almost copied from the infamous WETH contract that lives in mainnet. This contract is supposed to receive the native currency of the blockchain (for example ETH) and wrap it into a tokenized, ERC-20 form. This contract computes the totalSupply() using the balance of the contract itself stored in the balanceOf mapping, when instead it should be using the native balance function. This way, totalSupply() always returns zero as the WETH contract itself has no way of calling deposit to itself and increase its own balance
Proof of Concept
- Alice transfers 100 ETH to
WETH.sol - Alice calls
balanceOf()for her address and it returns 100 WETH - Alice calls
totalSupply(), expecting to see 100 WETH, but it returns 0
Tools Used
Editor
Recommended Mitigation Steps
function totalSupply() public view returns (uint) {
return address(this).balance
}
Alex the Entreprenerd (judge) commented:
The warden has shown how, due to a programming mistake, the WETH totalSupply will be incorrect.
Mitigation seems straightforward, however, because the vulnerability would have causes totalSupply to return 0, and shows a broken functionality for a core contract, I think High Severity to be appropriate
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 totalSupply() function was written to read the contract's own entry in the token balance mapping rather than the contract's native currency balance.
Impact
The total supply of the token is always reported as zero, so any system relying on that figure sees a broken core function; the report does not claim any theft or loss of funds.
What the attacker needed
None
The fix
The totalSupply() function should return the contract's native currency balance instead of its own token balance.
How it was found
- Alice transfers 100 ETH to the WETH contract.
- Alice checks her token balance and sees 100 WETH.
- Alice calls totalSupply() and gets 0 instead of 100 WETH.
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.
This contract lets people turn ordinary cryptocurrency into a token version of it. The function that is supposed to report how many tokens exist in total looks in the wrong place, so it always says zero. That does not let anyone steal money, but it makes the contract report false information.
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.