Skip to content

Commit

Permalink
Merge pull request #43 from etherspot/arbitrum
Browse files Browse the repository at this point in the history
Fix issue with the tracer on arbitrum
  • Loading branch information
0xSulpiride authored Jun 20, 2023
2 parents 2e20e33 + a800be0 commit c5cec0b
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.0.8",
"version": "0.0.9",
"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": "0.0.8",
"version": "0.0.9",
"engines": {
"node": ">=18.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.0.8",
"version": "0.0.9",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,12 +35,12 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^0.0.8",
"executor": "^0.0.9",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^0.0.8"
"types": "^0.0.9"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastify, { FastifyInstance } from "fastify";
import cors from "@fastify/cors";
import RpcError from "types/lib/api/errors/rpc-error";
import { ServerConfig } from "types/src/api/interfaces";
import { ServerConfig } from "types/lib/api/interfaces";
import logger from "./logger";

export class Server {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "0.0.8",
"version": "0.0.9",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -31,13 +31,13 @@
"url": "https://https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"api": "^0.0.8",
"db": "^0.0.8",
"executor": "^0.0.8",
"api": "^0.0.9",
"db": "^0.0.9",
"executor": "^0.0.9",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"types": "^0.0.8",
"types": "^0.0.9",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db",
"version": "0.0.8",
"version": "0.0.9",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -37,6 +37,6 @@
"devDependencies": {
"@types/rocksdb": "3.0.1",
"prettier": "^2.8.4",
"types": "^0.0.8"
"types": "^0.0.9"
}
}
8 changes: 6 additions & 2 deletions packages/executor/customTracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function tracer() {
switch (opcode) {
case 'SLOAD':
case 'SSTORE':
this.pSloadStore(log);
if (log.getDepth() !== 1) {
this.pSloadStore(log);
}
break;
case 'REVERT':
case 'RETURN':
Expand All @@ -73,7 +75,9 @@ function tracer() {
}
break;
case 'KECCAK256':
this.pKeccak(log);
if (log.getDepth() !== 1) {
this.pKeccak(log);
}
break;
case 'NUMBER':
if (log.getDepth() == 1) {
Expand Down
6 changes: 3 additions & 3 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "executor",
"version": "0.0.8",
"version": "0.0.9",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"params": "^0.0.8",
"types": "^0.0.8"
"params": "^0.0.9",
"types": "^0.0.9"
}
}
1 change: 1 addition & 0 deletions packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class Executor {
this.reputationService
);
this.eth = new Eth(
this.network,
this.provider,
this.userOpValidationService,
this.mempoolService,
Expand Down
27 changes: 23 additions & 4 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, ethers } from "ethers";
import { BigNumber, BigNumberish, ethers } from "ethers";
import { arrayify, hexlify } from "ethers/lib/utils";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
Expand All @@ -13,6 +13,9 @@ import {
UserOperationReceipt,
} from "types/lib/api/interfaces";
import { EntryPoint__factory } from "types/lib/executor/contracts/factories";
import { NetworkName } from "types/lib";
import { estimateArbitrumPVG } from "params/lib/gas-estimation/arbitrum";
import { IPVGEstimator } from "params/lib/types/IPVGEstimator";
import { NetworkConfig } from "../config";
import { deepHexlify, packUserOp } from "../utils";
import { UserOpValidationService, MempoolService } from "../services";
Expand All @@ -23,13 +26,22 @@ import {
} from "./interfaces";

export class Eth {
private pvgEstimator: IPVGEstimator | null = null;

constructor(
private networkName: NetworkName,
private provider: ethers.providers.JsonRpcProvider,
private userOpValidationService: UserOpValidationService,
private mempoolService: MempoolService,
private config: NetworkConfig,
private logger: Logger
) {}
) {
if (
["arbitrum", "arbitrumNitro", "arbitrumNova"].includes(this.networkName)
) {
this.pvgEstimator = estimateArbitrumPVG(this.provider);
}
}

/**
*
Expand Down Expand Up @@ -86,14 +98,21 @@ export class Eth {
preVerificationGas: 0,
...userOp,
};
const preVerificationGas = this.calcPreVerificationGas(userOp);
let preVerificationGas: BigNumberish = this.calcPreVerificationGas(userOp);
userOpComplemented.preVerificationGas = preVerificationGas;

const { returnInfo } =
await this.userOpValidationService.validateForEstimation(
userOpComplemented,
entryPoint
);
if (this.pvgEstimator) {
preVerificationGas = await this.pvgEstimator(
entryPoint,
userOpComplemented,
preVerificationGas
);
}

// eslint-disable-next-line prefer-const
let { preOpGas, validAfter, validUntil } = returnInfo;
Expand All @@ -110,7 +129,7 @@ export class Eth {
err.message.match(/reason="(.*?)"/)?.at(1) ?? "execution reverted";
throw new RpcError(message, RpcErrorCodes.EXECUTION_REVERTED);
});
// const preVerificationGas = this.calcPreVerificationGas(userOp);

const verificationGas = BigNumber.from(preOpGas).toNumber();
validAfter = BigNumber.from(validAfter);
validUntil = BigNumber.from(validUntil);
Expand Down
15 changes: 15 additions & 0 deletions packages/executor/src/services/GethTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ if (tracer == null) {
const regexp = /function \w+\s*\(\s*\)\s*{\s*return\s*(\{[\s\S]+\});?\s*\}\s*$/;
const stringifiedTracer = tracer.match(regexp)![1];

// UNCOMMENT FOR DEBUG PURPOSES
// eslint-disable-next-line no-console
// console.log(
// JSON.stringify(
// {
// tracer: stringifiedTracer.replace(
// /0xffffffffffffffffffffffffffffffffffffffff/g,
// "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"
// ),
// },
// undefined,
// 2
// )
// );

export class GethTracer {
constructor(private provider: providers.JsonRpcProvider) {}

Expand Down
6 changes: 4 additions & 2 deletions packages/params/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "params",
"version": "0.0.8",
"version": "0.0.9",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -21,7 +21,9 @@
"url": "https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"types": "^0.0.8"
"types": "^0.0.9",
"ethers": "5.7.2",
"@arbitrum/sdk": "3.1.4"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
Expand Down
1 change: 1 addition & 0 deletions packages/params/src/eip1559.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const chainsWithoutEIP1559: NetworkName[] = [
"fuseSparknet",
"bsc",
"bscTest",
"polygonzkevm",
];
45 changes: 45 additions & 0 deletions packages/params/src/gas-estimation/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NodeInterface__factory } from "@arbitrum/sdk/dist/lib/abi/factories/NodeInterface__factory";
import { NODE_INTERFACE_ADDRESS } from "@arbitrum/sdk/dist/lib/dataEntities/constants";
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
import { BigNumber, BigNumberish, ethers } from "ethers";
import { EntryPoint__factory } from "types/lib/executor/contracts";
import { IPVGEstimator, IPVGEstimatorWrapper } from "../types/IPVGEstimator";

export const estimateArbitrumPVG: IPVGEstimatorWrapper = (
provider
): IPVGEstimator => {
const nodeInterface = NodeInterface__factory.connect(
NODE_INTERFACE_ADDRESS,
provider
);
const dummyWallet = ethers.Wallet.createRandom();
return async (
entryPointAddr: string,
userOp: UserOperationStruct,
initial: BigNumberish
): Promise<BigNumber> => {
const entryPoint = EntryPoint__factory.connect(entryPointAddr, provider);
const handleOpsData = entryPoint.interface.encodeFunctionData("handleOps", [
[userOp],
dummyWallet.address,
]);

const contractCreation = BigNumber.from(userOp.nonce).eq(0);
try {
const gasEstimateComponents =
await nodeInterface.callStatic.gasEstimateL1Component(
entryPoint.address,
contractCreation,
handleOpsData
);
const l1GasEstimated = gasEstimateComponents.gasEstimateForL1;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const baseFee = gasEstimateComponents.baseFee;
return l1GasEstimated.add(initial);
} catch (err) {
// eslint-disable-next-line no-console
console.error("Error while estimating arbitrum PVG", err);
return BigNumber.from(initial);
}
};
};
12 changes: 12 additions & 0 deletions packages/params/src/types/IPVGEstimator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BigNumber, BigNumberish, providers } from "ethers";
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";

export type IPVGEstimatorWrapper = (
provider: providers.StaticJsonRpcProvider
) => IPVGEstimator;

export type IPVGEstimator = (
entryPointAddr: string,
userOp: UserOperationStruct,
initial: BigNumberish // initial amount of gas. It will be added to the estimated gas
) => Promise<BigNumber>;
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types",
"version": "0.0.8",
"version": "0.0.9",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/networks/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type NetworkName =
| "dev"
| "baseGoerli"
| "sepolia"
| "chiado";
| "chiado"
| "polygonzkevm";

export const networkNames: NetworkName[] = [
"mainnet",
Expand Down Expand Up @@ -61,6 +62,7 @@ export const networkNames: NetworkName[] = [
"baseGoerli",
"sepolia",
"chiado",
"polygonzkevm",
];

export const NETWORK_NAME_TO_CHAIN_ID: {
Expand Down Expand Up @@ -96,4 +98,5 @@ export const NETWORK_NAME_TO_CHAIN_ID: {
baseGoerli: 84531,
sepolia: 11155111,
chiado: 10200,
polygonzkevm: 1442,
};
Loading

0 comments on commit c5cec0b

Please sign in to comment.