Skip to content

Commit

Permalink
Merge branch 'fix/error-500-validation' of github.com:pimlicolabs/alt…
Browse files Browse the repository at this point in the history
…o into gas-est-500-fix
  • Loading branch information
nikmel2803 committed Dec 2, 2023
2 parents cad12e6 + b3160da commit debd1b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/rpc/src/vatidation/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export interface LogCallFrame {
export interface LogFrameResult {
getGasUsed: () => number // - returns amount of gas used throughout the frame as a Number
getOutput: () => Buffer // - returns the output as a buffer
getError: () => any // - returns an error if one occured during execution and undefined` otherwise
getError: () => any // - returns an error if one occurred during execution and undefined` otherwise
}

export interface LogOpCode {
Expand Down Expand Up @@ -238,7 +238,7 @@ export interface LogStep {
getCost: () => number // returns the cost of the opcode as a Number
getDepth: () => number // returns the execution depth as a Number
getRefund: () => number // returns the amount to be refunded as a Number
getError: () => string | undefined // returns information about the error if one occured, otherwise returns undefined
getError: () => string | undefined // returns information about the error if one occurred, otherwise returns undefined
// If error is non-empty, all other fields should be ignored.
}

Expand Down
38 changes: 32 additions & 6 deletions packages/rpc/src/vatidation/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ import {
} from "@alto/types"
import { ValidationResult } from "@alto/types"
import { Logger, Metrics } from "@alto/utils"
import { PublicClient, getContract, encodeFunctionData, decodeErrorResult, Account, Transport, Chain } from "viem"
import {
PublicClient,
getContract,
encodeFunctionData,
decodeErrorResult,
Account,
Transport,
Chain,
ContractFunctionExecutionError,
BaseError
} from "viem"
import { hexDataSchema } from "@alto/types"
import { z } from "zod"
import { fromZodError } from "zod-validation-error"
import * as sentry from "@sentry/node"
export interface IValidator {
getExecutionResult(userOperation: UserOperation, usingTenderly?: boolean): Promise<ExecutionResult>
getValidationResult(userOperation: UserOperation, usingTenderly?: boolean): Promise<ValidationResult>
Expand Down Expand Up @@ -50,12 +61,27 @@ async function getSimulationResult(
const entryPointErrorSchemaParsing = usingTenderly
? entryPointErrorsSchema.safeParse(errorResult)
: entryPointExecutionErrorSchema.safeParse(errorResult)

if (!entryPointErrorSchemaParsing.success) {
const err = fromZodError(entryPointErrorSchemaParsing.error)
logger.error({ error: err.message }, "unexpected error during valiation")
logger.error(JSON.stringify(errorResult))
err.message = `User Operation simulation returned unexpected invalid response: ${err.message}`
throw err
try {
const err = fromZodError(entryPointErrorSchemaParsing.error)
logger.error({ error: err.message }, "unexpected error during valiation")
logger.error(JSON.stringify(errorResult))
err.message = `User Operation simulation returned unexpected invalid response: ${err.message}`
throw err
} catch {
if (errorResult instanceof BaseError) {
const revertError = errorResult.walk((err) => err instanceof ContractFunctionExecutionError)
throw new RpcError(
`User Operation simulation returned unexpected invalid response: ${
(revertError?.cause as any)?.reason
}`,
ValidationErrors.SimulateValidation
)
}
sentry.captureException(errorResult)
throw new Error(`User Operation simulation returned unexpected invalid response: ${errorResult}`)
}
}

const errorData = entryPointErrorSchemaParsing.data
Expand Down

0 comments on commit debd1b6

Please sign in to comment.