Skip to content

Commit

Permalink
Merge pull request #289 from pimlicolabs/fix-aa10-validation
Browse files Browse the repository at this point in the history
check all mempools for aa10 validation
  • Loading branch information
mouseless-eth authored Sep 6, 2024
2 parents 563dfe9 + 479aba9 commit d6917ae
Showing 1 changed file with 53 additions and 41 deletions.
94 changes: 53 additions & 41 deletions src/mempool/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,48 +281,68 @@ export class MemoryMempool {
}

this.reputationManager.updateUserOperationSeenStatus(op, entryPoint)
const oldUserOp = outstandingOps.find(({ mempoolUserOperation }) => {
const userOperation = deriveUserOperation(mempoolUserOperation)
const oldUserOp = [...outstandingOps, ...processedOrSubmittedOps].find(
({ mempoolUserOperation }) => {
const userOperation = deriveUserOperation(mempoolUserOperation)

const isSameSender = userOperation.sender === op.sender
const isSameSender = userOperation.sender === op.sender

if (isSameSender && userOperation.nonce === op.nonce) {
return true
}
if (isSameSender && userOperation.nonce === op.nonce) {
return true
}

// Check if there is already a userOperation with initCode + same sender (stops rejected ops due to AA10).
if (
isVersion06(userOperation) &&
isVersion06(op) &&
op.initCode &&
op.initCode !== "0x"
) {
return (
isSameSender &&
userOperation.initCode &&
userOperation.initCode !== "0x"
)
}
// Check if there is already a userOperation with initCode + same sender (stops rejected ops due to AA10).
if (
isVersion06(userOperation) &&
isVersion06(op) &&
op.initCode &&
op.initCode !== "0x"
) {
return (
isSameSender &&
userOperation.initCode &&
userOperation.initCode !== "0x"
)
}

// Check if there is already a userOperation with factory + same sender (stops rejected ops due to AA10).
if (
isVersion07(userOperation) &&
isVersion07(op) &&
op.factory &&
op.factory !== "0x"
) {
return (
isSameSender &&
userOperation.factory &&
userOperation.factory !== "0x"
)
// Check if there is already a userOperation with factory + same sender (stops rejected ops due to AA10).
if (
isVersion07(userOperation) &&
isVersion07(op) &&
op.factory &&
op.factory !== "0x"
) {
return (
isSameSender &&
userOperation.factory &&
userOperation.factory !== "0x"
)
}

return false
}
)

return false
})
const isOldUserOpProcessingOrSubmitted = processedOrSubmittedOps.some(
(op) => op.userOperationHash === oldUserOp?.userOperationHash
)

if (oldUserOp) {
const oldOp = deriveUserOperation(oldUserOp.mempoolUserOperation)

let reason =
"AA10 sender already constructed: A conflicting userOperation with initCode for this sender is already in the mempool. bump the gas price by minimum 10%"

if (oldOp.nonce === op.nonce) {
reason =
"AA25 invalid account nonce: User operation already present in mempool, bump the gas price by minimum 10%"
}

// if oldOp is already in processing or submitted mempool, we can't replace it so early exit.
if (isOldUserOpProcessingOrSubmitted) {
return [false, reason]
}

const oldMaxPriorityFeePerGas = oldOp.maxPriorityFeePerGas
const newMaxPriorityFeePerGas = op.maxPriorityFeePerGas
const oldMaxFeePerGas = oldOp.maxFeePerGas
Expand All @@ -333,14 +353,6 @@ export class MemoryMempool {
const incrementMaxFeePerGas =
(oldMaxFeePerGas * BigInt(10)) / BigInt(100)

let reason =
"AA10 sender already constructed: A conflicting userOperation with initCode for this sender is already in the mempool. bump the gas price by minimum 10%"

if (oldOp.nonce === op.nonce) {
reason =
"AA25 invalid account nonce: User operation already present in mempool, bump the gas price by minimum 10%"
}

if (
newMaxPriorityFeePerGas <
oldMaxPriorityFeePerGas + incrementMaxPriorityFeePerGas ||
Expand Down

0 comments on commit d6917ae

Please sign in to comment.