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

Improve Proxy Behaviour With the IR Optimizer #451

Merged
merged 1 commit into from
Jul 9, 2024
Merged

Conversation

nlordell
Copy link
Collaborator

@nlordell nlordell commented Jun 28, 2024

This PR marks regions of assembly that previously weren't as memory safe - this allows the IR optimizer to do a few extra optimizations and improve overall gas consumption for the contracts.

Before

  Gas Benchmarking [@bench]
    SafeWebAuthnSignerProxy
      ⛽ deployment: 91107
      ✔ Benchmark signer deployment cost (517ms)
      ⛽ verification (Dummy): 12564
      ✔ Benchmark signer verification cost with Dummy verifier (108ms)
      ⛽ verification (Precompile): 13379
      ✔ Benchmark signer verification cost with Precompile verifier (109ms)

After

  Gas Benchmarking [@bench]
    SafeWebAuthnSignerProxy
      ⛽ deployment: 89900
      ✔ Benchmark signer deployment cost (518ms)
      ⛽ verification (Dummy): 12553
      ✔ Benchmark signer verification cost with Dummy verifier (110ms)
      ⛽ verification (Precompile): 13368
      ✔ Benchmark signer verification cost with Precompile verifier (113ms)

Note that writing to ptr instead of 0 and changing the position of the revert and return actually helps the compiler produce more optimal code 🤷. Solidity optimizer is really a black box to me sometimes 😅.

Additionally, marking the proxy implementation as "memory safe" has a net negative effect on the optimizer, so we intentionally don't mark it as such (even if the changes make it memory safe)
  Gas Benchmarking [@bench]
    SafeWebAuthnSignerProxy
      ⛽ deployment: 90100
      ✔ Benchmark signer deployment cost (529ms)
      ⛽ verification (Dummy): 12570
      ✔ Benchmark signer verification cost with Dummy verifier (113ms)
      ⛽ verification (Precompile): 13385
      ✔ Benchmark signer verification cost with Precompile verifier (113ms)

This PR is a DRAFT - as it would change the code in a meaningful way that would require us to re-audit it. If we decide that the audit competition is not enough for the SafeWebAuthnSharedSigner and we want an additional audit for that contract (likely), then we should merge this. Otherwise, the changes are not meaningful and can wait until a future version. Since we are re-auditing the SafeWebAuthnSharedSigner, we can include this small change as part of an incremental audit.

@nlordell nlordell marked this pull request as ready for review July 8, 2024 09:19
@nlordell nlordell requested a review from a team as a code owner July 8, 2024 09:19
@nlordell nlordell requested review from akshay-ap, mmv08 and remedcu and removed request for a team July 8, 2024 09:19
@mmv08 mmv08 merged commit 19b4715 into main Jul 9, 2024
9 checks passed
@mmv08 mmv08 deleted the chore/ir-optimizations branch July 9, 2024 13:18
@github-actions github-actions bot locked and limited conversation to collaborators Jul 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants