Skip to content

Commit

Permalink
Separate 'fixedGasOverhead' and 'transactionGasStipend' chain config …
Browse files Browse the repository at this point in the history
…params
  • Loading branch information
forshtat committed Oct 15, 2024
1 parent 67349f8 commit 4b4f1e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export class BundlerServer {
} = reqItem
debug('>>', { jsonrpc, id, method, params })
try {
const result = deepHexlify(await this.handleMethod(method, params))
const handleResult = await this.handleMethod(method, params)
const result = deepHexlify(handleResult)
debug('sent', method, '-', result)
debug('<<', { jsonrpc, id, result })
return {
Expand Down
6 changes: 4 additions & 2 deletions packages/bundler/src/MethodHandlerERC4337.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@account-abstraction/utils'
import { ExecutionManager } from './modules/ExecutionManager'
import { StateOverride, UserOperationByHashResponse, UserOperationReceipt } from './RpcTypes'
import { PreVerificationGasCalculator } from '@account-abstraction/sdk'
import { MainnetConfig, PreVerificationGasCalculator } from '@account-abstraction/sdk'
import { EventFragment } from '@ethersproject/abi'

export const HEX_REGEX = /^0x[a-fA-F\d]*$/i
Expand Down Expand Up @@ -144,14 +144,16 @@ export class MethodHandlerERC4337 {
} = returnInfo

// todo: use simulateHandleOp for this too...
const callGasLimit = await this.provider.estimateGas({
let callGasLimit = await this.provider.estimateGas({
from: this.entryPoint.address,
to: userOp.sender,
data: userOp.callData
}).then(b => b.toNumber()).catch(err => {
const message = err.message.match(/reason="(.*?)"/)?.at(1) ?? 'execution reverted'
throw new RpcError(message, ValidationErrors.UserOperationReverted)
})
// Results from 'estimateGas' assume making a standalone transaction and paying 21'000 gas extra for it
callGasLimit -= MainnetConfig.transactionGasStipend

const preVerificationGas = this.preVerificationGasCalculator.estimatePreVerificationGas(userOp)
const verificationGasLimit = BigNumber.from(preOpGas).toNumber()
Expand Down
9 changes: 7 additions & 2 deletions packages/sdk/src/PreVerificationGasCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { encodeUserOp, packUserOp, UserOperation } from '@account-abstraction/ut
import { arrayify, hexlify } from 'ethers/lib/utils'

export interface PreVerificationGasCalculatorConfig {
/**
* Cost of sending a basic transaction on the current chain.
*/
readonly transactionGasStipend: number
/**
* Gas overhead is added to entire 'handleOp' bundle.
*/
Expand Down Expand Up @@ -38,8 +42,9 @@ export interface PreVerificationGasCalculatorConfig {
}

export const MainnetConfig: PreVerificationGasCalculatorConfig = {
fixedGasOverhead: 21000,
perUserOpGasOverhead: 18300,
transactionGasStipend: 21000,
fixedGasOverhead: 38000,
perUserOpGasOverhead: 11000,
perUserOpWordGasOverhead: 4,
zeroByteGasCost: 4,
nonZeroByteGasCost: 16,
Expand Down

0 comments on commit 4b4f1e9

Please sign in to comment.