Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding tenderly simulation for userop validation #277

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages/*"
],
"npmClient": "yarn",
"version": "1.5.34",
"version": "1.5.35",
"stream": "true",
"command": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "1.5.34",
"version": "1.5.35",
"engines": {
"node": ">=18.0.0"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -34,10 +34,10 @@
"dependencies": {
"@fastify/cors": "9.0.1",
"@fastify/websocket": "10.0.1",
"@skandha/executor": "^1.5.34",
"@skandha/monitoring": "^1.5.34",
"@skandha/types": "^1.5.34",
"@skandha/utils": "^1.5.34",
"@skandha/executor": "^1.5.35",
"@skandha/monitoring": "^1.5.35",
"@skandha/types": "^1.5.35",
"@skandha/utils": "^1.5.35",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"ethers": "5.7.2",
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -40,12 +40,12 @@
"@libp2p/peer-id-factory": "2.0.1",
"@libp2p/prometheus-metrics": "1.1.3",
"@multiformats/multiaddr": "12.1.3",
"@skandha/api": "^1.5.34",
"@skandha/db": "^1.5.34",
"@skandha/executor": "^1.5.34",
"@skandha/monitoring": "^1.5.34",
"@skandha/node": "^1.5.34",
"@skandha/types": "^1.5.34",
"@skandha/api": "^1.5.35",
"@skandha/db": "^1.5.35",
"@skandha/executor": "^1.5.35",
"@skandha/monitoring": "^1.5.35",
"@skandha/node": "^1.5.35",
"@skandha/types": "^1.5.35",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "Smart contracts of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@chainsafe/ssz": "0.10.1",
"@farcaster/rocksdb": "5.5.0",
"@skandha/types": "^1.5.34"
"@skandha/types": "^1.5.35"
},
"devDependencies": {
"@types/rocksdb": "3.0.1",
Expand Down
11 changes: 6 additions & 5 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,11 +35,12 @@
},
"dependencies": {
"@flashbots/ethers-provider-bundle": "0.6.2",
"@skandha/monitoring": "^1.5.34",
"@skandha/params": "^1.5.34",
"@skandha/types": "^1.5.34",
"@skandha/utils": "^1.5.34",
"@skandha/monitoring": "^1.5.35",
"@skandha/params": "^1.5.35",
"@skandha/types": "^1.5.35",
"@skandha/utils": "^1.5.35",
"async-mutex": "0.4.0",
"axios": "^1.7.9",
"ethers": "5.7.2",
"strict-event-emitter-types": "2.0.0",
"ws": "8.16.0"
Expand Down
16 changes: 16 additions & 0 deletions packages/executor/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ export class Config {
)
);

config.tenderlyApiUrl = String(
fromEnvVar(
"TENDERLY_API_URL",
config.tenderlyApiUrl || bundlerDefaultConfigs.tenderlyApiUrl
)
);

config.tenderlyKey = String(
fromEnvVar(
"TENDERLY_KEY",
config.tenderlyKey || bundlerDefaultConfigs.tenderlyKey
)
);

config.blockscoutApiKeys = fromEnvVar(
"BLOCKSCOUT_API_KEYS",
config.blockscoutApiKeys != undefined
Expand Down Expand Up @@ -433,6 +447,8 @@ const bundlerDefaultConfigs: BundlerConfig = {
fastlaneValidators: [],
blockscoutUrl: "",
blockscoutApiKeys: [],
tenderlyApiUrl: "",
tenderlyKey: "",
};

function getEnvVar<T>(envVar: string, fallback: T): T | string {
Expand Down
2 changes: 2 additions & 0 deletions packages/executor/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export interface NetworkConfig {
fastlaneValidators: string[];
blockscoutUrl: string;
blockscoutApiKeys: string[];
tenderlyApiUrl: string;
tenderlyKey: string;
}

export type BundlerConfig = Omit<
Expand Down
2 changes: 2 additions & 0 deletions packages/executor/src/modules/skandha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export class Skandha {
vglMarkupPercent: this.networkConfig.vglMarkupPercent,
blockscoutUrl: this.networkConfig.blockscoutUrl,
blockscoutApiKeys: this.networkConfig.blockscoutApiKeys.length,
tenderlyApiUrl: this.networkConfig.tenderlyApiUrl,
tenderlyKey: this.networkConfig.tenderlyKey,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/executor/src/services/UserOpValidation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class UserOpValidationService {
);
this.unsafeValidationService = new UnsafeValidationService(
this.provider,
this.chainId,
this.networkConfig,
this.logger
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { UserOperationStruct } from "@skandha/types/lib/executor/contracts/EntryPoint";
import { IEntryPoint } from "@skandha/types/src/executor/contracts";
import axios from "axios";
import { BigNumber, constants } from "ethers";
import { Logger } from "@skandha/types/lib";

export class TenderlyValidationService {
constructor(
private tenderlyApiUrl: string,
private tenderlyAccessKey: string,
private chainId: number,
private logger: Logger
) {}

async validate(
userOp: UserOperationStruct,
entryPoint: IEntryPoint,
gasLimit?: BigNumber
): Promise<any> {
const config = {
method: "post",
url: `${this.tenderlyApiUrl}/simulate`,
headers: {
"Content-Type": "application/json",
"X-Access-Key": this.tenderlyAccessKey,
},
data: JSON.stringify({
network_id: `${this.chainId}`,
from: constants.AddressZero,
to: entryPoint.address,
input: entryPoint.interface.encodeFunctionData("simulateValidation", [
userOp,
]),
gas: gasLimit?.toNumber(),
}),
};
return await axios
.request(config)
.then((response) => {
const parsed = entryPoint.interface.parseError(
response.data.transaction.transaction_info.call_trace.error_hex_data
);
return {
...parsed,
errorName: parsed.name,
errorArgs: parsed.args,
};
})
.catch((err) => {
this.logger.error(`Tenderly validation failed: ${err}`);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ import { IEntryPoint__factory } from "@skandha/types/lib/executor/contracts";
import { UserOperationStruct } from "@skandha/types/lib/executor/contracts/EntryPoint";
import { Contract, providers, constants } from "ethers";
import { Logger } from "@skandha/types/lib";
import * as RpcErrorCodes from "@skandha/types/lib/api/errors/rpc-error-codes";
import RpcError from "@skandha/types/lib/api/errors/rpc-error";
import { NetworkConfig, UserOpValidationResult } from "../../../interfaces";
import { nonGethErrorHandler, parseErrorResult } from "../utils";
import { getUserOpGasLimit } from "../../BundlingService/utils";
import { TenderlyValidationService } from "./tenderly";

export class UnsafeValidationService {
private tenderlyValidationService: TenderlyValidationService | null = null;
constructor(
private provider: providers.Provider,
private chainId: number,
private networkConfig: NetworkConfig,
private logger: Logger
) {}
) {
if (networkConfig.tenderlyKey && networkConfig.tenderlyApiUrl) {
this.tenderlyValidationService = new TenderlyValidationService(
networkConfig.tenderlyApiUrl,
networkConfig.tenderlyKey,
chainId,
logger
);
}
}

async validateUnsafely(
userOp: UserOperationStruct,
Expand All @@ -30,12 +44,38 @@ export class UnsafeValidationService {
)
: undefined;

const errorResult = await entryPointContract.callStatic
.simulateValidation(userOp, {
gasLimit,
})
.catch((e: any) => nonGethErrorHandler(entryPointContract, e));
return parseErrorResult(userOp, errorResult, false);
let errorResult;

if (this.tenderlyValidationService) {
errorResult = await this.tenderlyValidationService.validate(
userOp,
entryPointContract,
gasLimit
);
} else {
errorResult = await entryPointContract.callStatic
.simulateValidation(userOp, {
gasLimit,
})
.catch((e: any) => nonGethErrorHandler(entryPointContract, e));
}

const result = parseErrorResult(userOp, errorResult, false);

const { returnInfo } = result;
if (returnInfo.sigFailed) {
throw new RpcError(
"Invalid UserOp signature or paymaster signature",
RpcErrorCodes.INVALID_SIGNATURE
);
}

const now = Math.floor(Date.now() / 1000);
if (returnInfo.validUntil != null && returnInfo.validUntil < now) {
throw new RpcError("already expired", RpcErrorCodes.USEROP_EXPIRED);
}

return result;
}

async validateUnsafelyWithForwarder(
Expand Down
4 changes: 2 additions & 2 deletions packages/monitoring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The Monitoring module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -32,7 +32,7 @@
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
"@skandha/types": "^1.5.34",
"@skandha/types": "^1.5.35",
"prom-client": "^14.2.0"
}
}
16 changes: 8 additions & 8 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The bundler node module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -56,13 +56,13 @@
"@libp2p/prometheus-metrics": "1.1.3",
"@libp2p/tcp": "6.1.0",
"@multiformats/multiaddr": "11.4.0",
"@skandha/api": "^1.5.34",
"@skandha/db": "^1.5.34",
"@skandha/executor": "^1.5.34",
"@skandha/monitoring": "^1.5.34",
"@skandha/params": "^1.5.34",
"@skandha/types": "^1.5.34",
"@skandha/utils": "^1.5.34",
"@skandha/api": "^1.5.35",
"@skandha/db": "^1.5.35",
"@skandha/executor": "^1.5.35",
"@skandha/monitoring": "^1.5.35",
"@skandha/params": "^1.5.35",
"@skandha/types": "^1.5.35",
"@skandha/utils": "^1.5.35",
"@types/varint": "6.0.1",
"abstract-leveldown": "7.2.0",
"datastore-core": "8.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/params/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -28,8 +28,8 @@
"@arbitrum/sdk": "3.1.4",
"@chainsafe/ssz": "0.10.1",
"@mantleio/sdk": "0.2.1",
"@skandha/types": "^1.5.34",
"@skandha/utils": "^1.5.34",
"@skandha/types": "^1.5.35",
"@skandha/utils": "^1.5.35",
"ethers": "5.7.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.5.34",
"version": "1.5.35",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/api/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export type GetConfigResponse = {
vglMarkupPercent: number;
blockscoutUrl: string;
blockscoutApiKeys: number;
tenderlyApiUrl: string;
tenderlyKey: string;
};

export type SupportedEntryPoints = string[];
Expand Down
Loading