Last week I was reviewing the staking engine of a protocol before its mainnet launch. Deep in a 1,400-line contract, I found what looked like a serious bug.

The reward math multiplied three values before dividing:

uint256 delta = (lot.amount * rBase * midpointRate) / (RAY * RAY);

Enter fullscreen mode

Exit fullscreen mode