cartesi/machine-emulator

Add mtimebase CSR to "decouple" mtime and mcycle

Opened this issue · 2 comments

Context

When we move to lambda, when we move from one input to the next, we will restore the machine back to the template (and carry over the dapp state only). This includes restoring the value of mcycle, on which the value of mtime = rtc_cycle_to_time(mcycle) is based. This means that, from the point of view of the system running inside the machine, no time was elapsed at all. Every input starts processing at the same time. It is a bit odd.

Moreover, to simplify disputes, it might be good to have mcycle zeroed out before each input is processed. At the moment, if we do that, we will move time backwards. This is problematic for a running system.

Possible solutions

The idea is to add a new CSR, called mtimebase. Then, we set mtime = mtimebase + rtc_cycle_to_time(mcycle).
When we want to reset mcycle, all we have to do is first set mtimebase = mtimebase + rtc_cycle_to_time(mcycle), and then set mcycle = 0. Time will not move backwards anymore.

I think we need to reevaluate our notion of cycle counter because of lambda and because of current discussions of the machine stack and alternatives to the machine stack. @miltonjonat