Submitted by sirhashalot
The safeDecimals() function, found in the SafeMetadata.sol contract and called in 3 different Timeswap Convenience contracts, can cause a revert. This is because the safeDecimals function attempts to use abi.decode to return a uint8 when data.length >= 32. However, a data.length value greater than 32 will cause abi.decode to revert.
A similar issue was found in a previoud code4rena contest: https://github.com/code-423n4/2021-05-nftx-findings/issues/46
The root cause is line 28 of the safeDecimals() function in SafeMetadata.sol
The following link shows the safeDecimals() function in the BoringCrypto library, which might be where this code was borrowed from, uses the strict equality check data.length == 32
https://github.com/boringcrypto/BoringSolidity/blob/ccb743d4c3363ca37491b87c6c9b24b1f5fa25dc/contracts/libraries/BoringERC20.sol#L54
safeDecimals() is used in multiple functions such as
Modify the safeDecimals() function to change >= 32 to == 32 like this
if (success && data.length == 32) return abi.decode(data, (uint8));
Mathepreneur (Timeswap) confirmed and resolved:
