Twav.sol#_getTwav() will revert when timestamp > 4294967296
The Twav contract's _getTwav function subtracts two uint32 timestamps without unchecked arithmetic, so when the current timestamp has overflowed uint32 but the previous one has not, the subtraction underflows and reverts. This would make the _rejectBuyout function unavailable, potentially freezing user funds in the vault.
The timestamp subtraction may revert due to underflow.
Impact
Since _getTwav() is used in NibblVault.sol#_rejectBuyout(), if it reverts and there is a buyout, an essential feature of the NibblVault contract will be unavailable, causing users’ funds to be frozen in the contract.
If I’m not mistaken, timestamp 4294967296 is 2106, I wouldn’t call the contract breaking in 84 years a high severity issue. Plus the contract is truncating the timestamp on purpose. Seems to me more like a design choice and less of a bug.
If I’m not mistaken, timestamp 4294967296 is 2106, I wouldn’t call the contract breaking in 84 years a high severity issue. Plus the contract is truncating the timestamp on purpose. Seems to me more like a design choice and less of a bug.
_getTwav would overflow once timestamps overflow uint32, but only when the current observation has overflowed while the previous observation did not.
The window for this vulnerability is very small, just at the time timestamp starts to overflow in 2106 - vaults active before or after that time should work as expected.
This appears to be a Medium risk finding. There’s potentially a case to be made for high here but it’s hard to make that call without a more complete POC included. The vault is an upgradeable contract so they have 84 years to sort this out — but it does seem like an issue that should be fixed.
The original report as published on Code4rena, by WatchPug. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the subtraction of two uint32 timestamps is not wrapped in an unchecked block, so it reverts on underflow when the current timestamp has overflowed but the previous one has not.
Impact
If _getTwav reverts during a buyout, the _rejectBuyout function becomes unavailable, which could freeze users' funds in the contract; the issue only occurs around the year 2106 when timestamps overflow uint32.
What the attacker needed
Timestamp exceeds uint32 max (year 2106); a buyout occurs
The fix
The subtraction should be placed inside an unchecked block so that underflow wraps as intended, matching the pattern used in _updateTWAV.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A smart contract stores timestamps as 32-bit numbers, which wrap around to zero after about 136 years. The code subtracts two such timestamps to calculate a time difference, but newer Solidity versions automatically block subtraction that would go negative. If the newer timestamp has wrapped but the older one has not, the subtraction fails and the function stops working, which could lock funds.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.