Skip to content

Commit

Permalink
PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Jan 6, 2025
1 parent dcfe286 commit f9685cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
54 changes: 14 additions & 40 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,38 +228,36 @@ export class BundleManager implements IBundleManager {
const common = new Common({ chain, eips: [2718, 2929, 2930, 7702] })

const authorizationList: AuthorizationList = eip7702Tuples.map(it => {
const res = {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion,@typescript-eslint/no-base-to-string
chainId: `0x${parseInt(it.chainId.toString()).toString(16)}`.replace(/0x0*/, '0x') as PrefixedHexString,
address: it.address as PrefixedHexString,
nonce: toRlpHex(it.nonce as PrefixedHexString),
yParity: toRlpHex(it.yParity as PrefixedHexString),
r: it.r as PrefixedHexString,
s: it.s as PrefixedHexString
return {
chainId: toRlpHex(it.chainId),
address: toRlpHex(it.address),
nonce: toRlpHex(it.nonce),
yParity: toRlpHex(it.yParity),
r: toRlpHex(it.r),
s: toRlpHex(it.s)
}
return res
})
const txData: EOACode7702TxData = {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
nonce: `0x${tx.nonce!.toString(16)}`,
nonce: hexlify(tx.nonce!) as PrefixedHexString,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
to: tx.to!.toString() as PrefixedHexString,
to: hexlify(tx.to!) as PrefixedHexString,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
value: '0x0',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
data: tx.data!.toString() as PrefixedHexString,
data: hexlify(tx.data) as PrefixedHexString,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
chainId: `0x${tx.chainId!.toString(16)}`,
chainId: hexlify(tx.chainId!) as PrefixedHexString,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
maxPriorityFeePerGas: tx.maxPriorityFeePerGas!.toHexString() as PrefixedHexString,
maxPriorityFeePerGas: hexlify(tx.maxPriorityFeePerGas!) as PrefixedHexString,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
maxFeePerGas: tx.maxPriorityFeePerGas!.toHexString() as PrefixedHexString,
maxFeePerGas: hexlify(tx.maxPriorityFeePerGas!) as PrefixedHexString,
accessList: [],
authorizationList
}
// TODO: not clear why but 'eth_estimateGas' gives an 'execution reverted' error
// txData.gasLimit = await this.provider.send('eth_estimateGas', [txData])
txData.gasLimit = `0x${(10000000).toString(16)}`
txData.gasLimit = 10_000_000
const objectTx = new EOACode7702Transaction(txData, { common })
const privateKey = Buffer.from(
// @ts-ignore
Expand Down Expand Up @@ -465,30 +463,6 @@ export class BundleManager implements IBundleManager {
return [bundle, sharedAuthorizationList, storageMap]
}

/**
* Merges the EIP-7702 authorizations from the given mempool entry into the provided authorization list.
*
* @param {MempoolEntry} entry - The mempool entry containing a list of UserOperation authorizations to be checked.
* @param {EIP7702Authorization[]} authList - The list of existing EIP-7702 authorizations to update.
* @return {boolean} - Returns `true` if the authorizations were successfully merged, otherwise `false`.
*/
mergeEip7702Authorizations (entry: MempoolEntry, authList: EIP7702Authorization[]): boolean {
// TODO: need to replace
for (const eip7702Authorization of getAuthorizationList(entry.userOp)) {
const existingAuthorization = authList
.find(it => {
return getEip7702AuthorizationSigner(it) === getEip7702AuthorizationSigner(eip7702Authorization)
})
if (existingAuthorization != null && existingAuthorization.address.toLowerCase() !== eip7702Authorization.address.toLowerCase()) {
return false
}
// if (existingAuthorization == null && entry.userOp.authorizationList != null) {
// authList.push(...getAuthorizationList(entry.userOp))
// }
}
return true
}

async _handleSecondValidationException (e: any, paymaster: string | undefined, entry: MempoolEntry): Promise<void> {
debug('failed 2nd validation:', e.message)

Expand Down
17 changes: 8 additions & 9 deletions packages/validation-manager/src/ValidationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ const entryPointSimulations = IEntryPointSimulations__factory.createInterface()
* (relevant only if unsafe=false)
*/
export class ValidationManager implements IValidationManager {
private readonly provider: JsonRpcProvider
constructor (
readonly entryPoint: IEntryPoint,
readonly unsafe: boolean,
readonly preVerificationGasCalculator: PreVerificationGasCalculator,
readonly providerForTracer?: JsonRpcProvider
) {
this.provider = this.entryPoint.provider as JsonRpcProvider
}

_getDebugConfiguration (): {
Expand Down Expand Up @@ -118,8 +120,7 @@ export class ValidationManager implements IValidationManager {
}
}
try {
const provider = this.entryPoint.provider as JsonRpcProvider
const simulationResult = await provider.send('eth_call', [tx, 'latest', stateOverride])
const simulationResult = await this.provider.send('eth_call', [tx, 'latest', stateOverride])
const [res] = entryPointSimulations.decodeFunctionResult('simulateValidation', simulationResult) as ValidationResultStructOutput[]

return this.parseValidationResult(userOp, res)
Expand Down Expand Up @@ -242,10 +243,10 @@ export class ValidationManager implements IValidationManager {
// relevant only for RIP-7562...
requireCond(authorizationList.length === 1, 'Only one authorization is supported', ValidationErrors.InvalidFields)

const currentChainId = BigNumber.from((this.entryPoint.provider as any)._network.chainId)
const chainId = await this.provider.getNetwork().then(n => n.chainId)
const authChainId = BigNumber.from(authorizationList[0].chainId)
requireCond(authChainId.eq(BigNumber.from(0)) ||
authChainId.eq(currentChainId), 'Invalid chainId in authorization', ValidationErrors.InvalidFields)
authChainId.eq(chainId), 'Invalid chainId in authorization', ValidationErrors.InvalidFields)
requireCond(getEip7702AuthorizationSigner(authorizationList[0]).toLowerCase() === userOp.sender.toLowerCase(), 'Authorization signer is not sender', ValidationErrors.InvalidFields)
}
const stateOverrideForEip7702 = await this.getAuthorizationsStateOverride(authorizationList)
Expand Down Expand Up @@ -312,17 +313,15 @@ export class ValidationManager implements IValidationManager {
authorizations: EIP7702Authorization[] = []
): Promise<{ [address: string]: { code: string } }> {
const stateOverride: { [address: string]: { code: string } } = {}
// TODO: why don't we have 'provider' as a member in here?
const provider = this.entryPoint.provider as JsonRpcProvider
for (const authorization of authorizations) {
const authSigner = getEip7702AuthorizationSigner(authorization)
const nonce = await provider.getTransactionCount(authSigner)
const nonce = await this.provider.getTransactionCount(authSigner)
const authNonce: any = authorization.nonce
if (nonce !== BigNumber.from(authNonce.replace(/0x$/, '0x0')).toNumber()) {
continue
}
const currentDelegateeCode = await provider.getCode(authSigner)
const newDelegateeCode = await provider.getCode(authorization.address)
const currentDelegateeCode = await this.provider.getCode(authSigner)
const newDelegateeCode = await this.provider.getCode(authorization.address)
// TODO should be: hexConcat(['0xef0100', authorization.address])
const noCurrentDelegation = currentDelegateeCode.length <= 2
// TODO: do not send such authorizations to 'handleOps' as it is a waste of gas
Expand Down

0 comments on commit f9685cb

Please sign in to comment.