A Reentrancy Exploit impacting Market XYZ from a Read-Only function in Curve LP Price Oracle

We discussed this vulnerability during Episode 165 on 07 November 2022

The problem starts in remove_liquidity where a contract can remove funds that they added. It will updated the total_supply and burn tokens, then in a loop for each coin it will decrement the balances and transfer them to the attacker’s contract. This is where control of execute goes back to the attacker and their fallback method and the contract’s state is somewhat inconsistent. total_supply has been decremented, but not all of the balance values have yet been updated.

This is where get_virtual_price comes into play. This is an @external (callable by other contracts) @view (doesn’t change any state) function, and as a view, has no reentrancy guard. This function calculates the price of the LP’s tokens based on the balances and total supply, leading to an incorrect calculation has the balances have not yet been fully updated. So any other protocol that depends on this function and trusts it could be manipulated.