Skip to content
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

feat(simulation): v0.7 call gas estimation #663

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

dphilipson
Copy link
Collaborator

Factors out the call gas estimation logic, which performs a binary search using the target and targetData arguments to simulateHandleOp along with some state override trickery, into a new trait, CallGasEstimator, then provides implementations for v0.6 and v0.7.

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 66.51982% with 76 lines in your changes are missing coverage. Please review.

Project coverage is 53.24%. Comparing base (4c59307) to head (e4b7f39).

Additional details and impacted files

Impacted file tree graph

Files Coverage Δ
crates/pool/src/chain.rs 94.78% <100.00%> (ø)
crates/rpc/src/eth/api.rs 74.20% <100.00%> (ø)
crates/rpc/src/task.rs 0.00% <ø> (ø)
crates/sim/src/estimation/mod.rs 80.00% <ø> (ø)
crates/sim/src/estimation/v0_6.rs 93.90% <100.00%> (+0.92%) ⬆️
crates/sim/src/simulation/v0_6/context.rs 65.58% <ø> (ø)
crates/types/src/user_operation/v0_6.rs 97.14% <ø> (+0.95%) ⬆️
crates/types/src/user_operation/v0_7.rs 45.48% <ø> (ø)
crates/types/src/validation_results.rs 26.95% <ø> (ø)
crates/rpc/src/eth/events/v0_6.rs 17.85% <66.66%> (ø)
... and 6 more
Flag Coverage Δ
unit-tests 53.24% <66.51%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
rundler binary 0.00% <0.00%> (ø)
builder 50.21% <ø> (ø)
dev 0.00% <0.00%> (ø)
pool 64.87% <100.00%> (ø)
provider 8.12% <0.00%> (-0.06%) ⬇️
rpc 27.88% <75.00%> (+0.18%) ⬆️
sim 73.36% <72.00%> (-0.30%) ⬇️
tasks ∅ <ø> (∅)
types 59.51% <ø> (+0.18%) ⬆️
utils 18.28% <ø> (ø)

@dphilipson dphilipson force-pushed the dp/0.7-call-gas-estimation branch 2 times, most recently from f112a84 to 05003dd Compare April 4, 2024 06:02
@@ -0,0 +1,1484 @@
/// Bytecode of the deployed v0.6 entry point, retrieved from on-chain
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be able to get this from our compiled contracts instead of including in a file?

Copy link
Collaborator Author

@dphilipson dphilipson Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually compile EntryPoint at the moment, only IEntryPoint for its ABI, although that would be easy enough to change. But also doing it this way means we get the same bytecode as the deployed entry point, whereas if we compile it ourselves the bytecode won't match because we won't have the same compiler settings, which could lead to minor differences in gas estimation.

I don't think it matters too much either way. Happy to switch to our compiled version if you prefer. That would have the advantage of reducing the Git repo size.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have the same imperfect match issue with v0.7 right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but in 0.7 we're using a state overriden EntryPointSimulations instead of EntryPoint and there is no canonical bytecode for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's sort of what I was referring to, since EntryPointSimulations contains the EntryPoint code and we're compiling it. Would prefer we keep this the same way across both EPs.

Although I did just notice we already have this https://github.com/alchemyplatform/rundler/blob/main/crates/types/contracts/bytecode/entrypoint/0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789.txt

So at a minimum we should dedup and use that

Copy link
Collaborator

@dancoombs dancoombs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work again. Awesome to see that we can reuse all of this logic between the entrypoints with pretty simple abstractions.

@dphilipson dphilipson force-pushed the dp/0.7-gas-estimation branch 3 times, most recently from 31cf334 to a61a95b Compare April 12, 2024 07:49
@dphilipson dphilipson force-pushed the dp/0.7-call-gas-estimation branch 2 times, most recently from a6e5da9 to 6e93036 Compare April 15, 2024 03:20
@dphilipson
Copy link
Collaborator Author

dphilipson commented Apr 15, 2024

I don't understand what is happening in this PR. The PR is showing added files like estimate_verification_gas.rs, but the PR target is dp/0.7-gas-estimation which already has that file.

Edit: Got it fixed, not sure what was wrong.

@dphilipson dphilipson force-pushed the dp/0.7-call-gas-estimation branch from 6e93036 to 13e81ab Compare April 15, 2024 03:35
@dphilipson dphilipson force-pushed the dp/0.7-gas-estimation branch from a61a95b to 73c9654 Compare April 15, 2024 05:27
@dphilipson dphilipson force-pushed the dp/0.7-call-gas-estimation branch from 13e81ab to 67e1d55 Compare April 15, 2024 05:48
Copy link
Collaborator

@0xfourzerofour 0xfourzerofour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! great work on this @dphilipson

Factors out the call gas estimation logic, which performs a binary
search using the `target` and `targetData` arguments to
`simulateHandleOp` along with some state override trickery, into a new
trait, `CallGasEstimator`, then provides implementations for v0.6 and
v0.7.
Rather than hardcoding v0.6 entry point bytecode in two places, one with
the init code and one with the deployed code, use abigen to generate
Rust code for the v0.6 `EntryPoint.sol` and use the bytecode that was
generated.

This makes v0.6 `IEntryPoint.sol` unnecessary, to remove it and convert
all occurrences of `v0_6::i_entry_point::IEntryPoint` to
`v0_6::entry_point::EntryPoint`.
@dphilipson dphilipson force-pushed the dp/0.7-call-gas-estimation branch from b4cbd03 to e4b7f39 Compare April 16, 2024 01:20
@dphilipson dphilipson merged commit 8bb336a into dp/0.7-gas-estimation Apr 16, 2024
8 checks passed
@dphilipson dphilipson deleted the dp/0.7-call-gas-estimation branch April 16, 2024 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants