-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix(gas): improve bundle gas estimation calculation #444
Conversation
Codecov Report
... and 4 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
e3dcad3
to
774cfa1
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.
Good job! that math seems accurate to me
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 🔥 . Math LGTM. Want to see this in action during our load tests ASAP.
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 base branch was changed.
899206a
to
04c9c75
Compare
Contributes to #349
Proposed Changes
Improve the bundle gas limit calculation. The bundle gas limit we now use is based off the following observation:
In the Entrypoint contract, the
innerHandleOp
call has this check that the bundle would need to pass for every single user op that it executes.Within a bundle, let$p_i$ , $v_i$ , and $c_i$ be the static pre-verification gas, verification gas limit, and call gas limit of user operation $i$ . Also let $m_i$ be $1$ if user op $i$ uses a paymaster, and $0$ if not. Suppose we start with initial gas $g$ . When processing user op $i$ , at the point of the the $i$ , and the check requires that at that point the remaining gas be greater than $c_i+v_i+5000$ . If user op $i$ uses a paymaster, because of the $c_i+2v_i$ , since the up to two $v_i$ gas.
innerHandleOp
check we have yet to execute the call for user oppostOp
calls, we would also need the remaining gas to also be greater thanpostOp
calls can each use upWe can express this condition as:
The worst case remaining gas at this check for user operation$i$ , since we have already processed user ops $1$ through $i-1$ and both the pre-verification gas and up to the verification gas limit of user op $i$ , is:
$$g-\sum_{j=1}^{i-1}\big(p_j+(1+2m_j)v_j+c_j\big)-p_i-v_i$$
In order to not run out of gas and pass all the checks, we would therefore need that for all$i$ :
$$g\geq \sum_{j=1}^{i-1}\big(p_j+(1+2m_j)v_j+c_j\big)+p_i+2v_i+c_i+5000+m_i \max(v_i-5000,0)$$
so the smallest initial gas limit we can assign the bundle would be the max over all$i$ of the right hand side of the inequality.