Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Oct 10, 2023
1 parent 7c9ecc8 commit 6f53769
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 57 deletions.
2 changes: 1 addition & 1 deletion packages/bundler/src/RpcTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumberish } from 'ethers'
import { TransactionReceipt } from '@ethersproject/providers'
import { UserOperation } from './modules/Types'
import { UserOperation } from '@account-abstraction/utils'

/**
* RPC calls return types
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler/src/UserOpMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { deepHexlify, erc4337RuntimeVersion, requireCond, RpcError, tostr, getAd
import { UserOperationStruct, EntryPoint } from '@account-abstraction/contracts'
import { UserOperationEventEvent } from '@account-abstraction/contracts/dist/types/EntryPoint'
import { calcPreVerificationGas } from '@account-abstraction/sdk'
import { UserOperation } from '@account-abstraction/utils'
import { ExecutionManager } from './modules/ExecutionManager'
import { UserOperationByHashResponse, UserOperationReceipt } from './RpcTypes'
import { ExecutionErrors, UserOperation } from './modules/Types'

const HEX_REGEX = /^0x[a-fA-F\d]*$/i

Expand Down Expand Up @@ -131,7 +131,7 @@ export class UserOpMethodHandler {
data: userOp.callData
}).then(b => b.toNumber()).catch(err => {
const message = err.message.match(/reason="(.*?)"/)?.at(1) ?? 'execution reverted'
throw new RpcError(message, ExecutionErrors.UserOperationReverted)
throw new RpcError(message, ValidationErrors.UserOperationReverted)
})
validAfter = BigNumber.from(validAfter)
validUntil = BigNumber.from(validUntil)
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Debug from 'debug'
import { ReputationManager, ReputationStatus } from './ReputationManager'
import { Mutex } from 'async-mutex'
import { GetUserOpHashes__factory } from '../types'
import { UserOperation } from './Types'
import { StorageMap, getAddr, mergeStorageMap, runContractScript } from '@account-abstraction/utils'
import { UserOperation, StorageMap, getAddr, mergeStorageMap, runContractScript } from '@account-abstraction/utils'
import { EventsManager } from './EventsManager'
import { ErrorDescription } from '@ethersproject/abi/lib/interface'

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/modules/ExecutionManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Debug from 'debug'
import { Mutex } from 'async-mutex'
import { ValidationManager } from '@account-abstraction/validation-manager'
import { UserOperation } from '@account-abstraction/utils'
import { clearInterval } from 'timers'

import { BundleManager, SendBundleReturn } from './BundleManager'
import { MempoolManager } from './MempoolManager'
import { ReputationManager } from './ReputationManager'
import { UserOperation } from './Types'

const debug = Debug('aa.exec')

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/modules/MempoolManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@account-abstraction/utils'
import { ReputationManager } from './ReputationManager'
import Debug from 'debug'
import { UserOperation } from './Types'
import { UserOperation } from '@account-abstraction/utils'

const debug = Debug('aa.mempool')

Expand Down
34 changes: 0 additions & 34 deletions packages/bundler/src/modules/Types.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Signer } from 'ethers'
import { BundlerConfig } from '../BundlerConfig'
import { EventsManager } from './EventsManager'
import { getNetworkProvider } from '../Config'
import { abi } from './Types'

/**
* initialize server modules.
Expand All @@ -21,7 +20,7 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
const entryPoint = EntryPoint__factory.connect(config.entryPoint, signer)
const reputationManager = new ReputationManager(getNetworkProvider(config.network), BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolManager = new MempoolManager(reputationManager)
const validationManager = new ValidationManager(entryPoint, config.unsafe, abi)
const validationManager = new ValidationManager(entryPoint, config.unsafe)
const eventsManager = new EventsManager(entryPoint, mempoolManager, reputationManager)
const bundleManager = new BundleManager(entryPoint, eventsManager, mempoolManager, validationManager, reputationManager,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler/test/BundlerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { assert, expect } from 'chai'
import { BundlerReputationParams, ReputationManager } from '../src/modules/ReputationManager'
import { AddressZero, getUserOpHash } from '@account-abstraction/utils'

import { supportsDebugTraceCall } from '@account-abstraction/validation-manager'
import { ValidationManager, supportsDebugTraceCall } from '@account-abstraction/validation-manager'
import { DeterministicDeployer } from '@account-abstraction/sdk'
import { MempoolManager } from '../src/modules/MempoolManager'
import { BundleManager } from '../src/modules/BundleManager'
import { ethers } from 'hardhat'
import { BundlerConfig } from '../src/BundlerConfig'
import { ValidationManager } from '../../validation-manager/src/ValidationManager'
import { TestFakeWalletToken__factory } from '../src/types'
import { UserOperation } from '../src/modules/Types'
import { UserOpMethodHandler } from '../src/UserOpMethodHandler'
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/test/UserOpMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
TestRulesAccount,
TestRulesAccount__factory
} from '../src/types'
import { ValidationManager } from '@account-abstraction/validation-manager'
import { resolveHexlify, waitFor } from '@account-abstraction/utils'
import { UserOperationEventEvent } from '@account-abstraction/contracts/dist/types/EntryPoint'
import { UserOperationReceipt } from '../src/RpcTypes'
import { ExecutionManager } from '../src/modules/ExecutionManager'
import { BundlerReputationParams, ReputationManager } from '../src/modules/ReputationManager'
import { MempoolManager } from '../src/modules/MempoolManager'
import { ValidationManager } from '../../validation-manager/src/ValidationManager'
import { BundleManager } from '../src/modules/BundleManager'
import { supportsDebugTraceCall } from '@account-abstraction/validation-manager'
import { UserOpMethodHandler } from '../src/UserOpMethodHandler'
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum ValidationErrors {
InsufficientStake = -32505,
UnsupportedSignatureAggregator = -32506,
InvalidSignature = -32507,
UserOperationReverted = -32521
}

export interface ReferencedCodeHashes {
Expand Down
2 changes: 1 addition & 1 deletion packages/validation-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import { UserOperation } from '@account-abstraction/utils'
import { checkRulesViolations } from '@account-abstraction/validation-manager'

const userOperation: UserOperation = createUserOp()
checkRulesViolations(provider, userOperation, entryPoint)
await checkRulesViolations(provider, userOperation, entryPoint)
```
24 changes: 17 additions & 7 deletions packages/validation-manager/src/TracerResultParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IEntryPoint,
IAccount__factory,
IPaymaster__factory,
SenderCreator__factory
SenderCreator__factory, IEntryPoint__factory
} from '@account-abstraction/contracts'
import { BundlerTracerResult } from './BundlerCollectorTracer'
import {
Expand All @@ -34,6 +34,19 @@ interface CallEntry {
value?: BigNumberish
}

const abi = Object.values([
...SenderCreator__factory.abi,
...IEntryPoint__factory.abi,
...IPaymaster__factory.abi
].reduce((set, entry) => {
const key = `${entry.name}(${entry.inputs.map(i => i.type).join(',')})`
// console.log('key=', key, keccak256(Buffer.from(key)).slice(0,10))
return {
...set,
[key]: entry
}
}, {})) as any

/**
* parse all call operation in the trace.
* notes:
Expand All @@ -43,8 +56,7 @@ interface CallEntry {
* @param abi
*/
function parseCallStack (
tracerResults: BundlerTracerResult,
abi: any[] = []
tracerResults: BundlerTracerResult
): CallEntry[] {
const xfaces = new Interface(abi)

Expand Down Expand Up @@ -164,15 +176,13 @@ const callsFromEntryPointMethodSigs: { [key: string]: string } = {
* @param tracerResults the tracer return value
* @param validationResult output from simulateValidation
* @param entryPoint the entryPoint that hosted the "simulatedValidation" traced call.
* @param abi
* @return list of contract addresses referenced by this UserOp
*/
export function tracerResultParser (
userOp: UserOperation,
tracerResults: BundlerTracerResult,
validationResult: ValidationResult,
entryPoint: IEntryPoint,
abi: any[] = []
entryPoint: IEntryPoint
): [string[], StorageMap] {
debug('=== simulation result:', inspect(tracerResults, true, 10, true))
// todo: block access to no-code addresses (might need update to tracer)
Expand All @@ -185,7 +195,7 @@ export function tracerResultParser (
if (Object.values(tracerResults.callsFromEntryPoint).length < 1) {
throw new Error('Unexpected traceCall result: no calls from entrypoint.')
}
const callStack = parseCallStack(tracerResults, abi)
const callStack = parseCallStack(tracerResults)

const callInfoEntryPoint = callStack.find(call =>
call.to === entryPointAddress && call.from !== entryPointAddress &&
Expand Down
5 changes: 2 additions & 3 deletions packages/validation-manager/src/ValidationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const HEX_REGEX = /^0x[a-fA-F\d]*$/i
export class ValidationManager {
constructor (
readonly entryPoint: IEntryPoint,
readonly unsafe: boolean,
readonly abi: any[] = []
readonly unsafe: boolean
) {}

// standard eth_call to simulateValidation
Expand Down Expand Up @@ -196,7 +195,7 @@ export class ValidationManager {
let tracerResult: BundlerTracerResult
[res, tracerResult] = await this._geth_traceCall_SimulateValidation(userOp)
let contractAddresses: string[]
[contractAddresses, storageMap] = tracerResultParser(userOp, tracerResult, res, this.entryPoint, this.abi)
[contractAddresses, storageMap] = tracerResultParser(userOp, tracerResult, res, this.entryPoint)
// if no previous contract hashes, then calculate hashes of contracts
if (previousCodeHashes == null) {
codeHashes = await this.getCodeHashes(contractAddresses)
Expand Down

0 comments on commit 6f53769

Please sign in to comment.