-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] adjust additionalGasUsed calculation + gas measurement docs #20
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
base: main
Are you sure you want to change the base?
Conversation
32dc376
to
daa69e6
Compare
int256 a11; | ||
int256 a12; | ||
int256 a13; | ||
int256 a14; | ||
int256 a21; | ||
int256 a22; | ||
int256 a23; | ||
int256 a24; | ||
int256 a31; | ||
int256 a32; | ||
int256 a33; | ||
int256 a34; | ||
int256 a41; | ||
int256 a42; | ||
int256 a43; | ||
int256 a44; |
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.
just curiosity why not use fixed size array?
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.
actually, we can use fixed-size arrays.
I just think that writing m.a12 is a little shorter than m[1][2] and avoids indexing out of bounds (dimensional safety).
RegressionTestHelper.Quadratic memory quad = RegressionTestHelper | ||
.quadratic(trainingSet); | ||
require(quad.c2 > 0 && quad.c1 > 0 && quad.c0 > 0, "bad quad fit"); |
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.
why do we call this bad quad fit? can we use negative coeff to have a better fit?
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.
allowing negative values violates physical priors based on the overhead per byte cost (linear) and memory expansion (quadratic)
function unpackCoeffs( | ||
uint256 packed | ||
) public pure returns (uint256 c2, uint256 c1, uint256 c0) { |
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.
can coeff be a negative? why not?
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.
they can be negative if the training calldata is overwhelmed by noise (a lot of '0')
however, they should not be negative in theory
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.
is it linear though? (also L1)
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.
The total gas on L2 is made up of L1 and L2 gas. In the experiment, the gas on L2 is strongly linear, despite the fact that memory expansion should still occur, but its effect on L2 is insignificant.
However, the behavior of L1 gas on L2 is linear, but the maximum error can be large due to the unknown behavior of the compression algorithm and the calldata itself.
@@ -0,0 +1,1938 @@ | |||
# Estimating Tunnel Relay Gas | |||
|
|||
This document explains the **Foundry** test design, the **polynomial models** (linear / quadratic / cubic), the **Monte-Carlo** validation, and the **conclusions** for the on-chain environment. |
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.
is it Monte-Carlo validation?
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.
yes
a3af018
to
ae2ffc4
Compare
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.
Pull Request Overview
This PR introduces a comprehensive overhaul of gas calculation for relay operations, replacing the previous constant additionalGasUsed with a dynamic quadratic model based on calldata size. It includes extensive documentation, test infrastructure, and calibration mechanisms.
- Replaces constant gas overhead with a quadratic model based on calldata size
- Adds comprehensive gas measurement test infrastructure and regression analysis
- Introduces detailed documentation explaining the mathematical modeling approach
Reviewed Changes
Copilot reviewed 16 out of 27 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/router/L1RouterGasCalculator.sol | New contract implementing quadratic gas calculation model with packed coefficients |
src/router/BaseTunnelRouter.sol | Updated to use dynamic gas calculation instead of constant additionalGasUsed |
test/RelayGasMeasurementTest.t.sol | Comprehensive test suite for measuring and validating gas usage patterns |
test/helper/RegressionTestHelper.sol | Mathematical library for polynomial regression analysis |
docs/contracts/05-relaygasused.md | Extensive documentation of gas measurement methodology and analysis |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.