zeko-labs / zeko

Zeko: zk-Rollup for Mina, a succinct blockchain
https://zeko.io
Apache License 2.0
23 stars 3 forks source link

Fix actions #170

Closed L-as closed 5 months ago

L-as commented 5 months ago

Each account has 5 action states, and an action state precondition can match against any of them. As time goes on, the action states are shifted backwards. Thus, even if your proving takes a little while, you can match against a somewhat recent historical action state.

The mechanism however relies on precise slots, which we don't have on Zeko. However, we can let the sequencer choose when to do the shifting. There is the possibility for abuse, but economically it would make no sense for the sequencer, and any damage would be gone once the next rational sequencer is elected.

We allow the prover to set this variable by passing in an "environment" when proving. The code will call into the environment (represented as an immediate object (class)), tell the sequencer what account is posting an action, and the sequencer can respond back with whether to shift the action state or not.

The mechanism isn't integrated into the sequencer yet, it is merely exposed. of_zkapp_command_segment_exn must not be used, instead of_zkapp_command_segment_zeko_exn must be used. The former uses a stub environment which always shifts.

For other functions there is an optional ?env parameter, which if ommitted, is stubbed out in the same way. Care must be taken to ensure that the same responses are given when proving and when executing, otherwise proving can fail after accepting a command.

Untested, of course.

Closes issue #64

L-as commented 5 months ago

There’s some code duplication but I deemed it not worth the time to remove.

L-as commented 5 months ago

I added a test and tested this.

As I posted on the internal slack, I will hold off from implementing this in the sequencer just yet, since this interacts with the DA: With this change, commands are non-deterministic. A command alone does not tell you what the output ledger is. You need to know the non-deterministic choices made. In this case it's easier since it's a boolean choice between shifting and not shifting, but it still means changes to DA, and we're already in the process of replacing the DA.

Hence integrating this work into the sequencer will be done later.