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