@feelyourprotocol/evm 8141.0.0

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 (565) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +690 -0
  3. package/dist/cjs/binaryTreeAccessWitness.d.ts +61 -0
  4. package/dist/cjs/binaryTreeAccessWitness.d.ts.map +1 -0
  5. package/dist/cjs/binaryTreeAccessWitness.js +314 -0
  6. package/dist/cjs/binaryTreeAccessWitness.js.map +1 -0
  7. package/dist/cjs/chunkCache.d.ts +13 -0
  8. package/dist/cjs/chunkCache.d.ts.map +1 -0
  9. package/dist/cjs/chunkCache.js +30 -0
  10. package/dist/cjs/chunkCache.js.map +1 -0
  11. package/dist/cjs/constructors.d.ts +11 -0
  12. package/dist/cjs/constructors.d.ts.map +1 -0
  13. package/dist/cjs/constructors.js +30 -0
  14. package/dist/cjs/constructors.js.map +1 -0
  15. package/dist/cjs/eip7708.d.ts +24 -0
  16. package/dist/cjs/eip7708.d.ts.map +1 -0
  17. package/dist/cjs/eip7708.js +37 -0
  18. package/dist/cjs/eip7708.js.map +1 -0
  19. package/dist/cjs/eof/constants.d.ts +22 -0
  20. package/dist/cjs/eof/constants.d.ts.map +1 -0
  21. package/dist/cjs/eof/constants.js +31 -0
  22. package/dist/cjs/eof/constants.js.map +1 -0
  23. package/dist/cjs/eof/container.d.ts +87 -0
  24. package/dist/cjs/eof/container.d.ts.map +1 -0
  25. package/dist/cjs/eof/container.js +380 -0
  26. package/dist/cjs/eof/container.js.map +1 -0
  27. package/dist/cjs/eof/errors.d.ts +66 -0
  28. package/dist/cjs/eof/errors.d.ts.map +1 -0
  29. package/dist/cjs/eof/errors.js +200 -0
  30. package/dist/cjs/eof/errors.js.map +1 -0
  31. package/dist/cjs/eof/setup.d.ts +9 -0
  32. package/dist/cjs/eof/setup.d.ts.map +1 -0
  33. package/dist/cjs/eof/setup.js +26 -0
  34. package/dist/cjs/eof/setup.js.map +1 -0
  35. package/dist/cjs/eof/stackDelta.d.ts +10 -0
  36. package/dist/cjs/eof/stackDelta.d.ts.map +1 -0
  37. package/dist/cjs/eof/stackDelta.js +164 -0
  38. package/dist/cjs/eof/stackDelta.js.map +1 -0
  39. package/dist/cjs/eof/util.d.ts +8 -0
  40. package/dist/cjs/eof/util.d.ts.map +1 -0
  41. package/dist/cjs/eof/util.js +18 -0
  42. package/dist/cjs/eof/util.js.map +1 -0
  43. package/dist/cjs/eof/verify.d.ts +38 -0
  44. package/dist/cjs/eof/verify.d.ts.map +1 -0
  45. package/dist/cjs/eof/verify.js +436 -0
  46. package/dist/cjs/eof/verify.js.map +1 -0
  47. package/dist/cjs/errors.d.ts +40 -0
  48. package/dist/cjs/errors.d.ts.map +1 -0
  49. package/dist/cjs/errors.js +43 -0
  50. package/dist/cjs/errors.js.map +1 -0
  51. package/dist/cjs/evm.d.ts +181 -0
  52. package/dist/cjs/evm.d.ts.map +1 -0
  53. package/dist/cjs/evm.js +1142 -0
  54. package/dist/cjs/evm.js.map +1 -0
  55. package/dist/cjs/frameContext.d.ts +50 -0
  56. package/dist/cjs/frameContext.d.ts.map +1 -0
  57. package/dist/cjs/frameContext.js +17 -0
  58. package/dist/cjs/frameContext.js.map +1 -0
  59. package/dist/cjs/index.d.ts +18 -0
  60. package/dist/cjs/index.d.ts.map +1 -0
  61. package/dist/cjs/index.js +43 -0
  62. package/dist/cjs/index.js.map +1 -0
  63. package/dist/cjs/interpreter.d.ts +361 -0
  64. package/dist/cjs/interpreter.d.ts.map +1 -0
  65. package/dist/cjs/interpreter.js +1057 -0
  66. package/dist/cjs/interpreter.js.map +1 -0
  67. package/dist/cjs/journal.d.ts +69 -0
  68. package/dist/cjs/journal.d.ts.map +1 -0
  69. package/dist/cjs/journal.js +247 -0
  70. package/dist/cjs/journal.js.map +1 -0
  71. package/dist/cjs/logger.d.ts +38 -0
  72. package/dist/cjs/logger.d.ts.map +1 -0
  73. package/dist/cjs/logger.js +126 -0
  74. package/dist/cjs/logger.js.map +1 -0
  75. package/dist/cjs/memory.d.ts +29 -0
  76. package/dist/cjs/memory.d.ts.map +1 -0
  77. package/dist/cjs/memory.js +75 -0
  78. package/dist/cjs/memory.js.map +1 -0
  79. package/dist/cjs/message.d.ts +70 -0
  80. package/dist/cjs/message.d.ts.map +1 -0
  81. package/dist/cjs/message.js +51 -0
  82. package/dist/cjs/message.js.map +1 -0
  83. package/dist/cjs/opcodes/EIP1283.d.ts +13 -0
  84. package/dist/cjs/opcodes/EIP1283.d.ts.map +1 -0
  85. package/dist/cjs/opcodes/EIP1283.js +58 -0
  86. package/dist/cjs/opcodes/EIP1283.js.map +1 -0
  87. package/dist/cjs/opcodes/EIP2200.d.ts +13 -0
  88. package/dist/cjs/opcodes/EIP2200.d.ts.map +1 -0
  89. package/dist/cjs/opcodes/EIP2200.js +64 -0
  90. package/dist/cjs/opcodes/EIP2200.js.map +1 -0
  91. package/dist/cjs/opcodes/EIP2929.d.ts +68 -0
  92. package/dist/cjs/opcodes/EIP2929.d.ts.map +1 -0
  93. package/dist/cjs/opcodes/EIP2929.js +146 -0
  94. package/dist/cjs/opcodes/EIP2929.js.map +1 -0
  95. package/dist/cjs/opcodes/codes.d.ts +45 -0
  96. package/dist/cjs/opcodes/codes.d.ts.map +1 -0
  97. package/dist/cjs/opcodes/codes.js +453 -0
  98. package/dist/cjs/opcodes/codes.js.map +1 -0
  99. package/dist/cjs/opcodes/functions.d.ts +11 -0
  100. package/dist/cjs/opcodes/functions.d.ts.map +1 -0
  101. package/dist/cjs/opcodes/functions.js +1778 -0
  102. package/dist/cjs/opcodes/functions.js.map +1 -0
  103. package/dist/cjs/opcodes/gas.d.ts +15 -0
  104. package/dist/cjs/opcodes/gas.d.ts.map +1 -0
  105. package/dist/cjs/opcodes/gas.js +1016 -0
  106. package/dist/cjs/opcodes/gas.js.map +1 -0
  107. package/dist/cjs/opcodes/index.d.ts +4 -0
  108. package/dist/cjs/opcodes/index.d.ts.map +1 -0
  109. package/dist/cjs/opcodes/index.js +20 -0
  110. package/dist/cjs/opcodes/index.js.map +1 -0
  111. package/dist/cjs/opcodes/util.d.ts +86 -0
  112. package/dist/cjs/opcodes/util.d.ts.map +1 -0
  113. package/dist/cjs/opcodes/util.js +281 -0
  114. package/dist/cjs/opcodes/util.js.map +1 -0
  115. package/dist/cjs/package.json +3 -0
  116. package/dist/cjs/params.d.ts +3 -0
  117. package/dist/cjs/params.d.ts.map +1 -0
  118. package/dist/cjs/params.js +424 -0
  119. package/dist/cjs/params.js.map +1 -0
  120. package/dist/cjs/precompiles/01-ecrecover.d.ts +4 -0
  121. package/dist/cjs/precompiles/01-ecrecover.d.ts.map +1 -0
  122. package/dist/cjs/precompiles/01-ecrecover.js +58 -0
  123. package/dist/cjs/precompiles/01-ecrecover.js.map +1 -0
  124. package/dist/cjs/precompiles/02-sha256.d.ts +4 -0
  125. package/dist/cjs/precompiles/02-sha256.d.ts.map +1 -0
  126. package/dist/cjs/precompiles/02-sha256.js +27 -0
  127. package/dist/cjs/precompiles/02-sha256.js.map +1 -0
  128. package/dist/cjs/precompiles/03-ripemd160.d.ts +4 -0
  129. package/dist/cjs/precompiles/03-ripemd160.d.ts.map +1 -0
  130. package/dist/cjs/precompiles/03-ripemd160.js +26 -0
  131. package/dist/cjs/precompiles/03-ripemd160.js.map +1 -0
  132. package/dist/cjs/precompiles/04-identity.d.ts +4 -0
  133. package/dist/cjs/precompiles/04-identity.d.ts.map +1 -0
  134. package/dist/cjs/precompiles/04-identity.js +24 -0
  135. package/dist/cjs/precompiles/04-identity.js.map +1 -0
  136. package/dist/cjs/precompiles/05-modexp.d.ts +5 -0
  137. package/dist/cjs/precompiles/05-modexp.d.ts.map +1 -0
  138. package/dist/cjs/precompiles/05-modexp.js +185 -0
  139. package/dist/cjs/precompiles/05-modexp.js.map +1 -0
  140. package/dist/cjs/precompiles/06-bn254-add.d.ts +4 -0
  141. package/dist/cjs/precompiles/06-bn254-add.d.ts.map +1 -0
  142. package/dist/cjs/precompiles/06-bn254-add.js +42 -0
  143. package/dist/cjs/precompiles/06-bn254-add.js.map +1 -0
  144. package/dist/cjs/precompiles/07-bn254-mul.d.ts +4 -0
  145. package/dist/cjs/precompiles/07-bn254-mul.d.ts.map +1 -0
  146. package/dist/cjs/precompiles/07-bn254-mul.js +43 -0
  147. package/dist/cjs/precompiles/07-bn254-mul.js.map +1 -0
  148. package/dist/cjs/precompiles/08-bn254-pairing.d.ts +4 -0
  149. package/dist/cjs/precompiles/08-bn254-pairing.d.ts.map +1 -0
  150. package/dist/cjs/precompiles/08-bn254-pairing.js +45 -0
  151. package/dist/cjs/precompiles/08-bn254-pairing.js.map +1 -0
  152. package/dist/cjs/precompiles/09-blake2f.d.ts +5 -0
  153. package/dist/cjs/precompiles/09-blake2f.d.ts.map +1 -0
  154. package/dist/cjs/precompiles/09-blake2f.js +201 -0
  155. package/dist/cjs/precompiles/09-blake2f.js.map +1 -0
  156. package/dist/cjs/precompiles/0a-kzg-point-evaluation.d.ts +5 -0
  157. package/dist/cjs/precompiles/0a-kzg-point-evaluation.d.ts.map +1 -0
  158. package/dist/cjs/precompiles/0a-kzg-point-evaluation.js +68 -0
  159. package/dist/cjs/precompiles/0a-kzg-point-evaluation.js.map +1 -0
  160. package/dist/cjs/precompiles/0b-bls12-g1add.d.ts +4 -0
  161. package/dist/cjs/precompiles/0b-bls12-g1add.d.ts.map +1 -0
  162. package/dist/cjs/precompiles/0b-bls12-g1add.js +49 -0
  163. package/dist/cjs/precompiles/0b-bls12-g1add.js.map +1 -0
  164. package/dist/cjs/precompiles/0c-bls12-g1msm.d.ts +4 -0
  165. package/dist/cjs/precompiles/0c-bls12-g1msm.d.ts.map +1 -0
  166. package/dist/cjs/precompiles/0c-bls12-g1msm.js +62 -0
  167. package/dist/cjs/precompiles/0c-bls12-g1msm.js.map +1 -0
  168. package/dist/cjs/precompiles/0d-bls12-g2add.d.ts +4 -0
  169. package/dist/cjs/precompiles/0d-bls12-g2add.d.ts.map +1 -0
  170. package/dist/cjs/precompiles/0d-bls12-g2add.js +51 -0
  171. package/dist/cjs/precompiles/0d-bls12-g2add.js.map +1 -0
  172. package/dist/cjs/precompiles/0e-bls12-g2msm.d.ts +4 -0
  173. package/dist/cjs/precompiles/0e-bls12-g2msm.d.ts.map +1 -0
  174. package/dist/cjs/precompiles/0e-bls12-g2msm.js +60 -0
  175. package/dist/cjs/precompiles/0e-bls12-g2msm.js.map +1 -0
  176. package/dist/cjs/precompiles/0f-bls12-pairing.d.ts +4 -0
  177. package/dist/cjs/precompiles/0f-bls12-pairing.d.ts.map +1 -0
  178. package/dist/cjs/precompiles/0f-bls12-pairing.js +66 -0
  179. package/dist/cjs/precompiles/0f-bls12-pairing.js.map +1 -0
  180. package/dist/cjs/precompiles/10-bls12-map-fp-to-g1.d.ts +4 -0
  181. package/dist/cjs/precompiles/10-bls12-map-fp-to-g1.d.ts.map +1 -0
  182. package/dist/cjs/precompiles/10-bls12-map-fp-to-g1.js +44 -0
  183. package/dist/cjs/precompiles/10-bls12-map-fp-to-g1.js.map +1 -0
  184. package/dist/cjs/precompiles/100-p256verify.d.ts +4 -0
  185. package/dist/cjs/precompiles/100-p256verify.d.ts.map +1 -0
  186. package/dist/cjs/precompiles/100-p256verify.js +131 -0
  187. package/dist/cjs/precompiles/100-p256verify.js.map +1 -0
  188. package/dist/cjs/precompiles/11-bls12-map-fp2-to-g2.d.ts +4 -0
  189. package/dist/cjs/precompiles/11-bls12-map-fp2-to-g2.d.ts.map +1 -0
  190. package/dist/cjs/precompiles/11-bls12-map-fp2-to-g2.js +47 -0
  191. package/dist/cjs/precompiles/11-bls12-map-fp2-to-g2.js.map +1 -0
  192. package/dist/cjs/precompiles/bls12_381/constants.d.ts +10 -0
  193. package/dist/cjs/precompiles/bls12_381/constants.d.ts.map +1 -0
  194. package/dist/cjs/precompiles/bls12_381/constants.js +274 -0
  195. package/dist/cjs/precompiles/bls12_381/constants.js.map +1 -0
  196. package/dist/cjs/precompiles/bls12_381/index.d.ts +5 -0
  197. package/dist/cjs/precompiles/bls12_381/index.d.ts.map +1 -0
  198. package/dist/cjs/precompiles/bls12_381/index.js +24 -0
  199. package/dist/cjs/precompiles/bls12_381/index.js.map +1 -0
  200. package/dist/cjs/precompiles/bls12_381/mcl.d.ts +45 -0
  201. package/dist/cjs/precompiles/bls12_381/mcl.d.ts.map +1 -0
  202. package/dist/cjs/precompiles/bls12_381/mcl.js +264 -0
  203. package/dist/cjs/precompiles/bls12_381/mcl.js.map +1 -0
  204. package/dist/cjs/precompiles/bls12_381/noble.d.ts +39 -0
  205. package/dist/cjs/precompiles/bls12_381/noble.d.ts.map +1 -0
  206. package/dist/cjs/precompiles/bls12_381/noble.js +228 -0
  207. package/dist/cjs/precompiles/bls12_381/noble.js.map +1 -0
  208. package/dist/cjs/precompiles/bls12_381/util.d.ts +35 -0
  209. package/dist/cjs/precompiles/bls12_381/util.d.ts.map +1 -0
  210. package/dist/cjs/precompiles/bls12_381/util.js +68 -0
  211. package/dist/cjs/precompiles/bls12_381/util.js.map +1 -0
  212. package/dist/cjs/precompiles/bn254/index.d.ts +3 -0
  213. package/dist/cjs/precompiles/bn254/index.d.ts.map +1 -0
  214. package/dist/cjs/precompiles/bn254/index.js +8 -0
  215. package/dist/cjs/precompiles/bn254/index.js.map +1 -0
  216. package/dist/cjs/precompiles/bn254/noble.d.ts +13 -0
  217. package/dist/cjs/precompiles/bn254/noble.d.ts.map +1 -0
  218. package/dist/cjs/precompiles/bn254/noble.js +124 -0
  219. package/dist/cjs/precompiles/bn254/noble.js.map +1 -0
  220. package/dist/cjs/precompiles/bn254/rustbn.d.ts +16 -0
  221. package/dist/cjs/precompiles/bn254/rustbn.d.ts.map +1 -0
  222. package/dist/cjs/precompiles/bn254/rustbn.js +33 -0
  223. package/dist/cjs/precompiles/bn254/rustbn.js.map +1 -0
  224. package/dist/cjs/precompiles/index.d.ts +67 -0
  225. package/dist/cjs/precompiles/index.d.ts.map +1 -0
  226. package/dist/cjs/precompiles/index.js +262 -0
  227. package/dist/cjs/precompiles/index.js.map +1 -0
  228. package/dist/cjs/precompiles/types.d.ts +13 -0
  229. package/dist/cjs/precompiles/types.d.ts.map +1 -0
  230. package/dist/cjs/precompiles/types.js +3 -0
  231. package/dist/cjs/precompiles/types.js.map +1 -0
  232. package/dist/cjs/precompiles/util.d.ts +30 -0
  233. package/dist/cjs/precompiles/util.d.ts.map +1 -0
  234. package/dist/cjs/precompiles/util.js +63 -0
  235. package/dist/cjs/precompiles/util.js.map +1 -0
  236. package/dist/cjs/stack.d.ts +55 -0
  237. package/dist/cjs/stack.d.ts.map +1 -0
  238. package/dist/cjs/stack.js +143 -0
  239. package/dist/cjs/stack.js.map +1 -0
  240. package/dist/cjs/stemCache.d.ts +20 -0
  241. package/dist/cjs/stemCache.d.ts.map +1 -0
  242. package/dist/cjs/stemCache.js +37 -0
  243. package/dist/cjs/stemCache.js.map +1 -0
  244. package/dist/cjs/transientStorage.d.ts +54 -0
  245. package/dist/cjs/transientStorage.d.ts.map +1 -0
  246. package/dist/cjs/transientStorage.js +113 -0
  247. package/dist/cjs/transientStorage.js.map +1 -0
  248. package/dist/cjs/types.d.ts +465 -0
  249. package/dist/cjs/types.d.ts.map +1 -0
  250. package/dist/cjs/types.js +28 -0
  251. package/dist/cjs/types.js.map +1 -0
  252. package/dist/esm/binaryTreeAccessWitness.d.ts +61 -0
  253. package/dist/esm/binaryTreeAccessWitness.d.ts.map +1 -0
  254. package/dist/esm/binaryTreeAccessWitness.js +308 -0
  255. package/dist/esm/binaryTreeAccessWitness.js.map +1 -0
  256. package/dist/esm/chunkCache.d.ts +13 -0
  257. package/dist/esm/chunkCache.d.ts.map +1 -0
  258. package/dist/esm/chunkCache.js +26 -0
  259. package/dist/esm/chunkCache.js.map +1 -0
  260. package/dist/esm/constructors.d.ts +11 -0
  261. package/dist/esm/constructors.d.ts.map +1 -0
  262. package/dist/esm/constructors.js +27 -0
  263. package/dist/esm/constructors.js.map +1 -0
  264. package/dist/esm/eip7708.d.ts +24 -0
  265. package/dist/esm/eip7708.d.ts.map +1 -0
  266. package/dist/esm/eip7708.js +32 -0
  267. package/dist/esm/eip7708.js.map +1 -0
  268. package/dist/esm/eof/constants.d.ts +22 -0
  269. package/dist/esm/eof/constants.d.ts.map +1 -0
  270. package/dist/esm/eof/constants.js +28 -0
  271. package/dist/esm/eof/constants.js.map +1 -0
  272. package/dist/esm/eof/container.d.ts +87 -0
  273. package/dist/esm/eof/container.d.ts.map +1 -0
  274. package/dist/esm/eof/container.js +375 -0
  275. package/dist/esm/eof/container.js.map +1 -0
  276. package/dist/esm/eof/errors.d.ts +66 -0
  277. package/dist/esm/eof/errors.d.ts.map +1 -0
  278. package/dist/esm/eof/errors.js +195 -0
  279. package/dist/esm/eof/errors.js.map +1 -0
  280. package/dist/esm/eof/setup.d.ts +9 -0
  281. package/dist/esm/eof/setup.d.ts.map +1 -0
  282. package/dist/esm/eof/setup.js +23 -0
  283. package/dist/esm/eof/setup.js.map +1 -0
  284. package/dist/esm/eof/stackDelta.d.ts +10 -0
  285. package/dist/esm/eof/stackDelta.d.ts.map +1 -0
  286. package/dist/esm/eof/stackDelta.js +161 -0
  287. package/dist/esm/eof/stackDelta.js.map +1 -0
  288. package/dist/esm/eof/util.d.ts +8 -0
  289. package/dist/esm/eof/util.d.ts.map +1 -0
  290. package/dist/esm/eof/util.js +14 -0
  291. package/dist/esm/eof/util.js.map +1 -0
  292. package/dist/esm/eof/verify.d.ts +38 -0
  293. package/dist/esm/eof/verify.d.ts.map +1 -0
  294. package/dist/esm/eof/verify.js +432 -0
  295. package/dist/esm/eof/verify.js.map +1 -0
  296. package/dist/esm/errors.d.ts +40 -0
  297. package/dist/esm/errors.d.ts.map +1 -0
  298. package/dist/esm/errors.js +39 -0
  299. package/dist/esm/errors.js.map +1 -0
  300. package/dist/esm/evm.d.ts +181 -0
  301. package/dist/esm/evm.d.ts.map +1 -0
  302. package/dist/esm/evm.js +1131 -0
  303. package/dist/esm/evm.js.map +1 -0
  304. package/dist/esm/frameContext.d.ts +50 -0
  305. package/dist/esm/frameContext.d.ts.map +1 -0
  306. package/dist/esm/frameContext.js +14 -0
  307. package/dist/esm/frameContext.js.map +1 -0
  308. package/dist/esm/index.d.ts +18 -0
  309. package/dist/esm/index.d.ts.map +1 -0
  310. package/dist/esm/index.js +15 -0
  311. package/dist/esm/index.js.map +1 -0
  312. package/dist/esm/interpreter.d.ts +361 -0
  313. package/dist/esm/interpreter.d.ts.map +1 -0
  314. package/dist/esm/interpreter.js +1054 -0
  315. package/dist/esm/interpreter.js.map +1 -0
  316. package/dist/esm/journal.d.ts +69 -0
  317. package/dist/esm/journal.d.ts.map +1 -0
  318. package/dist/esm/journal.js +243 -0
  319. package/dist/esm/journal.js.map +1 -0
  320. package/dist/esm/logger.d.ts +38 -0
  321. package/dist/esm/logger.d.ts.map +1 -0
  322. package/dist/esm/logger.js +121 -0
  323. package/dist/esm/logger.js.map +1 -0
  324. package/dist/esm/memory.d.ts +29 -0
  325. package/dist/esm/memory.d.ts.map +1 -0
  326. package/dist/esm/memory.js +71 -0
  327. package/dist/esm/memory.js.map +1 -0
  328. package/dist/esm/message.d.ts +70 -0
  329. package/dist/esm/message.d.ts.map +1 -0
  330. package/dist/esm/message.js +47 -0
  331. package/dist/esm/message.js.map +1 -0
  332. package/dist/esm/opcodes/EIP1283.d.ts +13 -0
  333. package/dist/esm/opcodes/EIP1283.d.ts.map +1 -0
  334. package/dist/esm/opcodes/EIP1283.js +55 -0
  335. package/dist/esm/opcodes/EIP1283.js.map +1 -0
  336. package/dist/esm/opcodes/EIP2200.d.ts +13 -0
  337. package/dist/esm/opcodes/EIP2200.d.ts.map +1 -0
  338. package/dist/esm/opcodes/EIP2200.js +61 -0
  339. package/dist/esm/opcodes/EIP2200.js.map +1 -0
  340. package/dist/esm/opcodes/EIP2929.d.ts +68 -0
  341. package/dist/esm/opcodes/EIP2929.d.ts.map +1 -0
  342. package/dist/esm/opcodes/EIP2929.js +138 -0
  343. package/dist/esm/opcodes/EIP2929.js.map +1 -0
  344. package/dist/esm/opcodes/codes.d.ts +45 -0
  345. package/dist/esm/opcodes/codes.d.ts.map +1 -0
  346. package/dist/esm/opcodes/codes.js +448 -0
  347. package/dist/esm/opcodes/codes.js.map +1 -0
  348. package/dist/esm/opcodes/functions.d.ts +11 -0
  349. package/dist/esm/opcodes/functions.d.ts.map +1 -0
  350. package/dist/esm/opcodes/functions.js +1775 -0
  351. package/dist/esm/opcodes/functions.js.map +1 -0
  352. package/dist/esm/opcodes/gas.d.ts +15 -0
  353. package/dist/esm/opcodes/gas.d.ts.map +1 -0
  354. package/dist/esm/opcodes/gas.js +1013 -0
  355. package/dist/esm/opcodes/gas.js.map +1 -0
  356. package/dist/esm/opcodes/index.d.ts +4 -0
  357. package/dist/esm/opcodes/index.d.ts.map +1 -0
  358. package/dist/esm/opcodes/index.js +4 -0
  359. package/dist/esm/opcodes/index.js.map +1 -0
  360. package/dist/esm/opcodes/util.d.ts +86 -0
  361. package/dist/esm/opcodes/util.d.ts.map +1 -0
  362. package/dist/esm/opcodes/util.js +257 -0
  363. package/dist/esm/opcodes/util.js.map +1 -0
  364. package/dist/esm/package.json +3 -0
  365. package/dist/esm/params.d.ts +3 -0
  366. package/dist/esm/params.d.ts.map +1 -0
  367. package/dist/esm/params.js +421 -0
  368. package/dist/esm/params.js.map +1 -0
  369. package/dist/esm/precompiles/01-ecrecover.d.ts +4 -0
  370. package/dist/esm/precompiles/01-ecrecover.d.ts.map +1 -0
  371. package/dist/esm/precompiles/01-ecrecover.js +55 -0
  372. package/dist/esm/precompiles/01-ecrecover.js.map +1 -0
  373. package/dist/esm/precompiles/02-sha256.d.ts +4 -0
  374. package/dist/esm/precompiles/02-sha256.d.ts.map +1 -0
  375. package/dist/esm/precompiles/02-sha256.js +24 -0
  376. package/dist/esm/precompiles/02-sha256.js.map +1 -0
  377. package/dist/esm/precompiles/03-ripemd160.d.ts +4 -0
  378. package/dist/esm/precompiles/03-ripemd160.d.ts.map +1 -0
  379. package/dist/esm/precompiles/03-ripemd160.js +23 -0
  380. package/dist/esm/precompiles/03-ripemd160.js.map +1 -0
  381. package/dist/esm/precompiles/04-identity.d.ts +4 -0
  382. package/dist/esm/precompiles/04-identity.d.ts.map +1 -0
  383. package/dist/esm/precompiles/04-identity.js +21 -0
  384. package/dist/esm/precompiles/04-identity.js.map +1 -0
  385. package/dist/esm/precompiles/05-modexp.d.ts +5 -0
  386. package/dist/esm/precompiles/05-modexp.d.ts.map +1 -0
  387. package/dist/esm/precompiles/05-modexp.js +181 -0
  388. package/dist/esm/precompiles/05-modexp.js.map +1 -0
  389. package/dist/esm/precompiles/06-bn254-add.d.ts +4 -0
  390. package/dist/esm/precompiles/06-bn254-add.d.ts.map +1 -0
  391. package/dist/esm/precompiles/06-bn254-add.js +39 -0
  392. package/dist/esm/precompiles/06-bn254-add.js.map +1 -0
  393. package/dist/esm/precompiles/07-bn254-mul.d.ts +4 -0
  394. package/dist/esm/precompiles/07-bn254-mul.d.ts.map +1 -0
  395. package/dist/esm/precompiles/07-bn254-mul.js +40 -0
  396. package/dist/esm/precompiles/07-bn254-mul.js.map +1 -0
  397. package/dist/esm/precompiles/08-bn254-pairing.d.ts +4 -0
  398. package/dist/esm/precompiles/08-bn254-pairing.d.ts.map +1 -0
  399. package/dist/esm/precompiles/08-bn254-pairing.js +42 -0
  400. package/dist/esm/precompiles/08-bn254-pairing.js.map +1 -0
  401. package/dist/esm/precompiles/09-blake2f.d.ts +5 -0
  402. package/dist/esm/precompiles/09-blake2f.d.ts.map +1 -0
  403. package/dist/esm/precompiles/09-blake2f.js +197 -0
  404. package/dist/esm/precompiles/09-blake2f.js.map +1 -0
  405. package/dist/esm/precompiles/0a-kzg-point-evaluation.d.ts +5 -0
  406. package/dist/esm/precompiles/0a-kzg-point-evaluation.d.ts.map +1 -0
  407. package/dist/esm/precompiles/0a-kzg-point-evaluation.js +64 -0
  408. package/dist/esm/precompiles/0a-kzg-point-evaluation.js.map +1 -0
  409. package/dist/esm/precompiles/0b-bls12-g1add.d.ts +4 -0
  410. package/dist/esm/precompiles/0b-bls12-g1add.d.ts.map +1 -0
  411. package/dist/esm/precompiles/0b-bls12-g1add.js +46 -0
  412. package/dist/esm/precompiles/0b-bls12-g1add.js.map +1 -0
  413. package/dist/esm/precompiles/0c-bls12-g1msm.d.ts +4 -0
  414. package/dist/esm/precompiles/0c-bls12-g1msm.d.ts.map +1 -0
  415. package/dist/esm/precompiles/0c-bls12-g1msm.js +59 -0
  416. package/dist/esm/precompiles/0c-bls12-g1msm.js.map +1 -0
  417. package/dist/esm/precompiles/0d-bls12-g2add.d.ts +4 -0
  418. package/dist/esm/precompiles/0d-bls12-g2add.d.ts.map +1 -0
  419. package/dist/esm/precompiles/0d-bls12-g2add.js +48 -0
  420. package/dist/esm/precompiles/0d-bls12-g2add.js.map +1 -0
  421. package/dist/esm/precompiles/0e-bls12-g2msm.d.ts +4 -0
  422. package/dist/esm/precompiles/0e-bls12-g2msm.d.ts.map +1 -0
  423. package/dist/esm/precompiles/0e-bls12-g2msm.js +57 -0
  424. package/dist/esm/precompiles/0e-bls12-g2msm.js.map +1 -0
  425. package/dist/esm/precompiles/0f-bls12-pairing.d.ts +4 -0
  426. package/dist/esm/precompiles/0f-bls12-pairing.d.ts.map +1 -0
  427. package/dist/esm/precompiles/0f-bls12-pairing.js +63 -0
  428. package/dist/esm/precompiles/0f-bls12-pairing.js.map +1 -0
  429. package/dist/esm/precompiles/10-bls12-map-fp-to-g1.d.ts +4 -0
  430. package/dist/esm/precompiles/10-bls12-map-fp-to-g1.d.ts.map +1 -0
  431. package/dist/esm/precompiles/10-bls12-map-fp-to-g1.js +41 -0
  432. package/dist/esm/precompiles/10-bls12-map-fp-to-g1.js.map +1 -0
  433. package/dist/esm/precompiles/100-p256verify.d.ts +4 -0
  434. package/dist/esm/precompiles/100-p256verify.d.ts.map +1 -0
  435. package/dist/esm/precompiles/100-p256verify.js +128 -0
  436. package/dist/esm/precompiles/100-p256verify.js.map +1 -0
  437. package/dist/esm/precompiles/11-bls12-map-fp2-to-g2.d.ts +4 -0
  438. package/dist/esm/precompiles/11-bls12-map-fp2-to-g2.d.ts.map +1 -0
  439. package/dist/esm/precompiles/11-bls12-map-fp2-to-g2.js +44 -0
  440. package/dist/esm/precompiles/11-bls12-map-fp2-to-g2.js.map +1 -0
  441. package/dist/esm/precompiles/bls12_381/constants.d.ts +10 -0
  442. package/dist/esm/precompiles/bls12_381/constants.d.ts.map +1 -0
  443. package/dist/esm/precompiles/bls12_381/constants.js +271 -0
  444. package/dist/esm/precompiles/bls12_381/constants.js.map +1 -0
  445. package/dist/esm/precompiles/bls12_381/index.d.ts +5 -0
  446. package/dist/esm/precompiles/bls12_381/index.d.ts.map +1 -0
  447. package/dist/esm/precompiles/bls12_381/index.js +5 -0
  448. package/dist/esm/precompiles/bls12_381/index.js.map +1 -0
  449. package/dist/esm/precompiles/bls12_381/mcl.d.ts +45 -0
  450. package/dist/esm/precompiles/bls12_381/mcl.d.ts.map +1 -0
  451. package/dist/esm/precompiles/bls12_381/mcl.js +254 -0
  452. package/dist/esm/precompiles/bls12_381/mcl.js.map +1 -0
  453. package/dist/esm/precompiles/bls12_381/noble.d.ts +39 -0
  454. package/dist/esm/precompiles/bls12_381/noble.d.ts.map +1 -0
  455. package/dist/esm/precompiles/bls12_381/noble.js +218 -0
  456. package/dist/esm/precompiles/bls12_381/noble.js.map +1 -0
  457. package/dist/esm/precompiles/bls12_381/util.d.ts +35 -0
  458. package/dist/esm/precompiles/bls12_381/util.d.ts.map +1 -0
  459. package/dist/esm/precompiles/bls12_381/util.js +63 -0
  460. package/dist/esm/precompiles/bls12_381/util.js.map +1 -0
  461. package/dist/esm/precompiles/bn254/index.d.ts +3 -0
  462. package/dist/esm/precompiles/bn254/index.d.ts.map +1 -0
  463. package/dist/esm/precompiles/bn254/index.js +3 -0
  464. package/dist/esm/precompiles/bn254/index.js.map +1 -0
  465. package/dist/esm/precompiles/bn254/noble.d.ts +13 -0
  466. package/dist/esm/precompiles/bn254/noble.d.ts.map +1 -0
  467. package/dist/esm/precompiles/bn254/noble.js +120 -0
  468. package/dist/esm/precompiles/bn254/noble.js.map +1 -0
  469. package/dist/esm/precompiles/bn254/rustbn.d.ts +16 -0
  470. package/dist/esm/precompiles/bn254/rustbn.d.ts.map +1 -0
  471. package/dist/esm/precompiles/bn254/rustbn.js +29 -0
  472. package/dist/esm/precompiles/bn254/rustbn.js.map +1 -0
  473. package/dist/esm/precompiles/index.d.ts +67 -0
  474. package/dist/esm/precompiles/index.d.ts.map +1 -0
  475. package/dist/esm/precompiles/index.js +251 -0
  476. package/dist/esm/precompiles/index.js.map +1 -0
  477. package/dist/esm/precompiles/types.d.ts +13 -0
  478. package/dist/esm/precompiles/types.d.ts.map +1 -0
  479. package/dist/esm/precompiles/types.js +2 -0
  480. package/dist/esm/precompiles/types.js.map +1 -0
  481. package/dist/esm/precompiles/util.d.ts +30 -0
  482. package/dist/esm/precompiles/util.d.ts.map +1 -0
  483. package/dist/esm/precompiles/util.js +57 -0
  484. package/dist/esm/precompiles/util.js.map +1 -0
  485. package/dist/esm/stack.d.ts +55 -0
  486. package/dist/esm/stack.d.ts.map +1 -0
  487. package/dist/esm/stack.js +139 -0
  488. package/dist/esm/stack.js.map +1 -0
  489. package/dist/esm/stemCache.d.ts +20 -0
  490. package/dist/esm/stemCache.d.ts.map +1 -0
  491. package/dist/esm/stemCache.js +33 -0
  492. package/dist/esm/stemCache.js.map +1 -0
  493. package/dist/esm/transientStorage.d.ts +54 -0
  494. package/dist/esm/transientStorage.d.ts.map +1 -0
  495. package/dist/esm/transientStorage.js +109 -0
  496. package/dist/esm/transientStorage.js.map +1 -0
  497. package/dist/esm/types.d.ts +465 -0
  498. package/dist/esm/types.d.ts.map +1 -0
  499. package/dist/esm/types.js +23 -0
  500. package/dist/esm/types.js.map +1 -0
  501. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  502. package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
  503. package/package.json +98 -0
  504. package/src/binaryTreeAccessWitness.ts +447 -0
  505. package/src/chunkCache.ts +36 -0
  506. package/src/constructors.ts +35 -0
  507. package/src/eip7708.ts +47 -0
  508. package/src/eof/constants.ts +36 -0
  509. package/src/eof/container.ts +495 -0
  510. package/src/eof/errors.ts +214 -0
  511. package/src/eof/setup.ts +27 -0
  512. package/src/eof/stackDelta.ts +169 -0
  513. package/src/eof/util.ts +16 -0
  514. package/src/eof/verify.ts +531 -0
  515. package/src/errors.ts +45 -0
  516. package/src/evm.ts +1415 -0
  517. package/src/frameContext.ts +56 -0
  518. package/src/index.ts +75 -0
  519. package/src/interpreter.ts +1437 -0
  520. package/src/journal.ts +317 -0
  521. package/src/logger.ts +180 -0
  522. package/src/memory.ts +82 -0
  523. package/src/message.ts +114 -0
  524. package/src/opcodes/EIP1283.ts +77 -0
  525. package/src/opcodes/EIP2200.ts +87 -0
  526. package/src/opcodes/EIP2929.ts +173 -0
  527. package/src/opcodes/codes.ts +528 -0
  528. package/src/opcodes/functions.ts +1937 -0
  529. package/src/opcodes/gas.ts +1329 -0
  530. package/src/opcodes/index.ts +3 -0
  531. package/src/opcodes/util.ts +313 -0
  532. package/src/params.ts +423 -0
  533. package/src/precompiles/01-ecrecover.ts +77 -0
  534. package/src/precompiles/02-sha256.ts +32 -0
  535. package/src/precompiles/03-ripemd160.ts +32 -0
  536. package/src/precompiles/04-identity.ts +29 -0
  537. package/src/precompiles/05-modexp.ts +215 -0
  538. package/src/precompiles/06-bn254-add.ts +49 -0
  539. package/src/precompiles/07-bn254-mul.ts +50 -0
  540. package/src/precompiles/08-bn254-pairing.ts +54 -0
  541. package/src/precompiles/09-blake2f.ts +243 -0
  542. package/src/precompiles/0a-kzg-point-evaluation.ts +94 -0
  543. package/src/precompiles/0b-bls12-g1add.ts +63 -0
  544. package/src/precompiles/0c-bls12-g1msm.ts +87 -0
  545. package/src/precompiles/0d-bls12-g2add.ts +66 -0
  546. package/src/precompiles/0e-bls12-g2msm.ts +84 -0
  547. package/src/precompiles/0f-bls12-pairing.ts +86 -0
  548. package/src/precompiles/10-bls12-map-fp-to-g1.ts +58 -0
  549. package/src/precompiles/100-p256verify.ts +152 -0
  550. package/src/precompiles/11-bls12-map-fp2-to-g2.ts +61 -0
  551. package/src/precompiles/bls12_381/constants.ts +278 -0
  552. package/src/precompiles/bls12_381/index.ts +4 -0
  553. package/src/precompiles/bls12_381/mcl.ts +376 -0
  554. package/src/precompiles/bls12_381/noble.ts +307 -0
  555. package/src/precompiles/bls12_381/util.ts +78 -0
  556. package/src/precompiles/bn254/index.ts +2 -0
  557. package/src/precompiles/bn254/noble.ts +156 -0
  558. package/src/precompiles/bn254/rustbn.ts +35 -0
  559. package/src/precompiles/index.ts +344 -0
  560. package/src/precompiles/types.ts +15 -0
  561. package/src/precompiles/util.ts +70 -0
  562. package/src/stack.ts +166 -0
  563. package/src/stemCache.ts +45 -0
  564. package/src/transientStorage.ts +131 -0
  565. package/src/types.ts +538 -0
