Loop termination
nmushegian opened this issue · comments
for (uint i = 1; term >= precision; i++) {
This expression somewhat obscures the fact that this is loop is not necessarily going to terminate. The actual concern here is that non-termination means draining all available gas before reverting. So you're still kicking this concern over to the caller!
You could give it a fixed maximum as before:
for (uint i = 1; i < MAX_ITERATIONS; i++) {
if( term < precision) break;
}
Or if we are going to separately prove that term goes to zero, refactor to use accumulators directly:
while (term >= precision) {
k += BONE;
term = f(term, k)
}
Tracked in #207