@pimlico/alto 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/esm/cli/alto.d.ts +6 -0
  2. package/esm/cli/alto.js +92 -0
  3. package/esm/cli/alto.js.map +1 -0
  4. package/esm/cli/config/bundler.d.ts +403 -0
  5. package/esm/cli/config/bundler.js +134 -0
  6. package/esm/cli/config/bundler.js.map +1 -0
  7. package/esm/cli/config/index.d.ts +3 -0
  8. package/esm/cli/config/index.js +3 -0
  9. package/esm/cli/config/index.js.map +1 -0
  10. package/esm/cli/config/options.d.ts +11 -0
  11. package/esm/cli/config/options.js +348 -0
  12. package/esm/cli/config/options.js.map +1 -0
  13. package/esm/cli/customTransport.d.ts +14 -0
  14. package/esm/cli/customTransport.js +53 -0
  15. package/esm/cli/customTransport.js.map +1 -0
  16. package/esm/cli/handler.d.ts +3 -0
  17. package/esm/cli/handler.js +140 -0
  18. package/esm/cli/handler.js.map +1 -0
  19. package/esm/cli/index.d.ts +4 -0
  20. package/esm/cli/index.js +4 -0
  21. package/esm/cli/index.js.map +1 -0
  22. package/esm/cli/instrumentation.d.ts +2 -0
  23. package/esm/cli/instrumentation.js +39 -0
  24. package/esm/cli/instrumentation.js.map +1 -0
  25. package/esm/cli/setupServer.d.ts +17 -0
  26. package/esm/cli/setupServer.js +155 -0
  27. package/esm/cli/setupServer.js.map +1 -0
  28. package/esm/cli/util.d.ts +22 -0
  29. package/esm/cli/util.js +30 -0
  30. package/esm/cli/util.js.map +1 -0
  31. package/esm/executor/executor.d.ts +55 -0
  32. package/esm/executor/executor.js +645 -0
  33. package/esm/executor/executor.js.map +1 -0
  34. package/esm/executor/executorManager.d.ts +34 -0
  35. package/esm/executor/executorManager.js +402 -0
  36. package/esm/executor/executorManager.js.map +1 -0
  37. package/esm/executor/index.d.ts +5 -0
  38. package/esm/executor/index.js +5 -0
  39. package/esm/executor/index.js.map +1 -0
  40. package/esm/executor/senderManager.d.ts +17 -0
  41. package/esm/executor/senderManager.js +160 -0
  42. package/esm/executor/senderManager.js.map +1 -0
  43. package/esm/executor/test/utils.d.ts +13 -0
  44. package/esm/executor/test/utils.js +75 -0
  45. package/esm/executor/test/utils.js.map +1 -0
  46. package/esm/executor/utils.d.ts +32 -0
  47. package/esm/executor/utils.js +241 -0
  48. package/esm/executor/utils.js.map +1 -0
  49. package/esm/index.d.ts +2 -0
  50. package/esm/index.js +2 -0
  51. package/esm/index.js.map +1 -0
  52. package/esm/mempool/index.d.ts +5 -0
  53. package/esm/mempool/index.js +5 -0
  54. package/esm/mempool/index.js.map +1 -0
  55. package/esm/mempool/mempool.d.ts +64 -0
  56. package/esm/mempool/mempool.js +487 -0
  57. package/esm/mempool/mempool.js.map +1 -0
  58. package/esm/mempool/monitoring.d.ts +10 -0
  59. package/esm/mempool/monitoring.js +34 -0
  60. package/esm/mempool/monitoring.js.map +1 -0
  61. package/esm/mempool/nullMempool.d.ts +15 -0
  62. package/esm/mempool/nullMempool.js +36 -0
  63. package/esm/mempool/nullMempool.js.map +1 -0
  64. package/esm/mempool/reputationManager.d.ts +115 -0
  65. package/esm/mempool/reputationManager.js +401 -0
  66. package/esm/mempool/reputationManager.js.map +1 -0
  67. package/esm/mempool/store.d.ts +22 -0
  68. package/esm/mempool/store.js +123 -0
  69. package/esm/mempool/store.js.map +1 -0
  70. package/esm/rpc/EntryPointSimulationsV07.d.ts +62 -0
  71. package/esm/rpc/EntryPointSimulationsV07.js +407 -0
  72. package/esm/rpc/EntryPointSimulationsV07.js.map +1 -0
  73. package/esm/rpc/ExecuteSimulator.d.ts +37 -0
  74. package/esm/rpc/ExecuteSimulator.js +48 -0
  75. package/esm/rpc/ExecuteSimulator.js.map +1 -0
  76. package/esm/rpc/gasEstimation.d.ts +17 -0
  77. package/esm/rpc/gasEstimation.js +414 -0
  78. package/esm/rpc/gasEstimation.js.map +1 -0
  79. package/esm/rpc/index.d.ts +5 -0
  80. package/esm/rpc/index.js +5 -0
  81. package/esm/rpc/index.js.map +1 -0
  82. package/esm/rpc/nonceQueuer.d.ts +25 -0
  83. package/esm/rpc/nonceQueuer.js +135 -0
  84. package/esm/rpc/nonceQueuer.js.map +1 -0
  85. package/esm/rpc/rpcHandler.d.ts +64 -0
  86. package/esm/rpc/rpcHandler.js +738 -0
  87. package/esm/rpc/rpcHandler.js.map +1 -0
  88. package/esm/rpc/server.d.ts +31 -0
  89. package/esm/rpc/server.js +243 -0
  90. package/esm/rpc/server.js.map +1 -0
  91. package/esm/rpc/validation/BundlerCollectorTracerV06.d.ts +102 -0
  92. package/esm/rpc/validation/BundlerCollectorTracerV06.js +255 -0
  93. package/esm/rpc/validation/BundlerCollectorTracerV06.js.map +1 -0
  94. package/esm/rpc/validation/BundlerCollectorTracerV07.d.ts +102 -0
  95. package/esm/rpc/validation/BundlerCollectorTracerV07.js +254 -0
  96. package/esm/rpc/validation/BundlerCollectorTracerV07.js.map +1 -0
  97. package/esm/rpc/validation/SafeValidator.d.ts +31 -0
  98. package/esm/rpc/validation/SafeValidator.js +330 -0
  99. package/esm/rpc/validation/SafeValidator.js.map +1 -0
  100. package/esm/rpc/validation/TracerResultParserV06.d.ts +13 -0
  101. package/esm/rpc/validation/TracerResultParserV06.js +578 -0
  102. package/esm/rpc/validation/TracerResultParserV06.js.map +1 -0
  103. package/esm/rpc/validation/TracerResultParserV07.d.ts +33 -0
  104. package/esm/rpc/validation/TracerResultParserV07.js +561 -0
  105. package/esm/rpc/validation/TracerResultParserV07.js.map +1 -0
  106. package/esm/rpc/validation/UnsafeValidator.d.ts +64 -0
  107. package/esm/rpc/validation/UnsafeValidator.js +257 -0
  108. package/esm/rpc/validation/UnsafeValidator.js.map +1 -0
  109. package/esm/rpc/validation/index.d.ts +3 -0
  110. package/esm/rpc/validation/index.js +3 -0
  111. package/esm/rpc/validation/index.js.map +1 -0
  112. package/esm/rpc/validation/tracer.d.ts +122 -0
  113. package/esm/rpc/validation/tracer.js +82 -0
  114. package/esm/rpc/validation/tracer.js.map +1 -0
  115. package/esm/types/contracts/BundleBulker.d.ts +120 -0
  116. package/esm/types/contracts/BundleBulker.js +157 -0
  117. package/esm/types/contracts/BundleBulker.js.map +1 -0
  118. package/esm/types/contracts/CallEngine.d.ts +28 -0
  119. package/esm/types/contracts/CallEngine.js +37 -0
  120. package/esm/types/contracts/CallEngine.js.map +1 -0
  121. package/esm/types/contracts/CodeHashGetter.d.ts +37 -0
  122. package/esm/types/contracts/CodeHashGetter.js +45 -0
  123. package/esm/types/contracts/CodeHashGetter.js.map +1 -0
  124. package/esm/types/contracts/EntryPoint.d.ts +1789 -0
  125. package/esm/types/contracts/EntryPoint.js +2304 -0
  126. package/esm/types/contracts/EntryPoint.js.map +1 -0
  127. package/esm/types/contracts/EntryPointSimulations.d.ts +152 -0
  128. package/esm/types/contracts/EntryPointSimulations.js +1954 -0
  129. package/esm/types/contracts/EntryPointSimulations.js.map +1 -0
  130. package/esm/types/contracts/IOpInflator.d.ts +61 -0
  131. package/esm/types/contracts/IOpInflator.js +80 -0
  132. package/esm/types/contracts/IOpInflator.js.map +1 -0
  133. package/esm/types/contracts/IPaymaster.d.ts +3 -0
  134. package/esm/types/contracts/IPaymaster.js +117 -0
  135. package/esm/types/contracts/IPaymaster.js.map +1 -0
  136. package/esm/types/contracts/Inflator.d.ts +65 -0
  137. package/esm/types/contracts/Inflator.js +84 -0
  138. package/esm/types/contracts/Inflator.js.map +1 -0
  139. package/esm/types/contracts/PerOpInflator.d.ts +176 -0
  140. package/esm/types/contracts/PerOpInflator.js +229 -0
  141. package/esm/types/contracts/PerOpInflator.js.map +1 -0
  142. package/esm/types/contracts/PimlicoEntryPointSimulations.d.ts +23 -0
  143. package/esm/types/contracts/PimlicoEntryPointSimulations.js +33 -0
  144. package/esm/types/contracts/PimlicoEntryPointSimulations.js.map +1 -0
  145. package/esm/types/contracts/SenderCreator.d.ts +4 -0
  146. package/esm/types/contracts/SenderCreator.js +23 -0
  147. package/esm/types/contracts/SenderCreator.js.map +1 -0
  148. package/esm/types/contracts/SimpleAccountFactory.d.ts +57 -0
  149. package/esm/types/contracts/SimpleAccountFactory.js +76 -0
  150. package/esm/types/contracts/SimpleAccountFactory.js.map +1 -0
  151. package/esm/types/contracts/TestOpcodesAccount.d.ts +4 -0
  152. package/esm/types/contracts/TestOpcodesAccount.js +281 -0
  153. package/esm/types/contracts/TestOpcodesAccount.js.map +1 -0
  154. package/esm/types/contracts/TestOpcodesAccountFactory.d.ts +4 -0
  155. package/esm/types/contracts/TestOpcodesAccountFactory.js +23 -0
  156. package/esm/types/contracts/TestOpcodesAccountFactory.js.map +1 -0
  157. package/esm/types/contracts/TestStorageAccount.d.ts +4 -0
  158. package/esm/types/contracts/TestStorageAccount.js +313 -0
  159. package/esm/types/contracts/TestStorageAccount.js.map +1 -0
  160. package/esm/types/contracts/index.d.ts +17 -0
  161. package/esm/types/contracts/index.js +17 -0
  162. package/esm/types/contracts/index.js.map +1 -0
  163. package/esm/types/gasPrice.d.ts +110 -0
  164. package/esm/types/gasPrice.js +52 -0
  165. package/esm/types/gasPrice.js.map +1 -0
  166. package/esm/types/index.d.ts +11 -0
  167. package/esm/types/index.js +11 -0
  168. package/esm/types/index.js.map +1 -0
  169. package/esm/types/interfaces.d.ts +26 -0
  170. package/esm/types/interfaces.js +2 -0
  171. package/esm/types/interfaces.js.map +1 -0
  172. package/esm/types/mempool.d.ts +79 -0
  173. package/esm/types/mempool.js +16 -0
  174. package/esm/types/mempool.js.map +1 -0
  175. package/esm/types/schemas.d.ts +4791 -0
  176. package/esm/types/schemas.js +497 -0
  177. package/esm/types/schemas.js.map +1 -0
  178. package/esm/types/test/validationTestErrors.d.ts +3 -0
  179. package/esm/types/test/validationTestErrors.js +229 -0
  180. package/esm/types/test/validationTestErrors.js.map +1 -0
  181. package/esm/types/utils.d.ts +24 -0
  182. package/esm/types/utils.js +30 -0
  183. package/esm/types/utils.js.map +1 -0
  184. package/esm/types/validation.d.ts +14327 -0
  185. package/esm/types/validation.js +304 -0
  186. package/esm/types/validation.js.map +1 -0
  187. package/esm/utils/bigInt.d.ts +3 -0
  188. package/esm/utils/bigInt.js +9 -0
  189. package/esm/utils/bigInt.js.map +1 -0
  190. package/esm/utils/compressionHandler.d.ts +11 -0
  191. package/esm/utils/compressionHandler.js +39 -0
  192. package/esm/utils/compressionHandler.js.map +1 -0
  193. package/esm/utils/gasPriceManager.d.ts +34 -0
  194. package/esm/utils/gasPriceManager.js +338 -0
  195. package/esm/utils/gasPriceManager.js.map +1 -0
  196. package/esm/utils/helpers.d.ts +4 -0
  197. package/esm/utils/helpers.js +13 -0
  198. package/esm/utils/helpers.js.map +1 -0
  199. package/esm/utils/index.d.ts +11 -0
  200. package/esm/utils/index.js +10 -0
  201. package/esm/utils/index.js.map +1 -0
  202. package/esm/utils/logger.d.ts +6 -0
  203. package/esm/utils/logger.js +76 -0
  204. package/esm/utils/logger.js.map +1 -0
  205. package/esm/utils/metrics.d.ts +22 -0
  206. package/esm/utils/metrics.js +150 -0
  207. package/esm/utils/metrics.js.map +1 -0
  208. package/esm/utils/rpc-reply.d.ts +17 -0
  209. package/esm/utils/rpc-reply.js +41 -0
  210. package/esm/utils/rpc-reply.js.map +1 -0
  211. package/esm/utils/test.d.ts +17 -0
  212. package/esm/utils/test.js +130 -0
  213. package/esm/utils/test.js.map +1 -0
  214. package/esm/utils/userop.d.ts +49 -0
  215. package/esm/utils/userop.js +408 -0
  216. package/esm/utils/userop.js.map +1 -0
  217. package/esm/utils/validation.d.ts +65 -0
  218. package/esm/utils/validation.js +461 -0
  219. package/esm/utils/validation.js.map +1 -0
  220. package/lib/cli/config/bundler.d.ts +12 -0
  221. package/lib/cli/config/bundler.js +3 -1
  222. package/lib/cli/config/bundler.js.map +1 -1
  223. package/lib/cli/config/options.js +12 -0
  224. package/lib/cli/config/options.js.map +1 -1
  225. package/lib/cli/handler.js +25 -1
  226. package/lib/cli/handler.js.map +1 -1
  227. package/lib/cli/setupServer.js +1 -1
  228. package/lib/cli/setupServer.js.map +1 -1
  229. package/lib/executor/executor.d.ts +2 -1
  230. package/lib/executor/executor.js +6 -4
  231. package/lib/executor/executor.js.map +1 -1
  232. package/lib/executor/utils.d.ts +1 -1
  233. package/lib/executor/utils.js +4 -4
  234. package/lib/executor/utils.js.map +1 -1
  235. package/lib/mempool/mempool.js +5 -7
  236. package/lib/mempool/mempool.js.map +1 -1
  237. package/lib/mempool/reputationManager.js +7 -3
  238. package/lib/mempool/reputationManager.js.map +1 -1
  239. package/lib/rpc/EntryPointSimulationsV07.d.ts +5 -1
  240. package/lib/rpc/EntryPointSimulationsV07.js +3 -2
  241. package/lib/rpc/EntryPointSimulationsV07.js.map +1 -1
  242. package/lib/rpc/gasEstimation.js +7 -3
  243. package/lib/rpc/gasEstimation.js.map +1 -1
  244. package/lib/rpc/rpcHandler.js +18 -7
  245. package/lib/rpc/rpcHandler.js.map +1 -1
  246. package/lib/rpc/server.js +4 -0
  247. package/lib/rpc/server.js.map +1 -1
  248. package/lib/rpc/validation/SafeValidator.d.ts +2 -6
  249. package/lib/rpc/validation/SafeValidator.js +48 -205
  250. package/lib/rpc/validation/SafeValidator.js.map +1 -1
  251. package/lib/rpc/validation/TracerResultParserV07.js +6 -2
  252. package/lib/rpc/validation/TracerResultParserV07.js.map +1 -1
  253. package/lib/rpc/validation/UnsafeValidator.d.ts +2 -1
  254. package/lib/rpc/validation/UnsafeValidator.js +45 -68
  255. package/lib/rpc/validation/UnsafeValidator.js.map +1 -1
  256. package/lib/types/contracts/EntryPointSimulations.d.ts +0 -1
  257. package/lib/types/contracts/EntryPointSimulations.js +1942 -3
  258. package/lib/types/contracts/EntryPointSimulations.js.map +1 -1
  259. package/lib/types/contracts/PimlicoEntryPointSimulations.d.ts +1 -1
  260. package/lib/types/contracts/PimlicoEntryPointSimulations.js +2 -2
  261. package/lib/types/contracts/PimlicoEntryPointSimulations.js.map +1 -1
  262. package/lib/utils/userop.js +2 -25
  263. package/lib/utils/userop.js.map +1 -1
  264. package/package.json +2 -1
