Skip to content

Commit

Permalink
STO-040 rule check implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Oct 2, 2023
1 parent a2cd779 commit 083936f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ export class BundleManager {
const senders = new Set<string>()

// all entities that are known to be valid senders in the mempool
const knownSenders = entries.map(it => {
return it.userOp.sender.toLowerCase()
})
const knownSenders = this.mempoolManager.getKnownSenders()

const storageMap: StorageMap = {}
let totalGas = BigNumber.from(0)
Expand Down
52 changes: 51 additions & 1 deletion packages/bundler/src/modules/MempoolManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class MempoolManager {
if (factory != null) {
this.incrementEntryCount(factory)
}
// this.checkSenderCountInMempool(userOp, senderInfo)
this.checkReputation(senderInfo, paymasterInfo, factoryInfo, aggregatorInfo)
this.checkMultipleRolesViolation(userOp)
this.mempool.push(entry)
}
this.updateSeenStatus(aggregatorInfo?.addr, userOp, senderInfo)
Expand Down Expand Up @@ -137,6 +137,27 @@ export class MempoolManager {
}
}

private checkMultipleRolesViolation (userOp: UserOperation): void {
const knownEntities = this.getKnownEntities()
requireCond(
!knownEntities.includes(userOp.sender.toLowerCase()),
`The sender address "${userOp.sender}" is used as a different entity in another UserOperation currently in mempool`,
ValidationErrors.OpcodeValidation
)

const knownSenders = this.getKnownSenders()
const paymaster = getAddr(userOp.paymasterAndData)?.toLowerCase()
const factory = getAddr(userOp.initCode)?.toLowerCase()

const isPaymasterSenderViolation = knownSenders.includes(paymaster?.toLowerCase() ?? '')
const isFactorySenderViolation = knownSenders.includes(factory?.toLowerCase() ?? '')
requireCond(
!isPaymasterSenderViolation && !isFactorySenderViolation,
`An entity in this UserOperation is used as a sender entity in another UserOperation currently in mempool. (${paymaster}:${isPaymasterSenderViolation};${factory}:${isFactorySenderViolation})`,
ValidationErrors.OpcodeValidation
)
}

private checkReputationStatus (
title: 'account' | 'paymaster' | 'aggregator' | 'deployer',
stakeInfo: StakeInfo,
Expand Down Expand Up @@ -234,4 +255,33 @@ export class MempoolManager {
this.mempool = []
this._entryCount = {}
}

/**
* Returns all addresses that are currently known to be "senders" according to the current mempool.
*/
getKnownSenders (): string[] {
return this.getSortedForInclusion().map(it => {
return it.userOp.sender.toLowerCase()
})
}

/**
* Returns all addresses that are currently known to be any kind of entity according to the current mempool.
* Note that "sender" addresses are not returned by this function. Use {@link getKnownSenders} instead.
*/
getKnownEntities (): string[] {
const res = []
const userOps = this.getSortedForInclusion()
res.push(
...userOps.map(it => {
return getAddr(it.userOp.paymasterAndData)
})
)
res.push(
...userOps.map(it => {
return getAddr(it.userOp.initCode)
})
)
return res.filter(it => it != null).map(it => (it as string).toLowerCase())
}
}

0 comments on commit 083936f

Please sign in to comment.