@@ -0,0 +1,1142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVM = void 0;
4
+ exports.OOGResult = OOGResult;
5
+ exports.COOGResult = COOGResult;
6
+ exports.INVALID_BYTECODE_RESULT = INVALID_BYTECODE_RESULT;
7
+ exports.INVALID_EOF_RESULT = INVALID_EOF_RESULT;
8
+ exports.CodesizeExceedsMaximumError = CodesizeExceedsMaximumError;
9
+ exports.EVMErrorResult = EVMErrorResult;
10
+ exports.defaultBlock = defaultBlock;
11
+ const common_1 = require("@feelyourprotocol/common");
12
+ const util_1 = require("@feelyourprotocol/util");
13
+ const debug_1 = require("debug");
14
+ const eventemitter3_1 = require("eventemitter3");
15
+ const eip7708_ts_1 = require("./eip7708.js");
16
+ const constants_ts_1 = require("./eof/constants.js");
17
+ const util_ts_1 = require("./eof/util.js");
18
+ const errors_ts_1 = require("./errors.js");
19
+ const interpreter_ts_1 = require("./interpreter.js");
20
+ const journal_ts_1 = require("./journal.js");
21
+ const logger_ts_1 = require("./logger.js");
22
+ const message_ts_1 = require("./message.js");
23
+ const index_ts_1 = require("./opcodes/index.js");
24
+ const params_ts_1 = require("./params.js");
25
+ const index_ts_2 = require("./precompiles/index.js");
26
+ const transientStorage_ts_1 = require("./transientStorage.js");
27
+ const types_ts_1 = require("./types.js");
28
+ const debug = (0, debug_1.default)('evm:evm');
29
+ const debugGas = (0, debug_1.default)('evm:gas');
30
+ const debugPrecompiles = (0, debug_1.default)('evm:precompiles');
31
+ /**
32
+ * Creates a standardized ExecResult for out-of-gas errors.
33
+ * @param gasLimit - Gas limit consumed by the failing frame
34
+ * @returns Execution result describing the OOG failure
35
+ */
36
+ function OOGResult(gasLimit) {
37
+ return {
38
+ returnValue: new Uint8Array(0),
39
+ executionGasUsed: gasLimit,
40
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.OUT_OF_GAS),
41
+ };
42
+ }
43
+ /**
44
+ * Creates an ExecResult for code-deposit out-of-gas errors (EIP-3541).
45
+ * @param gasUsedCreateCode - Gas consumed while attempting to store code
46
+ */
47
+ function COOGResult(gasUsedCreateCode) {
48
+ return {
49
+ returnValue: new Uint8Array(0),
50
+ executionGasUsed: gasUsedCreateCode,
51
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.CODESTORE_OUT_OF_GAS),
52
+ };
53
+ }
54
+ /**
55
+ * Returns an ExecResult signalling invalid bytecode input.
56
+ * @param gasLimit - Gas consumed up to the point of failure
57
+ */
58
+ function INVALID_BYTECODE_RESULT(gasLimit) {
59
+ return {
60
+ returnValue: new Uint8Array(0),
61
+ executionGasUsed: gasLimit,
62
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.INVALID_BYTECODE_RESULT),
63
+ };
64
+ }
65
+ /**
66
+ * Returns an ExecResult signalling invalid EOF formatting.
67
+ * @param gasLimit - Gas consumed up to the point of failure
68
+ */
69
+ function INVALID_EOF_RESULT(gasLimit) {
70
+ return {
71
+ returnValue: new Uint8Array(0),
72
+ executionGasUsed: gasLimit,
73
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.INVALID_EOF_FORMAT),
74
+ };
75
+ }
76
+ /**
77
+ * Returns an ExecResult for code size violations.
78
+ * @param gasUsed - Gas consumed before the violation was detected
79
+ */
80
+ function CodesizeExceedsMaximumError(gasUsed) {
81
+ return {
82
+ returnValue: new Uint8Array(0),
83
+ executionGasUsed: gasUsed,
84
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.CODESIZE_EXCEEDS_MAXIMUM),
85
+ };
86
+ }
87
+ /**
88
+ * Wraps an {@link EVMError} in an ExecResult.
89
+ * @param error - Error encountered during execution
90
+ * @param gasUsed - Gas consumed up to the error
91
+ */
92
+ function EVMErrorResult(error, gasUsed) {
93
+ return {
94
+ returnValue: new Uint8Array(0),
95
+ executionGasUsed: gasUsed,
96
+ exceptionError: error,
97
+ };
98
+ }
99
+ /**
100
+ * Creates a default block header used by stand-alone executions.
101
+ * @returns Block-like object with zeroed header fields
102
+ */
103
+ function defaultBlock() {
104
+ return {
105
+ header: {
106
+ number: util_1.BIGINT_0,
107
+ coinbase: (0, util_1.createZeroAddress)(),
108
+ timestamp: util_1.BIGINT_0,
109
+ difficulty: util_1.BIGINT_0,
110
+ prevRandao: new Uint8Array(32),
111
+ gasLimit: util_1.BIGINT_0,
112
+ baseFeePerGas: undefined,
113
+ getBlobGasPrice: () => undefined,
114
+ },
115
+ };
116
+ }
117
+ /**
118
+ * The EVM (Ethereum Virtual Machine) is responsible for executing EVM bytecode, processing transactions, and managing state changes. It handles both contract calls and contract creation operations.
119
+ *
120
+ * An EVM instance can be created with the constructor method:
121
+ *
122
+ * - {@link createEVM}
123
+ */
124
+ class EVM {
125
+ get precompiles() {
126
+ return this._precompiles;
127
+ }
128
+ get opcodes() {
129
+ return this._opcodes;
130
+ }
131
+ /**
132
+ *
133
+ * Creates new EVM object
134
+ *
135
+ * @deprecated The direct usage of this constructor is replaced since
136
+ * non-finalized async initialization lead to side effects. Please
137
+ * use the async {@link createEVM} constructor instead (same API).
138
+ *
139
+ * @param opts The EVM options
140
+ * @param bn128 Initialized bn128 WASM object for precompile usage (internal)
141
+ */
142
+ constructor(opts) {
143
+ /**
144
+ * EVM is run in DEBUG mode (default: false)
145
+ * Taken from DEBUG environment variable
146
+ *
147
+ * Safeguards on debug() calls are added for
148
+ * performance reasons to avoid string literal evaluation
149
+ * @hidden
150
+ */
151
+ this.DEBUG = false;
152
+ this.common = opts.common;
153
+ this.blockchain = opts.blockchain;
154
+ this.stateManager = opts.stateManager;
155
+ if (this.common.isActivatedEIP(7864)) {
156
+ const mandatory = ['checkChunkWitnessPresent'];
157
+ for (const m of mandatory) {
158
+ if (!(m in this.stateManager)) {
159
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`State manager used must implement ${m} if Binary Trees (EIP-7864) is activated`);
160
+ }
161
+ }
162
+ }
163
+ if (this.common.isActivatedEIP(7928)) {
164
+ this.blockLevelAccessList = opts.blockLevelAccessList ?? (0, util_1.createBlockLevelAccessList)();
165
+ }
166
+ this.events = new eventemitter3_1.EventEmitter();
167
+ this._optsCached = opts;
168
+ // Supported EIPs
169
+ const supportedEIPs = [
170
+ 1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3198, 3529, 3540, 3541, 3607, 3651, 3670,
171
+ 3855, 3860, 4200, 4399, 4750, 4788, 4844, 4895, 5133, 5450, 5656, 6110, 6206, 6780, 7002,
172
+ 7069, 7251, 7480, 7516, 7594, 7620, 7685, 7691, 7692, 7698, 7702, 7709, 7823, 7825, 7934,
173
+ 7939, 7951, 8024, 8141,
174
+ ];
175
+ for (const eip of this.common.eips()) {
176
+ if (!supportedEIPs.includes(eip)) {
177
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`EIP-${eip} is not supported by the EVM`);
178
+ }
179
+ }
180
+ if (!EVM.supportedHardforks.includes(this.common.hardfork())) {
181
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`Hardfork ${this.common.hardfork()} not set as supported in supportedHardforks`);
182
+ }
183
+ this.common.updateParams(opts.params ?? params_ts_1.paramsEVM);
184
+ this.allowUnlimitedContractSize = opts.allowUnlimitedContractSize ?? false;
185
+ this.allowUnlimitedInitCodeSize = opts.allowUnlimitedInitCodeSize ?? false;
186
+ this._customOpcodes = opts.customOpcodes;
187
+ this._customPrecompiles = opts.customPrecompiles;
188
+ this.journal = new journal_ts_1.Journal(this.stateManager, this.common);
189
+ this.transientStorage = new transientStorage_ts_1.TransientStorage();
190
+ this.common.events.on('hardforkChanged', () => {
191
+ this.getActiveOpcodes();
192
+ this._precompiles = (0, index_ts_2.getActivePrecompiles)(this.common, this._customPrecompiles);
193
+ });
194
+ // Initialize the opcode data
195
+ this.getActiveOpcodes();
196
+ this._precompiles = (0, index_ts_2.getActivePrecompiles)(this.common, this._customPrecompiles);
197
+ // Precompile crypto libraries
198
+ if (this.common.isActivatedEIP(2537)) {
199
+ this._bls = opts.bls ?? new index_ts_2.NobleBLS();
200
+ this._bls.init?.();
201
+ }
202
+ this._bn254 = opts.bn254;
203
+ this._emit = async (topic, data) => {
204
+ const listeners = this.events.listeners(topic);
205
+ for (const listener of listeners) {
206
+ if (listener.length === 2) {
207
+ await new Promise((resolve) => {
208
+ listener(data, resolve);
209
+ });
210
+ }
211
+ else {
212
+ listener(data);
213
+ }
214
+ }
215
+ };
216
+ this.performanceLogger = new logger_ts_1.EVMPerformanceLogger();
217
+ // Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables
218
+ this.DEBUG = (0, util_1.isDebugEnabled)('ethjs');
219
+ }
220
+ /**
221
+ * Returns a list with the currently activated opcodes
222
+ * available for EVM execution
223
+ */
224
+ getActiveOpcodes() {
225
+ const data = (0, index_ts_1.getOpcodesForHF)(this.common, this._customOpcodes);
226
+ this._opcodes = data.opcodes;
227
+ this._dynamicGasHandlers = data.dynamicGasHandlers;
228
+ this._handlers = data.handlers;
229
+ this._opcodeMap = data.opcodeMap;
230
+ return data.opcodes;
231
+ }
232
+ async _executeCall(message) {
233
+ let gasLimit = message.gasLimit;
234
+ const fromAddress = message.caller;
235
+ if (this.common.isActivatedEIP(7864)) {
236
+ if (message.accessWitness === undefined) {
237
+ throw (0, util_1.EthereumJSErrorWithoutCode)('accessWitness is required for EIP-7864');
238
+ }
239
+ const sendsValue = message.value !== util_1.BIGINT_0;
240
+ if (message.depth === 0) {
241
+ const originAccessGas = message.accessWitness.readAccountHeader(fromAddress);
242
+ debugGas(`originAccessGas=${originAccessGas} waived off for origin at depth=0`);
243
+ let destAccessGas = message.accessWitness.readAccountCodeHash(message.to);
244
+ if (sendsValue) {
245
+ destAccessGas += message.accessWitness.writeAccountBasicData(message.to);
246
+ }
247
+ else {
248
+ destAccessGas += message.accessWitness.readAccountBasicData(message.to);
249
+ }
250
+ debugGas(`destAccessGas=${destAccessGas} waived off for target at depth=0`);
251
+ }
252
+ let callAccessGas = message.accessWitness.readAccountBasicData(message.to);
253
+ if (sendsValue) {
254
+ callAccessGas += message.accessWitness.writeAccountBasicData(message.to);
255
+ }
256
+ gasLimit -= callAccessGas;
257
+ if (gasLimit < util_1.BIGINT_0) {
258
+ if (this.DEBUG) {
259
+ debugGas(`callAccessGas charged(${callAccessGas}) caused OOG (-> ${gasLimit})`);
260
+ }
261
+ message.accessWitness.revert();
262
+ return { execResult: OOGResult(message.gasLimit) };
263
+ }
264
+ else {
265
+ if (this.DEBUG) {
266
+ debugGas(`callAccessGas used (${callAccessGas} gas (-> ${gasLimit}))`);
267
+ }
268
+ message.accessWitness.commit();
269
+ }
270
+ }
271
+ let account = await this.stateManager.getAccount(fromAddress);
272
+ if (!account) {
273
+ account = new util_1.Account();
274
+ }
275
+ let errorMessage;
276
+ // Reduce tx value from sender
277
+ if (!message.delegatecall) {
278
+ try {
279
+ await this._reduceSenderBalance(account, message);
280
+ }
281
+ catch (e) {
282
+ errorMessage = e;
283
+ }
284
+ }
285
+ // Load `to` account
286
+ let toAccount = await this.stateManager.getAccount(message.to);
287
+ if (!toAccount) {
288
+ if (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) {
289
+ const absenceProofAccessGas = message.accessWitness.readAccountHeader(message.to);
290
+ gasLimit -= absenceProofAccessGas;
291
+ if (gasLimit < util_1.BIGINT_0) {
292
+ if (this.DEBUG) {
293
+ debugGas(`Proof of absence access charged(${absenceProofAccessGas}) caused OOG (-> ${gasLimit})`);
294
+ }
295
+ message.accessWitness?.revert();
296
+ return { execResult: OOGResult(message.gasLimit) };
297
+ }
298
+ else {
299
+ if (this.DEBUG) {
300
+ debugGas(`Proof of absence access used (${absenceProofAccessGas} gas (-> ${gasLimit}))`);
301
+ }
302
+ message.accessWitness?.commit();
303
+ }
304
+ }
305
+ toAccount = new util_1.Account();
306
+ }
307
+ // Add tx value to the `to` account
308
+ if (!message.delegatecall) {
309
+ try {
310
+ await this._addToBalance(toAccount, message);
311
+ }
312
+ catch (e) {
313
+ errorMessage = e;
314
+ }
315
+ }
316
+ // EIP-7928: Add codeAddress to BAL for DELEGATECALL/CALLCODE
317
+ // For these opcodes, `to` is the current contract but `codeAddress` is the target
318
+ // whose code is being executed. The target MUST be included in the BAL.
319
+ if (this.common.isActivatedEIP(7928) &&
320
+ message.codeAddress !== undefined &&
321
+ message.codeAddress.toString() !== message.to.toString()) {
322
+ this.blockLevelAccessList.addAddress(message.codeAddress.toString());
323
+ }
324
+ // Load code
325
+ await this._loadCode(message);
326
+ let exit = false;
327
+ if (!message.code || (typeof message.code !== 'function' && message.code.length === 0)) {
328
+ exit = true;
329
+ if (this.DEBUG) {
330
+ debug(`Exit early on no code (CALL)`);
331
+ }
332
+ }
333
+ if (errorMessage !== undefined) {
334
+ exit = true;
335
+ if (this.DEBUG) {
336
+ debug(`Exit early on value transfer overflowed (CALL)`);
337
+ }
338
+ }
339
+ // EIP-7708: Create ETH transfer log for non-zero value transfers to a different account.
340
+ // CALLCODE always executes in the caller's context (to == caller), so it is a self-transfer.
341
+ // Self-transfers (caller == to) and DELEGATECALL do not emit a log.
342
+ let eip7708Log;
343
+ const isTransferToDifferentAccount = !(0, util_1.equalsBytes)(message.caller.bytes, message.to.bytes);
344
+ if (this.common.isActivatedEIP(7708) &&
345
+ !message.delegatecall &&
346
+ message.value > util_1.BIGINT_0 &&
347
+ isTransferToDifferentAccount &&
348
+ errorMessage === undefined) {
349
+ eip7708Log = (0, eip7708_ts_1.createEIP7708TransferLog)(message.caller, message.to, message.value);
350
+ if (this.DEBUG) {
351
+ debug(`EIP-7708: Created ETH transfer log from ${message.caller} to ${message.to} value=${message.value}`);
352
+ }
353
+ }
354
+ if (exit) {
355
+ // Even on early exit, we may need to return the EIP-7708 log if value was transferred
356
+ return {
357
+ execResult: {
358
+ gasRefund: message.gasRefund,
359
+ executionGasUsed: message.gasLimit - gasLimit,
360
+ exceptionError: errorMessage, // Only defined if addToBalance failed
361
+ returnValue: new Uint8Array(0),
362
+ logs: eip7708Log ? [eip7708Log] : undefined,
363
+ },
364
+ };
365
+ }
366
+ let result;
367
+ if (message.isCompiled) {
368
+ let timer;
369
+ let callTimer;
370
+ let target;
371
+ if (this._optsCached.profiler?.enabled === true) {
372
+ // Using deprecated bytesToUnprefixedHex for performance: used for profiler string formatting.
373
+ target = (0, util_1.bytesToUnprefixedHex)(message.codeAddress.bytes);
374
+ // TODO: map target precompile not to address, but to a name
375
+ target = (0, index_ts_2.getPrecompileName)(target) ?? target.slice(20);
376
+ if (this.performanceLogger.hasTimer()) {
377
+ callTimer = this.performanceLogger.pauseTimer();
378
+ }
379
+ timer = this.performanceLogger.startTimer(target);
380
+ }
381
+ result = await this.runPrecompile(message.code, message.data, gasLimit);
382
+ if (eip7708Log !== undefined) {
383
+ result.logs = result.logs !== undefined ? [eip7708Log, ...result.logs] : [eip7708Log];
384
+ }
385
+ if (this._optsCached.profiler?.enabled === true) {
386
+ this.performanceLogger.stopTimer(timer, Number(result.executionGasUsed), 'precompiles');
387
+ if (callTimer !== undefined) {
388
+ this.performanceLogger.unpauseTimer(callTimer);
389
+ }
390
+ }
391
+ result.gasRefund = message.gasRefund;
392
+ }
393
+ else {
394
+ if (this.DEBUG) {
395
+ debug(`Start bytecode processing...`);
396
+ }
397
+ result = await this.runInterpreter({
398
+ ...{ codeAddress: message.codeAddress },
399
+ ...message,
400
+ gasLimit,
401
+ }, { initialLogs: eip7708Log ? [eip7708Log] : undefined });
402
+ }
403
+ if (message.depth === 0) {
404
+ this.postMessageCleanup();
405
+ }
406
+ result.executionGasUsed += message.gasLimit - gasLimit;
407
+ return {
408
+ execResult: result,
409
+ };
410
+ }
411
+ async _executeCreate(message) {
412
+ let gasLimit = message.gasLimit;
413
+ const fromAddress = message.caller;
414
+ if (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) {
415
+ if (message.depth === 0) {
416
+ const originAccessGas = message.accessWitness.readAccountHeader(fromAddress);
417
+ debugGas(`originAccessGas=${originAccessGas} waived off for origin at depth=0`);
418
+ }
419
+ }
420
+ let account = await this.stateManager.getAccount(message.caller);
421
+ if (!account) {
422
+ account = new util_1.Account();
423
+ }
424
+ // Reduce tx value from sender
425
+ await this._reduceSenderBalance(account, message);
426
+ if (this.common.isActivatedEIP(3860)) {
427
+ if (message.data.length > Number(this.common.param('maxInitCodeSize')) &&
428
+ !this.allowUnlimitedInitCodeSize) {
429
+ return {
430
+ createdAddress: message.to,
431
+ execResult: {
432
+ returnValue: new Uint8Array(0),
433
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.INITCODE_SIZE_VIOLATION),
434
+ executionGasUsed: message.gasLimit,
435
+ },
436
+ };
437
+ }
438
+ }
439
+ // TODO at some point, figure out why we swapped out data to code in the first place
440
+ message.code = message.data;
441
+ message.data = message.eofCallData ?? new Uint8Array();
442
+ message.to = await this._generateAddress(message);
443
+ if (this.common.isActivatedEIP(6780)) {
444
+ message.createdAddresses.add(message.to.toString());
445
+ }
446
+ if (this.DEBUG) {
447
+ debug(`Generated CREATE contract address ${message.to}`);
448
+ }
449
+ let toAccount = await this.stateManager.getAccount(message.to);
450
+ if (!toAccount) {
451
+ toAccount = new util_1.Account();
452
+ }
453
+ if (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) {
454
+ const contractCreateAccessGas = message.accessWitness.writeAccountBasicData(message.to) +
455
+ message.accessWitness.readAccountCodeHash(message.to);
456
+ gasLimit -= contractCreateAccessGas;
457
+ if (gasLimit < util_1.BIGINT_0) {
458
+ if (this.DEBUG) {
459
+ debugGas(`ContractCreateInit charge(${contractCreateAccessGas}) caused OOG (-> ${gasLimit})`);
460
+ message.accessWitness?.revert();
461
+ }
462
+ return { execResult: OOGResult(message.gasLimit) };
463
+ }
464
+ else {
465
+ if (this.DEBUG) {
466
+ debugGas(`ContractCreateInit charged (${contractCreateAccessGas} gas (-> ${gasLimit}))`);
467
+ }
468
+ message.accessWitness?.commit();
469
+ }
470
+ }
471
+ // Check for collision
472
+ if ((toAccount.nonce && toAccount.nonce > util_1.BIGINT_0) ||
473
+ !((0, util_1.equalsBytes)(toAccount.codeHash, util_1.KECCAK256_NULL) === true) ||
474
+ // See EIP 7610 and the discussion `https://ethereum-magicians.org/t/eip-7610-revert-creation-in-case-of-non-empty-storage`
475
+ !((0, util_1.equalsBytes)(toAccount.storageRoot, util_1.KECCAK256_RLP) === true)) {
476
+ if (this.DEBUG) {
477
+ debug(`Returning on address collision`);
478
+ }
479
+ if (this.common.isActivatedEIP(7928)) {
480
+ this.blockLevelAccessList.addAddress(message.to.toString());
481
+ }
482
+ return {
483
+ createdAddress: message.to,
484
+ execResult: {
485
+ returnValue: new Uint8Array(0),
486
+ exceptionError: new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.CREATE_COLLISION),
487
+ executionGasUsed: message.gasLimit,
488
+ },
489
+ };
490
+ }
491
+ await this.journal.putAccount(message.to, toAccount);
492
+ await this.stateManager.clearStorage(message.to);
493
+ const newContractEvent = {
494
+ address: message.to,
495
+ code: message.code,
496
+ };
497
+ await this._emit('newContract', newContractEvent);
498
+ toAccount = await this.stateManager.getAccount(message.to);
499
+ if (!toAccount) {
500
+ toAccount = new util_1.Account();
501
+ }
502
+ // EIP-161 on account creation and CREATE execution
503
+ if (this.common.gteHardfork(common_1.Hardfork.SpuriousDragon)) {
504
+ toAccount.nonce += util_1.BIGINT_1;
505
+ }
506
+ if (this.common.isActivatedEIP(7928)) {
507
+ this.blockLevelAccessList.addNonceChange(message.to.toString(), toAccount.nonce, this.blockLevelAccessList.blockAccessIndex);
508
+ }
509
+ // Add tx value to the `to` account
510
+ let errorMessage;
511
+ try {
512
+ await this._addToBalance(toAccount, message);
513
+ }
514
+ catch (e) {
515
+ errorMessage = e;
516
+ }
517
+ let exit = false;
518
+ if (message.code === undefined ||
519
+ (typeof message.code !== 'function' && message.code.length === 0)) {
520
+ exit = true;
521
+ if (this.DEBUG) {
522
+ debug(`Exit early on no code (CREATE)`);
523
+ }
524
+ }
525
+ if (errorMessage !== undefined) {
526
+ exit = true;
527
+ if (this.DEBUG) {
528
+ debug(`Exit early on value transfer overflowed (CREATE)`);
529
+ }
530
+ }
531
+ // EIP-7708: Create ETH transfer log for contract creation with value
532
+ let eip7708CreateLog;
533
+ if (this.common.isActivatedEIP(7708) &&
534
+ message.value > util_1.BIGINT_0 &&
535
+ message.to !== undefined &&
536
+ !(0, util_1.equalsBytes)(message.caller.bytes, message.to.bytes) &&
537
+ errorMessage === undefined) {
538
+ eip7708CreateLog = (0, eip7708_ts_1.createEIP7708TransferLog)(message.caller, message.to, message.value);
539
+ if (this.DEBUG) {
540
+ debug(`EIP-7708: Created ETH transfer log for CREATE from ${message.caller} to ${message.to} value=${message.value}`);
541
+ }
542
+ }
543
+ if (exit) {
544
+ if (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) {
545
+ const createCompleteAccessGas = message.accessWitness.writeAccountHeader(message.to);
546
+ gasLimit -= createCompleteAccessGas;
547
+ if (gasLimit < util_1.BIGINT_0) {
548
+ if (this.DEBUG) {
549
+ debug(`ContractCreateComplete access gas (${createCompleteAccessGas}) caused OOG (-> ${gasLimit})`);
550
+ }
551
+ message.accessWitness?.revert();
552
+ return { execResult: OOGResult(message.gasLimit) };
553
+ }
554
+ else {
555
+ if (this.DEBUG) {
556
+ debug(`ContractCreateComplete access used (${createCompleteAccessGas}) gas (-> ${gasLimit})`);
557
+ }
558
+ message.accessWitness?.commit();
559
+ }
560
+ }
561
+ return {
562
+ createdAddress: message.to,
563
+ execResult: {
564
+ executionGasUsed: message.gasLimit - gasLimit,
565
+ gasRefund: message.gasRefund,
566
+ exceptionError: errorMessage, // only defined if addToBalance failed
567
+ returnValue: new Uint8Array(0),
568
+ logs: eip7708CreateLog ? [eip7708CreateLog] : undefined,
569
+ },
570
+ };
571
+ }
572
+ if (this.DEBUG) {
573
+ debug(`Start bytecode processing...`);
574
+ }
575
+ // run the message with the updated gas limit and add accessed gas used to the result
576
+ let result = await this.runInterpreter({ ...message, gasLimit, isCreate: true }, {
577
+ initialLogs: eip7708CreateLog ? [eip7708CreateLog] : undefined,
578
+ });
579
+ result.executionGasUsed += message.gasLimit - gasLimit;
580
+ // fee for size of the return value
581
+ let totalGas = result.executionGasUsed;
582
+ let returnFee = util_1.BIGINT_0;
583
+ if (!result.exceptionError && !this.common.isActivatedEIP(6800)) {
584
+ returnFee = BigInt(result.returnValue.length) * BigInt(this.common.param('createDataGas'));
585
+ totalGas = totalGas + returnFee;
586
+ if (this.DEBUG) {
587
+ debugGas(`Add return value size fee (${returnFee} to gas used (-> ${totalGas}))`);
588
+ }
589
+ }
590
+ // Check for SpuriousDragon EIP-170 code size limit
591
+ let allowedCodeSize = true;
592
+ if (!result.exceptionError &&
593
+ this.common.gteHardfork(common_1.Hardfork.SpuriousDragon) &&
594
+ result.returnValue.length > Number(this.common.param('maxCodeSize'))) {
595
+ allowedCodeSize = false;
596
+ }
597
+ // If enough gas and allowed code size
598
+ let CodestoreOOG = false;
599
+ if (totalGas <= message.gasLimit && (this.allowUnlimitedContractSize || allowedCodeSize)) {
600
+ if (this.common.isActivatedEIP(3541) && result.returnValue[0] === constants_ts_1.FORMAT) {
601
+ if (!this.common.isActivatedEIP(3540)) {
602
+ result = { ...result, ...INVALID_BYTECODE_RESULT(message.gasLimit) };
603
+ }
604
+ else if (
605
+ // TODO check if this is correct
606
+ // Also likely cleanup this eofCallData stuff
607
+ /*(message.depth > 0 && message.eofCallData === undefined) ||
608
+ (message.depth === 0 && !isEOF(message.code))*/
609
+ !(0, util_ts_1.isEOF)(message.code)) {
610
+ // TODO the message.eof was flagged for this to work for this first
611
+ // Running into Legacy mode: unable to deploy EOF contract
612
+ result = { ...result, ...INVALID_BYTECODE_RESULT(message.gasLimit) };
613
+ }
614
+ else {
615
+ // 3541 is active and current runtime mode is EOF
616
+ result.executionGasUsed = totalGas;
617
+ }
618
+ }
619
+ else {
620
+ result.executionGasUsed = totalGas;
621
+ }
622
+ }
623
+ else {
624
+ if (this.common.gteHardfork(common_1.Hardfork.Homestead)) {
625
+ if (!allowedCodeSize) {
626
+ if (this.DEBUG) {
627
+ debug(`Code size exceeds maximum code size (>= SpuriousDragon)`);
628
+ }
629
+ result = { ...result, ...CodesizeExceedsMaximumError(message.gasLimit) };
630
+ }
631
+ else {
632
+ if (this.DEBUG) {
633
+ debug(`Contract creation: out of gas`);
634
+ }
635
+ message.accessWitness?.revert();
636
+ result = { ...result, ...OOGResult(message.gasLimit) };
637
+ }
638
+ }
639
+ else {
640
+ // we are in Frontier
641
+ if (totalGas - returnFee <= message.gasLimit) {
642
+ // we cannot pay the code deposit fee (but the deposit code actually did run)
643
+ if (this.DEBUG) {
644
+ debug(`Not enough gas to pay the code deposit fee (Frontier)`);
645
+ }
646
+ message.accessWitness?.revert();
647
+ result = { ...result, ...COOGResult(totalGas - returnFee) };
648
+ CodestoreOOG = true;
649
+ }
650
+ else {
651
+ if (this.DEBUG) {
652
+ debug(`Contract creation: out of gas`);
653
+ }
654
+ message.accessWitness?.revert();
655
+ result = { ...result, ...OOGResult(message.gasLimit) };
656
+ }
657
+ }
658
+ }
659
+ // get the fresh gas limit for the rest of the ops
660
+ gasLimit = message.gasLimit - result.executionGasUsed;
661
+ if (!result.exceptionError &&
662
+ (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864))) {
663
+ const createCompleteAccessGas = message.accessWitness.writeAccountHeader(message.to);
664
+ gasLimit -= createCompleteAccessGas;
665
+ if (gasLimit < util_1.BIGINT_0) {
666
+ if (this.DEBUG) {
667
+ debug(`ContractCreateComplete access gas (${createCompleteAccessGas}) caused OOG (-> ${gasLimit})`);
668
+ }
669
+ message.accessWitness?.revert();
670
+ result = { ...result, ...OOGResult(message.gasLimit) };
671
+ }
672
+ else {
673
+ debug(`ContractCreateComplete access used (${createCompleteAccessGas}) gas (-> ${gasLimit})`);
674
+ result.executionGasUsed += createCompleteAccessGas;
675
+ }
676
+ }
677
+ // Save code if a new contract was created
678
+ if (!result.exceptionError &&
679
+ result.returnValue !== undefined &&
680
+ result.returnValue.length !== 0) {
681
+ // Add access charges for writing this code to the state
682
+ if (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) {
683
+ const byteCodeWriteAccessfee = message.accessWitness.writeAccountCodeChunks(message.to, 0, result.returnValue.length - 1);
684
+ gasLimit -= byteCodeWriteAccessfee;
685
+ if (gasLimit < util_1.BIGINT_0) {
686
+ if (this.DEBUG) {
687
+ debug(`byteCodeWrite access gas (${byteCodeWriteAccessfee}) caused OOG (-> ${gasLimit})`);
688
+ }
689
+ message.accessWitness?.revert();
690
+ result = { ...result, ...OOGResult(message.gasLimit) };
691
+ }
692
+ else {
693
+ debug(`byteCodeWrite access used (${byteCodeWriteAccessfee}) gas (-> ${gasLimit})`);
694
+ message.accessWitness?.commit();
695
+ result.executionGasUsed += byteCodeWriteAccessfee;
696
+ }
697
+ }
698
+ await this.stateManager.putCode(message.to, result.returnValue);
699
+ if (this.common.isActivatedEIP(7928)) {
700
+ this.blockLevelAccessList.addCodeChange(message.to.toString(), result.returnValue, this.blockLevelAccessList.blockAccessIndex);
701
+ }
702
+ if (this.DEBUG) {
703
+ debug(`Code saved on new contract creation`);
704
+ }
705
+ }
706
+ else if (CodestoreOOG) {
707
+ // This only happens at Frontier. But, let's do a sanity check;
708
+ if (!this.common.gteHardfork(common_1.Hardfork.Homestead)) {
709
+ // Pre-Homestead behavior; put an empty contract.
710
+ // This contract would be considered "DEAD" in later hard forks.
711
+ // It is thus an unnecessary default item, which we have to save to disk
712
+ // It does change the state root, but it only wastes storage.
713
+ const account = await this.stateManager.getAccount(message.to);
714
+ await this.journal.putAccount(message.to, account ?? new util_1.Account());
715
+ }
716
+ }
717
+ if (message.depth === 0) {
718
+ this.postMessageCleanup();
719
+ }
720
+ return {
721
+ createdAddress: message.to,
722
+ execResult: result,
723
+ };
724
+ }
725
+ /**
726
+ * Starts the actual bytecode processing for a CALL or CREATE
727
+ */
728
+ async runInterpreter(message, opts = {}) {
729
+ let contract = await this.stateManager.getAccount(message.to ?? (0, util_1.createZeroAddress)());
730
+ if (!contract) {
731
+ contract = new util_1.Account();
732
+ }
733
+ const env = {
734
+ address: message.to ?? (0, util_1.createZeroAddress)(),
735
+ caller: message.caller ?? (0, util_1.createZeroAddress)(),
736
+ callData: message.data ?? Uint8Array.from([0]),
737
+ callValue: message.value ?? util_1.BIGINT_0,
738
+ code: message.code,
739
+ isStatic: message.isStatic ?? false,
740
+ isCreate: message.isCreate ?? false,
741
+ depth: message.depth ?? 0,
742
+ gasPrice: this._tx.gasPrice,
743
+ origin: this._tx.origin ?? message.caller ?? (0, util_1.createZeroAddress)(),
744
+ block: this._block ?? defaultBlock(),
745
+ contract,
746
+ codeAddress: message.codeAddress,
747
+ gasRefund: message.gasRefund,
748
+ chargeCodeAccesses: message.chargeCodeAccesses,
749
+ blobVersionedHashes: message.blobVersionedHashes ?? [],
750
+ accessWitness: message.accessWitness,
751
+ createdAddresses: message.createdAddresses,
752
+ initialLogs: opts.initialLogs,
753
+ };
754
+ const interpreter = new interpreter_ts_1.Interpreter(this, this.stateManager, this.blockchain, env, message.gasLimit, this.journal, this.performanceLogger, this._optsCached.profiler);
755
+ if (message.selfdestruct) {
756
+ interpreter._result.selfdestruct = message.selfdestruct;
757
+ }
758
+ if (message.createdAddresses) {
759
+ interpreter._result.createdAddresses = message.createdAddresses;
760
+ }
761
+ const interpreterRes = await interpreter.run(message.code, opts);
762
+ let result = interpreter._result;
763
+ let gasUsed = message.gasLimit - interpreterRes.runState.gasLeft;
764
+ if (interpreterRes.exceptionError) {
765
+ if (interpreterRes.exceptionError.error !== errors_ts_1.EVMError.errorMessages.REVERT &&
766
+ interpreterRes.exceptionError.error !== errors_ts_1.EVMError.errorMessages.INVALID_EOF_FORMAT) {
767
+ gasUsed = message.gasLimit;
768
+ }
769
+ // Clear the result on error
770
+ result = {
771
+ ...result,
772
+ logs: [],
773
+ selfdestruct: new Map(),
774
+ createdAddresses: new Set(),
775
+ };
776
+ }
777
+ message.accessWitness?.commit();
778
+ return {
779
+ ...result,
780
+ runState: {
781
+ ...interpreterRes.runState,
782
+ ...result,
783
+ ...interpreter._env,
784
+ },
785
+ exceptionError: interpreterRes.exceptionError,
786
+ gas: interpreterRes.runState?.gasLeft,
787
+ executionGasUsed: gasUsed,
788
+ gasRefund: interpreterRes.runState.gasRefund,
789
+ returnValue: result.returnValue ?? new Uint8Array(0),
790
+ };
791
+ }
792
+ /**
793
+ * Executes an EVM message, determining whether it's a call or create
794
+ * based on the `to` address. It checkpoints the state and reverts changes
795
+ * if an exception happens during the message execution.
796
+ */
797
+ async runCall(opts) {
798
+ let timer;
799
+ if ((opts.depth === 0 || opts.message === undefined) &&
800
+ this._optsCached.profiler?.enabled === true) {
801
+ timer = this.performanceLogger.startTimer('Initialization');
802
+ }
803
+ let message = opts.message;
804
+ let callerAccount;
805
+ if (!message) {
806
+ this._block = opts.block ?? defaultBlock();
807
+ const caller = opts.caller ?? (0, util_1.createZeroAddress)();
808
+ this._tx = {
809
+ gasPrice: opts.gasPrice ?? util_1.BIGINT_0,
810
+ origin: opts.origin ?? caller,
811
+ };
812
+ const value = opts.value ?? util_1.BIGINT_0;
813
+ if (opts.skipBalance === true) {
814
+ callerAccount = await this.stateManager.getAccount(caller);
815
+ if (!callerAccount) {
816
+ callerAccount = new util_1.Account();
817
+ }
818
+ const originalBalance = callerAccount.balance;
819
+ if (callerAccount.balance < value) {
820
+ // if skipBalance and balance less than value, set caller balance to `value` to ensure sufficient funds
821
+ callerAccount.balance = value;
822
+ await this.journal.putAccount(caller, callerAccount);
823
+ if (this.common.isActivatedEIP(7928)) {
824
+ this.blockLevelAccessList.addBalanceChange(caller.toString(), callerAccount.balance, this.blockLevelAccessList.blockAccessIndex, originalBalance);
825
+ }
826
+ }
827
+ }
828
+ message = new message_ts_1.Message({
829
+ caller,
830
+ gasLimit: opts.gasLimit ?? BigInt(0xffffff),
831
+ to: opts.to,
832
+ value,
833
+ data: opts.data,
834
+ code: opts.code,
835
+ depth: opts.depth,
836
+ isCompiled: opts.isCompiled,
837
+ isStatic: opts.isStatic,
838
+ salt: opts.salt,
839
+ selfdestruct: opts.selfdestruct ?? new Map(),
840
+ createdAddresses: opts.createdAddresses ?? new Set(),
841
+ delegatecall: opts.delegatecall,
842
+ blobVersionedHashes: opts.blobVersionedHashes,
843
+ });
844
+ }
845
+ if (message.depth === 0) {
846
+ if (!callerAccount) {
847
+ callerAccount = await this.stateManager.getAccount(message.caller);
848
+ }
849
+ if (!callerAccount) {
850
+ callerAccount = new util_1.Account();
851
+ }
852
+ callerAccount.nonce++;
853
+ await this.journal.putAccount(message.caller, callerAccount);
854
+ if (this.common.isActivatedEIP(7928)) {
855
+ this.blockLevelAccessList.addNonceChange(message.caller.toString(), callerAccount.nonce, this.blockLevelAccessList.blockAccessIndex);
856
+ }
857
+ if (this.DEBUG) {
858
+ debug(`Update fromAccount (caller) nonce (-> ${callerAccount.nonce}))`);
859
+ }
860
+ }
861
+ await this._emit('beforeMessage', message);
862
+ if (!message.to && this.common.isActivatedEIP(2929)) {
863
+ message.code = message.data;
864
+ this.journal.addWarmedAddress((await this._generateAddress(message)).bytes);
865
+ }
866
+ if (this.common.isActivatedEIP(7928)) {
867
+ this.blockLevelAccessList?.checkpoint();
868
+ }
869
+ await this.journal.checkpoint();
870
+ if (this.common.isActivatedEIP(1153))
871
+ this.transientStorage.checkpoint();
872
+ if (this.DEBUG) {
873
+ debug('-'.repeat(100));
874
+ debug(`message checkpoint`);
875
+ }
876
+ let result;
877
+ if (this.DEBUG) {
878
+ const { caller, gasLimit, to, value, delegatecall } = message;
879
+ debug(`New message caller=${caller} gasLimit=${gasLimit} to=${to?.toString() ?? 'none'} value=${value} delegatecall=${delegatecall ? 'yes' : 'no'}`);
880
+ }
881
+ if (message.to) {
882
+ if (this.DEBUG) {
883
+ debug(`Message CALL execution (to: ${message.to})`);
884
+ }
885
+ result = await this._executeCall(message);
886
+ }
887
+ else {
888
+ if (this.DEBUG) {
889
+ debug(`Message CREATE execution (to: undefined)`);
890
+ }
891
+ result = await this._executeCreate(message);
892
+ }
893
+ if (this.DEBUG) {
894
+ const { executionGasUsed, exceptionError, returnValue } = result.execResult;
895
+ debug(`Received message execResult: [ gasUsed=${executionGasUsed} exceptionError=${exceptionError ? `'${exceptionError.error}'` : 'none'} returnValue=${(0, util_1.short)(returnValue)} gasRefund=${result.execResult.gasRefund ?? 0} ]`);
896
+ }
897
+ const err = result.execResult.exceptionError;
898
+ // This clause captures any error which happened during execution
899
+ // If that is the case, then all refunds are forfeited
900
+ // There is one exception: if the CODESTORE_OUT_OF_GAS error is thrown
901
+ // (this only happens the Frontier/Chainstart fork)
902
+ // then the error is dismissed
903
+ if (err && err.error !== errors_ts_1.EVMError.errorMessages.CODESTORE_OUT_OF_GAS) {
904
+ result.execResult.selfdestruct = new Map();
905
+ result.execResult.createdAddresses = new Set();
906
+ result.execResult.gasRefund = util_1.BIGINT_0;
907
+ }
908
+ if (err &&
909
+ !(this.common.hardfork() === common_1.Hardfork.Chainstart &&
910
+ err.error === errors_ts_1.EVMError.errorMessages.CODESTORE_OUT_OF_GAS)) {
911
+ result.execResult.logs = [];
912
+ await this.journal.revert();
913
+ if (this.common.isActivatedEIP(1153))
914
+ this.transientStorage.revert();
915
+ if (this.common.isActivatedEIP(7928)) {
916
+ this.blockLevelAccessList?.revert();
917
+ }
918
+ if (this.DEBUG) {
919
+ debug(`message checkpoint reverted`);
920
+ }
921
+ }
922
+ else {
923
+ await this.journal.commit();
924
+ if (this.common.isActivatedEIP(1153))
925
+ this.transientStorage.commit();
926
+ if (this.common.isActivatedEIP(7928)) {
927
+ this.blockLevelAccessList?.commit();
928
+ }
929
+ if (this.DEBUG) {
930
+ debug(`message checkpoint committed`);
931
+ }
932
+ }
933
+ await this._emit('afterMessage', result);
934
+ if (message.depth === 0 && this._optsCached.profiler?.enabled === true) {
935
+ this.performanceLogger.stopTimer(timer, 0);
936
+ }
937
+ message.accessWitness?.commit();
938
+ return result;
939
+ }
940
+ /**
941
+ * Bound to the global VM and therefore
942
+ * shouldn't be used directly from the evm class
943
+ */
944
+ async runCode(opts) {
945
+ this._block = opts.block ?? defaultBlock();
946
+ this._tx = {
947
+ gasPrice: opts.gasPrice ?? util_1.BIGINT_0,
948
+ origin: opts.origin ?? opts.caller ?? (0, util_1.createZeroAddress)(),
949
+ };
950
+ const message = new message_ts_1.Message({
951
+ code: opts.code,
952
+ data: opts.data,
953
+ gasLimit: opts.gasLimit ?? BigInt(0xffffff),
954
+ to: opts.to ?? (0, util_1.createZeroAddress)(),
955
+ caller: opts.caller,
956
+ value: opts.value,
957
+ depth: opts.depth,
958
+ selfdestruct: opts.selfdestruct ?? new Map(),
959
+ isStatic: opts.isStatic,
960
+ blobVersionedHashes: opts.blobVersionedHashes,
961
+ });
962
+ return this.runInterpreter(message, { pc: opts.pc });
963
+ }
964
+ /**
965
+ * Returns the precompile function registered at the given address,
966
+ * or `undefined` if no precompile is active there.
967
+ *
968
+ * Accepts either an `Address` instance or a `0x`-prefixed hex string.
969
+ *
970
+ * ```ts
971
+ * const evm = await createEVM({
972
+ * customPrecompiles: [{ address: '0x000000000000000000000000000000000000ff01', function: myFn }],
973
+ * })
974
+ * const fn = evm.getPrecompile('0x000000000000000000000000000000000000ff01')
975
+ * ```
976
+ */
977
+ getPrecompile(address) {
978
+ if (typeof address === 'string') {
979
+ return this.precompiles.get(address.slice(2).padStart(40, '0').toLowerCase());
980
+ }
981
+ return this.precompiles.get((0, util_1.bytesToUnprefixedHex)(address.bytes));
982
+ }
983
+ /**
984
+ * Executes a precompiled contract with given data and gas limit.
985
+ */
986
+ runPrecompile(code, data, gasLimit) {
987
+ if (typeof code !== 'function') {
988
+ throw (0, util_1.EthereumJSErrorWithoutCode)('Invalid precompile');
989
+ }
990
+ const opts = {
991
+ data,
992
+ gasLimit,
993
+ common: this.common,
994
+ _EVM: this,
995
+ _debug: this.DEBUG ? debugPrecompiles : undefined,
996
+ stateManager: this.stateManager,
997
+ };
998
+ return code(opts);
999
+ }
1000
+ async _loadCode(message) {
1001
+ if (!message.code) {
1002
+ const precompile = this.getPrecompile(message.codeAddress);
1003
+ if (precompile) {
1004
+ message.code = precompile;
1005
+ message.isCompiled = true;
1006
+ }
1007
+ else {
1008
+ message.code = await this.stateManager.getCode(message.codeAddress);
1009
+ // EIP-7702 delegation check
1010
+ if (this.common.isActivatedEIP(7702) &&
1011
+ (0, util_1.equalsBytes)(message.code.slice(0, 3), types_ts_1.DELEGATION_7702_FLAG)) {
1012
+ const address = new util_1.Address(message.code.slice(3, 24));
1013
+ message.code = await this.stateManager.getCode(address);
1014
+ // EIP-7928: Track delegation target access in BAL
1015
+ if (this.common.isActivatedEIP(7928)) {
1016
+ this.blockLevelAccessList?.addAddress(address.toString());
1017
+ }
1018
+ if (message.depth === 0) {
1019
+ this.journal.addAlwaysWarmAddress(address.toString());
1020
+ }
1021
+ }
1022
+ message.isCompiled = false;
1023
+ message.chargeCodeAccesses = true;
1024
+ }
1025
+ }
1026
+ }
1027
+ async _generateAddress(message) {
1028
+ let addr;
1029
+ if (message.salt) {
1030
+ addr = (0, util_1.generateAddress2)(message.caller.bytes, message.salt, message.code);
1031
+ }
1032
+ else {
1033
+ let acc = await this.stateManager.getAccount(message.caller);
1034
+ if (!acc) {
1035
+ acc = new util_1.Account();
1036
+ }
1037
+ const newNonce = acc.nonce - util_1.BIGINT_1;
1038
+ addr = (0, util_1.generateAddress)(message.caller.bytes, (0, util_1.bigIntToBytes)(newNonce));
1039
+ }
1040
+ return new util_1.Address(addr);
1041
+ }
1042
+ async _reduceSenderBalance(account, message) {
1043
+ const originalBalance = account.balance;
1044
+ account.balance -= message.value;
1045
+ if (account.balance < util_1.BIGINT_0) {
1046
+ throw new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.INSUFFICIENT_BALANCE);
1047
+ }
1048
+ // EIP-7928: Record the sender's reduced balance in BAL
1049
+ // Per spec, CALL/CALLCODE senders must have their balance recorded
1050
+ if (this.common.isActivatedEIP(7928)) {
1051
+ this.blockLevelAccessList.addBalanceChange(message.caller.toString(), account.balance, this.blockLevelAccessList.blockAccessIndex, originalBalance);
1052
+ }
1053
+ const result = this.journal.putAccount(message.caller, account);
1054
+ if (this.DEBUG) {
1055
+ debug(`Reduced sender (${message.caller}) balance (-> ${account.balance})`);
1056
+ }
1057
+ return result;
1058
+ }
1059
+ async _addToBalance(toAccount, message) {
1060
+ const originalBalance = toAccount.balance;
1061
+ const newBalance = toAccount.balance + message.value;
1062
+ if (newBalance > util_1.MAX_INTEGER) {
1063
+ throw new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.VALUE_OVERFLOW);
1064
+ }
1065
+ toAccount.balance = newBalance;
1066
+ if (this.common.isActivatedEIP(7928)) {
1067
+ this.blockLevelAccessList.addAddress(message.to.toString());
1068
+ if (message.value !== util_1.BIGINT_0) {
1069
+ this.blockLevelAccessList.addBalanceChange(message.to.toString(), newBalance, this.blockLevelAccessList.blockAccessIndex, originalBalance);
1070
+ }
1071
+ }
1072
+ // putAccount as the nonce may have changed for contract creation
1073
+ await this.journal.putAccount(message.to, toAccount);
1074
+ if (this.DEBUG) {
1075
+ debug(`Added toAccount (${message.to}) balance (-> ${toAccount.balance})`);
1076
+ }
1077
+ }
1078
+ /**
1079
+ * Once the interpreter has finished depth 0, a post-message cleanup should be done
1080
+ */
1081
+ postMessageCleanup() {
1082
+ if (this.common.isActivatedEIP(1153))
1083
+ this.transientStorage.clear();
1084
+ }
1085
+ /**
1086
+ * This method copies the EVM, current HF and EIP settings
1087
+ * and returns a new EVM instance.
1088
+ *
1089
+ * Note: this is only a shallow copy and both EVM instances
1090
+ * will point to the same underlying state DB.
1091
+ *
1092
+ * @returns EVM
1093
+ */
1094
+ shallowCopy() {
1095
+ const common = this.common.copy();
1096
+ common.setHardfork(this.common.hardfork());
1097
+ const opts = {
1098
+ ...this._optsCached,
1099
+ common,
1100
+ stateManager: this.stateManager.shallowCopy(),
1101
+ };
1102
+ // @ts-expect-error -- Assigning a StateManager property that is absent from the interface
1103
+ opts.stateManager['common'] = common;
1104
+ return new EVM(opts);
1105
+ }
1106
+ getPerformanceLogs() {
1107
+ return this.performanceLogger.getLogs();
1108
+ }
1109
+ clearPerformanceLogs() {
1110
+ this.performanceLogger.clear();
1111
+ }
1112
+ }
1113
+ exports.EVM = EVM;
1114
+ EVM.supportedHardforks = [
1115
+ common_1.Hardfork.Chainstart,
1116
+ common_1.Hardfork.Homestead,
1117
+ common_1.Hardfork.Dao,
1118
+ common_1.Hardfork.TangerineWhistle,
1119
+ common_1.Hardfork.SpuriousDragon,
1120
+ common_1.Hardfork.Byzantium,
1121
+ common_1.Hardfork.Constantinople,
1122
+ common_1.Hardfork.Petersburg,
1123
+ common_1.Hardfork.Istanbul,
1124
+ common_1.Hardfork.MuirGlacier,
1125
+ common_1.Hardfork.Berlin,
1126
+ common_1.Hardfork.London,
1127
+ common_1.Hardfork.ArrowGlacier,
1128
+ common_1.Hardfork.GrayGlacier,
1129
+ common_1.Hardfork.MergeNetsplitBlock,
1130
+ common_1.Hardfork.Paris,
1131
+ common_1.Hardfork.Shanghai,
1132
+ common_1.Hardfork.Cancun,
1133
+ common_1.Hardfork.Prague,
1134
+ common_1.Hardfork.Osaka,
1135
+ common_1.Hardfork.Bpo1,
1136
+ common_1.Hardfork.Bpo2,
1137
+ common_1.Hardfork.Bpo3,
1138
+ common_1.Hardfork.Bpo4,
1139
+ common_1.Hardfork.Bpo5,
1140
+ common_1.Hardfork.Amsterdam,
1141
+ ];
1142
+ //# sourceMappingURL=evm.js.map