Skip to content

Commit

Permalink
Enable configuring PVG calculation overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Oct 1, 2024
1 parent 033e568 commit 32b21c2
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 81 deletions.
25 changes: 24 additions & 1 deletion packages/bundler/src/BundlerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import ow from 'ow'
// RIP-7560 EntyPoint address
const MIN_UNSTAKE_DELAY = 86400
const MIN_STAKE_VALUE = 1e18.toString()

export interface BundlerConfig {
chainId: number
beneficiary: string
entryPoint: string
gasFactor: string
Expand All @@ -27,10 +29,21 @@ export interface BundlerConfig {
rip7560: boolean
rip7560Mode: string
gethDevMode: boolean

// Config overrides for PreVerificationGas calculation
fixedGasOverhead?: number
perUserOpGasOverhead?: number
perUserOpWordGasOverhead?: number
zeroByteGasCost?: number
nonZeroByteGasCost?: number
expectedBundleSize?: number
estimationSignatureSize?: number
estimationPaymasterDataSize?: number
}

// TODO: implement merging config (args -> config.js -> default) and runtime shape validation
export const BundlerConfigShape = {
chainId: ow.number,
beneficiary: ow.string,
entryPoint: ow.string,
gasFactor: ow.string,
Expand All @@ -52,7 +65,17 @@ export const BundlerConfigShape = {
autoBundleMempoolSize: ow.number,
rip7560: ow.boolean,
rip7560Mode: ow.string.oneOf(['PULL', 'PUSH']),
gethDevMode: ow.boolean
gethDevMode: ow.boolean,

// Config overrides for PreVerificationGas calculation
fixedGasOverhead: ow.optional.number,
perUserOpGasOverhead: ow.optional.number,
perUserOpWordGasOverhead: ow.optional.number,
zeroByteGasCost: ow.optional.number,
nonZeroByteGasCost: ow.optional.number,
expectedBundleSize: ow.optional.number,
estimationSignatureSize: ow.optional.number,
estimationPaymasterDataSize: ow.optional.number
}

// TODO: consider if we want any default fields at all
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { BundleManagerRIP7560 } from './BundleManagerRIP7560'
import { IBundleManager } from './IBundleManager'
import { DepositManager } from './DepositManager'
import { IRip7560StakeManager__factory } from '@account-abstraction/utils/dist/src/types'
import { PreVerificationGasCalculator } from '@account-abstraction/sdk'
import { PreVerificationGasCalculator, ChainConfigs } from '@account-abstraction/sdk'

/**
* initialize server modules.
Expand All @@ -33,7 +33,8 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
const reputationManager = new ReputationManager(getNetworkProvider(config.network), BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolManager = new MempoolManager(reputationManager)
const eventsManager = new EventsManager(entryPoint, mempoolManager, reputationManager)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const mergedPvgcConfig = Object.assign({}, ChainConfigs[config.chainId] ?? {}, config)
const preVerificationGasCalculator = new PreVerificationGasCalculator(mergedPvgcConfig)
let validationManager: IValidationManager
let bundleManager: IBundleManager
if (!config.rip7560) {
Expand Down
8 changes: 5 additions & 3 deletions packages/bundler/test/BundlerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UserOperation,
deployEntryPoint, IEntryPoint, DeterministicDeployer
} from '@account-abstraction/utils'
import { PreVerificationGasCalculator, MainnetConfig } from '@account-abstraction/sdk'

import { ValidationManager, supportsDebugTraceCall } from '@account-abstraction/validation-manager'
import { MempoolManager } from '../src/modules/MempoolManager'
Expand All @@ -22,7 +23,6 @@ import { ExecutionManager } from '../src/modules/ExecutionManager'
import { EventsManager } from '../src/modules/EventsManager'
import { createSigner } from './testUtils'
import { DepositManager } from '../src/modules/DepositManager'
import { PreVerificationGasCalculator } from '@account-abstraction/sdk'

describe('#BundlerManager', () => {
let bm: BundleManager
Expand All @@ -37,6 +37,7 @@ describe('#BundlerManager', () => {
DeterministicDeployer.init(provider)

const config: BundlerConfig = {
chainId: 1337,
beneficiary: await signer.getAddress(),
entryPoint: entryPoint.address,
gasFactor: '0.2',
Expand All @@ -60,7 +61,7 @@ describe('#BundlerManager', () => {

const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
bm = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('#BundlerManager', () => {
const bundlerSigner = await createSigner()
const _entryPoint = entryPoint.connect(bundlerSigner)
const config: BundlerConfig = {
chainId: 1337,
beneficiary: await bundlerSigner.getAddress(),
entryPoint: _entryPoint.address,
gasFactor: '0.2',
Expand All @@ -114,7 +116,7 @@ describe('#BundlerManager', () => {
}
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const validMgr = new ValidationManager(_entryPoint, config.unsafe, preVerificationGasCalculator)
const evMgr = new EventsManager(_entryPoint, mempoolMgr, repMgr)
bundleMgr = new BundleManager(_entryPoint, _entryPoint.provider as JsonRpcProvider, _entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/test/BundlerServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
deployEntryPoint
} from '@account-abstraction/utils'
import { supportsDebugTraceCall, ValidationManager } from '@account-abstraction/validation-manager'
import { PreVerificationGasCalculator, MainnetConfig } from '@account-abstraction/sdk'

import { BundlerServer } from '../src/BundlerServer'
import { createSigner } from './testUtils'
Expand All @@ -22,7 +23,6 @@ import { ExecutionManager } from '../src/modules/ExecutionManager'
import { MethodHandlerERC4337 } from '../src/MethodHandlerERC4337'
import { BundlerConfig } from '../src/BundlerConfig'
import { DepositManager } from '../src/modules/DepositManager'
import { PreVerificationGasCalculator } from '@account-abstraction/sdk'

describe('BundleServer', function () {
let entryPoint: IEntryPoint
Expand All @@ -33,6 +33,7 @@ describe('BundleServer', function () {
entryPoint = await deployEntryPoint(provider)

const config: BundlerConfig = {
chainId: 1337,
beneficiary: await signer.getAddress(),
entryPoint: entryPoint.address,
gasFactor: '0.2',
Expand All @@ -56,7 +57,7 @@ describe('BundleServer', function () {

const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/test/DebugMethodHandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { PreVerificationGasCalculator, SimpleAccountAPI } from '@account-abstraction/sdk'
import { MainnetConfig, PreVerificationGasCalculator, SimpleAccountAPI } from '@account-abstraction/sdk'
import { Signer, Wallet } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
import { expect } from 'chai'
Expand Down Expand Up @@ -43,6 +43,7 @@ describe('#DebugMethodHandler', () => {
DeterministicDeployer.init(provider)

const config: BundlerConfig = {
chainId: 1337,
beneficiary: await signer.getAddress(),
entryPoint: entryPoint.address,
gasFactor: '0.2',
Expand All @@ -66,7 +67,7 @@ describe('#DebugMethodHandler', () => {

const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator)
const eventsManager = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, eventsManager, mempoolMgr, validMgr, repMgr,
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/test/UserOpMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BundlerConfig } from '../src/BundlerConfig'

import { toHex } from 'hardhat/internal/util/bigint'
import { Signer, Wallet } from 'ethers'
import { PreVerificationGasCalculator, SimpleAccountAPI } from '@account-abstraction/sdk'
import { MainnetConfig, PreVerificationGasCalculator, SimpleAccountAPI } from '@account-abstraction/sdk'
import { postExecutionDump } from '@account-abstraction/utils/dist/src/postExecCheck'
import {
SampleRecipient,
Expand Down Expand Up @@ -61,6 +61,7 @@ describe('UserOpMethodHandler', function () {
sampleRecipient = await sampleRecipientFactory.deploy()

const config: BundlerConfig = {
chainId: 1337,
beneficiary: await signer.getAddress(),
entryPoint: entryPoint.address,
gasFactor: '0.2',
Expand All @@ -84,7 +85,7 @@ describe('UserOpMethodHandler', function () {

const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
24 changes: 12 additions & 12 deletions packages/bundler/test/ValidateManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
checkRulesViolations,
supportsDebugTraceCall
} from '@account-abstraction/validation-manager'
import { PreVerificationGasCalculator } from '@account-abstraction/sdk'
import { PreVerificationGasCalculator, MainnetConfig } from '@account-abstraction/sdk'

import {
TestCoin,
Expand Down Expand Up @@ -77,11 +77,11 @@ describe('#ValidationManager', () => {
const pmd = pmRule === ''
? {}
: {
paymaster: paymaster.address,
paymasterVerificationGasLimit: 1e5,
paymasterPostOpGasLimit: 1e5,
paymasterData: Buffer.from(pmRule)
}
paymaster: paymaster.address,
paymasterVerificationGasLimit: 1e5,
paymasterPostOpGasLimit: 1e5,
paymasterData: Buffer.from(pmRule)
}
const signature = hexlify(Buffer.from(validateRule))
return {
...cEmptyUserOp,
Expand All @@ -103,11 +103,11 @@ describe('#ValidationManager', () => {
const pmInfo = pmRule == null
? {}
: {
paymaster: paymaster.address,
paymasterVerificationGasLimit: 1e6,
paymasterPostOpGasLimit: 1e6,
paymasterData: Buffer.from(pmRule)
}
paymaster: paymaster.address,
paymasterVerificationGasLimit: 1e6,
paymasterPostOpGasLimit: 1e6,
paymasterData: Buffer.from(pmRule)
}
const signature = hexlify(Buffer.from(validateRule))
const callinitCodeForAddr = await provider.call({
to: factoryAddress,
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('#ValidationManager', () => {
await entryPoint.depositTo(rulesAccount.address, { value: parseEther('1') })

const unsafe = !await supportsDebugTraceCall(provider, false)
const preVerificationGasCalculator = new PreVerificationGasCalculator(0, 0, 0, 0, 0, 0, 0, 0)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
vm = new ValidationManager(entryPoint, unsafe, preVerificationGasCalculator)

if (!await supportsDebugTraceCall(ethers.provider, false)) {
Expand Down
Loading

0 comments on commit 32b21c2

Please sign in to comment.