From 91eb518f1c7b0225b77b6443419ec5b1d9bf23f3 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Wed, 26 Jul 2023 16:17:54 +0500 Subject: [PATCH 1/2] fallback values for gas limits during estimation --- packages/executor/src/modules/eth.ts | 63 ++++++++++--------- .../executor/src/services/UserOpValidation.ts | 6 +- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/executor/src/modules/eth.ts b/packages/executor/src/modules/eth.ts index 11fbb492..a3cc8a3a 100644 --- a/packages/executor/src/modules/eth.ts +++ b/packages/executor/src/modules/eth.ts @@ -104,6 +104,16 @@ export class Eth { ...userOp, }; + if (BigNumber.from(userOpComplemented.callGasLimit).eq(0)) { + userOpComplemented.callGasLimit = BigNumber.from(10e6); + } + if (BigNumber.from(userOpComplemented.preVerificationGas).eq(0)) { + userOpComplemented.preVerificationGas = BigNumber.from(1e6); + } + if (BigNumber.from(userOpComplemented.verificationGasLimit).eq(0)) { + userOpComplemented.verificationGasLimit = BigNumber.from(10e6); + } + if (userOpComplemented.signature === "0x") { userOpComplemented.signature = await this.getDummySignature({ userOp: userOpComplemented, @@ -111,13 +121,13 @@ export class Eth { }); } - let preVerificationGas: BigNumberish = this.calcPreVerificationGas(userOp); - userOpComplemented.preVerificationGas = preVerificationGas; - const returnInfo = await this.userOpValidationService.validateForEstimation( userOpComplemented, entryPoint ); + + let preVerificationGas: BigNumberish = this.calcPreVerificationGas(userOp); + userOpComplemented.preVerificationGas = preVerificationGas; if (this.pvgEstimator) { preVerificationGas = await this.pvgEstimator( entryPoint, @@ -132,34 +142,26 @@ export class Eth { let callGasLimit: BigNumber = BigNumber.from(0); // calculate callGasLimit based on paid fee - // only for undeployed wallets - if (BigNumber.from(userOp.nonce).eq(0)) { - const block = await this.provider.getBlock("latest"); - const { estimationBaseFeeDivisor, estimationStaticBuffer } = this.config; - const estimatedBaseFee = block.baseFeePerGas - ?.mul(100) - .div(100 + (estimationBaseFeeDivisor || 0)); - - if (!estimatedBaseFee) { - callGasLimit = BigNumber.from(paid).div( - userOpComplemented.maxFeePerGas - ); - } else { - const lhs = BigNumber.from(userOpComplemented.maxFeePerGas); - const rhs = estimatedBaseFee.add( - userOpComplemented.maxPriorityFeePerGas - ); - const divisor = lhs.lt(rhs) ? lhs : rhs; // min(maxFeePerGas, base + priorityFee) - callGasLimit = BigNumber.from(paid).div(divisor); - } - callGasLimit = callGasLimit - .sub(preOpGas) - .add(estimationStaticBuffer || 0); + const block = await this.provider.getBlock("latest"); + const { estimationBaseFeeDivisor, estimationStaticBuffer } = this.config; + const estimatedBaseFee = block.baseFeePerGas + ?.mul(100) + .div(100 + (estimationBaseFeeDivisor || 0)); + + if (!estimatedBaseFee) { + callGasLimit = BigNumber.from(paid).div(userOpComplemented.maxFeePerGas); + } else { + const lhs = BigNumber.from(userOpComplemented.maxFeePerGas); + const rhs = estimatedBaseFee.add(userOpComplemented.maxPriorityFeePerGas); + const divisor = lhs.lt(rhs) ? lhs : rhs; // min(maxFeePerGas, base + priorityFee) + callGasLimit = BigNumber.from(paid).div(divisor); + } + callGasLimit = callGasLimit.sub(preOpGas).add(estimationStaticBuffer || 0); - if (callGasLimit.lt(0)) { - callGasLimit = BigNumber.from(estimationStaticBuffer || 0); - } + if (callGasLimit.lt(0)) { + callGasLimit = BigNumber.from(estimationStaticBuffer || 0); } + // } //< checking for execution revert const estimatedCallGasLimit = await this.provider @@ -175,7 +177,8 @@ export class Eth { }); //> - // if wallet is deployed it's better to use more precise estimateGas + // if calculation on paid fee failed + // fallback to estimateGas if (callGasLimit.eq(0)) { callGasLimit = estimatedCallGasLimit; } diff --git a/packages/executor/src/services/UserOpValidation.ts b/packages/executor/src/services/UserOpValidation.ts index ae570330..63015778 100644 --- a/packages/executor/src/services/UserOpValidation.ts +++ b/packages/executor/src/services/UserOpValidation.ts @@ -75,8 +75,6 @@ export class UserOpValidationService { userOp: UserOperationStruct, entryPoint: string ): Promise { - const { validationGasLimit } = this.networkConfig; - const entryPointContract = EntryPoint__factory.connect( entryPoint, this.provider @@ -91,9 +89,7 @@ export class UserOpValidationService { }; const errorResult = await entryPointContract.callStatic - .simulateHandleOp(userOp, AddressZero, BytesZero, { - gasLimit: validationGasLimit, - }) + .simulateHandleOp(userOp, AddressZero, BytesZero) .catch((e: any) => this.nethermindErrorHandler(entryPointContract, e)); if (errorResult.errorName === "FailedOp") { From 7e662982340c8406b88ca414eb25c40cc7c53d89 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Wed, 26 Jul 2023 16:19:35 +0500 Subject: [PATCH 2/2] chore(release): v0.0.22 --- lerna.json | 2 +- package.json | 2 +- packages/api/package.json | 6 +++--- packages/cli/package.json | 10 +++++----- packages/db/package.json | 4 ++-- packages/executor/package.json | 6 +++--- packages/params/package.json | 4 ++-- packages/types/package.json | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lerna.json b/lerna.json index cd55fe42..ddc64551 100644 --- a/lerna.json +++ b/lerna.json @@ -4,7 +4,7 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "0.0.21", + "version": "0.0.22", "stream": "true", "command": { "version": { diff --git a/package.json b/package.json index 28ebed00..4756ba0e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "root", "private": true, - "version": "0.0.21", + "version": "0.0.22", "engines": { "node": ">=18.0.0" }, diff --git a/packages/api/package.json b/packages/api/package.json index 28ac4217..80317ed9 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "0.0.21", + "version": "0.0.22", "description": "The API module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -35,12 +35,12 @@ "class-transformer": "0.5.1", "class-validator": "0.14.0", "ethers": "5.7.2", - "executor": "^0.0.21", + "executor": "^0.0.22", "fastify": "4.14.1", "pino": "8.11.0", "pino-pretty": "10.0.0", "reflect-metadata": "0.1.13", - "types": "^0.0.21" + "types": "^0.0.22" }, "devDependencies": { "@types/connect": "3.4.35" diff --git a/packages/cli/package.json b/packages/cli/package.json index 5cf28924..c39f713d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "cli", - "version": "0.0.21", + "version": "0.0.22", "description": "> TODO: description", "author": "zincoshine ", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -31,13 +31,13 @@ "url": "https://https://github.com/etherspot/skandha/issues" }, "dependencies": { - "api": "^0.0.21", - "db": "^0.0.21", - "executor": "^0.0.21", + "api": "^0.0.22", + "db": "^0.0.22", + "executor": "^0.0.22", "find-up": "5.0.0", "got": "12.5.3", "js-yaml": "4.1.0", - "types": "^0.0.21", + "types": "^0.0.22", "yargs": "17.6.2" }, "devDependencies": { diff --git a/packages/db/package.json b/packages/db/package.json index 79f898ee..87e5c91e 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "db", - "version": "0.0.21", + "version": "0.0.22", "description": "The DB module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://github.com/etherspot/etherspot-bundler#readme", @@ -37,6 +37,6 @@ "devDependencies": { "@types/rocksdb": "3.0.1", "prettier": "^2.8.4", - "types": "^0.0.21" + "types": "^0.0.22" } } diff --git a/packages/executor/package.json b/packages/executor/package.json index 0ecbee59..8965892e 100644 --- a/packages/executor/package.json +++ b/packages/executor/package.json @@ -1,6 +1,6 @@ { "name": "executor", - "version": "0.0.21", + "version": "0.0.22", "description": "The Relayer module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -33,7 +33,7 @@ "dependencies": { "async-mutex": "0.4.0", "ethers": "5.7.2", - "params": "^0.0.21", - "types": "^0.0.21" + "params": "^0.0.22", + "types": "^0.0.22" } } diff --git a/packages/params/package.json b/packages/params/package.json index 444024e8..ad5b8530 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -1,6 +1,6 @@ { "name": "params", - "version": "0.0.21", + "version": "0.0.22", "description": "Various bundler parameters", "author": "Etherspot", "homepage": "https://github.com/etherspot/skandha#readme", @@ -24,7 +24,7 @@ "@arbitrum/sdk": "3.1.4", "@eth-optimism/sdk": "3.0.0", "ethers": "5.7.2", - "types": "^0.0.21" + "types": "^0.0.22" }, "scripts": { "clean": "rm -rf lib && rm -f *.tsbuildinfo", diff --git a/packages/types/package.json b/packages/types/package.json index 9029e022..f81f8a30 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "types", - "version": "0.0.21", + "version": "0.0.22", "description": "The types of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme",