Skip to content

Commit

Permalink
Fix/nonce queue (#410)
Browse files Browse the repository at this point in the history
* fix nonce check in nonceQueue

* fix

---------

Co-authored-by: mouseless <[email protected]>
  • Loading branch information
mouseless0x and mouseless0x authored Jan 23, 2025
1 parent f7077d8 commit 210b730
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/rpc/nonceQueuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@alto/types"
import type { Logger } from "@alto/utils"
import {
encodeNonce,
getNonceKeyAndValue,
getUserOperationHash,
isVersion06
Expand All @@ -26,7 +27,7 @@ type QueuedUserOperation = {
userOperationHash: Hash
mempoolUserOperation: MempoolUserOperation
nonceKey: bigint
nonceValue: bigint
nonceSequence: bigint
addedAt: number
}

Expand Down Expand Up @@ -98,23 +99,25 @@ export class NonceQueuer {

add(mempoolUserOperation: MempoolUserOperation, entryPoint: Address) {
const userOperation = deriveUserOperation(mempoolUserOperation)
const [nonceKey, nonceValue] = getNonceKeyAndValue(userOperation.nonce)
const [nonceKey, nonceSequence] = getNonceKeyAndValue(
userOperation.nonce
)

const hash = getUserOperationHash(
const userOperationHash = getUserOperationHash(
deriveUserOperation(mempoolUserOperation),
entryPoint,
this.config.publicClient.chain.id
)
this.queuedUserOperations.push({
entryPoint,
userOperationHash: hash,
mempoolUserOperation: mempoolUserOperation,
nonceKey: nonceKey,
nonceValue: nonceValue,
userOperationHash,
mempoolUserOperation,
nonceKey,
nonceSequence,
addedAt: Date.now()
})

this.eventManager.emitQueued(hash)
this.eventManager.emitQueued(userOperationHash)
}

resubmitUserOperation(
Expand Down Expand Up @@ -227,9 +230,13 @@ export class NonceQueuer {
continue
}

const onchainNonceValue = result.result
const onchainNonce = result.result
const qopNonce = encodeNonce({
nonceSequence: qop.nonceSequence,
nonceKey: qop.nonceKey
})

if (onchainNonceValue === qop.nonceValue) {
if (onchainNonce === qopNonce) {
currentOutstandingOps.push(qop)
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/utils/userop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,16 @@ export const getUserOperationHash = (

export const getNonceKeyAndValue = (nonce: bigint) => {
const nonceKey = nonce >> 64n // first 192 bits of nonce
const userOperationNonceValue = nonce & 0xffffffffffffffffn // last 64 bits of nonce
const nonceSequence = nonce & 0xffffffffffffffffn // last 64 bits of nonce

return [nonceKey, userOperationNonceValue]
return [nonceKey, nonceSequence]
}

export const encodeNonce = ({
nonceKey,
nonceSequence
}: { nonceKey: bigint; nonceSequence: bigint }) => {
return (nonceKey << 64n) | nonceSequence
}

export function toUnpackedUserOperation(
Expand Down

0 comments on commit 210b730

Please sign in to comment.