Skip to content

Commit

Permalink
AA-236: paymaster opsSeen
Browse files Browse the repository at this point in the history
paymaster should not be "blamed" if account or deployer causes a 2nd
validation failure.
  • Loading branch information
drortirosh committed Nov 9, 2023
1 parent 09056eb commit bd65372
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 21 additions & 0 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ export class BundleManager {
} = parsedError.args
const userOp = userOps[opIndex]
const reasonStr: string = reason.toString()
if (reasonStr.startsWith('AA1') || reasonStr.startsWith('AA2')) {
// UserOp crashed this bundle, but it's not the paymaster's fault.
// its probably an attack by deployer (and/or account) on this paymaster.
this.reputationManager.updateSeenStatus(getAddr(userOp.paymasterAndData), true)
}
if (reasonStr.startsWith('AA3')) {
this.reputationManager.crashedHandleOps(getAddr(userOp.paymasterAndData))
} else if (reasonStr.startsWith('AA2')) {
Expand Down Expand Up @@ -194,6 +199,22 @@ export class BundleManager {
validationResult = await this.validationManager.validateUserOp(entry.userOp, entry.referencedContracts, false)
} catch (e: any) {
debug('failed 2nd validation:', e.message)

let parsedError: ErrorDescription
try {
parsedError = this.entryPoint.interface.parseError((e.data?.data ?? e.data))
} catch (e1) {
this.checkFatal(e)
console.warn('2nd validation reverts, but non-FailedOp error', e)
continue
}
const reasonStr: string = parsedError.args.reason.toString()
if (reasonStr.startsWith('AA1') || reasonStr.startsWith('AA2')) {
// UserOp failed 2nd validation, but it's not the paymaster's fault.
// it's probably an attack by deployer (and/or account) on this paymaster.
this.reputationManager.updateSeenStatus(getAddr(entry.userOp.paymasterAndData), true)
}

// failed validation. don't try anymore
this.mempoolManager.removeUserOp(entry.userOp)
continue
Expand Down
12 changes: 9 additions & 3 deletions packages/bundler/src/modules/ReputationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ export class ReputationManager {
/**
* address seen in the mempool triggered by the
* @param addr
* @param reverse - true to reverse the operation ("unsee" the given entry)
*/
updateSeenStatus (addr?: string): void {
updateSeenStatus (addr?: string, reverse = false): void {
if (addr == null) {
return
}
const entry = this._getOrCreate(addr)
entry.opsSeen++
debug('after seen++', addr, entry)
if (reverse) {
entry.opsSeen--
debug('after reverse seen', addr, entry)
} else {
entry.opsSeen++
debug('after seen++', addr, entry)
}
}

/**
Expand Down

0 comments on commit bd65372

Please sign in to comment.