-
Notifications
You must be signed in to change notification settings - Fork 175
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 <[email protected]>
Signed-off-by: Ryan Goulding <[email protected]>
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! |
I would say we're ready to review this. |
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#6253](foundry-rs/foundry#6253), so the gas units returned are only part of the profile necessary to determine
enforcedOptions
. However, this is acceptable for LayerZero options, as the L1 data fee is handled by the Executor and added to the fee charged on the source chain for the provision of gas resources.Additionally, accurate testing requires supplying different types of payload conditions to the script.
Key Features
Commands for Gas Profiling:
gas:lzReceive
: Profiles thelzReceive
function.gas:lzCompose
: Profiles thelzCompose
function.Dynamic Arguments:
Detailed Output:
Payload Condition Testing:
Extended Script Functionality:
Usage Examples
lzReceive
Gas ProfilinglzCompose
Gas ProfilingExtending the Profiler with Foundry Methods
In addition to the provided
pnpm
commands, you can extend the existing script as demonstrated in theOFTProfilerExample
. This allows you to simulate payload generation using Foundry methods and pass multiple scenarios to the profiler to determine the optimal gas for your_options
parameter.Important Notes:
Optimal Gas Allocation:
Use the highest returned gas usage for
enforcedOptions
to prevent edge cases where calls revert due to insufficient gas being supplied.Custom
msgTypes
:Add custom
msgTypes
to your_options
to specify gas requirements for different types of send function calls, enhancing the precision of gas profiling.Benefits
enforcedOptions
andextraOptions
, preventing edge cases where calls might revert due to insufficient gas.Limitations
Custom Safety Checks:
L1 Data Fees Exclusion:
zk Chains Consideration:
Payload Condition Testing:
Recommendations
Use Private RPCs:
Adjust Test Parameters:
numOfRuns
andmsgValue
to match your specific use case for more reliable results.Validate Custom Logic:
Benefits of the Updates
Clarity in Gas Analysis:
By excluding L1 data fees, developers can focus solely on L2 execution costs, simplifying optimization efforts.
Comprehensive Testing:
Supporting diverse payload conditions ensures that gas profiling covers a wide range of real-world scenarios, leading to more robust and reliable results.
Specialized zk Chain Support:
Addressing zk chains separately with zk-foundry ensures accurate profiling without interference from other profiling processes.
Enhanced Gas Optimization:
Utilizing the highest gas usage metrics for
enforcedOptions
helps prevent transaction reverts due to insufficient gas, ensuring smoother operations.