-
Notifications
You must be signed in to change notification settings - Fork 164
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
🗞️ Add _options gas profiler #1099
base: main
Are you sure you want to change the base?
Conversation
This is not yet tested, do not merge. Signed-off-by: Ryan Goulding <goulding@layerzerolabs.org>
Based on some feedback and back and forth with off-chain team, I think that the scope of this can be reduced slightly. Fork testing might not even be needed if we strictly just need to predict the EVM L2 execution cost. Since L1 data fee is not something we're in a place to abstract right now, the In the future, we may have teams try to estimate the L1 data fee, but for today L2 execution cost maximum's is likely the best possible state. |
@St0rmBr3w is this ready for review or do you want to make some more updates based on your above comment? Thanks! |
In this PR:
This PR introduces a Gas Profiler for estimating the gas usage of LayerZero's
lzReceive
andlzCompose
functions. It simplifies running Foundry scripts by addingpnpm
commands that allow dynamic argument passing, making gas profiling more accessible and efficient for developers.Some limitations are that Foundry does not accurately return L1 data fees on most L2s as referenced in foundry-rs/foundry/issues/6253, so the gas units returned are only part of the profile necessary to determine enforcedOptions, but would be curious if you have any ideas on making it better / more performant.
Key Features
Commands for Gas Profiling:
gas:lzReceive
: Profiles thelzReceive
function.gas:lzCompose
: Profiles thelzCompose
function.Dynamic Arguments:
Detailed Output:
Usage Examples
lzReceive
Gas ProfilinglzCompose
Gas ProfilingBenefits
This addition enhances developer tooling for LayerZero's protocol, providing actionable insights into gas optimization for
enforcedOptions
andextraOptions
configuration.Limitations
1. Overestimation of Gas:This implementation tends to overestimate gas usage by approximately 3,000 gas units.This is most likely due to Foundry leaking memory, which causes additional gas costs for subsequent calls in the same environment stack (e.g., multiple event logs). #Memory leak in forge vm.snapshot and vm.revertTo foundry-rs/foundry#6411 (comment)EDIT: This was solved with the addition of
vm.lastCallGas()
.Custom Safety Checks:
Snapshot and Fork Dependency:Results are dependent on the snapshot or fork state at the time of execution.The gas profiling does not produce accurate results across multiple calls with different nonces. While calls execute successfully, the gas amount returned is often significantly lower, suggesting some state inconsistencies during resets.EDIT: This again is solved with the addition of
vm.lastCallGas()
.Recommendations
numOfRuns
,msgValue
, etc.) to match your specific use case for more reliable results.