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

epv7 fixes after testing #155

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ module.exports = {
},
{
files: ["**/test/**/*.test.ts"],
plugins: ["mocha", "chai-expect"],
extends: ["plugin:mocha/recommended", "plugin:chai-expect/recommended"],
plugins: ["mocha"],
extends: ["plugin:mocha/recommended"],
rules: {
// We observed that having multiple top level "describe" save valuable indentation
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md
Expand Down
13 changes: 9 additions & 4 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { Logger } from "types/lib";
import { PerChainMetrics } from "monitoring/lib";
import { UserOperation } from "types/lib/contracts/UserOperation";
import { UserOperationStruct } from "types/lib/contracts/EPv6/EntryPoint";
import {
UserOpValidationService,
MempoolService,
Expand All @@ -30,7 +31,6 @@ import {
SendUserOperationGasArgs,
} from "./interfaces";
import { Skandha } from "./skandha";
import { UserOperationStruct } from "types/lib/contracts/EPv6/EntryPoint";

export class Eth {
private pvgEstimator: IPVGEstimator | null = null;
Expand Down Expand Up @@ -112,7 +112,10 @@ export class Eth {
const nodeApi = this.getNodeAPI();
if (nodeApi) {
const { canonicalEntryPoint, canonicalMempoolId } = this.config;
if (canonicalEntryPoint.toLowerCase() == entryPoint.toLowerCase() && canonicalMempoolId.length > 0) {
if (
canonicalEntryPoint.toLowerCase() == entryPoint.toLowerCase() &&
canonicalMempoolId.length > 0
) {
const blockNumber = await this.provider.getBlockNumber(); // TODO: fetch blockNumber from simulateValidation
await nodeApi.publishVerifiedUserOperationJSON(
entryPoint,
Expand Down Expand Up @@ -229,7 +232,9 @@ export class Eth {
data,
preVerificationGas,
{
contractCreation: Boolean(userOp.factory && userOp.factory.length > 2),
contractCreation: Boolean(
userOp.factory && userOp.factory.length > 2
),
userOp: userOpComplemented,
}
);
Expand Down Expand Up @@ -296,7 +301,7 @@ export class Eth {
validUntil: BigNumber.from(validUntil),
callGasLimit,
maxFeePerGas: gasFee.maxFeePerGas,
maxPriorityFeePerGas: gasFee.maxPriorityFeePerGas
maxPriorityFeePerGas: gasFee.maxPriorityFeePerGas,
};
}

Expand Down
4 changes: 1 addition & 3 deletions packages/executor/src/modules/skandha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ export class Skandha {
minSignerBalance: `${ethers.utils.formatEther(
this.networkConfig.minSignerBalance
)} eth`,
minStake: `${ethers.utils.formatEther(
this.networkConfig.minStake!
)} eth`,
minStake: `${ethers.utils.formatEther(this.networkConfig.minStake!)} eth`,
multicall: this.networkConfig.multicall,
estimationStaticBuffer: BigNumber.from(
this.networkConfig.estimationStaticBuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const DefaultGasOverheads = {
nonZeroByte: 16,
bundleSize: 1,
sigSize: 65,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export enum EntryPointVersion {

export type StateOverrides = {
[address: string]: {
code: string
}
}
code: string;
};
};
24 changes: 5 additions & 19 deletions packages/executor/src/services/EntryPointService/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import { BigNumber, providers } from "ethers";
import {
UserOperation
} from "types/lib/contracts/UserOperation";
import { UserOperation } from "types/lib/contracts/UserOperation";
import { IDbController, Logger } from "types/lib";
import {
UserOperationByHashResponse,
Expand All @@ -13,10 +11,7 @@ import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { NetworkConfig, UserOpValidationResult } from "../../interfaces";
import { ReputationService } from "../ReputationService";
import {
EntryPointV7Service,
IEntryPointService,
} from "./versions";
import { EntryPointV7Service, IEntryPointService } from "./versions";
import { EntryPointVersion } from "./interfaces";
import {
EntryPointV7EventsService,
Expand Down Expand Up @@ -161,10 +156,7 @@ export class EntryPointService {
);
}

encodeSimulateValidation(
entryPoint: string,
userOp: UserOperation
): any {
encodeSimulateValidation(entryPoint: string, userOp: UserOperation): any {
return this.entryPoints[entryPoint.toLowerCase()].encodeSimulateValidation(
userOp
);
Expand Down Expand Up @@ -213,17 +205,11 @@ export class EntryPointService {
);
}

getFactory(
entryPoint: string,
userOp: UserOperation
): string | undefined {
getFactory(entryPoint: string, userOp: UserOperation): string | undefined {
return userOp.factory?.toLowerCase();
}

getPaymaster(
entryPoint: string,
userOp: UserOperation
): string | undefined {
getPaymaster(entryPoint: string, userOp: UserOperation): string | undefined {
return userOp.paymaster?.toLowerCase();
}
}
130 changes: 77 additions & 53 deletions packages/executor/src/services/EntryPointService/versions/0.0.7.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import {
EntryPoint,
UserOperationEventEvent
UserOperationEventEvent,
} from "types/lib/contracts/EPv7/core/EntryPoint";
import { _deployedBytecode } from "types/lib/contracts/EPv7/factories/core/EntryPointSimulations__factory";
import { IStakeManager } from "types/lib/contracts/EPv7/core/EntryPointSimulations";
import {
EntryPoint__factory
} from "types/lib/contracts/EPv7/factories/core";
import { EntryPoint__factory } from "types/lib/contracts/EPv7/factories/core";
import { BigNumber, providers } from "ethers";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { PackedUserOperation, UserOperation } from "types/lib/contracts/UserOperation";
import {
PackedUserOperation,
UserOperation,
} from "types/lib/contracts/UserOperation";
import { AddressZero, BytesZero } from "params/lib";
import { StakeManager__factory } from "types/lib/contracts/EPv7/factories/core";
import { IEntryPointSimulations } from "types/lib/contracts/EPv7/interfaces";
import { IEntryPointSimulations__factory } from "types/lib/contracts/EPv7/factories/interfaces";
import {
hexlify,
arrayify,
} from "ethers/lib/utils";
import { hexlify, arrayify } from "ethers/lib/utils";
import { Logger } from "types/lib";
import {
UserOperationReceipt,
UserOperationByHashResponse,
} from "types/lib/api/interfaces";
import { encodeUserOp, mergeValidationDataValues, packUserOp, unpackUserOp } from "../utils";
import {
encodeUserOp,
mergeValidationDataValues,
packUserOp,
unpackUserOp,
} from "../utils";
import {
Log,
NetworkConfig,
Expand All @@ -33,11 +36,11 @@ import {
} from "../../../interfaces";
import { deepHexlify } from "../../../utils";
import { DefaultGasOverheads } from "../constants";
import { IEntryPointService } from "./base";
import { StateOverrides } from "../interfaces";
import { decodeRevertReason } from "../utils/decodeRevertReason";
import { IEntryPointService } from "./base";

const entryPointSimulations = IEntryPointSimulations__factory.createInterface()
const entryPointSimulations = IEntryPointSimulations__factory.createInterface();

export class EntryPointV7Service implements IEntryPointService {
contract: EntryPoint;
Expand All @@ -59,40 +62,52 @@ export class EntryPointV7Service implements IEntryPointService {
}

async simulateHandleOp(userOp: UserOperation): Promise<any> {
const [data, stateOverrides] = this.encodeSimulateHandleOp(userOp, AddressZero, BytesZero);
const [data, stateOverrides] = this.encodeSimulateHandleOp(
userOp,
AddressZero,
BytesZero
);
const tx: providers.TransactionRequest = {
to: this.address,
data
}
data,
};
try {
const simulationResult = await this.provider.send('eth_call', [tx, 'latest', stateOverrides])
const res = entryPointSimulations.decodeFunctionResult('simulateHandleOp', simulationResult)
return res[0]
const simulationResult = await this.provider.send("eth_call", [
tx,
"latest",
stateOverrides,
]);
const res = entryPointSimulations.decodeFunctionResult(
"simulateHandleOp",
simulationResult
);
return res[0];
} catch (error: any) {
const err = decodeRevertReason(error)
const err = decodeRevertReason(error);
if (err != null) {
throw new Error(err)
throw new RpcError(err, RpcErrorCodes.EXECUTION_REVERTED);
}
throw error
throw error;
}
}

async simulateValidation(userOp: UserOperation): Promise<any> {
const [data, stateOverrides] = this.encodeSimulateValidation(userOp);
const tx: providers.TransactionRequest = {
to: this.address,
data
}
data,
};
try {
const errorResult = await this.provider
.send('eth_call', [tx, "latest", stateOverrides])
.send("eth_call", [tx, "latest", stateOverrides])
.catch((err) => this.nonGethErrorHandler(err));
return this.parseValidationResult(userOp, errorResult);
return this.parseValidationResult(userOp, errorResult);
} catch (err: any) {
const decodedError = decodeRevertReason(err)
const decodedError = decodeRevertReason(err);
if (decodedError != null) {
throw new RpcError(decodedError, RpcErrorCodes.VALIDATION_FAILED)
throw new RpcError(decodedError, RpcErrorCodes.VALIDATION_FAILED);
}
throw err;
}
}

Expand Down Expand Up @@ -121,30 +136,30 @@ export class EntryPointV7Service implements IEntryPointService {
targetCallData: string
): [string, StateOverrides] {
return [
entryPointSimulations.encodeFunctionData(
"simulateHandleOp",
[packUserOp(userOp), target, targetCallData]
),
entryPointSimulations.encodeFunctionData("simulateHandleOp", [
packUserOp(userOp),
target,
targetCallData,
]),
{
[this.address]: {
code: _deployedBytecode
}
}
]
code: _deployedBytecode,
},
},
];
}

encodeSimulateValidation(userOp: UserOperation): [string, StateOverrides] {
return [
entryPointSimulations.encodeFunctionData(
"simulateValidation",
[packUserOp(userOp)]
),
entryPointSimulations.encodeFunctionData("simulateValidation", [
packUserOp(userOp),
]),
{
[this.address]: {
code: _deployedBytecode
}
}
]
code: _deployedBytecode,
},
},
];
}

/******************/
Expand Down Expand Up @@ -247,7 +262,7 @@ export class EntryPointV7Service implements IEntryPointService {
signature: hexlify(Buffer.alloc(ov.sigSize, 1)),
...userOp,
} as any);
let encoded: string = encodeUserOp(packedUserOp, forSignature);
const encoded: string = encodeUserOp(packedUserOp, forSignature);
const packed = arrayify(encoded);
const lengthInWord = (packed.length + 31) / 32;
const callDataCost = packed
Expand All @@ -266,34 +281,43 @@ export class EntryPointV7Service implements IEntryPointService {
userOp: UserOperation,
data: string
): UserOpValidationResult {
const [decoded] = entryPointSimulations.decodeFunctionResult("simulateValidation", data) as IEntryPointSimulations.ValidationResultStructOutput[];
const [decoded] = entryPointSimulations.decodeFunctionResult(
"simulateValidation",
data
) as IEntryPointSimulations.ValidationResultStructOutput[];
const mergedValidation = mergeValidationDataValues(
decoded.returnInfo.accountValidationData,
decoded.returnInfo.paymasterValidationData
);
function fillEntity (addr: string | undefined, info: IStakeManager.StakeInfoStructOutput): StakeInfo | undefined {
if (addr == null || addr === AddressZero) return undefined
function fillEntity(
addr: string | undefined,
info: IStakeManager.StakeInfoStructOutput
): StakeInfo | undefined {
if (addr == null || addr === AddressZero) return undefined;
return {
addr,
stake: info.stake,
unstakeDelaySec: info.unstakeDelaySec
}
unstakeDelaySec: info.unstakeDelaySec,
};
}

const returnInfo = {
sigFailed: mergedValidation.aggregator !== AddressZero,
validUntil: mergedValidation.validUntil,
validAfter: mergedValidation.validAfter,
preOpGas: decoded.returnInfo.preOpGas,
prefund: decoded.returnInfo.prefund
}
prefund: decoded.returnInfo.prefund,
};
return {
returnInfo,
senderInfo: fillEntity(userOp.sender, decoded.senderInfo) as StakeInfo,
paymasterInfo: fillEntity(userOp.paymaster, decoded.paymasterInfo),
factoryInfo: fillEntity(userOp.factory, decoded.factoryInfo),
aggregatorInfo: fillEntity(decoded.aggregatorInfo.aggregator, decoded.aggregatorInfo.stakeInfo)
}
aggregatorInfo: fillEntity(
decoded.aggregatorInfo.aggregator,
decoded.aggregatorInfo.stakeInfo
),
};
}

private nonGethErrorHandler(errorResult: any): any {
Expand Down
8 changes: 6 additions & 2 deletions packages/executor/src/services/UserOpValidation/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { BigNumber, BytesLike } from "ethers";
import { Interface, hexZeroPad, hexlify, keccak256 } from "ethers/lib/utils";
import { BundlerCollectorReturn, CallEntry } from "types/lib/executor";
import { StakeInfo } from "../../interfaces";
import { IEntryPoint__factory, IPaymaster__factory, IAccount__factory } from "types/lib/contracts/EPv7/factories/interfaces";
import {
IEntryPoint__factory,
IPaymaster__factory,
IAccount__factory,
} from "types/lib/contracts/EPv7/factories/interfaces";
import { SenderCreator__factory } from "types/lib/contracts/EPv7/factories/core";
import { StakeInfo } from "../../interfaces";

export function compareBytecode(
artifactBytecode: string,
Expand Down
Loading
Loading