From 9380c0aaa6a97a64f0b7ba902115b6196eeb90d0 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Wed, 14 Feb 2024 19:10:59 +0500 Subject: [PATCH] feat: aa51 validation rule --- .github/workflows/bundler-spec-tests.yml | 2 +- .../BundlingService/relayers/classic.ts | 3 +++ .../UserOpValidation/validators/safe.ts | 13 +++++++++++ .../UserOpValidation/validators/unsafe.ts | 23 +++++++++++++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bundler-spec-tests.yml b/.github/workflows/bundler-spec-tests.yml index 4bfc23c8..dfcd38f5 100644 --- a/.github/workflows/bundler-spec-tests.yml +++ b/.github/workflows/bundler-spec-tests.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v3 with: repository: eth-infinitism/bundler-spec-tests - ref: f01eb0f44287b981a953a742a42bcd6a719c8812 + ref: 85f39e8d86afe616b885c1498e29dd71c5108a70 path: ./bundler-spec-tests submodules: true diff --git a/packages/executor/src/services/BundlingService/relayers/classic.ts b/packages/executor/src/services/BundlingService/relayers/classic.ts index 0243620c..bb24f5d8 100644 --- a/packages/executor/src/services/BundlingService/relayers/classic.ts +++ b/packages/executor/src/services/BundlingService/relayers/classic.ts @@ -161,6 +161,9 @@ export class ClassicRelayer extends BaseRelayer { } else { await relayer .sendTransaction(transaction) + .then((response) => { + this.logger.debug(`Bundle submitted: ${response.hash}`); + }) .catch((err: any) => this.handleUserOpFail(entries, err)); await this.mempoolService.removeAll(entries); } diff --git a/packages/executor/src/services/UserOpValidation/validators/safe.ts b/packages/executor/src/services/UserOpValidation/validators/safe.ts index d463a5ed..bcf5bdcc 100644 --- a/packages/executor/src/services/UserOpValidation/validators/safe.ts +++ b/packages/executor/src/services/UserOpValidation/validators/safe.ts @@ -138,6 +138,19 @@ export class SafeValidationService { } } + const verificationCost = BigNumber.from(returnInfo.preOpGas).sub( + userOp.preVerificationGas + ); + const extraGas = BigNumber.from(userOp.verificationGasLimit) + .sub(verificationCost) + .toNumber(); + if (extraGas < 2000) { + throw new RpcError( + `verificationGas should have extra 2000 gas. has only ${extraGas}`, + RpcErrorCodes.VALIDATION_FAILED + ); + } + let hash = "", addresses: string[] = []; try { diff --git a/packages/executor/src/services/UserOpValidation/validators/unsafe.ts b/packages/executor/src/services/UserOpValidation/validators/unsafe.ts index 63641301..3834daca 100644 --- a/packages/executor/src/services/UserOpValidation/validators/unsafe.ts +++ b/packages/executor/src/services/UserOpValidation/validators/unsafe.ts @@ -1,7 +1,9 @@ import { IEntryPoint__factory } from "types/lib/executor/contracts"; import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; -import { providers } from "ethers"; +import { BigNumber, providers } from "ethers"; import { Logger } from "types/lib"; +import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes"; +import RpcError from "types/lib/api/errors/rpc-error"; import { NetworkConfig, UserOpValidationResult } from "../../../interfaces"; import { nonGethErrorHandler, parseErrorResult } from "../utils"; @@ -26,6 +28,23 @@ export class UnsafeValidationService { gasLimit: validationGasLimit, }) .catch((e: any) => nonGethErrorHandler(entryPointContract, e)); - return parseErrorResult(userOp, errorResult); + const validationResult = parseErrorResult(userOp, errorResult); + + const { returnInfo } = validationResult; + + const verificationCost = BigNumber.from(returnInfo.preOpGas).sub( + userOp.preVerificationGas + ); + const extraGas = BigNumber.from(userOp.verificationGasLimit) + .sub(verificationCost) + .toNumber(); + if (extraGas < 2000) { + throw new RpcError( + `verificationGas should have extra 2000 gas. has only ${extraGas}`, + RpcErrorCodes.VALIDATION_FAILED + ); + } + + return validationResult; } }