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 1 commit
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 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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
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
2 changes: 1 addition & 1 deletion 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
1 change: 1 addition & 0 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@skandha/types": "^1.5.34",
"@skandha/utils": "^1.5.34",
"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.tenderlyUrl = String(
fromEnvVar(
"TENDERLY_URL",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please call this TENDERLY_API_URL instead?

config.tenderlyUrl || bundlerDefaultConfigs.tenderlyUrl
)
);

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: [],
tenderlyUrl: "",
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[];
tenderlyUrl: 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,
tenderlyUrl: this.networkConfig.tenderlyUrl,
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 tenderlyUrl: 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.tenderlyUrl}/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.tenderlyUrl) {
this.tenderlyValidationService = new TenderlyValidationService(
networkConfig.tenderlyUrl,
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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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 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;
tenderlyUrl: string;
tenderlyKey: string;
};

export type SupportedEntryPoints = string[];
Expand Down
40 changes: 37 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,15 @@ axios@^1.0.0, axios@^1.6.1:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.7.9:
version "1.7.9"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -9354,7 +9363,16 @@ [email protected], strict-event-emitter-types@^2.0.0:
resolved "https://registry.yarnpkg.com/strict-event-emitter-types/-/strict-event-emitter-types-2.0.0.tgz#05e15549cb4da1694478a53543e4e2f4abcf277f"
integrity sha512-Nk/brWYpD85WlOgzw5h173aci0Teyv8YdIAEtV+N88nDB0dLlazZyJMIsN6eo1/AR61l+p6CJTG1JIyFaoNEEA==

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9414,7 +9432,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -10264,7 +10289,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -10282,6 +10307,15 @@ wrap-ansi@^6.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down