Submitted by MrPotatoMagic, also found by cccz
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/MaxHeap.sol#L156 https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/MaxHeap.sol#L94
During the extraction of the max element through the function extractMax(), the positionMapping for the last element in the heap tree is not updated when the last element is equal to its parent.
These are the following impacts:
Note: Point 3 in the impacts above breaks an invariant of the MaxHeap tree mentioned in the README.
Here is the whole process:
Note: to view the provided image, please see the original submission here.
Note: to view the provided image, please see the original submission here.
Note: to view the provided image, please see the original submission here.
maxHeapify() function:
Note: to view the provided image, please see the original submission here.
Some points to note about this issue:
Note: to view the provided image, please see the original submission here.
The most straightforward solution to this would be to consider this type of case in the extractMax() function itself.
The following check ensures that if the last element is equal to the parent and it is greater than equal to the right index of the root node (i.e. index 2), we update the positionMapping correctly to 0. This check needs to be placed after this statement.
rocketman-21 (Revolution) commented:
0xTheC0der (Judge) commented:
Although I acknowledge that this is a good and severe find, any PoC so far was only focused on MaxHeap itself and not its current usage through the main entry points of the protocol. Therefore, Medium severity seems appropriate since further impacts on the main functionality of the protocol need to be proven.
Note: See full discussion here.
