matter-labs / era-test-node

In-memory node that can be used for integration testing and debugging.
https://matter-labs.github.io/era-test-node
Apache License 2.0
313 stars 76 forks source link

feat: allow mixing impersonated and non-impersonated transactions #407

Open itegulov opened 6 days ago

itegulov commented 6 days ago

We can't mix impersonated and non-impersonated transactions inside a single batch due to limitation of our current approach. Batch VM is initialized with either normal or impersonated bootloader at the start of a batch and it can't change dynamically without sealing both current block and current batch.

Our current solution is to force block/batch sealing when we see a transaction with impersonation status that differs from the first transactions in the batch. Thus making us start a new block/batch with flipped impersonation status.

Alternatives I currently see:

  1. Find a way to change VM's bootloader on the fly. Roughly speaking, we would overwrite VM's memory at BOOTLOADER_CODE_PAGE to the other bootloader's payload. Problems with this: we will have to expose low-level access to VM from upstream, concerns over how hacky and brittle this is, unsure if this will even work in general (I tried to prepare a quick PoC and met a lot of hard to debug VM errors).
  2. Make impersonated bootloader parametrized with the set of impersonated accounts. Meaning it would only skip verification for accounts from that set. We would initialize the set at the start of every batch and any impersonation state change will result in force sealing of a batch which should happen a lot less frequently.

Regardless of direction we go with, I would consult with protocol first to see if there is another option that fits better here.

Marking as low priority for now as there has been no real demand/complaints here from real users.

PatrickAlphaC commented 3 days ago

How do you impersonate an address at all that is not an account you have? I seem to be unable to figure this one out.

itegulov commented 3 days ago

@PatrickAlphaC you can use anvil_impersonate endpoint to enable impersonation for the provided account. Here is an example.

For future though please ask questions under https://github.com/ZKsync-Community-Hub/zksync-developers/discussions.