Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AA-453: Support EIP-7702 tuples in ERC-4337 bundlers #226

Merged
merged 19 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"runop": "yarn --cwd packages/bundler runop",
"runop-goerli": "yarn runop --network goerli --unsafe",
"create-all-deps": "jq '.dependencies,.devDependencies' packages/*/package.json |sort -u > all.deps",
"depcheck": "lerna exec --no-bail --stream --parallel -- npx depcheck --ignores @account-abstraction/contracts,@openzeppelin/contracts,@uniswap/v3-periphery",
"depcheck": "lerna exec --no-bail --stream --parallel --ignore \"@account-abstraction/contracts\" -- npx depcheck --ignores=\"@account-abstraction/contracts,@openzeppelin/contracts,@uniswap/v3-periphery\"",
"hardhat-node": "lerna run hardhat-node --stream --no-prefix --",
"hardhat-deploy": "lerna run hardhat-deploy --stream --no-prefix --",
"lerna-clear": "lerna run clear",
Expand All @@ -39,6 +39,9 @@
"ci": "env && yarn depcheck && yarn preprocess && yarn lerna-test"
},
"dependencies": {
"@ethereumjs/common": "^5.0.0-alpha.1",
"@ethereumjs/tx": "^6.0.0-alpha.1",
"@ethereumjs/util": "^10.0.0-alpha.1",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"depcheck": "^1.4.3",
Expand All @@ -48,7 +51,7 @@
"eslint-plugin-n": "^15.2.4",
"eslint-plugin-promise": "^6.0.0",
"lerna": "^5.4.0",
"typescript": "^4.7.4",
"typescript": "^5.6.2",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"@account-abstraction/sdk": "^0.7.0",
"@account-abstraction/utils": "^0.7.0",
"@account-abstraction/validation-manager": "^0.7.0",
"@ethereumjs/common": "^5.0.0-alpha.1",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/tx": "^6.0.0-alpha.1",
"@ethereumjs/util": "^10.0.0-alpha.1",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@types/cors": "^2.8.12",
Expand Down
5 changes: 4 additions & 1 deletion packages/bundler/src/BundlerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface BundlerConfig {
rip7560Mode: string
gethDevMode: boolean

eip7702Support: boolean
// Config overrides for PreVerificationGas calculation
fixedGasOverhead?: number
perUserOpGasOverhead?: number
Expand Down Expand Up @@ -68,6 +69,7 @@ export const BundlerConfigShape = {
rip7560: ow.boolean,
rip7560Mode: ow.string.oneOf(['PULL', 'PUSH']),
gethDevMode: ow.boolean,
eip7702Support: ow.boolean,

// Config overrides for PreVerificationGas calculation
fixedGasOverhead: ow.optional.number,
Expand Down Expand Up @@ -103,5 +105,6 @@ export const bundlerConfigDefault: Partial<BundlerConfig> = {
unsafe: false,
conditionalRpc: false,
minStake: MIN_STAKE_VALUE,
minUnstakeDelay: MIN_UNSTAKE_DELAY
minUnstakeDelay: MIN_UNSTAKE_DELAY,
eip7702Support: true
}
9 changes: 5 additions & 4 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bodyParser from 'body-parser'
import cors from 'cors'
import express, { Express, Response, Request, RequestHandler } from 'express'
import { JsonRpcProvider, Provider } from '@ethersproject/providers'
import { JsonRpcProvider } from '@ethersproject/providers'
import { Signer, utils } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
import { Server } from 'http'
Expand Down Expand Up @@ -39,7 +39,7 @@ export class BundlerServer {
readonly methodHandlerRip7560: MethodHandlerRIP7560,
readonly debugHandler: DebugMethodHandler,
readonly config: BundlerConfig,
readonly provider: Provider,
readonly provider: JsonRpcProvider,
readonly wallet: Signer
) {
this.appPublic = express()
Expand Down Expand Up @@ -95,7 +95,8 @@ export class BundlerServer {
callGasLimit: 0,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
signature: '0x'
signature: '0x',
authorizationList: []
}
// await EntryPoint__factory.connect(this.config.entryPoint,this.provider).callStatic.addStake(0)
try {
Expand Down Expand Up @@ -260,7 +261,7 @@ export class BundlerServer {
}
break
case 'eth_getRip7560TransactionDebugInfo':
result = await (this.provider as JsonRpcProvider).send('eth_getRip7560TransactionDebugInfo', [params[0]])
result = await this.provider.send('eth_getRip7560TransactionDebugInfo', [params[0]])
break
case 'eth_getTransactionReceipt':
if (!this.config.rip7560) {
Expand Down
38 changes: 29 additions & 9 deletions packages/bundler/src/MethodHandlerERC4337.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import debug from 'debug'
import { BigNumber, BigNumberish, Signer } from 'ethers'
import { JsonRpcProvider, Log } from '@ethersproject/providers'
import { EventFragment } from '@ethersproject/abi'
import { JsonRpcProvider, Log } from '@ethersproject/providers'
import { toNumber } from '@nomicfoundation/hardhat-network-helpers/dist/src/utils'

import { MainnetConfig, PreVerificationGasCalculator } from '@account-abstraction/sdk'

Expand Down Expand Up @@ -118,7 +119,14 @@ export class MethodHandlerERC4337 {
* @param entryPointInput
* @param stateOverride
*/
async estimateUserOperationGas (userOp1: Partial<UserOperation>, entryPointInput: string, stateOverride?: StateOverride): Promise<EstimateUserOpGasResult> {
async estimateUserOperationGas (
userOp1: Partial<UserOperation>,
entryPointInput: string,
stateOverride?: StateOverride
): Promise<EstimateUserOpGasResult> {
if (!this.config.eip7702Support && userOp1.authorizationList != null && userOp1.authorizationList.length !== 0) {
throw new Error('EIP-7702 tuples are not supported')
}
const userOp: UserOperation = {
// default values for missing fields.
maxFeePerGas: 0,
Expand Down Expand Up @@ -146,17 +154,26 @@ export class MethodHandlerERC4337 {

const returnInfo = decodeSimulateHandleOpResult(ret)

const { validAfter, validUntil } = mergeValidationDataValues(returnInfo.accountValidationData, returnInfo.paymasterValidationData)
const {
validAfter,
validUntil
} = mergeValidationDataValues(returnInfo.accountValidationData, returnInfo.paymasterValidationData)
const {
preOpGas
} = returnInfo

// todo: use simulateHandleOp for this too...
let callGasLimit = await this.provider.estimateGas({
from: this.entryPoint.address,
to: userOp.sender,
data: userOp.callData
}).then(b => b.toNumber()).catch(err => {
let callGasLimit = await this.provider.send(
'eth_estimateGas', [
{
from: this.entryPoint.address,
to: userOp.sender,
data: userOp.callData,
// @ts-ignore
authorizationList: userOp.authorizationList
}
]
).then(b => toNumber(b)).catch(err => {
const message = err.message.match(/reason="(.*?)"/)?.at(1) ?? 'execution reverted'
throw new RpcError(message, ValidationErrors.UserOperationReverted)
})
Expand All @@ -175,9 +192,12 @@ export class MethodHandlerERC4337 {
}

async sendUserOperation (userOp: UserOperation, entryPointInput: string): Promise<string> {
if (!this.config.eip7702Support && userOp.authorizationList != null && userOp.authorizationList.length !== 0) {
throw new Error('EIP-7702 tuples are not supported')
}
await this._validateParameters(userOp, entryPointInput)

debug(`UserOperation: Sender=${userOp.sender} Nonce=${tostr(userOp.nonce)} EntryPoint=${entryPointInput} Paymaster=${userOp.paymaster ?? ''}`)
debug(`UserOperation: Sender=${userOp.sender} Nonce=${tostr(userOp.nonce)} EntryPoint=${entryPointInput} Paymaster=${userOp.paymaster ?? ''} EIP-7702TuplesSize=${userOp.authorizationList?.length}`)
await this.execManager.sendUserOperation(userOp, entryPointInput, false)
return await this.entryPoint.getUserOpHash(packUserOp(userOp))
}
Expand Down
10 changes: 9 additions & 1 deletion packages/bundler/src/MethodHandlerRIP7560.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BigNumberish } from 'ethers'
import { JsonRpcProvider, TransactionReceipt } from '@ethersproject/providers'
import {
AddressZero,
EIP7702Authorization,
OperationBase,
OperationRIP7560,
StorageMap,
Expand Down Expand Up @@ -29,11 +30,18 @@ export class MethodHandlerRIP7560 {
return getRIP7560TransactionHash(transaction)
}

/**
* @param minBaseFee
* @param maxBundleGas
* @param maxBundleSize
* @return An array of transactions included in the bundle.
* @return The EIP7702Authorization array is always empty as each individual RIP-7560 transaction performs its own authorizations.
*/
async getRip7560Bundle (
minBaseFee: BigNumberish,
maxBundleGas: BigNumberish,
maxBundleSize: BigNumberish
): Promise<[OperationBase[], StorageMap]> {
): Promise<[OperationBase[], EIP7702Authorization[], StorageMap]> {
return await this.execManager.createBundle(minBaseFee, maxBundleGas, maxBundleSize)
}

Expand Down
Loading
Loading