-
Notifications
You must be signed in to change notification settings - Fork 81
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 a new logUserOperationGas function and improve user operation gas estimation #446
Add a new logUserOperationGas function and improve user operation gas estimation #446
Conversation
0b045e9
to
4305341
Compare
Pull Request Test Coverage Report for Build 9583033693Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9583999402Details
💛 - Coveralls |
732165b
to
65352d4
Compare
Pull Request Test Coverage Report for Build 9616845351Details
💛 - Coveralls |
65352d4
to
4f04ba5
Compare
c05a47c
to
4e16f66
Compare
Pull Request Test Coverage Report for Build 9646722637Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9646759500Details
💛 - Coveralls |
4e16f66
to
10f95ec
Compare
Pull Request Test Coverage Report for Build 9646992241Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9647336964Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9647423005Details
💛 - Coveralls |
f803ec3
to
e88d3d4
Compare
Pull Request Test Coverage Report for Build 9647468294Details
💛 - Coveralls |
12304ad
to
9e23b01
Compare
Pull Request Test Coverage Report for Build 9647573606Details
💛 - Coveralls |
9e23b01
to
ab61a97
Compare
Pull Request Test Coverage Report for Build 9647650551Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9647772115Details
💛 - Coveralls |
@@ -18,6 +18,6 @@ | |||
"verify": "Safe4337Module:certora/specs/TransactionExecutionMethods.spec", | |||
"packages": [ | |||
"@account-abstraction=../../node_modules/.pnpm/@account-abstraction+contracts@0.7.0/node_modules/@account-abstraction", | |||
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.12.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global" | |||
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global" |
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 didn't survive the lockfile regeneration
|
||
bytes32 dataHash = keccak256(operationData); | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
(v, r, s) = _signatureSplit(signatures); | ||
bool validSignature = owner == ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)), v - 4, r, s); | ||
|
||
validationData = _packValidationData(!validSignature, validUntil, validAfter); |
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.
Attention
I had to inline the signature validation to Safe4337Mock because the checkSignatures
function always reverted, which doesn't comply with the ERC4337 standard. It also made the simulations fail because if you use a placeholder signature, it'd just revert. Try/catch is not available for internal function calls.
I did not find any security implications, but I didn't spend much time on it since it's a mock contract.
@@ -50,27 +50,27 @@ | |||
"@account-abstraction/contracts": "^0.7.0", | |||
"@noble/curves": "^1.4.0", | |||
"@nomicfoundation/hardhat-ethers": "^3.0.6", | |||
"@nomicfoundation/hardhat-network-helpers": "^1.0.10", | |||
"@nomicfoundation/hardhat-network-helpers": "^1.0.11", |
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.
I ran into some bizzare typescript error again and did a dependency bump. It wasn't it in the end, but I decided to keep it - no breaking changes here.
actualGasUsed: parsedUserOperationEvent.args.actualGasUsed, | ||
actualGasCost: parsedUserOperationEvent.args.actualGasCost, |
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.
initially, I wanted to use those values in tests, but then I realised that the actual gas cost and paid prefund vary, so in the end, they were not needed, but IMO, it's handy to have them available, so I kept them. LMK if you disagree
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.
Makes sense to include it.
} from '../../src/utils/userOp' | ||
import { chainId, timestamp } from '../utils/encoding' | ||
import { estimateUserOperationGas } from '../utils/simulations' | ||
|
||
describe('Safe4337Mock', () => { |
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.
rewriting tests is always annoying 😅
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.
LGTM. Just some smaller nits, but nothing blocking the merge.
3f9ef43
to
105c00f
Compare
Pull Request Test Coverage Report for Build 9667332437Details
💛 - Coveralls |
eb6bc94
to
87b998a
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.
Awesomesauce.
This PR fixes #425 by introducing a new
estimateUserOperationGas
function, which runs the simulation using AA's referenceEntryPointSimulations
contract to ensure we use correct estimations for our test user operations. Previously, we set them to arbitrarily high numbers to make the tests pass. I also improved a couple of tests where we setmaxFeePerGas
to 0 by actually obtaining the prefund value the account paid for the operation.The code was mostly borrowed from the account-abstraction reference bundler and is not suitable for use in a production environment.
It also includes the
logUserOperationGas
function, which fixes the core issue of displaying the actual gas used by the user operation.Example log:
I ran into some types issues on CI and just working on the issue. I'll add a GitHub comment to each one.