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

Optimize gas estimation running time #124

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

dartdart26
Copy link
Collaborator

Optimize gas estimation running time with two approaches:

  1. Don't call any storage methods on SSTORE during gas estimation. Instead, return early if we are in gas estimation (Commit = false). For that to work, make sure that on SLOAD, we first lookup the ciphertext hash in memory and, if found, use it without going to storage. That improves performance by not doing heavy work of splitting a ciphertext to 32 byte slots and persisting it to a memory-backed store for no reason.
  2. When importing a random ciphertext during gas estimation, do not use public key encryption. Instead, just genearate an unique hash for the random ciphertext by utilizing a counter that is part of the EVM itself. That improves performance by not doing public key encryption and serialization just to compute a ciphertext hash (handle).

Copy link
Contributor

@tremblaythibaultl tremblaythibaultl left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@dartdart26 dartdart26 force-pushed the petar/optimize-gas-estimation branch from 45482b3 to b560924 Compare June 26, 2023 09:09
Optimize gas estimation running time with two approaches:
1. Don't call any storage methods on SSTORE during gas estimation.
Instead, return early if we are in gas estimation (Commit = false). For
that to work, make sure that on SLOAD, we first lookup the ciphertext
hash in memory and, if found, use it without going to storage. That
improves performance by not doing heavy work of splitting a ciphertext
to 32 byte slots and persisting it to a memory-backed store for no
reason.
2. When importing a random ciphertext during gas estimation, do not use
public key encryption. Instead, just genearate an unique hash for the
random ciphertext by utilizing a counter that is part of the EVM itself.
That improves performance by not doing public key encryption and
serialization just to compute a ciphertext hash (handle).
Rationale is that SSTORE charges less for zeroes. Using hash(counter),
we make gas estimation close to random ciphertext bytes.
@dartdart26 dartdart26 force-pushed the petar/optimize-gas-estimation branch from b560924 to ac05771 Compare June 26, 2023 11:04
@dartdart26 dartdart26 merged commit 88f7c50 into 1.10.19-zama Jun 26, 2023
1 check passed
@dartdart26 dartdart26 deleted the petar/optimize-gas-estimation branch June 26, 2023 11:13
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.

2 participants