Skip to content

Commit

Permalink
single auth tuple for UserOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Dec 16, 2024
1 parent 9a5bc12 commit d2e5987
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 30 deletions.
3 changes: 1 addition & 2 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export class BundlerServer {
callGasLimit: 0,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
signature: '0x',
authorizationList: []
signature: '0x'
}
// await EntryPoint__factory.connect(this.config.entryPoint,this.provider).callStatic.addStake(0)
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/bundler/src/MethodHandlerERC4337.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class MethodHandlerERC4337 {
entryPointInput: string,
stateOverride?: StateOverride
): Promise<EstimateUserOpGasResult> {
if (!this.config.eip7702Support && userOp1.authorizationList != null && userOp1.authorizationList.length !== 0) {
if (!this.config.eip7702Support && userOp1.eip7712auth != null) {
throw new Error('EIP-7702 tuples are not supported')
}
const userOp: UserOperation = {
Expand Down Expand Up @@ -192,12 +192,12 @@ export class MethodHandlerERC4337 {
}

async sendUserOperation (userOp: UserOperation, entryPointInput: string): Promise<string> {
if (!this.config.eip7702Support && userOp.authorizationList != null && userOp.authorizationList.length !== 0) {
if (!this.config.eip7702Support && userOp.eip7712auth != null) {
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 ?? ''} EIP-7702TuplesSize=${userOp.authorizationList?.length}`)
debug(`UserOperation: Sender=${userOp.sender} Nonce=${tostr(userOp.nonce)} EntryPoint=${entryPointInput} Paymaster=${userOp.paymaster ?? ''} ${userOp.eip7712auth != null ? 'eip-7702 auth' : ''}`)
await this.execManager.sendUserOperation(userOp, entryPointInput, false)
return await this.entryPoint.getUserOpHash(packUserOp(userOp))
}
Expand Down
9 changes: 5 additions & 4 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getEip7702AuthorizationSigner,
mergeStorageMap,
packUserOp,
getUserOpHash
getUserOpHash, getAuthorizationList
} from '@account-abstraction/utils'

import { EventsManager } from './EventsManager'
Expand Down Expand Up @@ -410,7 +410,8 @@ export class BundleManager implements IBundleManager {
}
mergeStorageMap(storageMap, validationResult.storageMap)

for (const eip7702Authorization of entry.userOp.authorizationList ?? []) {
const authorizationList = getAuthorizationList(entry.userOp)
for (const eip7702Authorization of authorizationList) {
const existingAuthorization = sharedAuthorizationList
.find(it => {
return getEip7702AuthorizationSigner(it) === getEip7702AuthorizationSigner(eip7702Authorization)
Expand All @@ -420,8 +421,8 @@ export class BundleManager implements IBundleManager {
// eslint-disable-next-line no-labels
continue mainLoop
}
if (existingAuthorization == null && entry.userOp.authorizationList != null) {
sharedAuthorizationList.push(...entry.userOp.authorizationList)
if (existingAuthorization == null && authorizationList.length > 0) {
sharedAuthorizationList.push(...authorizationList)
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/bundler/test/BundlerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ describe('#BundlerManager', () => {
verificationGasLimit: 7,
maxFeePerGas: 8,
maxPriorityFeePerGas: 9,
preVerificationGas: 10,
authorizationList: []
preVerificationGas: 10
}

const hash = await entryPoint.getUserOpHash(packUserOp(userOp))
Expand Down Expand Up @@ -161,8 +160,7 @@ describe('#BundlerManager', () => {
verificationGasLimit: '0x50000',
maxFeePerGas: '0x0',
maxPriorityFeePerGas: '0x0',
preVerificationGas: '0x50000',
authorizationList: []
preVerificationGas: '0x50000'
}
const userOp1: UserOperation = {
...cEmptyUserOp,
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler/test/UserOpMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ describe('UserOpMethodHandler', function () {
preVerificationGas: 50000,
maxFeePerGas: 1e6,
maxPriorityFeePerGas: 1e6,
signature: Buffer.from('emit-msg'),
authorizationList: []
signature: Buffer.from('emit-msg')
}
await entryPoint.depositTo(acc.address, { value: parseEther('1') })
// await signer.sendTransaction({to:acc.address, value: parseEther('1')})
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler/test/ValidateManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const cEmptyUserOp: UserOperation = {
verificationGasLimit: 50000,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
preVerificationGas: 0,
authorizationList: []
preVerificationGas: 0
}

describe('#ValidationManager', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/test/0-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ describe('utils', () => {
callData: '333',
maxFeePerGas: 5,
maxPriorityFeePerGas: 6,
signature: '777',
authorizationList: []
signature: '777'
})).to.eql({
sender: 'a',
nonce: '0x01',
Expand Down Expand Up @@ -95,8 +94,7 @@ describe('utils', () => {
paymaster,
paymasterVerificationGasLimit: 8,
paymasterPostOpGasLimit: 9,
paymasterData: '0xcafebabe',
authorizationList: []
paymasterData: '0xcafebabe'
})).to.eql({
sender: 'a',
nonce: '0x01',
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/test/1-SimpleAccountAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ describe('SimpleAccountAPI', () => {
preVerificationGas: 7,
maxFeePerGas: 8,
maxPriorityFeePerGas: 9,
signature: '0xbbbb',
authorizationList: []
signature: '0xbbbb'
}
const hash = await api.getUserOpHash(userOp)
const epHash = await entryPoint.getUserOpHash(packUserOp(userOp))
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/src/ERC4337Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export function unpackUserOp (packed: PackedUserOperation): UserOperation {
callGasLimit,
maxFeePerGas,
maxPriorityFeePerGas,
signature: packed.signature,
authorizationList: []
signature: packed.signature
}
if (packed.initCode != null && packed.initCode.length > 2) {
const factory = hexDataSlice(packed.initCode, 0, 20)
Expand Down
10 changes: 10 additions & 0 deletions packages/utils/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PackedUserOperationStruct } from './soltypes'
import { UserOperation } from './interfaces/UserOperation'
import { OperationBase } from './interfaces/OperationBase'
import { OperationRIP7560 } from './interfaces/OperationRIP7560'
import { EIP7702Authorization } from './interfaces/EIP7702Authorization'

export interface SlotMap {
[slot: string]: string
Expand Down Expand Up @@ -236,3 +237,12 @@ export function getPackedNonce (userOp: OperationBase): BigNumber {
const bigNumberNonce = BigNumber.from(packed)
return bigNumberNonce
}

export function getAuthorizationList (op: OperationBase): EIP7702Authorization[] {
const userOp = op as UserOperation
if (userOp.eip7712auth != null) {
return [userOp.eip7712auth]
} else {
return (op as OperationRIP7560).authorizationList ?? []
}
}
3 changes: 0 additions & 3 deletions packages/utils/src/interfaces/OperationBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { BigNumberish, BytesLike } from 'ethers'

import { EIP7702Authorization } from './EIP7702Authorization'

/**
* The operation interface that is shared by ERC-4337 and RIP-7560 types.
*/
Expand All @@ -22,5 +20,4 @@ export interface OperationBase {
verificationGasLimit: BigNumberish
paymasterVerificationGasLimit?: BigNumberish
paymasterPostOpGasLimit?: BigNumberish
authorizationList?: EIP7702Authorization[]
}
3 changes: 3 additions & 0 deletions packages/utils/src/interfaces/OperationRIP7560.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OperationBase } from './OperationBase'
import { BigNumberish, BytesLike } from 'ethers'
import { EIP7702Authorization } from './EIP7702Authorization'

export interface OperationRIP7560 extends OperationBase {
chainId: BigNumberish
Expand All @@ -12,4 +13,6 @@ export interface OperationRIP7560 extends OperationBase {

// todo: we discussed using 'nonceKey' in the JSON schema for ERC-4337 as well but we did not finalize this decision
nonceKey: BigNumberish

authorizationList?: EIP7702Authorization[]
}
2 changes: 2 additions & 0 deletions packages/utils/src/interfaces/UserOperation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumberish, BytesLike } from 'ethers'
import { OperationBase } from './OperationBase'
import { EIP7702Authorization } from './EIP7702Authorization'

export interface UserOperation extends OperationBase {
// these fields have same meaning but different names between ERC-4337 and RIP-7560/RIP-7712
Expand All @@ -8,4 +9,5 @@ export interface UserOperation extends OperationBase {
nonce: BigNumberish

preVerificationGas: BigNumberish
eip7712auth?: EIP7702Authorization
}
4 changes: 2 additions & 2 deletions packages/validation-manager/src/ValidationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
packUserOp,
requireAddressAndFields,
requireCond,
runContractScript
runContractScript, getAuthorizationList
} from '@account-abstraction/utils'

import { tracerResultParser } from './TracerResultParser'
Expand Down Expand Up @@ -222,7 +222,7 @@ export class ValidationManager implements IValidationManager {
addresses: [],
hash: ''
}
const stateOverrideForEip7702 = await this.getAuthorizationsStateOverride(userOp.authorizationList ?? [])
const stateOverrideForEip7702 = await this.getAuthorizationsStateOverride(getAuthorizationList(userOp))
let storageMap: StorageMap = {}
if (!this.unsafe) {
let tracerResult: BundlerTracerResult
Expand Down

0 comments on commit d2e5987

Please sign in to comment.