Skip to content

Commit

Permalink
AA-474 Migrate to native tracer (#234)
Browse files Browse the repository at this point in the history
* Handling calls recursively in parser

* Changin usedOpcodes types

* Running 7702 bundler with preState tracer

* Reenabling js tracer, for 7702

* Adding usingErc7562NativeTracer
  • Loading branch information
shahafn authored Dec 22, 2024
1 parent 1736790 commit 3579626
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 309 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"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",
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
}
1 change: 1 addition & 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 Down
5 changes: 0 additions & 5 deletions packages/bundler/src/runBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<
console.error('FATAL: --tracerRpcUrl requires the network provider to support prestateTracer')
process.exit(1)
}
const tracerProvider = new ethers.providers.JsonRpcProvider(config.tracerRpcUrl)
if (!await supportsNativeTracer(tracerProvider)) {
console.error('FATAL: --tracerRpcUrl requires a provider to support bundlerCollectorTracer')
process.exit(1)
}
} else {
// check standard javascript tracer:
if (!await supportsDebugTraceCall(provider as any, config.rip7560)) {
Expand Down
1 change: 1 addition & 0 deletions packages/validation-manager/src/BundlerCollectorTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface TopLevelCallInfo {
contractSize: { [addr: string]: ContractSizeInfo }
extCodeAccessInfo: { [addr: string]: string }
oog?: boolean
calls?: []
}

/**
Expand Down
30 changes: 18 additions & 12 deletions packages/validation-manager/src/GethTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { Deferrable } from '@ethersproject/properties'
import { JsonRpcProvider, TransactionRequest } from '@ethersproject/providers'
import { resolveProperties } from 'ethers/lib/utils'
import { OperationRIP7560, RpcError } from '@account-abstraction/utils'
import { bundlerCollectorTracer } from './BundlerCollectorTracer'
// from:https://geth.ethereum.org/docs/rpc/ns-debug#javascript-based-tracing

const debug = Debug('aa.tracer')

// the name of the native tracer.
// equivalent to the javascript "bundlerCollectorTracer".
export const bundlerNativeTracerName = 'bundlerCollectorTracer'
export const bundlerJSTracerName = 'bundlerCollectorTracer'
export const GethNativeTracerName = 'erc7562Tracer'

/**
* a function returning a LogTracer.
Expand All @@ -26,16 +28,17 @@ type LogTracerFunc = () => LogTracer
* @param provider the network node to trace on
* @param tx the transaction to trace
* @param options the trace options
* @param nativeTracerProvider if set, submit only preStateTracer to the network provider, and use this (second) provider with native tracer.
* @param prestateTracerProvider if set, submit only preStateTracer to the network provider, and use this (second) provider with native tracer.
* if null, then use javascript tracer on the first provider.
*/

// eslint-disable-next-line @typescript-eslint/naming-convention
export async function debug_traceCall (provider: JsonRpcProvider, tx: Deferrable<TransactionRequest>, options: TraceOptions, nativeTracerProvider?: JsonRpcProvider): Promise<TraceResult | any> {
export async function debug_traceCall (provider: JsonRpcProvider, tx: Deferrable<TransactionRequest>, options: TraceOptions, prestateTracerProvider?: JsonRpcProvider): Promise<TraceResult | any> {
const tx1 = await resolveProperties(tx)
const traceOptions = tracer2string(options)
if (nativeTracerProvider != null) {
// there is a nativeTracerProvider: use it for the native tracer, but first we need preStateTracer from the main provider:
let traceOptions: TraceOptions
if (prestateTracerProvider != null) {
traceOptions = tracer2string(options)
// there is a prestateTracerProvider: use it for the native tracer, but first we need preStateTracer from the main provider:
const preState: { [addr: string]: any } = await provider.send('debug_traceCall', [tx1, 'latest', { ...traceOptions, tracer: 'prestateTracer' }])

// fix prestate to be valid "state overrides"
Expand All @@ -51,15 +54,18 @@ export async function debug_traceCall (provider: JsonRpcProvider, tx: Deferrable
delete preState[key].storage
}
}

const ret = await nativeTracerProvider.send('debug_traceCall', [tx1, 'latest', {
tracer: bundlerNativeTracerName,
stateOverrides: preState
traceOptions.tracer = getTracerBodyString(bundlerCollectorTracer)
traceOptions.stateOverrides = preState
const ret = await prestateTracerProvider.send('debug_traceCall', [tx1, 'latest', {
...traceOptions
}])

return ret
} else if (options.tracer != null) {
traceOptions = tracer2string(options)
} else {
traceOptions = options
traceOptions.tracer = GethNativeTracerName
}

const ret = await provider.send('debug_traceCall', [tx1, 'latest', traceOptions]).catch(e => {
if (debug.enabled) {
debug('ex=', e.error)
Expand Down
Loading

0 comments on commit 3579626

Please sign in to comment.