ZcToken.withdraw will send user 0 tokens if called after maturity deadline but before market is set mature
The ZcToken contract's withdraw function calculates the amount to send using a maturityRate that can still be zero after the maturity deadline if no transactions have set it. An attacker or user calling withdraw at that time receives zero tokens despite the transaction succeeding.
Submitted by panprog
Impact
If maturityRate is still 0 after maturity deadline (because no transactions setting maturityRate have been executed yet), then previewWithdraw calculated amount (used by ZcToken.withdraw function) is 0 and thus withdraw function will send 0 underlying tokens to user, which might be very confusing to user. Subsequent call to the same function will send him correct amount.
The same problem applies to all view functions in ZcToken contract - they use saved market maturityRate, which can be 0 even past deadline time and functions revert or return 0 in this case.
Incorrect withdrawal behaviour:
- Bob has some
ZcTokens. - Right at the time of maturity Bob tries to withdraw his underlying tokens by calling
ZcToken.withdrawwith some underlying amount. - Instead of receiving corresponding amount, Bob receives nothing (but transaction still succeeds and he uses gas for it).
Proof of Concept
withdraw: calculatespreviewAmountfrompreviewWithdraw
previewWithdraw: multiplication bymaturityRatereturns 0
Recommended Mitigation Steps
Add getMaturityRate function to ZcToken, which will return either market’s maturityRate or (if it’s 0) current market’s exchangeRate. Use this function instead of maturityRate everywhere across ZcToken.
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 contract uses a stored maturityRate that defaults to zero and is only set by certain transactions, without a fallback to the current exchange rate when it is zero.
Impact
A user withdrawing right after maturity could receive zero tokens instead of the correct amount, though a subsequent call would work.
What the attacker needed
User holds ZcTokens; Maturity deadline has passed; No prior transaction set maturityRate
The fix
The issue was fixed by adding a getMaturityRate function that returns the market's maturityRate or, if zero, the current exchangeRate, and using it everywhere in ZcToken.
How it was found
- Bob holds some ZcTokens.
- At the maturity time, Bob calls ZcToken.withdraw with an underlying amount.
- The withdraw function calls previewWithdraw, which multiplies by maturityRate (still zero) and returns zero.
- Bob receives zero tokens, but the transaction succeeds and he pays gas.
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 lets users withdraw tokens after a certain date. But if nobody has triggered a specific update before that date, the contract still thinks the exchange rate is zero, so it sends zero tokens even though the withdrawal appears to succeed. The user loses gas and gets nothing, though a second try would work.
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.