The DateTime.sol contract's timestamp-to-date conversion functions (parseTimestamp, getYear, getMonth, getDay) are implemented with highly inefficient iterative logic. This design leads to significantly increased gas costs for any operation in the Plume network that relies on these date calculations, directly impacting user transaction fees and protocol efficiency.
Vulnerability Details
The gas inefficiency arises from iterative calculations instead of using optimized mathematical algorithms:
getYear's Inefficient while loop: getYear starts with an approximation then iteratively adjusts year and secondsAccountedFor using a while loop, repeatedly checking leap years and subtracting seconds until the correct year is found.
parseTimestamp's Cascading Iterations: parseTimestamp calls the iterative getYear, then uses loops to determine month (up to 12 iterations) and day (up to 31 iterations). Each iteration invokes additional calculations (e.g., getDaysInMonth), compounding gas usage.
This chain of iterative loops for year, month, and day results in much higher gas consumption than optimized direct-algorithm implementations (for example, Solady's DateTimeLib), which convert timestamps to date components in a single, non-iterative pass.
Impact Details
Primary impact: high gas consumption (Gas Optimization), affecting economic efficiency and user experience in the Plume protocol. The PoC demonstrates an example optimization of 29,087 gas saved.