The burn function in the RToken contract contains redundant state updates to the user's index value, resulting in unnecessary gas costs. The same value is written to storage twice within the same function execution. There is also a redundant calculation of uint256 amountScaled = amount.rayMul(index);
in the function.
The liquidity index for a user is set twice with the same value (index.toUint128()) This redundancy results in an unnecessary SSTORE operation, increasing gas consumption. Each extra storage write incurs additional gas costs. In this case, the duplicate update of _userState[from].index does not alter the contract state but still costs extra gas.
The redundant state update leads to higher gas usage for the burn function
Manual code review
Remove the duplicate update and the so that the liquidity index is updated only once.
also remove the uint256 amountScaled = amount.rayMul(index);
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.