The onAfterRemoveLiquidity function in UpliftOnlyExample contains a critical flaw in its array management logic when processing position removals. The function attempts to maintain a FILO (First-In-Last-Out) order while removing positions, but incorrectly combines array deletion and pop operations:
The function iterates backwards through the array while simultaneously removing elements from the end, causing misalignment between iteration and array state.
The severity of this vulnerability stems from fundamental data corruption in the position management system. When processing removals, the code's array manipulation logic creates fatal inconsistencies in position tracking data.
The corruption occurs through a precise technical sequence: when processing any given index i, the function first deletes data at that index and then pops from the end of the array. For example, when processing index 3 in an array [0,1,2,3,4], the delete operation creates [0,1,2,empty,4], followed by a pop resulting in [0,1,2,empty]. This operation irreversibly loses the data at index 4 and misaligns all subsequent array processing.
This implementation flaw cascades through the protocol's core functionality. Position tracking data becomes corrupted or lost, leading to incorrect fee calculations based on invalid position values. The FILO ordering - critical for the protocol's uplift fee assessment - breaks down completely. The system may double-count positions in fee calculations or miss them entirely, while the remaining position data in the protocol state becomes unreliable. These issues compound with each removal operation, progressively degrading the protocol's state.
The cumulative effect fundamentally undermines the protocol's ability to maintain accurate position management and fee assessments, potentially leading to permanent data loss and incorrect economic calculations across the system.
Revise the removal logic to maintain array integrity:
Alternative approach using a separate array:
The second approach may be more gas intensive but provides clearer and safer array management.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.