Skip to content

Commit

Permalink
validate eip7702Auth + add eip7702 overhead to PVG
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Jan 27, 2025
1 parent 60c14c3 commit bad5946
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
import { base, baseSepolia, optimism } from "viem/chains"
import type { NonceQueuer } from "./nonceQueuer"
import type { AltoConfig } from "../createConfig"
import { recoverAuthorizationAddress } from "viem/experimental"

export interface IRpcEndpoint {
handleMethod(
Expand Down Expand Up @@ -817,6 +818,7 @@ export class RpcHandler implements IRpcEndpoint {
}

this.ensureEntryPointIsSupported(entryPoint)
await this.validateEip7702Auth(userOperation)

try {
await this.addToMempoolIfValid(
Expand Down Expand Up @@ -915,6 +917,26 @@ export class RpcHandler implements IRpcEndpoint {
return userOperationReceipt
}

async validateEip7702Auth(userOperation: UserOperation) {
if (!userOperation.eip7702Auth) {
throw new RpcError(
"UserOperation is missing eip7702Auth",
ValidationErrors.InvalidFields
)
}

// Check that auth is valid.
const sender = await recoverAuthorizationAddress({
authorization: userOperation.eip7702Auth
})
if (sender !== userOperation.sender) {
throw new RpcError(
"Invalid EIP-7702 authorization: The recovered signer address does not match the userOperation sender address",
ValidationErrors.InvalidFields
)
}
}

async getNonceValue(userOperation: UserOperation, entryPoint: Address) {
const entryPointContract = getContract({
address: entryPoint,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,14 @@ export function calcDefaultPreVerificationGas(
const callDataCost = packed
.map((x) => (x === 0 ? ov.zeroByte : ov.nonZeroByte))
.reduce((sum, x) => sum + x)

const authorizationCost = userOperation.eip7702Auth
? 37500 // overhead for PER_EMPTY_ACCOUNT_COST + PER_AUTH_BASE_COST
: 0

const ret = Math.round(
callDataCost +
authorizationCost +
callDataCost +
ov.fixed / ov.bundleSize +
ov.perUserOp +
ov.perUserOpWord * lengthInWord
Expand Down

0 comments on commit bad5946

Please sign in to comment.