Blog

What is Read-Only-Reentrancy?

In this contract, the stake and withdraw functions are protected with the nonReentrant modifier from the ReentrancyGuard contract, which prevents reentrant calls to these functions.

However, the displayBalance function is marked as view, which means it doesn't modify the contract state and is considered read-only.

This is just a trivial example and there is no harm being done here. However, in more complex contracts there may be some sort of conversion rates which are depending on the correct state update and in such a scenario it can quickly get exploited.

The prevention is clear: Checks-Effects-Interactions.

https://bailsec.io/tpost/gxcih1xoy1-checks-effects-interactions