Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(StateVariables): Only write if value is changed in public #1742

Open
Tracked by #5759
LHerskind opened this issue Aug 22, 2023 · 5 comments
Open
Tracked by #5759

feat(StateVariables): Only write if value is changed in public #1742

LHerskind opened this issue Aug 22, 2023 · 5 comments
Labels
T-feature-request Type: Adding a brand new feature (not to be confused with improving an existing feature). T-optimisation Type: Optimisation. Making something faster / cheaper / smaller

Comments

@LHerskind
Copy link
Contributor

LHerskind commented Aug 22, 2023

We should only need to perform write operations in public if the value is different from the current one. Otherwise we are simply wasting resources.

There are multiple variations of this. Differing in how complex they are and the savings they support. Namely at what level we perform the "cleaning".

  • At write level: Updating a struct of 4 elements where only 1 changed in a call should just write that 1 value. Can initially be done by the simulator and should be relatively straightforward for us to support in the kernels
  • At call level: If the slot takes same value at end and start of a call it should not be doing a write in the call.
  • At transaction level: If updating a value to an intermediate value and then setting in back at the end of the transaction should mean that the value is not emitting a state update to L1, the transaction itself is executed as if both updates happened. More complex as needs to go across kernels.
  • At block level: Any value that ends in the same value that it started in a block should not emit a change. Meaning that if a transaction is increasing a balance by 10, and another later transaction is reducing the same transaction by 10, it should not emit any changes to L1. The block should have happened as if these changes happened.

The overall goal is:

    1. reduce the number of writes that are done in a transactions/call such that you can do more complex stuff without running out of writes,
    1. reduce the number of updates that need to emitted to L1 to cut cost generally.

As a note on this, it should also be considered if it is desired to keep posting diffs as now, or posting the public calls (from private -> public) instead.

@LHerskind LHerskind added the T-feature-request Type: Adding a brand new feature (not to be confused with improving an existing feature). label Aug 22, 2023
@github-project-automation github-project-automation bot moved this to Todo in A3 Aug 22, 2023
@iAmMichaelConnor
Copy link
Contributor

iAmMichaelConnor commented Aug 23, 2023

At call level: If the slot takes same value at end and start of a call it should not be doing a write in the call.

There's a slight complication to this one. If in the first 'frame' of a function foo, the slot is changed from 10 to 20, then an external function call is made, and then in the second 'frame' of function foo, the slot is changed from 20 back to 10, then the reads and writes do need to be passed to the public kernel circuit, because re-entrancy might happen. But they're transient reads and writes which can be 'squashed' by the kernel before the 'final' reads and writes are passed to the base rollup circuit.

@iAmMichaelConnor iAmMichaelConnor added the T-optimisation Type: Optimisation. Making something faster / cheaper / smaller label Aug 25, 2023
@LHerskind
Copy link
Contributor Author

@dbanks12 again relates to circuits and how we are collapsing state changes.

@LHerskind
Copy link
Contributor Author

Disregarding the squishing/collapsing discussed above. The same goal but achieved entirely inside the public state should be possible for the case where we are overwriting a struct but not the entire thing? I think we right now might still be sending multiple write requests even if the values are unchanged?

@LHerskind LHerskind changed the title feat: Only write if value is changed in public feat(StateVariables): Only write if value is changed in public Mar 9, 2024
@iAmMichaelConnor
Copy link
Contributor

I haven't kept up with how public state is being serialised into "write requests" for the kernel to process, or serialised to L1.
I suppose we need to decide whether we want Aztec to publish intents or state diffs, and I guess that depends on whether we can do a based rollup design?

@LHerskind
Copy link
Contributor Author

I suppose we need to decide whether we want Aztec to publish intents or state diffs

Yes. Which depends on how independent we make sequencing from proving, which depends on performance and costs of the proving system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature-request Type: Adding a brand new feature (not to be confused with improving an existing feature). T-optimisation Type: Optimisation. Making something faster / cheaper / smaller
Projects
Status: Todo
Development

No branches or pull requests

2 participants