-
Notifications
You must be signed in to change notification settings - Fork 86
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 Compiler Settings #448
Conversation
I noticed that the IR optimizer is better for all contracts **except** the FCL library. This PR optimizes the compiler configuration to take advantage of the IR optimizer, while adding an exception for the FCL P-256 verifier contract so that it does not suffer any regressions. ``` === BEFORE === Gas Benchmarking [@bench] SafeWebAuthnSignerProxy ⛽ deployment: 94366 ✔ Benchmark signer deployment cost (476ms) ⛽ verification (FreshCryptoLib): 216907 ✔ Benchmark signer verification cost with FreshCryptoLib verifier (116ms) ⛽ verification (Daimo): 346809 ✔ Benchmark signer verification cost with Daimo verifier (103ms) ⛽ verification (Dummy): 14309 ✔ Benchmark signer verification cost with Dummy verifier (100ms) ⛽ verification (Precompile): 15098 ✔ Benchmark signer verification cost with Precompile verifier (104ms) === AFTER === Gas Benchmarking [@bench] SafeWebAuthnSignerProxy ⛽ deployment: 90399 ✔ Benchmark signer deployment cost (494ms) ⛽ verification (FreshCryptoLib): 215532 ✔ Benchmark signer verification cost with FreshCryptoLib verifier (123ms) ⛽ verification (Daimo): 345458 ✔ Benchmark signer verification cost with Daimo verifier (103ms) ⛽ verification (Dummy): 12911 ✔ Benchmark signer verification cost with Dummy verifier (96ms) ⛽ verification (Precompile): 13726 ✔ Benchmark signer verification cost with Precompile verifier (106ms) ```
Pull Request Test Coverage Report for Build 9615641386Details
💛 - Coveralls |
modules/passkey/hardhat.config.ts
Outdated
@@ -31,6 +31,18 @@ const customNetwork = CUSTOM_NODE_URL | |||
} | |||
: {} | |||
|
|||
const compilerSettings = { | |||
version: '0.8.24', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're changing the compiler settings, what about using the latest version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rationale for not doing it is as such:
- from the changelog there are no significant features or fixes that were added since 0.8.24: source
Currently, theThis appears to be false 😞FCL256Verifier
is byte-for-byte the same (and won't change with any of the planned changes 🎉, none of the audit competition changes affect it). Updating the compiler version would change that- The audit was done for compiler v0.8.24, I know we are changing the compiler settings, but it feels less extreme than a new compiler version.
I don't feel strongly either way, I did consider it when making this PR but opted to err on the side of caution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran the benchmarks with 0.8.26
and it seems it slightly improves runtime gas costs:
Gas Benchmarking [@bench]
SafeWebAuthnSignerProxy
⛽ deployment: 91042
✔ Benchmark signer deployment cost (568ms)
⛽ verification (FreshCryptoLib): 215607
✔ Benchmark signer verification cost with FreshCryptoLib verifier (107ms)
⛽ verification (Daimo): 345542
✔ Benchmark signer verification cost with Daimo verifier (100ms)
⛽ verification (Dummy): 12564
✔ Benchmark signer verification cost with Dummy verifier (107ms)
⛽ verification (Precompile): 13379
✔ Benchmark signer verification cost with Precompile verifier (117ms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With 0.8.25
they're almost identical except the Daimo verifier:
Gas Benchmarking [@bench]
SafeWebAuthnSignerProxy
⛽ deployment: 90399
✔ Benchmark signer deployment cost (508ms)
⛽ verification (FreshCryptoLib): 213844
✔ Benchmark signer verification cost with FreshCryptoLib verifier (145ms)
⛽ verification (Daimo): 342496
✔ Benchmark signer verification cost with Daimo verifier (121ms)
⛽ verification (Dummy): 12911
✔ Benchmark signer verification cost with Dummy verifier (110ms)
⛽ verification (Precompile): 13726
✔ Benchmark signer verification cost with Precompile verifier (111ms)
I guess those small improvements (from the 0.8.26 changelog) made a slight difference, not a compiler engineer, though:
Compiler Features:
Yul IR Code Generation: Cheaper code for reverting with errors of a small static encoding size.
Yul Optimizer: New, faster default optimizer step sequence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the code got slightly bigger from v0.8.25 -> v0.8.26
=== v0.8.25 ===
Gas Benchmarking [@bench]
SafeWebAuthnSignerProxy
⛽ deployment: 90399
✔ Benchmark signer deployment cost (508ms)
=== v0.8.26 ===
Gas Benchmarking [@bench]
SafeWebAuthnSignerProxy
⛽ deployment: 91042
✔ Benchmark signer deployment cost (568ms)
Still, overall, I think you are right, we can bump the compiler version here. My main argument was to reuse the FCLP256Verifier
, but that is moot apparently 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except the Daimo verifier:
This is slightly random because the verifiers have different gas characteristics depending on what public key/signature is used (which is random in the tests).
I would look specifically at deployment
, dummy
and precompile
gas metrics only (unless you collect data from many runs and compute averages for FCL and Daimo).
Also, Daimo verifier is not compiled (we vendor bytecode directly), so compiler settings should not affect it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMplemented suggestion in a6cd15a and updated PR description.
runs: 10_000_000, | ||
}, | ||
viaIR: true, | ||
evmVersion: 'paris', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paris is pre-push0, right? maybe we don't need this either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, so we are BNB compatible.
Also, note that hardhat
currently defaults to paris
anyway (at least it did when I experimented with switching this setting off), so this is more to explicitly document the EVM version that is being targetted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like BNB already has push0? https://forum.bnbchain.org/t/bnb-chain-roadmap-mainnet/936
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super recent! It wasn't the case 4 days ago: hats-finance#19 (comment)
Then s/BNB/Linea/g
: I think the point remains the same that PUSH0
isn't generally well supported across L2s:
$ curl -s https://rpc.linea.build -H 'content-type: application/json' --data '{"jsonrpc":"2.0","id":0,"method":"eth_call","params":[{"data":"0x5f"},"latest"]}'
{"jsonrpc":"2.0","id":0,"error":{"code":-32000,"message":"invalid opcode: PUSH0"}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, the forum post says it was implemented in Kepler: 2024/01/23
hardfork
// in the rest of the project without causing significant regressions to the FCL verifier, we | ||
// add a compiler setting override for that specific contract. | ||
'contracts/verifiers/FCLP256Verifier.sol': { | ||
...compilerSettings, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...compilerSettings, | |
version: compilerSettings.version, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this on purpose to future proof in case new fields were added. Agree it isn't strictly necessary here, but wanted to future proof just in case. Also it feels to convey intent a bit more IMO: we want exactly compilerSettings
except for this single value.
Pull Request Test Coverage Report for Build 9617116293Details
💛 - Coveralls |
I noticed that the IR optimizer is better for all contracts except the FCL library. This PR optimizes the compiler configuration to take advantage of the IR optimizer, while adding an exception for the FCL P-256 verifier contract so that it does not suffer any regressions.
Furthermore, we bump the compiler version to v0.8.26 as it is the lastest stable release and brings some small gas improvements.