I've seen a particular code style, where after any "critical" state modification operation, a check is done in order to assess the true good result of the operation.
uint _count = currentStruct.count--; assert(currentStruct.count == --_count); // check and revert if something is strange
currentStruct.level = 0; assert(currentStruct.level == 0);
currentStruct.level = externalContract.zerosCurrentLevel(); assert(currentStruct.level == 0);
where those operations are to be considered critical because either they are:
- very costly in terms of possible manipulation;
- depending on the results of some external contracts deployed elsewhere
- and so on.
Is this a justified way of code, or it is simply redundant? And if it be justified, why and when?
==== after comments ====
After that both goodvibration and Rob constructively commented, I precise that, as far as I understood, the problem were not to check for overflow, but for proper EVM context execution of the operation to be checked. It was said to me that it is not clear today what will be an attack tomorrow and that checking whatever critical (for double spending for instance, or to avoid reentrancy attacks) can avoid future problems. In that sense even if today it is not clear why they are checking, tomorrow they should discover that their code in not attack-able by some new attack... this is the declared rationale.