Submitted by shaka
https://github.com/GenerationSoftware/pt-v5-vault/blob/b1deb5d494c25f885c34c83f014c8a855c5e2749/src/Vault.sol#L1155
https://github.com/GenerationSoftware/pt-v5-twab-controller/blob/0145eeac23301ee5338c659422dd6d69234f5d50/src/libraries/TwabLib.sol#L48
Vault::_transfer overrides the ERC20::_transfer function so the transfer is performed using the TwabController contract. In the implementation, _shares is downcasted to uint96 and this can result in an underflow silently.
There are nat spec comments indicating that the balance in TwapController is stored in uint96, which would mean that there is no real risk of underflow. However, the TwapController contract uses uint112 to store the balance, so the risk of underflow is real.
Integrations of other contracts or protocols with the Vault contract may result in accounting errors, due to the amount of shares transferred being less than expected due to silent underflow.
Foundry test:
Use OpenZeppelins SafeCast library to convert uint256 to uint96.
Under/Overflow
asselstine (PoolTogether) confirmed
PierrickGT (PoolTogether) commented:
PoolTogether mitigated:
Status: Mitigation confirmed. Full details in report from 0xStalin, dirk_y and rvierdiiev.
