Skip to content

Commit

Permalink
Merge branch 'master' into AA-488-replace-by-fee-reputation
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Dec 27, 2024
2 parents 7527c66 + 3579626 commit c9987fe
Show file tree
Hide file tree
Showing 46 changed files with 2,609 additions and 3,110 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"scripts": {
"bundler": "yarn --cwd packages/bundler bundler",
"bundler-rip7560": "yarn --cwd packages/bundler bundler-rip7560",
"bundler-eip7702": "yarn --cwd packages/bundler bundler-eip7702",
"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 +40,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 +52,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
20 changes: 20 additions & 0 deletions packages/bundler/localconfig/bundler.eip7702.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"chainId": 1337,
"gasFactor": "1",
"port": "3000",
"privateApiPort": "3001",
"network": "http://127.0.0.1:8545",
"tracerRpcUrl": "http://127.0.0.1:8545",
"entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"beneficiary": "0xd21934eD8eAf27a67f0A70042Af50A1D6d195E81",
"minBalance": "1",
"mnemonic": "./localconfig/mnemonic.txt",
"maxBundleGas": 30e6,
"minStake": "1",
"minUnstakeDelay": 0,
"autoBundleInterval": 3,
"autoBundleMempoolSize": 10,
"rip7560": false,
"rip7560Mode": "PULL",
"gethDevMode": true
}
4 changes: 4 additions & 0 deletions packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"runop": "ts-node ./src/runner/runop.ts",
"bundler": "TS_NODE_TRANSPILE_ONLY=1 ts-node ./src/exec.ts --config ./localconfig/bundler.config.json",
"bundler-rip7560": "ts-node ./src/exec.ts --config ./localconfig/bundler.rip7560.config.json",
"bundler-eip7702": "ts-node ./src/exec.ts --config ./localconfig/bundler.eip7702.config.json",
"clear": "rm -rf dist artifacts cache src/types",
"hardhat-compile": "hardhat compile",
"hardhat-node": "npx hardhat node --no-deploy",
Expand All @@ -28,7 +29,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

0 comments on commit c9987fe

Please sign in to comment.