Skip to content

Commit

Permalink
use real gas values when finding pvg
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Dec 12, 2024
1 parent 1842a73 commit 751e433
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
26 changes: 16 additions & 10 deletions src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,10 @@ export class RpcHandler implements IRpcEndpoint {
)
}

let preVerificationGas = await calcPreVerificationGas({
config: this.config,
userOperation,
entryPoint,
gasPriceManager: this.gasPriceManager,
validate: false
})
preVerificationGas = scaleBigIntByPercent(preVerificationGas, 110)

// biome-ignore lint/style/noParameterAssign: prepare userOperaiton for simulation
userOperation = {
...userOperation,
preVerificationGas,
preVerificationGas: 0n,
verificationGasLimit: 10_000_000n,
callGasLimit: 10_000_000n
}
Expand Down Expand Up @@ -534,6 +525,21 @@ export class RpcHandler implements IRpcEndpoint {
)
}

let preVerificationGas = await calcPreVerificationGas({
config: this.config,
userOperation: {
...userOperation,
callGasLimit, // use actual callGasLimit
verificationGasLimit, // use actual verificationGasLimit
paymasterPostOpGasLimit, // use actual paymasterPostOpGasLimit
paymasterVerificationGasLimit // use actual paymasterVerificationGasLimit
},
entryPoint,
gasPriceManager: this.gasPriceManager,
validate: false
})
preVerificationGas = scaleBigIntByPercent(preVerificationGas, 110)

// TODO: uncomment this
// Check if userOperation passes
if (isVersion06(userOperation)) {
Expand Down
32 changes: 19 additions & 13 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function removeZeroBytesFromUserOp<T extends UserOperation>(
} as T extends UserOperationV06 ? UserOperationV06 : PackedUserOperation
}

export function randomizeUserOp<T extends UserOperation>(
export function randomizeUserOpSignature<T extends UserOperation>(
userOpearation: T
): T extends UserOperationV06 ? UserOperationV06 : PackedUserOperation {
if (isVersion06(userOpearation)) {
Expand All @@ -238,11 +238,11 @@ export function randomizeUserOp<T extends UserOperation>(
nonce: userOpearation.nonce,
initCode: userOpearation.initCode,
callData: userOpearation.callData,
callGasLimit: maxUint256,
verificationGasLimit: maxUint256,
preVerificationGas: maxUint256,
maxFeePerGas: maxUint256,
maxPriorityFeePerGas: maxUint256,
callGasLimit: userOpearation.callGasLimit,
verificationGasLimit: userOpearation.verificationGasLimit,
preVerificationGas: userOpearation.preVerificationGas,
maxFeePerGas: userOpearation.maxFeePerGas,
maxPriorityFeePerGas: userOpearation.maxPriorityFeePerGas,
paymasterAndData: userOpearation.paymasterAndData,
signature: randomizeBytes(size(userOpearation.signature))
} as T extends UserOperationV06 ? UserOperationV06 : PackedUserOperation
Expand All @@ -257,14 +257,15 @@ export function randomizeUserOp<T extends UserOperation>(
nonce: packedUserOperation.nonce,
initCode: packedUserOperation.initCode,
callData: packedUserOperation.callData,
accountGasLimits: toHex(maxUint256),
preVerificationGas: maxUint256,
gasFees: toHex(maxUint256),
accountGasLimits: packedUserOperation.accountGasLimits,
preVerificationGas: packedUserOperation.preVerificationGas,
gasFees: packedUserOperation.gasFees,
paymasterAndData: packedUserOperation.paymasterAndData,
signature: randomizeBytes(size(packedUserOperation.signature))
} as T extends UserOperationV06 ? UserOperationV06 : PackedUserOperation
}

// Return ranomized bytes of certain length.
export function randomizeBytes(length: number) {
return toHex(crypto.randomBytes(length).toString("hex"))
}
Expand Down Expand Up @@ -462,18 +463,22 @@ export function calcDefaultPreVerificationGas(
}

// Returns back the bytes for the handleOps call
function getHandleOpsCallData(op: UserOperation, entryPoint: Address) {
function getHandleOpsCallData(
op: UserOperation,
entryPoint: Address,
verify: boolean
) {
if (isVersion07(op)) {
return encodeFunctionData({
abi: EntryPointV07Abi,
functionName: "handleOps",
args: [[randomizeUserOp(op)], entryPoint]
args: [[randomizeUserOpSignature(op)], entryPoint]
})
}
return encodeFunctionData({
abi: EntryPointV06Abi,
functionName: "handleOps",
args: [[randomizeUserOp(op)], entryPoint]
args: [[randomizeUserOpSignature(op)], entryPoint]
})
}

Expand Down Expand Up @@ -600,7 +605,8 @@ export async function calcOptimismPreVerificationGas(
opGasPriceOracle.read.getL1Fee([serializedTx]),
verify
? gasPriceManager.getMaxBaseFeePerGas()
: gasPriceManager.getBaseFee()
: gasPriceManager.getBaseFee(),
opGasPriceOracle.read.getL1GasUsed([serializedTx])
])

if (op.maxFeePerGas <= 1n || op.maxPriorityFeePerGas <= 1n) {
Expand Down

0 comments on commit 751e433

Please sign in to comment.