@@ -0,0 +1,257 @@
1
+ import { EntryPointV06Abi, ExecutionErrors, RpcError, ValidationErrors, entryPointErrorsSchema, entryPointExecutionErrorSchemaV06, entryPointExecutionErrorSchemaV07 } from "../../types/index.js";
2
+ import { calcPreVerificationGas, calcVerificationGasAndCallGasLimit, isVersion06, isVersion07 } from "../../utils/index.js";
3
+ import { captureException } from "@sentry/node";
4
+ import { BaseError, ContractFunctionExecutionError, getContract, pad, slice, toHex, zeroAddress } from "viem";
5
+ import { fromZodError } from "zod-validation-error";
6
+ import { simulateValidation } from "../EntryPointSimulationsV07.js";
7
+ import { simulateHandleOp, simulateHandleOpV06 } from "../gasEstimation.js";
8
+ export class UnsafeValidator {
9
+ publicClient;
10
+ logger;
11
+ metrics;
12
+ usingTenderly;
13
+ balanceOverrideEnabled;
14
+ expirationCheck;
15
+ chainId;
16
+ gasPriceManager;
17
+ entryPointSimulationsAddress;
18
+ fixedGasLimitForEstimation;
19
+ chainType;
20
+ constructor(publicClient, logger, metrics, gasPriceManager, chainType, entryPointSimulationsAddress, fixedGasLimitForEstimation, usingTenderly = false, balanceOverrideEnabled = false, expirationCheck = true) {
21
+ this.publicClient = publicClient;
22
+ this.logger = logger;
23
+ this.metrics = metrics;
24
+ this.usingTenderly = usingTenderly;
25
+ this.balanceOverrideEnabled = balanceOverrideEnabled;
26
+ this.expirationCheck = expirationCheck;
27
+ this.chainId = publicClient.chain.id;
28
+ this.gasPriceManager = gasPriceManager;
29
+ this.entryPointSimulationsAddress = entryPointSimulationsAddress;
30
+ this.fixedGasLimitForEstimation = fixedGasLimitForEstimation;
31
+ this.chainType = chainType;
32
+ }
33
+ async getSimulationResult(isVersion06, errorResult, logger, simulationType, usingTenderly = false) {
34
+ const entryPointExecutionErrorSchema = isVersion06
35
+ ? entryPointExecutionErrorSchemaV06
36
+ : entryPointExecutionErrorSchemaV07;
37
+ const entryPointErrorSchemaParsing = usingTenderly
38
+ ? entryPointErrorsSchema.safeParse(errorResult)
39
+ : entryPointExecutionErrorSchema.safeParse(errorResult);
40
+ if (!entryPointErrorSchemaParsing.success) {
41
+ try {
42
+ const err = fromZodError(entryPointErrorSchemaParsing.error);
43
+ logger.error({ error: err.message }, "unexpected error during valiation");
44
+ logger.error(JSON.stringify(errorResult));
45
+ err.message = `User Operation simulation returned unexpected invalid response: ${err.message}`;
46
+ throw err;
47
+ }
48
+ catch {
49
+ if (errorResult instanceof BaseError) {
50
+ const revertError = errorResult.walk((err) => err instanceof ContractFunctionExecutionError);
51
+ throw new RpcError(`UserOperation reverted during simulation with reason: ${
52
+ // biome-ignore lint/suspicious/noExplicitAny: it's a generic type
53
+ revertError?.cause?.reason}`, ValidationErrors.SimulateValidation);
54
+ }
55
+ captureException(errorResult);
56
+ throw new Error(`User Operation simulation returned unexpected invalid response: ${JSON.stringify(errorResult)}`);
57
+ }
58
+ }
59
+ const errorData = entryPointErrorSchemaParsing.data;
60
+ if (errorData.errorName === "FailedOp") {
61
+ const reason = errorData.args.reason;
62
+ throw new RpcError(`UserOperation reverted during simulation with reason: ${reason}`, ValidationErrors.SimulateValidation);
63
+ }
64
+ if (simulationType === "validation") {
65
+ if (errorData.errorName !== "ValidationResult" &&
66
+ errorData.errorName !== "ValidationResultWithAggregation") {
67
+ throw new Error("Unexpected error - errorName is not ValidationResult or ValidationResultWithAggregation");
68
+ }
69
+ }
70
+ else if (errorData.errorName !== "ExecutionResult") {
71
+ throw new Error("Unexpected error - errorName is not ExecutionResult");
72
+ }
73
+ const simulationResult = errorData.args;
74
+ return simulationResult;
75
+ }
76
+ async getExecutionResult(userOperation, entryPoint, queuedUserOperations, stateOverrides) {
77
+ const error = await simulateHandleOp(userOperation, queuedUserOperations, entryPoint, this.publicClient, false, zeroAddress, "0x", this.balanceOverrideEnabled, this.chainId, stateOverrides, this.entryPointSimulationsAddress, this.fixedGasLimitForEstimation);
78
+ if (error.result === "failed") {
79
+ throw new RpcError(`UserOperation reverted during simulation with reason: ${error.data}`, ExecutionErrors.UserOperationReverted);
80
+ }
81
+ return error;
82
+ }
83
+ async getValidationResultV06(userOperation, entryPoint, _codeHashes) {
84
+ const entryPointContract = getContract({
85
+ address: entryPoint,
86
+ abi: EntryPointV06Abi,
87
+ client: {
88
+ public: this.publicClient
89
+ }
90
+ });
91
+ const simulateValidationPromise = entryPointContract.simulate
92
+ .simulateValidation([userOperation])
93
+ .catch((e) => {
94
+ if (e instanceof Error) {
95
+ return e;
96
+ }
97
+ throw e;
98
+ });
99
+ const runtimeValidationPromise = simulateHandleOpV06(userOperation, entryPoint, this.publicClient, zeroAddress, "0x");
100
+ const [simulateValidationResult, runtimeValidation] = await Promise.all([simulateValidationPromise, runtimeValidationPromise]);
101
+ const validationResult = {
102
+ ...(await this.getSimulationResult(isVersion06(userOperation), simulateValidationResult, this.logger, "validation", this.usingTenderly)),
103
+ storageMap: {}
104
+ };
105
+ if (validationResult.returnInfo.sigFailed) {
106
+ throw new RpcError("Invalid UserOperation signature or paymaster signature", ValidationErrors.InvalidSignature);
107
+ }
108
+ const now = Date.now() / 1000;
109
+ this.logger.debug({
110
+ validAfter: validationResult.returnInfo.validAfter,
111
+ validUntil: validationResult.returnInfo.validUntil,
112
+ now
113
+ });
114
+ if (validationResult.returnInfo.validAfter > now - 5 &&
115
+ this.expirationCheck) {
116
+ throw new RpcError("User operation is not valid yet", ValidationErrors.ExpiresShortly);
117
+ }
118
+ if (validationResult.returnInfo.validUntil < now + 30 &&
119
+ this.expirationCheck) {
120
+ throw new RpcError("expires too soon", ValidationErrors.ExpiresShortly);
121
+ }
122
+ // validate runtime
123
+ if (runtimeValidation.result === "failed") {
124
+ throw new RpcError(`UserOperation reverted during simulation with reason: ${runtimeValidation.data}`, ValidationErrors.SimulateValidation);
125
+ }
126
+ return validationResult;
127
+ }
128
+ parseValidationData(validationData) {
129
+ const maxUint48 = 2 ** 48 - 1;
130
+ const data = pad(toHex(validationData), { size: 32 });
131
+ // string offsets start from left (msb)
132
+ const aggregator = slice(data, 32 - 20);
133
+ let validUntil = Number.parseInt(slice(data, 32 - 26, 32 - 20), 16);
134
+ if (validUntil === 0) {
135
+ validUntil = maxUint48;
136
+ }
137
+ const validAfter = Number.parseInt(slice(data, 0, 6), 16);
138
+ return {
139
+ aggregator,
140
+ validAfter,
141
+ validUntil
142
+ };
143
+ }
144
+ mergeValidationData(accountValidationData, paymasterValidationData) {
145
+ return {
146
+ paymasterSigFailed: paymasterValidationData.aggregator !== zeroAddress,
147
+ accountSigFailed: accountValidationData.aggregator !== zeroAddress,
148
+ validAfter: Math.max(accountValidationData.validAfter, paymasterValidationData.validAfter),
149
+ validUntil: Math.min(accountValidationData.validUntil, paymasterValidationData.validUntil)
150
+ };
151
+ }
152
+ mergeValidationDataValues(accountValidationData, paymasterValidationData) {
153
+ return this.mergeValidationData(this.parseValidationData(accountValidationData), this.parseValidationData(paymasterValidationData));
154
+ }
155
+ async getValidationResultV07(userOperation, queuedUserOperations, entryPoint, _codeHashes) {
156
+ if (!this.entryPointSimulationsAddress) {
157
+ throw new Error("entryPointSimulationsAddress is not set");
158
+ }
159
+ const { simulateValidationResult } = await simulateValidation(userOperation, queuedUserOperations, entryPoint, this.publicClient, this.entryPointSimulationsAddress);
160
+ if (simulateValidationResult.status === "failed") {
161
+ throw new RpcError(`UserOperation reverted with reason: ${simulateValidationResult.data}`, ValidationErrors.SimulateValidation);
162
+ }
163
+ const validationResult = simulateValidationResult.data;
164
+ const mergedValidation = this.mergeValidationDataValues(validationResult.returnInfo.accountValidationData, validationResult.returnInfo.paymasterValidationData);
165
+ const res = {
166
+ returnInfo: {
167
+ ...validationResult.returnInfo,
168
+ accountSigFailed: mergedValidation.accountSigFailed,
169
+ paymasterSigFailed: mergedValidation.paymasterSigFailed,
170
+ validUntil: mergedValidation.validUntil,
171
+ validAfter: mergedValidation.validAfter
172
+ },
173
+ senderInfo: {
174
+ ...validationResult.senderInfo,
175
+ addr: userOperation.sender
176
+ },
177
+ factoryInfo: userOperation.factory && validationResult.factoryInfo
178
+ ? {
179
+ ...validationResult.factoryInfo,
180
+ addr: userOperation.factory
181
+ }
182
+ : undefined,
183
+ paymasterInfo: userOperation.paymaster && validationResult.paymasterInfo
184
+ ? {
185
+ ...validationResult.paymasterInfo,
186
+ addr: userOperation.paymaster
187
+ }
188
+ : undefined,
189
+ aggregatorInfo: validationResult.aggregatorInfo,
190
+ storageMap: {}
191
+ };
192
+ // this.validateStorageAccessList(userOperation, res, accessList)
193
+ if (res.returnInfo.accountSigFailed) {
194
+ throw new RpcError("Invalid UserOp signature", ValidationErrors.InvalidSignature);
195
+ }
196
+ if (res.returnInfo.paymasterSigFailed) {
197
+ throw new RpcError("Invalid UserOp paymasterData", ValidationErrors.InvalidSignature);
198
+ }
199
+ const now = Math.floor(Date.now() / 1000);
200
+ if (res.returnInfo.validAfter > now - 5) {
201
+ throw new RpcError(`User operation is not valid yet, validAfter=${res.returnInfo.validAfter}, now=${now}`, ValidationErrors.ExpiresShortly);
202
+ }
203
+ if (res.returnInfo.validUntil == null ||
204
+ res.returnInfo.validUntil < now + 30) {
205
+ throw new RpcError(`UserOperation expires too soon, validUntil=${res.returnInfo.validUntil}, now=${now}`, ValidationErrors.ExpiresShortly);
206
+ }
207
+ return res;
208
+ }
209
+ getValidationResult(userOperation, queuedUserOperations, entryPoint, _codeHashes) {
210
+ if (isVersion06(userOperation)) {
211
+ return this.getValidationResultV06(userOperation, entryPoint, _codeHashes);
212
+ }
213
+ return this.getValidationResultV07(userOperation, queuedUserOperations, entryPoint, _codeHashes);
214
+ }
215
+ async validatePreVerificationGas(userOperation, entryPoint) {
216
+ const preVerificationGas = await calcPreVerificationGas(this.publicClient, userOperation, entryPoint, this.chainId, this.chainType, this.gasPriceManager, true);
217
+ if (preVerificationGas > userOperation.preVerificationGas) {
218
+ throw new RpcError(`preVerificationGas is not enough, required: ${preVerificationGas}, got: ${userOperation.preVerificationGas}`, ValidationErrors.SimulateValidation);
219
+ }
220
+ }
221
+ async validateUserOperation(shouldCheckPrefund, userOperation, queuedUserOperations, entryPoint, _referencedContracts) {
222
+ try {
223
+ const validationResult = await this.getValidationResult(userOperation, queuedUserOperations, entryPoint);
224
+ if (shouldCheckPrefund) {
225
+ const prefund = validationResult.returnInfo.prefund;
226
+ const { verificationGasLimit, callGasLimit } = calcVerificationGasAndCallGasLimit(userOperation, {
227
+ preOpGas: validationResult.returnInfo.preOpGas,
228
+ paid: validationResult.returnInfo.prefund
229
+ }, this.chainId);
230
+ let mul = 1n;
231
+ if (isVersion06(userOperation) &&
232
+ userOperation.paymasterAndData) {
233
+ mul = 3n;
234
+ }
235
+ if (isVersion07(userOperation) &&
236
+ userOperation.paymaster === "0x") {
237
+ mul = 3n;
238
+ }
239
+ const requiredPreFund = callGasLimit +
240
+ verificationGasLimit * mul +
241
+ userOperation.preVerificationGas;
242
+ if (requiredPreFund > prefund) {
243
+ throw new RpcError(`prefund is not enough, required: ${requiredPreFund}, got: ${prefund}`, ValidationErrors.SimulateValidation);
244
+ }
245
+ // TODO prefund should be greater than it costs us to add it to mempool
246
+ }
247
+ this.metrics.userOperationsValidationSuccess.inc();
248
+ return validationResult;
249
+ }
250
+ catch (e) {
251
+ // console.log(e)
252
+ this.metrics.userOperationsValidationFailure.inc();
253
+ throw e;
254
+ }
255
+ }
256
+ }
257
+ //# sourceMappingURL=UnsafeValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnsafeValidator.js","sourceRoot":"","sources":["../../../rpc/validation/UnsafeValidator.ts"],"names":[],"mappings":"AAYA,OAAO,EAEH,gBAAgB,EAChB,eAAe,EAGf,QAAQ,EAGR,gBAAgB,EAEhB,sBAAsB,EACtB,iCAAiC,EACjC,iCAAiC,EACpC,MAAM,aAAa,CAAA;AAEpB,OAAO,EACH,sBAAsB,EACtB,kCAAkC,EAClC,WAAW,EACX,WAAW,EACd,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EACH,SAAS,EAET,8BAA8B,EAG9B,WAAW,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A;gBACL,CAAC;gBAED,uEAAuE;YAC3E,CAAC;YAED,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAAC,GAAG,EAAE,CAAA;YAElD,OAAO,gBAAgB,CAAA;QAC3B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,iBAAiB;YACjB,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAAC,GAAG,EAAE,CAAA;YAClD,MAAM,CAAC,CAAA;QACX,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export * from "./SafeValidator.js";
2
+ export * from "./UnsafeValidator.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from "./SafeValidator.js";
2
+ export * from "./UnsafeValidator.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../rpc/validation/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,122 @@
1
+ /// <reference types="node" />
2
+ import { type Account, type Chain, type PublicClient, type TransactionRequest, type Transport, type WalletClient } from "viem";
3
+ /**
4
+ * a function returning a LogTracer.
5
+ * the function's body must be "{ return {...} }"
6
+ * the body is executed as "geth" tracer, and thus must be self-contained (no external functions or references)
7
+ * may only reference external functions defined by geth (see go-ethereum/eth/tracers/js): toHex, toWord, isPrecompiled, slice, toString(16)
8
+ * (its OK if original function was in typescript: we extract its value as javascript
9
+ */
10
+ type LogTracerFunc = () => LogTracer;
11
+ export declare function debug_traceCall(client: PublicClient | WalletClient, tx: TransactionRequest, options: TraceOptions): Promise<any>;
12
+ export declare function execAndTrace(_walletClient: WalletClient<Transport, Chain, Account>, _tx: TransactionRequest, _options: TraceOptions): TraceResult;
13
+ export declare function debug_traceTransaction(client: PublicClient | WalletClient, hash: string, options: TraceOptions): Promise<TraceResult>;
14
+ /**
15
+ * extract the body of "LogTracerFunc".
16
+ * note that we extract the javascript body, even if the function was created as typescript
17
+ * @param func
18
+ */
19
+ export declare function getTracerBodyString(func: LogTracerFunc): string;
20
+ export interface TraceOptions {
21
+ disableStorage?: boolean;
22
+ disableStack?: boolean;
23
+ enableMemory?: boolean;
24
+ enableReturnData?: boolean;
25
+ tracer?: LogTracerFunc | string;
26
+ timeout?: string;
27
+ }
28
+ export interface TraceResult {
29
+ gas: number;
30
+ returnValue: string;
31
+ structLogs: [TraceResultEntry];
32
+ }
33
+ export interface TraceResultEntry {
34
+ depth: number;
35
+ error: string;
36
+ gas: number;
37
+ gasCost: number;
38
+ memory?: [string];
39
+ op: string;
40
+ pc: number;
41
+ stack: [string];
42
+ storage?: [string];
43
+ }
44
+ export interface LogContext {
45
+ type: string;
46
+ from: string;
47
+ to: string;
48
+ input: Buffer;
49
+ gas: number;
50
+ gasUsed: number;
51
+ gasPrice: number;
52
+ intrinsicGas: number;
53
+ value: bigint;
54
+ block: number;
55
+ output: Buffer;
56
+ time: string;
57
+ blockHash?: Buffer;
58
+ txIndex?: number;
59
+ txHash?: Buffer;
60
+ }
61
+ export interface LogTracer {
62
+ result: (ctx: LogContext, db: LogDb) => any;
63
+ fault: (log: LogStep, db: LogDb) => void;
64
+ setup?: (config: any) => any;
65
+ step?: (log: LogStep, db: LogDb) => any;
66
+ enter?: (frame: LogCallFrame) => void;
67
+ exit?: (frame: LogFrameResult) => void;
68
+ }
69
+ export interface LogCallFrame {
70
+ getType: () => string;
71
+ getFrom: () => string;
72
+ getTo: () => string;
73
+ getInput: () => string;
74
+ getGas: () => number;
75
+ getValue: () => bigint;
76
+ }
77
+ export interface LogFrameResult {
78
+ getGasUsed: () => number;
79
+ getOutput: () => Buffer;
80
+ getError: () => any;
81
+ }
82
+ export interface LogOpCode {
83
+ isPush: () => boolean;
84
+ toString: () => string;
85
+ toNumber: () => number;
86
+ }
87
+ export interface LogMemory {
88
+ slice: (start: number, stop: number) => any;
89
+ getUint: (offset: number) => any;
90
+ length: () => number;
91
+ }
92
+ export interface LogStack {
93
+ peek: (idx: number) => any;
94
+ length: () => number;
95
+ }
96
+ export interface LogContract {
97
+ getCaller: () => any;
98
+ getAddress: () => string;
99
+ getValue: () => bigint;
100
+ getInput: () => any;
101
+ }
102
+ export interface LogStep {
103
+ op: LogOpCode;
104
+ stack: LogStack;
105
+ memory: LogMemory;
106
+ contract: LogContract;
107
+ getPC: () => number;
108
+ getGas: () => number;
109
+ getCost: () => number;
110
+ getDepth: () => number;
111
+ getRefund: () => number;
112
+ getError: () => string | undefined;
113
+ }
114
+ export interface LogDb {
115
+ getBalance: (address: string) => bigint;
116
+ getNonce: (address: string) => number;
117
+ getCode: (address: string) => any;
118
+ getState: (address: string, hash: string) => any;
119
+ exists: (address: string) => boolean;
120
+ }
121
+ export {};
122
+ //# sourceMappingURL=tracer.d.ts.map
@@ -0,0 +1,82 @@
1
+ import * as sentry from "@sentry/node";
2
+ import { formatTransactionRequest } from "viem";
3
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4
+ export async function debug_traceCall(client, tx, options
5
+ // biome-ignore lint/suspicious/noExplicitAny: it's a generic type
6
+ ) {
7
+ const traceOptions = tracer2string(options);
8
+ const ret = await client
9
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
10
+ // @ts-ignore
11
+ .request({
12
+ method: "debug_traceCall",
13
+ params: [formatTransactionRequest(tx), "latest", traceOptions]
14
+ })
15
+ .catch((e) => {
16
+ if (e instanceof Error) {
17
+ // console.log("ex=", e.message)
18
+ // console.log(
19
+ // "tracer=",
20
+ // traceOptions.tracer
21
+ // ?.toString()
22
+ // .split("\n")
23
+ // .map((line, index) => `${index + 1}: ${line}`)
24
+ // .join("\n")
25
+ // )
26
+ throw e;
27
+ }
28
+ sentry.captureException(e);
29
+ });
30
+ // console.log("ret=", ret)
31
+ return ret;
32
+ }
33
+ // a hack for network that doesn't have traceCall: mine the transaction, and use debug_traceTransaction
34
+ export function execAndTrace(_walletClient, _tx, _options) {
35
+ //const hash = await walletClient.sendTransaction(tx)
36
+ throw new Error("not implemented");
37
+ //return await debug_traceTransaction(walletClient, hash, options)
38
+ }
39
+ // eslint-disable-next-line @typescript-eslint/naming-convention
40
+ export async function debug_traceTransaction(client, hash, options) {
41
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
+ // @ts-ignore
43
+ const ret = await client.request({
44
+ method: "debug_traceTransaction",
45
+ params: [hash, tracer2string(options)]
46
+ });
47
+ // const tx = await provider.getTransaction(hash)
48
+ // return applyTracer(tx, ret, options)
49
+ return ret;
50
+ }
51
+ /**
52
+ * extract the body of "LogTracerFunc".
53
+ * note that we extract the javascript body, even if the function was created as typescript
54
+ * @param func
55
+ */
56
+ export function getTracerBodyString(func) {
57
+ const tracerFunc = func.toString();
58
+ // function must return a plain object:
59
+ // function xyz() { return {...}; }
60
+ const regexp = /function \w+\s*\(\s*\)\s*{\s*return\s*(\{[\s\S]+\});?\s*\}\s*$/; // (\{[\s\S]+\}); \} $/
61
+ const match = tracerFunc.match(regexp);
62
+ if (match === null) {
63
+ throw new Error("Not a simple method returning value");
64
+ }
65
+ let ret = match[1];
66
+ ret = ret
67
+ // .replace(/\/\/.*\n/g,'\n')
68
+ // .replace(/\n\s*\n/g, '\n')
69
+ .replace(/\b(?:const|let)\b/g, "");
70
+ // console.log('== tracer source',ret.split('\n').map((line,index)=>`${index}: ${line}`).join('\n'))
71
+ return ret;
72
+ }
73
+ function tracer2string(options) {
74
+ if (typeof options.tracer === "function") {
75
+ return {
76
+ ...options,
77
+ tracer: getTracerBodyString(options.tracer)
78
+ };
79
+ }
80
+ return options;
81
+ }
82
+ //# sourceMappingURL=tracer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracer.js","sourceRoot":"","sources":["../../../rpc/validation/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAOH,wBAAwB,EAC3B,MAAM,MAAM,CAAA;AAab,gEAAgE;AAChE,MAAM,CAAC,K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AM,UAAU,mBAAmB,CAAC,IAAmB;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;IAClC,uCAAuC;IACvC,oCAAoC;IACpC,MAAM,MAAM,GACR,gEAAgE,CAAA,CAAC,uBAAuB;IAC5F,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAEtC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IAClB,GAAG,GAAG,GAAG;QACL,6BAA6B;QAC7B,6BAA6B;SAC5B,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;IACtC,oGAAoG;IACpG,OAAO,GAAG,CAAA;AACd,CAAC;AAED,SAAS,aAAa,CAAC,OAAqB;IACxC,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACvC,OAAO;YACH,GAAG,OAAO;YACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;SAC9C,CAAA;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
@@ -0,0 +1,120 @@
1
+ export declare const BundleBulkerAbi: readonly [{
2
+ readonly type: "fallback";
3
+ readonly stateMutability: "nonpayable";
4
+ }, {
5
+ readonly type: "function";
6
+ readonly name: "ENTRY_POINT";
7
+ readonly inputs: readonly [];
8
+ readonly outputs: readonly [{
9
+ readonly name: "";
10
+ readonly type: "address";
11
+ readonly internalType: "address";
12
+ }];
13
+ readonly stateMutability: "view";
14
+ }, {
15
+ readonly type: "function";
16
+ readonly name: "idToInflator";
17
+ readonly inputs: readonly [{
18
+ readonly name: "";
19
+ readonly type: "uint32";
20
+ readonly internalType: "uint32";
21
+ }];
22
+ readonly outputs: readonly [{
23
+ readonly name: "";
24
+ readonly type: "address";
25
+ readonly internalType: "contract IInflator";
26
+ }];
27
+ readonly stateMutability: "view";
28
+ }, {
29
+ readonly type: "function";
30
+ readonly name: "inflate";
31
+ readonly inputs: readonly [{
32
+ readonly name: "compressed";
33
+ readonly type: "bytes";
34
+ readonly internalType: "bytes";
35
+ }];
36
+ readonly outputs: readonly [{
37
+ readonly name: "ops";
38
+ readonly type: "tuple[]";
39
+ readonly internalType: "struct UserOperation[]";
40
+ readonly components: readonly [{
41
+ readonly name: "sender";
42
+ readonly type: "address";
43
+ readonly internalType: "address";
44
+ }, {
45
+ readonly name: "nonce";
46
+ readonly type: "uint256";
47
+ readonly internalType: "uint256";
48
+ }, {
49
+ readonly name: "initCode";
50
+ readonly type: "bytes";
51
+ readonly internalType: "bytes";
52
+ }, {
53
+ readonly name: "callData";
54
+ readonly type: "bytes";
55
+ readonly internalType: "bytes";
56
+ }, {
57
+ readonly name: "callGasLimit";
58
+ readonly type: "uint256";
59
+ readonly internalType: "uint256";
60
+ }, {
61
+ readonly name: "verificationGasLimit";
62
+ readonly type: "uint256";
63
+ readonly internalType: "uint256";
64
+ }, {
65
+ readonly name: "preVerificationGas";
66
+ readonly type: "uint256";
67
+ readonly internalType: "uint256";
68
+ }, {
69
+ readonly name: "maxFeePerGas";
70
+ readonly type: "uint256";
71
+ readonly internalType: "uint256";
72
+ }, {
73
+ readonly name: "maxPriorityFeePerGas";
74
+ readonly type: "uint256";
75
+ readonly internalType: "uint256";
76
+ }, {
77
+ readonly name: "paymasterAndData";
78
+ readonly type: "bytes";
79
+ readonly internalType: "bytes";
80
+ }, {
81
+ readonly name: "signature";
82
+ readonly type: "bytes";
83
+ readonly internalType: "bytes";
84
+ }];
85
+ }, {
86
+ readonly name: "beneficiary";
87
+ readonly type: "address";
88
+ readonly internalType: "address payable";
89
+ }];
90
+ readonly stateMutability: "view";
91
+ }, {
92
+ readonly type: "function";
93
+ readonly name: "inflatorToID";
94
+ readonly inputs: readonly [{
95
+ readonly name: "";
96
+ readonly type: "address";
97
+ readonly internalType: "contract IInflator";
98
+ }];
99
+ readonly outputs: readonly [{
100
+ readonly name: "";
101
+ readonly type: "uint32";
102
+ readonly internalType: "uint32";
103
+ }];
104
+ readonly stateMutability: "view";
105
+ }, {
106
+ readonly type: "function";
107
+ readonly name: "registerInflator";
108
+ readonly inputs: readonly [{
109
+ readonly name: "inflatorId";
110
+ readonly type: "uint32";
111
+ readonly internalType: "uint32";
112
+ }, {
113
+ readonly name: "inflator";
114
+ readonly type: "address";
115
+ readonly internalType: "contract IInflator";
116
+ }];
117
+ readonly outputs: readonly [];
118
+ readonly stateMutability: "nonpayable";
119
+ }];
120
+ //# sourceMappingURL=BundleBulker.d.ts.map