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

refactor(protocol): optimize storage reads/writes in proveBlock #17532

Merged
merged 22 commits into from
Jun 12, 2024

Conversation

dantaik
Copy link
Contributor

@dantaik dantaik commented Jun 8, 2024

Most proveBlock transactions submit a new state transition for blocks. Previously we would fetch and compare storage values from the state transition ring buffer with the prover's values, updating each slot one by one.

With the new optimization, we bypass fetching these values for new state transitions (because the slots' current values don't matter), instead opting to perform a direct storage save at the end.

This optimisation reduces gas by 20K.

@dantaik dantaik marked this pull request as ready for review June 8, 2024 13:34
Copy link

openzeppelin-code bot commented Jun 8, 2024

refactor(protocol): optimize storage reads/writes in proveBlock

Generated at commit: 46e0ff5a2803df01526703a316e1c6a3a6a722ee

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
2
0
8
42
54
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

Copy link
Contributor

@Brechtpd Brechtpd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay, but there's a lot of logic related to these state transitions and it's too much for me to keep in my head just reviewing these PRs without going through all the logic again so I don't know for sure.

@dantaik
Copy link
Contributor Author

dantaik commented Jun 8, 2024

Looks okay, but there's a lot of logic related to these state transitions and it's too much for me to keep in my head just reviewing these PRs without going through all the logic again so I don't know for sure.

We do need to review the changes more carefully before pushing them. Please take your time.

@dantaik dantaik marked this pull request as draft June 8, 2024 23:59
@dantaik dantaik requested a review from Brechtpd June 9, 2024 00:25
@dantaik dantaik marked this pull request as ready for review June 9, 2024 00:25
@dantaik
Copy link
Contributor Author

dantaik commented Jun 9, 2024

Looks okay, but there's a lot of logic related to these state transitions and it's too much for me to keep in my head just reviewing these PRs without going through all the logic again so I don't know for sure.

Brecht, please take another look. I made some new changes.

@dantaik dantaik changed the title refactor(protocol): further optimize unnecessary storage writes in proveBlock refactor(protocol): optimize storage reads/writes in proveBlock Jun 9, 2024
dantaik added 3 commits June 10, 2024 11:52
This reverts commit 42c45d70a741ac879b90fbb778289f9475a96387.
@dantaik dantaik requested a review from adaki2004 June 10, 2024 14:33
@dantaik dantaik enabled auto-merge June 12, 2024 03:57
@dantaik dantaik added this pull request to the merge queue Jun 12, 2024
Merged via the queue into main with commit ba5c25b Jun 12, 2024
4 checks passed
@dantaik dantaik deleted the optimize_proving_writes branch June 12, 2024 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants