@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,1437 @@
1
+ import { ConsensusAlgorithm } from '@feelyourprotocol/common'
2
+ import {
3
+ Account,
4
+ BIGINT_0,
5
+ BIGINT_1,
6
+ BIGINT_2,
7
+ EthereumJSErrorWithoutCode,
8
+ MAX_UINT64,
9
+ bigIntToBytes,
10
+ bigIntToHex,
11
+ bytesToBigInt,
12
+ bytesToHex,
13
+ equalsBytes,
14
+ setLengthLeft,
15
+ setLengthRight,
16
+ } from '@feelyourprotocol/util'
17
+ import debugDefault from 'debug'
18
+
19
+ import {
20
+ EIP7708_SELFDESTRUCT_TOPIC,
21
+ EIP7708_SYSTEM_ADDRESS,
22
+ EIP7708_TRANSFER_TOPIC,
23
+ } from './eip7708.ts'
24
+ import { FORMAT, MAGIC, VERSION } from './eof/constants.ts'
25
+ import { EOFContainerMode, validateEOF } from './eof/container.ts'
26
+ import { setupEOF } from './eof/setup.ts'
27
+ import { ContainerSectionType } from './eof/verify.ts'
28
+ import { EVMError, EVMErrorTypeString } from './errors.ts'
29
+ import { type EVMPerformanceLogger, type Timer } from './logger.ts'
30
+ import { Memory } from './memory.ts'
31
+ import { Message } from './message.ts'
32
+ import { trap } from './opcodes/index.ts'
33
+ import { isEIP8024PairImmediateValid, isEIP8024SingleImmediateValid } from './opcodes/util.ts'
34
+ import { Stack } from './stack.ts'
35
+
36
+ import type {
37
+ BinaryTreeAccessWitnessInterface,
38
+ Common,
39
+ StateManagerInterface,
40
+ } from '@feelyourprotocol/common'
41
+ import type { Address, PrefixedHexString } from '@feelyourprotocol/util'
42
+ import { stackDelta } from './eof/stackDelta.ts'
43
+ import type { EVM } from './evm.ts'
44
+ import type { Journal } from './journal.ts'
45
+ import type { AsyncOpHandler, Opcode, OpcodeMapEntry } from './opcodes/index.ts'
46
+ import type {
47
+ Block,
48
+ EOFEnv,
49
+ EVMMockBlockchainInterface,
50
+ EVMProfilerOpts,
51
+ EVMResult,
52
+ Log,
53
+ } from './types.ts'
54
+
55
+ const debugGas = debugDefault('evm:gas')
56
+
57
+ export interface InterpreterOpts {
58
+ pc?: number
59
+ /** Logs to prepend to the result (e.g. EIP-7708 ETH transfer log from message-level value transfer) */
60
+ initialLogs?: Log[]
61
+ }
62
+
63
+ /**
64
+ * Immediate (unprocessed) result of running an EVM bytecode.
65
+ */
66
+ export interface RunResult {
67
+ logs: Log[]
68
+ returnValue?: Uint8Array
69
+ /**
70
+ * Selfdestructed accounts mapped to their beneficiary
71
+ */
72
+ selfdestruct: Map<PrefixedHexString, PrefixedHexString>
73
+
74
+ /**
75
+ * A map which tracks which addresses were created (used in EIP 6780)
76
+ */
77
+ createdAddresses?: Set<PrefixedHexString>
78
+ }
79
+
80
+ export interface Env {
81
+ address: Address
82
+ caller: Address
83
+ callData: Uint8Array
84
+ callValue: bigint
85
+ code: Uint8Array
86
+ isStatic: boolean
87
+ isCreate: boolean
88
+ depth: number
89
+ gasPrice: bigint
90
+ origin: Address
91
+ block: Block
92
+ contract: Account
93
+ codeAddress: Address /* Different than address for DELEGATECALL and CALLCODE */
94
+ gasRefund: bigint /* Current value (at begin of the frame) of the gas refund */
95
+ eof?: EOFEnv /* Optional EOF environment in case of EOF execution */
96
+ blobVersionedHashes: PrefixedHexString[] /** Versioned hashes for blob transactions */
97
+ createdAddresses?: Set<string>
98
+ accessWitness?: BinaryTreeAccessWitnessInterface
99
+ chargeCodeAccesses?: boolean
100
+ /** Logs to prepend (e.g. EIP-7708 ETH transfer log from message-level value transfer) */
101
+ initialLogs?: Log[]
102
+ }
103
+
104
+ export interface RunState {
105
+ programCounter: number
106
+ opCode: number
107
+ memory: Memory
108
+ memoryWordCount: bigint
109
+ highestMemCost: bigint
110
+ stack: Stack
111
+ code: Uint8Array
112
+ shouldDoJumpAnalysis: boolean
113
+ validJumps: Uint8Array // array of values where validJumps[index] has value 0 (default), 1 (jumpdest), 2 (beginsub)
114
+ cachedPushes: { [pc: number]: bigint }
115
+ stateManager: StateManagerInterface
116
+ blockchain: EVMMockBlockchainInterface
117
+ env: Env
118
+ messageGasLimit?: bigint // Cache value from `gas.ts` to save gas limit for a message call
119
+ interpreter: Interpreter
120
+ gasRefund: bigint // Tracks the current refund
121
+ gasLeft: bigint // Current gas left
122
+ returnBytes: Uint8Array /* Current bytes in the return Uint8Array. Cleared each time a CALL/CREATE is made in the current frame. */
123
+ }
124
+
125
+ export interface InterpreterResult {
126
+ runState: RunState
127
+ exceptionError?: EVMError
128
+ }
129
+
130
+ export interface InterpreterStep {
131
+ gasLeft: bigint
132
+ gasRefund: bigint
133
+ stateManager: StateManagerInterface
134
+ stack: bigint[]
135
+ pc: number
136
+ depth: number
137
+ opcode: {
138
+ name: string
139
+ fee: number
140
+ dynamicFee?: bigint
141
+ isAsync: boolean
142
+ code: number // The hexadecimal representation of the opcode (e.g. 0x60 for PUSH1)
143
+ }
144
+ account: Account
145
+ address: Address
146
+ memory: Uint8Array
147
+ memoryWordCount: bigint
148
+ codeAddress: Address
149
+ eofSection?: number // Current EOF section being executed
150
+ immediate?: Uint8Array // Immediate argument of the opcode
151
+ eofFunctionDepth?: number // Depth of CALLF return stack
152
+ error?: Uint8Array // Error bytes returned if revert occurs
153
+ storage?: [PrefixedHexString, PrefixedHexString][]
154
+ }
155
+
156
+ /**
157
+ * Parses and executes EVM bytecode.
158
+ */
159
+ export class Interpreter {
160
+ protected _vm: any
161
+ protected _runState: RunState
162
+ protected _stateManager: StateManagerInterface
163
+ protected common: Common
164
+ public _evm: EVM
165
+ public journal: Journal
166
+ _env: Env
167
+
168
+ // Keep track of this Interpreter run result
169
+ // TODO move into Env?
170
+ _result: RunResult
171
+
172
+ // Opcode debuggers (e.g. { 'push': [debug Object], 'sstore': [debug Object], ...})
173
+ private opDebuggers: { [key: string]: (debug: string) => void } = {}
174
+
175
+ private profilerOpts?: EVMProfilerOpts
176
+ private performanceLogger: EVMPerformanceLogger
177
+
178
+ // TODO remove gasLeft as constructor argument
179
+ constructor(
180
+ evm: EVM,
181
+ stateManager: StateManagerInterface,
182
+ blockchain: EVMMockBlockchainInterface,
183
+ env: Env,
184
+ gasLeft: bigint,
185
+ journal: Journal,
186
+ performanceLogs: EVMPerformanceLogger,
187
+ profilerOpts?: EVMProfilerOpts,
188
+ ) {
189
+ this._evm = evm
190
+ this._stateManager = stateManager
191
+ this.common = this._evm.common
192
+
193
+ if (
194
+ this.common.consensusType() === 'poa' &&
195
+ this._evm['_optsCached'].cliqueSigner === undefined
196
+ )
197
+ throw EthereumJSErrorWithoutCode(
198
+ 'Must include cliqueSigner function if clique/poa is being used for consensus type',
199
+ )
200
+
201
+ this._runState = {
202
+ programCounter: 0,
203
+ opCode: 0xfe, // INVALID opcode
204
+ memory: new Memory(),
205
+ memoryWordCount: BIGINT_0,
206
+ highestMemCost: BIGINT_0,
207
+ stack: new Stack(),
208
+ code: new Uint8Array(0),
209
+ validJumps: Uint8Array.from([]),
210
+ cachedPushes: {},
211
+ stateManager: this._stateManager,
212
+ blockchain,
213
+ env,
214
+ shouldDoJumpAnalysis: true,
215
+ interpreter: this,
216
+ gasRefund: env.gasRefund,
217
+ gasLeft,
218
+ returnBytes: new Uint8Array(0),
219
+ }
220
+ this.journal = journal
221
+ this._env = env
222
+ this._result = {
223
+ logs: env.initialLogs ? [...env.initialLogs] : [],
224
+ returnValue: undefined,
225
+ selfdestruct: new Map(),
226
+ }
227
+ this.profilerOpts = profilerOpts
228
+ this.performanceLogger = performanceLogs
229
+ }
230
+
231
+ async run(code: Uint8Array, opts: InterpreterOpts = {}): Promise<InterpreterResult> {
232
+ if (!this.common.isActivatedEIP(3540) || code[0] !== FORMAT) {
233
+ // EIP-3540 isn't active and first byte is not 0xEF - treat as legacy bytecode
234
+ this._runState.code = code
235
+ } else if (this.common.isActivatedEIP(3540)) {
236
+ if (code[1] !== MAGIC) {
237
+ // Bytecode contains invalid EOF magic byte
238
+ return {
239
+ runState: this._runState,
240
+ exceptionError: new EVMError(EVMError.errorMessages.INVALID_BYTECODE_RESULT),
241
+ }
242
+ }
243
+ if (code[2] !== VERSION) {
244
+ // Bytecode contains invalid EOF version number
245
+ return {
246
+ runState: this._runState,
247
+ exceptionError: new EVMError(EVMError.errorMessages.INVALID_EOF_FORMAT),
248
+ }
249
+ }
250
+ this._runState.code = code
251
+
252
+ const isTxCreate = this._env.isCreate && this._env.depth === 0
253
+ const eofMode = isTxCreate ? EOFContainerMode.TxInitmode : EOFContainerMode.Default
254
+
255
+ try {
256
+ setupEOF(this._runState, eofMode)
257
+ } catch {
258
+ return {
259
+ runState: this._runState,
260
+ exceptionError: new EVMError(EVMError.errorMessages.INVALID_EOF_FORMAT), // TODO: verify if all gas should be consumed
261
+ }
262
+ }
263
+
264
+ if (isTxCreate) {
265
+ // Tx tries to deploy container
266
+ try {
267
+ validateEOF(
268
+ this._runState.code,
269
+ this._evm,
270
+ ContainerSectionType.InitCode,
271
+ EOFContainerMode.TxInitmode,
272
+ )
273
+ } catch {
274
+ // Trying to deploy an invalid EOF container
275
+ return {
276
+ runState: this._runState,
277
+ exceptionError: new EVMError(EVMError.errorMessages.INVALID_EOF_FORMAT), // TODO: verify if all gas should be consumed
278
+ }
279
+ }
280
+ }
281
+ }
282
+ this._runState.programCounter = opts.pc ?? this._runState.programCounter
283
+ // Check that the programCounter is in range
284
+ const pc = this._runState.programCounter
285
+ if (pc !== 0 && (pc < 0 || pc >= this._runState.code.length)) {
286
+ throw EthereumJSErrorWithoutCode('Internal error: program counter not in range')
287
+ }
288
+
289
+ let err
290
+ let cachedOpcodes: OpcodeMapEntry[]
291
+ let doJumpAnalysis = true
292
+
293
+ let timer: Timer | undefined
294
+ let overheadTimer: Timer | undefined
295
+ if (this.profilerOpts?.enabled === true && this.performanceLogger.hasTimer()) {
296
+ timer = this.performanceLogger.pauseTimer()
297
+ overheadTimer = this.performanceLogger.startTimer('Overhead')
298
+ }
299
+
300
+ // Iterate through the given ops until something breaks or we hit STOP
301
+ while (this._runState.programCounter < this._runState.code.length) {
302
+ const programCounter = this._runState.programCounter
303
+ let opCode: number
304
+ let opCodeObj: OpcodeMapEntry | undefined
305
+ if (doJumpAnalysis) {
306
+ opCode = this._runState.code[programCounter]
307
+ // Only run the jump destination analysis if `code` actually contains a JUMP/JUMPI/JUMPSUB opcode
308
+ if (opCode === 0x56 || opCode === 0x57 || opCode === 0x5e) {
309
+ const { jumps, pushes, opcodesCached } = this._getValidJumpDestinations(
310
+ this._runState.code,
311
+ )
312
+ this._runState.validJumps = jumps
313
+ this._runState.cachedPushes = pushes
314
+ this._runState.shouldDoJumpAnalysis = false
315
+ cachedOpcodes = opcodesCached
316
+ doJumpAnalysis = false
317
+ }
318
+ } else {
319
+ opCodeObj = cachedOpcodes![programCounter]
320
+ opCode = opCodeObj.opcodeInfo.code
321
+ }
322
+
323
+ // if its an invalid opcode with binary activated, then check if its because of a missing code
324
+ // chunk in the witness, and throw appropriate error to distinguish from an actual invalid opcode
325
+ if (
326
+ opCode === 0xfe &&
327
+ this.common.isActivatedEIP(7864) &&
328
+ // is this a code loaded from state using witnesses
329
+ this._runState.env.chargeCodeAccesses === true
330
+ ) {
331
+ const contract = this._runState.interpreter.getAddress()
332
+
333
+ if (
334
+ !(await this._runState.stateManager.checkChunkWitnessPresent!(contract, programCounter))
335
+ ) {
336
+ throw Error(`Invalid witness with missing codeChunk for pc=${programCounter}`)
337
+ }
338
+ }
339
+
340
+ this._runState.opCode = opCode
341
+
342
+ try {
343
+ if (overheadTimer !== undefined) {
344
+ this.performanceLogger.pauseTimer()
345
+ }
346
+ await this.runStep(opCodeObj)
347
+ if (overheadTimer !== undefined) {
348
+ this.performanceLogger.unpauseTimer(overheadTimer)
349
+ }
350
+ } catch (e: any) {
351
+ // Revert access witness changes if we revert - per EIP-4762
352
+ this._runState.env.accessWitness?.revert()
353
+ if (overheadTimer !== undefined) {
354
+ this.performanceLogger.unpauseTimer(overheadTimer)
355
+ }
356
+ // re-throw on non-VM errors
357
+ if (!('errorType' in e && e.errorType === EVMErrorTypeString)) {
358
+ throw e
359
+ }
360
+ // STOP is not an exception
361
+ if (e.error !== EVMError.errorMessages.STOP) {
362
+ err = e
363
+ }
364
+ break
365
+ }
366
+ }
367
+
368
+ if (timer !== undefined) {
369
+ this.performanceLogger.stopTimer(overheadTimer!, 0)
370
+ this.performanceLogger.unpauseTimer(timer)
371
+ }
372
+
373
+ return {
374
+ runState: this._runState,
375
+ exceptionError: err,
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Executes the opcode to which the program counter is pointing,
381
+ * reducing its base gas cost, and increments the program counter.
382
+ */
383
+ async runStep(opcodeObj?: OpcodeMapEntry): Promise<void> {
384
+ const opEntry = opcodeObj ?? this.lookupOpInfo(this._runState.opCode)
385
+ const opInfo = opEntry.opcodeInfo
386
+
387
+ let timer: Timer
388
+
389
+ if (this.profilerOpts?.enabled === true) {
390
+ timer = this.performanceLogger.startTimer(opInfo.name)
391
+ }
392
+
393
+ let gas = opInfo.feeBigInt
394
+
395
+ // Cache pre-gas memory size if doing tracing (EIP-7756)
396
+ const memorySizeCache = this._runState.memoryWordCount
397
+
398
+ try {
399
+ if (opInfo.dynamicGas) {
400
+ // This function updates the gas in-place.
401
+ // It needs the base fee, for correct gas limit calculation for the CALL opcodes
402
+ gas = await opEntry.gasHandler(this._runState, gas, this.common)
403
+ }
404
+
405
+ if (this._evm.events.listenerCount('step') > 0 || this._evm.DEBUG) {
406
+ // Only run this stepHook function if there is an event listener (e.g. test runner)
407
+ // or if the vm is running in debug mode (to display opcode debug logs)
408
+ await this._runStepHook(gas, this.getGasLeft(), memorySizeCache)
409
+ }
410
+
411
+ if (
412
+ (this.common.isActivatedEIP(6800) || this.common.isActivatedEIP(7864)) &&
413
+ this._env.chargeCodeAccesses === true
414
+ ) {
415
+ const contract = this._runState.interpreter.getAddress()
416
+ const statelessGas = this._runState.env.accessWitness!.readAccountCodeChunks(
417
+ contract,
418
+ this._runState.programCounter,
419
+ this._runState.programCounter,
420
+ )
421
+ gas += statelessGas
422
+ debugGas(`codechunk accessed statelessGas=${statelessGas} (-> ${gas})`)
423
+ }
424
+
425
+ // Check for invalid opcode
426
+ if (opInfo.isInvalid) {
427
+ throw new EVMError(EVMError.errorMessages.INVALID_OPCODE)
428
+ }
429
+
430
+ // Reduce opcode's base fee
431
+ this.useGas(gas, opInfo)
432
+
433
+ // Advance program counter
434
+ this._runState.programCounter++
435
+
436
+ // Execute opcode handler
437
+ const opFn = opEntry.opHandler
438
+
439
+ if (opInfo.isAsync) {
440
+ await (opFn as AsyncOpHandler).apply(null, [this._runState, this.common])
441
+ } else {
442
+ opFn.apply(null, [this._runState, this.common])
443
+ }
444
+ this._runState.env.accessWitness?.commit()
445
+ } finally {
446
+ if (this.profilerOpts?.enabled === true) {
447
+ this.performanceLogger.stopTimer(
448
+ timer!,
449
+ Number(gas),
450
+ 'opcodes',
451
+ opInfo.fee,
452
+ Number(gas) - opInfo.fee,
453
+ )
454
+ }
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Get info for an opcode from EVM's list of opcodes.
460
+ */
461
+ lookupOpInfo(op: number): OpcodeMapEntry {
462
+ return this._evm['_opcodeMap'][op]
463
+ }
464
+
465
+ async _runStepHook(dynamicFee: bigint, gasLeft: bigint, memorySize: bigint): Promise<void> {
466
+ const opcodeInfo = this.lookupOpInfo(this._runState.opCode).opcodeInfo
467
+ const section = this._env.eof?.container.header.getSectionFromProgramCounter(
468
+ this._runState.programCounter,
469
+ )
470
+ let error = undefined
471
+ let immediate = undefined
472
+ if (opcodeInfo.code === 0xfd) {
473
+ // If opcode is REVERT, read error data and return in trace
474
+ const [offset, length] = this._runState.stack.peek(2)
475
+ error = new Uint8Array(0)
476
+ if (length !== BIGINT_0) {
477
+ error = this._runState.memory.read(Number(offset), Number(length))
478
+ }
479
+ }
480
+
481
+ // Add immediate if present (i.e. bytecode parameter for a preceding opcode like (RJUMP 01 - jumps to PC 1))
482
+ if (
483
+ stackDelta[opcodeInfo.code] !== undefined &&
484
+ stackDelta[opcodeInfo.code].intermediates > 0
485
+ ) {
486
+ immediate = this._runState.code.slice(
487
+ this._runState.programCounter + 1, // immediates start "immediately" following current opcode
488
+ this._runState.programCounter + 1 + stackDelta[opcodeInfo.code].intermediates,
489
+ )
490
+ }
491
+
492
+ // Create event object for step
493
+ const eventObj: InterpreterStep = {
494
+ pc: this._runState.programCounter,
495
+ gasLeft,
496
+ gasRefund: this._runState.gasRefund,
497
+ opcode: {
498
+ name: opcodeInfo.fullName,
499
+ fee: opcodeInfo.fee,
500
+ dynamicFee,
501
+ isAsync: opcodeInfo.isAsync,
502
+ code: opcodeInfo.code,
503
+ },
504
+ stack: this._runState.stack.getStack(),
505
+ depth: this._env.depth,
506
+ address: this._env.address,
507
+ account: this._env.contract,
508
+ memory: this._runState.memory._store.subarray(0, Number(memorySize) * 32),
509
+ memoryWordCount: memorySize,
510
+ codeAddress: this._env.codeAddress,
511
+ stateManager: this._runState.stateManager,
512
+ eofSection: section,
513
+ immediate,
514
+ error,
515
+ eofFunctionDepth:
516
+ this._env.eof !== undefined ? this._env.eof?.eofRunState.returnStack.length + 1 : undefined,
517
+ }
518
+
519
+ if (this._evm.DEBUG) {
520
+ // Create opTrace for debug functionality
521
+ let hexStack = []
522
+ hexStack = eventObj.stack.map((item: any) => {
523
+ return bigIntToHex(BigInt(item))
524
+ })
525
+
526
+ const name = eventObj.opcode.name
527
+
528
+ const opTrace = {
529
+ pc: eventObj.pc,
530
+ op: name,
531
+ gas: bigIntToHex(eventObj.gasLeft),
532
+ gasCost: bigIntToHex(dynamicFee),
533
+ stack: hexStack,
534
+ depth: eventObj.depth,
535
+ }
536
+
537
+ if (!(name in this.opDebuggers)) {
538
+ this.opDebuggers[name] = debugDefault(`evm:ops:${name}`)
539
+ }
540
+ this.opDebuggers[name](JSON.stringify(opTrace))
541
+ }
542
+
543
+ /**
544
+ * The `step` event for trace output
545
+ *
546
+ * @event Event: step
547
+ * @type {Object}
548
+ * @property {Number} pc representing the program counter
549
+ * @property {Object} opcode the next opcode to be ran
550
+ * @property {string} opcode.name
551
+ * @property {fee} opcode.number Base fee of the opcode
552
+ * @property {dynamicFee} opcode.dynamicFee Dynamic opcode fee
553
+ * @property {boolean} opcode.isAsync opcode is async
554
+ * @property {number} opcode.code opcode code
555
+ * @property {BigInt} gasLeft amount of gasLeft
556
+ * @property {BigInt} gasRefund gas refund
557
+ * @property {StateManager} stateManager a {@link StateManager} instance
558
+ * @property {Array} stack an `Array` of `Uint8Arrays` containing the stack
559
+ * @property {Array} returnStack the return stack
560
+ * @property {Account} account the Account which owns the code running
561
+ * @property {Address} address the address of the `account`
562
+ * @property {Number} depth the current number of calls deep the contract is
563
+ * @property {Uint8Array} memory the memory of the EVM as a `Uint8Array`
564
+ * @property {BigInt} memoryWordCount current size of memory in words
565
+ * @property {Address} codeAddress the address of the code which is currently being ran (this differs from `address` in a `DELEGATECALL` and `CALLCODE` call)
566
+ * @property {number} eofSection the current EOF code section referenced by the PC
567
+ * @property {Uint8Array} immediate the immediate argument of the opcode
568
+ * @property {Uint8Array} error the error data of the opcode (only present for REVERT)
569
+ * @property {number} eofFunctionDepth the depth of the function call (only present for EOF)
570
+ * @property {Array} storage an array of tuples, where each tuple contains a storage key and value
571
+ */
572
+ await this._evm['_emit']('step', eventObj)
573
+ }
574
+
575
+ // Returns all valid jump and jumpsub destinations.
576
+ _getValidJumpDestinations(code: Uint8Array) {
577
+ const jumps = new Uint8Array(code.length)
578
+ const pushes: { [pc: number]: bigint } = {}
579
+
580
+ const opcodesCached = Array(code.length)
581
+
582
+ for (let i = 0; i < code.length; i++) {
583
+ const opcode = code[i]
584
+ opcodesCached[i] = this.lookupOpInfo(opcode)
585
+ // skip over PUSH0-32 since no jump destinations in the middle of a push block
586
+ if (opcode <= 0x7f) {
587
+ if (opcode >= 0x60) {
588
+ const bytesToPush = opcode - 0x5f
589
+ let pushBytes = code.subarray(i + 1, i + opcode - 0x5e)
590
+ if (pushBytes.length < bytesToPush) {
591
+ pushBytes = setLengthRight(pushBytes, bytesToPush)
592
+ }
593
+ const push = bytesToBigInt(pushBytes)
594
+ pushes[i + 1] = push
595
+ i += bytesToPush
596
+ } else if (opcode === 0x5b) {
597
+ // Define a JUMPDEST as a 1 in the valid jumps array
598
+ jumps[i] = 1
599
+ }
600
+ } else if (
601
+ this.common.isActivatedEIP(8024) &&
602
+ (opcode === 0xe6 || opcode === 0xe7 || opcode === 0xe8)
603
+ ) {
604
+ const immediate = code[i + 1]
605
+ if (immediate === undefined) {
606
+ continue
607
+ }
608
+ const skipImmediate =
609
+ opcode === 0xe8
610
+ ? isEIP8024PairImmediateValid(immediate)
611
+ : isEIP8024SingleImmediateValid(immediate)
612
+ if (skipImmediate === true) {
613
+ i++
614
+ }
615
+ }
616
+ }
617
+ return { jumps, pushes, opcodesCached }
618
+ }
619
+
620
+ /**
621
+ * Subtracts an amount from the gas counter.
622
+ * @param amount - Amount of gas to consume
623
+ * @param context - Usage context for debugging
624
+ * @throws if out of gas
625
+ */
626
+ useGas(amount: bigint, context?: string | Opcode): void {
627
+ this._runState.gasLeft -= amount
628
+ if (this._evm.DEBUG) {
629
+ let tempString = ''
630
+ if (typeof context === 'string') {
631
+ tempString = context + ': '
632
+ } else if (context !== undefined) {
633
+ tempString = `${context.name} fee: `
634
+ }
635
+ debugGas(`${tempString}used ${amount} gas (-> ${this._runState.gasLeft})`)
636
+ }
637
+ if (this._runState.gasLeft < BIGINT_0) {
638
+ this._runState.gasLeft = BIGINT_0
639
+ trap(EVMError.errorMessages.OUT_OF_GAS)
640
+ }
641
+ }
642
+
643
+ /**
644
+ * Adds a positive amount to the gas counter.
645
+ * @param amount - Amount of gas refunded
646
+ * @param context - Usage context for debugging
647
+ */
648
+ refundGas(amount: bigint, context?: string): void {
649
+ if (this._evm.DEBUG) {
650
+ debugGas(
651
+ `${typeof context === 'string' ? context + ': ' : ''}refund ${amount} gas (-> ${
652
+ this._runState.gasRefund
653
+ })`,
654
+ )
655
+ }
656
+ this._runState.gasRefund += amount
657
+ }
658
+
659
+ /**
660
+ * Reduces amount of gas to be refunded by a positive value.
661
+ * @param amount - Amount to subtract from gas refunds
662
+ * @param context - Usage context for debugging
663
+ */
664
+ subRefund(amount: bigint, context?: string): void {
665
+ if (this._evm.DEBUG) {
666
+ debugGas(
667
+ `${typeof context === 'string' ? context + ': ' : ''}sub gas refund ${amount} (-> ${
668
+ this._runState.gasRefund
669
+ })`,
670
+ )
671
+ }
672
+ this._runState.gasRefund -= amount
673
+ if (this._runState.gasRefund < BIGINT_0) {
674
+ this._runState.gasRefund = BIGINT_0
675
+ trap(EVMError.errorMessages.REFUND_EXHAUSTED)
676
+ }
677
+ }
678
+
679
+ /**
680
+ * Increments the internal gasLeft counter. Used for adding callStipend.
681
+ * @param amount - Amount to add
682
+ */
683
+ addStipend(amount: bigint): void {
684
+ if (this._evm.DEBUG) {
685
+ debugGas(`add stipend ${amount} (-> ${this._runState.gasLeft})`)
686
+ }
687
+ this._runState.gasLeft += amount
688
+ }
689
+
690
+ /**
691
+ * Returns balance of the given account.
692
+ * @param address - Address of account
693
+ */
694
+ async getExternalBalance(address: Address): Promise<bigint> {
695
+ // Track address access for EIP-7928 BAL
696
+ if (this._evm.common.isActivatedEIP(7928)) {
697
+ this._evm.blockLevelAccessList?.addAddress(address.toString())
698
+ }
699
+ // shortcut if current account
700
+ if (address.equals(this._env.address)) {
701
+ return this._env.contract.balance
702
+ }
703
+
704
+ let account = await this._stateManager.getAccount(address)
705
+ if (!account) {
706
+ account = new Account()
707
+ }
708
+ return account.balance
709
+ }
710
+
711
+ /**
712
+ * Store 256-bit a value in memory to persistent storage.
713
+ */
714
+ async storageStore(key: Uint8Array, value: Uint8Array): Promise<void> {
715
+ // EIP-7928: Get the original (pre-transaction) value BEFORE storing
716
+ // This is needed to detect no-op writes (where new value equals original value)
717
+ let originalValue: Uint8Array | undefined
718
+ if (this._evm.common.isActivatedEIP(7928)) {
719
+ originalValue = await this._stateManager.originalStorageCache.get(this._env.address, key)
720
+ }
721
+
722
+ await this._stateManager.putStorage(this._env.address, key, value)
723
+
724
+ if (this._evm.common.isActivatedEIP(7928)) {
725
+ this._evm.blockLevelAccessList?.addStorageWrite(
726
+ this._env.address.toString(),
727
+ key,
728
+ value,
729
+ this._evm.blockLevelAccessList!.blockAccessIndex,
730
+ originalValue,
731
+ )
732
+ }
733
+ const account = await this._stateManager.getAccount(this._env.address)
734
+ if (!account) {
735
+ throw EthereumJSErrorWithoutCode('could not read account while persisting memory')
736
+ }
737
+ this._env.contract = account
738
+ }
739
+
740
+ /**
741
+ * Loads a 256-bit value to memory from persistent storage.
742
+ * @param key - Storage key
743
+ * @param original - If true, return the original storage value (default: false)
744
+ * @param trackBAL - If true, track in BAL storageReads (default: true). Set to false for
745
+ * implicit reads (e.g., SSTORE gas calculation) that should not appear in BAL.
746
+ */
747
+ async storageLoad(key: Uint8Array, original = false, trackBAL = true): Promise<Uint8Array> {
748
+ if (this._evm.common.isActivatedEIP(7928) && trackBAL) {
749
+ this._evm.blockLevelAccessList?.addStorageRead(this._env.address.toString(), key)
750
+ }
751
+ if (original) {
752
+ return this._stateManager.originalStorageCache.get(this._env.address, key)
753
+ } else {
754
+ return this._stateManager.getStorage(this._env.address, key)
755
+ }
756
+ }
757
+
758
+ /**
759
+ * Store 256-bit a value in memory to transient storage.
760
+ * @param address Address to use
761
+ * @param key Storage key
762
+ * @param value Storage value
763
+ */
764
+ transientStorageStore(key: Uint8Array, value: Uint8Array): void {
765
+ return this._evm.transientStorage.put(this._env.address, key, value)
766
+ }
767
+
768
+ /**
769
+ * Loads a 256-bit value to memory from transient storage.
770
+ * @param address Address to use
771
+ * @param key Storage key
772
+ */
773
+ transientStorageLoad(key: Uint8Array): Uint8Array {
774
+ return this._evm.transientStorage.get(this._env.address, key)
775
+ }
776
+
777
+ /**
778
+ * Set the returning output data for the execution.
779
+ * @param returnData - Output data to return
780
+ */
781
+ finish(returnData: Uint8Array): void {
782
+ this._result.returnValue = returnData
783
+ trap(EVMError.errorMessages.STOP)
784
+ }
785
+
786
+ /**
787
+ * Set the returning output data for the execution. This will halt the
788
+ * execution immediately and set the execution result to "reverted".
789
+ * @param returnData - Output data to return
790
+ */
791
+ revert(returnData: Uint8Array): void {
792
+ this._result.returnValue = returnData
793
+ trap(EVMError.errorMessages.REVERT)
794
+ }
795
+
796
+ /**
797
+ * Returns address of currently executing account.
798
+ */
799
+ getAddress(): Address {
800
+ return this._env.address
801
+ }
802
+
803
+ /**
804
+ * Returns balance of self.
805
+ */
806
+ getSelfBalance(): bigint {
807
+ return this._env.contract.balance
808
+ }
809
+
810
+ /**
811
+ * Returns the deposited value by the instruction/transaction
812
+ * responsible for this execution.
813
+ */
814
+ getCallValue(): bigint {
815
+ return this._env.callValue
816
+ }
817
+
818
+ /**
819
+ * Returns input data in current environment. This pertains to the input
820
+ * data passed with the message call instruction or transaction.
821
+ */
822
+ getCallData(): Uint8Array {
823
+ return this._env.callData
824
+ }
825
+
826
+ /**
827
+ * Returns size of input data in current environment. This pertains to the
828
+ * input data passed with the message call instruction or transaction.
829
+ */
830
+ getCallDataSize(): bigint {
831
+ return BigInt(this._env.callData.length)
832
+ }
833
+
834
+ /**
835
+ * Returns caller address. This is the address of the account
836
+ * that is directly responsible for this execution.
837
+ */
838
+ getCaller(): bigint {
839
+ return bytesToBigInt(this._env.caller.bytes)
840
+ }
841
+
842
+ /**
843
+ * Returns the size of code running in current environment.
844
+ */
845
+ getCodeSize(): bigint {
846
+ return BigInt(this._env.code.length)
847
+ }
848
+
849
+ /**
850
+ * Returns the code running in current environment.
851
+ */
852
+ getCode(): Uint8Array {
853
+ return this._env.code
854
+ }
855
+
856
+ /**
857
+ * Returns the current gasCounter.
858
+ */
859
+ getGasLeft(): bigint {
860
+ return this._runState.gasLeft
861
+ }
862
+
863
+ /**
864
+ * Returns size of current return data buffer. This contains the return data
865
+ * from the last executed call, callCode, callDelegate, callStatic or create.
866
+ * Note: create only fills the return data buffer in case of a failure.
867
+ */
868
+ getReturnDataSize(): bigint {
869
+ return BigInt(this._runState.returnBytes.length)
870
+ }
871
+
872
+ /**
873
+ * Returns the current return data buffer. This contains the return data
874
+ * from last executed call, callCode, callDelegate, callStatic or create.
875
+ * Note: create only fills the return data buffer in case of a failure.
876
+ */
877
+ getReturnData(): Uint8Array {
878
+ return this._runState.returnBytes
879
+ }
880
+
881
+ /**
882
+ * Returns true if the current call must be executed statically.
883
+ */
884
+ isStatic(): boolean {
885
+ return this._env.isStatic
886
+ }
887
+
888
+ /**
889
+ * Returns price of gas in current environment.
890
+ */
891
+ getTxGasPrice(): bigint {
892
+ return this._env.gasPrice
893
+ }
894
+
895
+ /**
896
+ * Returns the execution's origination address. This is the
897
+ * sender of original transaction; it is never an account with
898
+ * non-empty associated code.
899
+ */
900
+ getTxOrigin(): bigint {
901
+ return bytesToBigInt(this._env.origin.bytes)
902
+ }
903
+
904
+ /**
905
+ * Returns the block's number.
906
+ */
907
+ getBlockNumber(): bigint {
908
+ return this._env.block.header.number
909
+ }
910
+
911
+ /**
912
+ * Returns the block's beneficiary address.
913
+ */
914
+ getBlockCoinbase(): bigint {
915
+ let coinbase: Address
916
+ if (this.common.consensusAlgorithm() === ConsensusAlgorithm.Clique) {
917
+ coinbase = this._evm['_optsCached'].cliqueSigner!(this._env.block.header)
918
+ } else {
919
+ coinbase = this._env.block.header.coinbase
920
+ }
921
+ return bytesToBigInt(coinbase.toBytes())
922
+ }
923
+
924
+ /**
925
+ * Returns the block's timestamp.
926
+ */
927
+ getBlockTimestamp(): bigint {
928
+ return this._env.block.header.timestamp
929
+ }
930
+
931
+ /**
932
+ * Returns the block's difficulty.
933
+ */
934
+ getBlockDifficulty(): bigint {
935
+ return this._env.block.header.difficulty
936
+ }
937
+
938
+ /**
939
+ * Returns the block's prevRandao field.
940
+ */
941
+ getBlockPrevRandao(): bigint {
942
+ return bytesToBigInt(this._env.block.header.prevRandao)
943
+ }
944
+
945
+ /**
946
+ * Returns the block's gas limit.
947
+ */
948
+ getBlockGasLimit(): bigint {
949
+ return this._env.block.header.gasLimit
950
+ }
951
+
952
+ /**
953
+ * Returns the block's slot number (EIP-7843).
954
+ */
955
+ getBlockSlotNumber(): bigint {
956
+ if (this._env.block.header.slotNumber === undefined) {
957
+ throw EthereumJSErrorWithoutCode('slotNumber is not available on this block')
958
+ }
959
+ return this._env.block.header.slotNumber
960
+ }
961
+
962
+ /**
963
+ * Returns the Base Fee of the block as proposed in [EIP-3198](https://eips.ethereum.org/EIPS/eip-3198)
964
+ */
965
+ getBlockBaseFee(): bigint {
966
+ const baseFee = this._env.block.header.baseFeePerGas
967
+ if (baseFee === undefined) {
968
+ // Sanity check
969
+ throw EthereumJSErrorWithoutCode('Block has no Base Fee')
970
+ }
971
+ return baseFee
972
+ }
973
+
974
+ /**
975
+ * Returns the Blob Base Fee of the block as proposed in [EIP-7516](https://eips.ethereum.org/EIPS/eip-7516)
976
+ */
977
+ getBlobBaseFee(): bigint {
978
+ const blobBaseFee = this._env.block.header.getBlobGasPrice()
979
+ if (blobBaseFee === undefined) {
980
+ // Sanity check
981
+ throw EthereumJSErrorWithoutCode('Block has no Blob Base Fee')
982
+ }
983
+ return blobBaseFee
984
+ }
985
+
986
+ /**
987
+ * Returns the chain ID for current chain. Introduced for the
988
+ * CHAINID opcode proposed in [EIP-1344](https://eips.ethereum.org/EIPS/eip-1344).
989
+ */
990
+ getChainId(): bigint {
991
+ return this.common.chainId()
992
+ }
993
+
994
+ /**
995
+ * Sends a message with arbitrary data to a given address path.
996
+ */
997
+ async call(gasLimit: bigint, address: Address, value: bigint, data: Uint8Array): Promise<bigint> {
998
+ const msg = new Message({
999
+ caller: this._env.address,
1000
+ gasLimit,
1001
+ to: address,
1002
+ value,
1003
+ data,
1004
+ isStatic: this._env.isStatic,
1005
+ depth: this._env.depth + 1,
1006
+ blobVersionedHashes: this._env.blobVersionedHashes,
1007
+ accessWitness: this._env.accessWitness,
1008
+ })
1009
+
1010
+ return this._baseCall(msg)
1011
+ }
1012
+
1013
+ /**
1014
+ * Message-call into this account with an alternative account's code.
1015
+ */
1016
+ async callCode(
1017
+ gasLimit: bigint,
1018
+ address: Address,
1019
+ value: bigint,
1020
+ data: Uint8Array,
1021
+ ): Promise<bigint> {
1022
+ const msg = new Message({
1023
+ caller: this._env.address,
1024
+ gasLimit,
1025
+ to: this._env.address,
1026
+ codeAddress: address,
1027
+ value,
1028
+ data,
1029
+ isStatic: this._env.isStatic,
1030
+ depth: this._env.depth + 1,
1031
+ blobVersionedHashes: this._env.blobVersionedHashes,
1032
+ accessWitness: this._env.accessWitness,
1033
+ })
1034
+
1035
+ return this._baseCall(msg)
1036
+ }
1037
+
1038
+ /**
1039
+ * Sends a message with arbitrary data to a given address path, but disallow
1040
+ * state modifications. This includes log, create, selfdestruct and call with
1041
+ * a non-zero value.
1042
+ */
1043
+ async callStatic(
1044
+ gasLimit: bigint,
1045
+ address: Address,
1046
+ value: bigint,
1047
+ data: Uint8Array,
1048
+ ): Promise<bigint> {
1049
+ const msg = new Message({
1050
+ caller: this._env.address,
1051
+ gasLimit,
1052
+ to: address,
1053
+ value,
1054
+ data,
1055
+ isStatic: true,
1056
+ depth: this._env.depth + 1,
1057
+ blobVersionedHashes: this._env.blobVersionedHashes,
1058
+ accessWitness: this._env.accessWitness,
1059
+ })
1060
+
1061
+ return this._baseCall(msg)
1062
+ }
1063
+
1064
+ /**
1065
+ * Message-call into this account with an alternative account's code, but
1066
+ * persisting the current values for sender and value.
1067
+ */
1068
+ async callDelegate(
1069
+ gasLimit: bigint,
1070
+ address: Address,
1071
+ value: bigint,
1072
+ data: Uint8Array,
1073
+ ): Promise<bigint> {
1074
+ const msg = new Message({
1075
+ caller: this._env.caller,
1076
+ gasLimit,
1077
+ to: this._env.address,
1078
+ codeAddress: address,
1079
+ value,
1080
+ data,
1081
+ isStatic: this._env.isStatic,
1082
+ delegatecall: true,
1083
+ depth: this._env.depth + 1,
1084
+ blobVersionedHashes: this._env.blobVersionedHashes,
1085
+ accessWitness: this._env.accessWitness,
1086
+ })
1087
+
1088
+ return this._baseCall(msg)
1089
+ }
1090
+
1091
+ async _baseCall(msg: Message): Promise<bigint> {
1092
+ const selfdestruct = new Map(this._result.selfdestruct)
1093
+ msg.selfdestruct = selfdestruct
1094
+ msg.gasRefund = this._runState.gasRefund
1095
+
1096
+ // empty the return data Uint8Array
1097
+ this._runState.returnBytes = new Uint8Array(0)
1098
+ let createdAddresses: Set<PrefixedHexString>
1099
+ if (this.common.isActivatedEIP(6780)) {
1100
+ createdAddresses = new Set(this._result.createdAddresses)
1101
+ msg.createdAddresses = createdAddresses
1102
+ }
1103
+
1104
+ // empty the return data Uint8Array
1105
+ this._runState.returnBytes = new Uint8Array(0)
1106
+
1107
+ // Check if account has enough ether and max depth not exceeded
1108
+ if (
1109
+ this._env.depth >= Number(this.common.param('stackLimit')) ||
1110
+ (msg.delegatecall !== true && this._env.contract.balance < msg.value)
1111
+ ) {
1112
+ return BIGINT_0
1113
+ }
1114
+
1115
+ const results = await this._evm.runCall({ message: msg })
1116
+
1117
+ if (results.execResult.logs) {
1118
+ this._result.logs = this._result.logs.concat(results.execResult.logs)
1119
+ }
1120
+
1121
+ // this should always be safe
1122
+ this.useGas(results.execResult.executionGasUsed, 'CALL, STATICCALL, DELEGATECALL, CALLCODE')
1123
+
1124
+ // Set return value
1125
+ if (
1126
+ results.execResult.returnValue !== undefined &&
1127
+ (!results.execResult.exceptionError ||
1128
+ results.execResult.exceptionError.error === EVMError.errorMessages.REVERT)
1129
+ ) {
1130
+ this._runState.returnBytes = results.execResult.returnValue
1131
+ }
1132
+
1133
+ if (!results.execResult.exceptionError) {
1134
+ for (const [addressToSelfdestructHex, beneficiaryHex] of selfdestruct) {
1135
+ this._result.selfdestruct.set(addressToSelfdestructHex, beneficiaryHex)
1136
+ }
1137
+ if (this.common.isActivatedEIP(6780)) {
1138
+ // copy over the items to result via iterator
1139
+ for (const item of createdAddresses!) {
1140
+ this._result.createdAddresses!.add(item)
1141
+ }
1142
+ }
1143
+ // update stateRoot on current contract
1144
+ const account = await this._stateManager.getAccount(this._env.address)
1145
+ if (!account) {
1146
+ throw EthereumJSErrorWithoutCode('could not read contract account')
1147
+ }
1148
+ this._env.contract = account
1149
+ this._runState.gasRefund = results.execResult.gasRefund ?? BIGINT_0
1150
+ }
1151
+
1152
+ return this._getReturnCode(results)
1153
+ }
1154
+
1155
+ /**
1156
+ * Creates a new contract with a given value.
1157
+ */
1158
+ async create(
1159
+ gasLimit: bigint,
1160
+ value: bigint,
1161
+ codeToRun: Uint8Array,
1162
+ salt?: Uint8Array,
1163
+ eofCallData?: Uint8Array,
1164
+ ): Promise<bigint> {
1165
+ const selfdestruct = new Map(this._result.selfdestruct)
1166
+ const caller = this._env.address
1167
+ const depth = this._env.depth + 1
1168
+
1169
+ // empty the return data buffer
1170
+ this._runState.returnBytes = new Uint8Array(0)
1171
+
1172
+ // Check if account has enough ether and max depth not exceeded
1173
+ if (
1174
+ this._env.depth >= Number(this.common.param('stackLimit')) ||
1175
+ this._env.contract.balance < value
1176
+ ) {
1177
+ return BIGINT_0
1178
+ }
1179
+
1180
+ // EIP-2681 check
1181
+ if (this._env.contract.nonce >= MAX_UINT64) {
1182
+ return BIGINT_0
1183
+ }
1184
+
1185
+ this._env.contract.nonce += BIGINT_1
1186
+ await this.journal.putAccount(this._env.address, this._env.contract)
1187
+ if (this.common.isActivatedEIP(7928)) {
1188
+ this._evm.blockLevelAccessList!.addNonceChange(
1189
+ this._env.address.toString(),
1190
+ this._env.contract.nonce,
1191
+ this._evm.blockLevelAccessList!.blockAccessIndex,
1192
+ )
1193
+ }
1194
+
1195
+ if (this.common.isActivatedEIP(3860)) {
1196
+ if (
1197
+ codeToRun.length > Number(this.common.param('maxInitCodeSize')) &&
1198
+ this._evm.allowUnlimitedInitCodeSize === false
1199
+ ) {
1200
+ return BIGINT_0
1201
+ }
1202
+ }
1203
+
1204
+ const message = new Message({
1205
+ caller,
1206
+ gasLimit,
1207
+ value,
1208
+ data: codeToRun,
1209
+ eofCallData,
1210
+ salt,
1211
+ depth,
1212
+ selfdestruct,
1213
+ gasRefund: this._runState.gasRefund,
1214
+ blobVersionedHashes: this._env.blobVersionedHashes,
1215
+ accessWitness: this._env.accessWitness,
1216
+ })
1217
+
1218
+ let createdAddresses: Set<PrefixedHexString>
1219
+ if (this.common.isActivatedEIP(6780)) {
1220
+ createdAddresses = new Set(this._result.createdAddresses)
1221
+ message.createdAddresses = createdAddresses
1222
+ }
1223
+
1224
+ const results = await this._evm.runCall({ message })
1225
+
1226
+ if (results.execResult.logs) {
1227
+ this._result.logs = this._result.logs.concat(results.execResult.logs)
1228
+ }
1229
+
1230
+ // this should always be safe
1231
+ this.useGas(results.execResult.executionGasUsed, 'CREATE')
1232
+
1233
+ // Set return buffer in case revert happened
1234
+ if (
1235
+ results.execResult.exceptionError &&
1236
+ results.execResult.exceptionError.error === EVMError.errorMessages.REVERT
1237
+ ) {
1238
+ this._runState.returnBytes = results.execResult.returnValue
1239
+ }
1240
+
1241
+ if (
1242
+ !results.execResult.exceptionError ||
1243
+ results.execResult.exceptionError.error === EVMError.errorMessages.CODESTORE_OUT_OF_GAS
1244
+ ) {
1245
+ for (const [addressToSelfdestructHex, beneficiaryHex] of selfdestruct) {
1246
+ this._result.selfdestruct.set(addressToSelfdestructHex, beneficiaryHex)
1247
+ }
1248
+ if (this.common.isActivatedEIP(6780)) {
1249
+ // copy over the items to result via iterator
1250
+ for (const item of createdAddresses!) {
1251
+ this._result.createdAddresses!.add(item)
1252
+ }
1253
+ }
1254
+ // update stateRoot on current contract
1255
+ const account = await this._stateManager.getAccount(this._env.address)
1256
+ if (!account) {
1257
+ throw EthereumJSErrorWithoutCode('could not read contract account')
1258
+ }
1259
+ this._env.contract = account
1260
+ this._runState.gasRefund = results.execResult.gasRefund ?? BIGINT_0
1261
+ if (results.createdAddress) {
1262
+ // push the created address to the stack
1263
+ return bytesToBigInt(results.createdAddress.bytes)
1264
+ }
1265
+ }
1266
+
1267
+ return this._getReturnCode(results, true)
1268
+ }
1269
+
1270
+ /**
1271
+ * Creates a new contract with a given value. Generates
1272
+ * a deterministic address via CREATE2 rules.
1273
+ */
1274
+ async create2(
1275
+ gasLimit: bigint,
1276
+ value: bigint,
1277
+ data: Uint8Array,
1278
+ salt: Uint8Array,
1279
+ ): Promise<bigint> {
1280
+ return this.create(gasLimit, value, data, salt)
1281
+ }
1282
+
1283
+ /**
1284
+ * Creates a new contract with a given value. Generates
1285
+ * a deterministic address via EOFCREATE rules.
1286
+ */
1287
+ async eofcreate(
1288
+ gasLimit: bigint,
1289
+ value: bigint,
1290
+ containerData: Uint8Array,
1291
+ salt: Uint8Array,
1292
+ callData: Uint8Array,
1293
+ ): Promise<bigint> {
1294
+ return this.create(gasLimit, value, containerData, salt, callData)
1295
+ }
1296
+
1297
+ /**
1298
+ * Mark account for later deletion and give the remaining balance to the
1299
+ * specified beneficiary address. This will cause a trap and the
1300
+ * execution will be aborted immediately.
1301
+ * @param toAddress - Beneficiary address
1302
+ */
1303
+ async selfDestruct(toAddress: Address): Promise<void> {
1304
+ return this._selfDestruct(toAddress)
1305
+ }
1306
+
1307
+ async _selfDestruct(toAddress: Address): Promise<void> {
1308
+ // only add to refund if this is the first selfdestruct for the address
1309
+ const selfdestructAddressHex = bytesToHex(this._env.address.bytes)
1310
+ if (!this._result.selfdestruct.has(selfdestructAddressHex)) {
1311
+ this.refundGas(this.common.param('selfdestructRefundGas'))
1312
+ }
1313
+
1314
+ this._result.selfdestruct.set(selfdestructAddressHex, toAddress.toString())
1315
+
1316
+ const toSelf = equalsBytes(toAddress.bytes, this._env.address.bytes)
1317
+ const contractBalance = this._env.contract.balance
1318
+
1319
+ // EIP-7708: Emit ETH transfer log for SELFDESTRUCT with value to a different account
1320
+ if (this.common.isActivatedEIP(7708) && contractBalance > BIGINT_0 && !toSelf) {
1321
+ // Transfer log: from contract to beneficiary
1322
+ const fromTopic = setLengthLeft(this._env.address.bytes, 32)
1323
+ const toTopic = setLengthLeft(toAddress.bytes, 32)
1324
+ const data = setLengthLeft(bigIntToBytes(contractBalance), 32)
1325
+ const transferLog: Log = [
1326
+ EIP7708_SYSTEM_ADDRESS,
1327
+ [EIP7708_TRANSFER_TOPIC, fromTopic, toTopic],
1328
+ data,
1329
+ ]
1330
+ this._result.logs.push(transferLog)
1331
+ }
1332
+
1333
+ // Add to beneficiary balance
1334
+ if (!toSelf) {
1335
+ let toAccount = await this._stateManager.getAccount(toAddress)
1336
+ if (!toAccount) {
1337
+ toAccount = new Account()
1338
+ }
1339
+ const originalBalance = toAccount.balance
1340
+ toAccount.balance += contractBalance
1341
+ await this.journal.putAccount(toAddress, toAccount)
1342
+ if (this.common.isActivatedEIP(7928)) {
1343
+ this._evm.blockLevelAccessList!.addBalanceChange(
1344
+ toAddress.toString(),
1345
+ toAccount.balance,
1346
+ this._evm.blockLevelAccessList!.blockAccessIndex,
1347
+ originalBalance,
1348
+ )
1349
+ }
1350
+ }
1351
+
1352
+ // Modify the account (set balance to 0) flag
1353
+ let doModify = !this.common.isActivatedEIP(6780) // Always do this if 6780 is not active
1354
+
1355
+ if (!doModify) {
1356
+ // If 6780 is active, check if current address is being created. If so
1357
+ // old behavior of SELFDESTRUCT exists and balance should be set to 0 of this account
1358
+ // (i.e. burn the ETH in current account)
1359
+ doModify = this._env.createdAddresses!.has(this._env.address.toString())
1360
+ // If contract is not being created in this tx...
1361
+ if (!doModify) {
1362
+ // Check if ETH being sent to another account (thus set balance to 0)
1363
+ doModify = !toSelf
1364
+ }
1365
+ }
1366
+
1367
+ // EIP-7708: Emit a Selfdestruct log for SELFDESTRUCT to self only when the balance
1368
+ // is actually zeroed (doModify=true, i.e. same-tx contract creation). Pre-existing
1369
+ // contracts where EIP-6780 prevents the burn should not emit a log.
1370
+ if (this.common.isActivatedEIP(7708) && contractBalance > BIGINT_0 && toSelf && doModify) {
1371
+ const contractTopic = setLengthLeft(this._env.address.bytes, 32)
1372
+ const data = setLengthLeft(bigIntToBytes(contractBalance), 32)
1373
+ const selfdestructLog: Log = [
1374
+ EIP7708_SYSTEM_ADDRESS,
1375
+ [EIP7708_SELFDESTRUCT_TOPIC, contractTopic],
1376
+ data,
1377
+ ]
1378
+ this._result.logs.push(selfdestructLog)
1379
+ }
1380
+
1381
+ // Set contract balance to 0
1382
+ if (doModify) {
1383
+ const originalBalance = this._env.contract.balance
1384
+ await this._stateManager.modifyAccountFields(this._env.address, {
1385
+ balance: BIGINT_0,
1386
+ })
1387
+ if (this.common.isActivatedEIP(7928)) {
1388
+ this._evm.blockLevelAccessList!.addBalanceChange(
1389
+ this._env.address.toString(),
1390
+ BIGINT_0,
1391
+ this._evm.blockLevelAccessList!.blockAccessIndex,
1392
+ originalBalance,
1393
+ )
1394
+ }
1395
+ }
1396
+
1397
+ trap(EVMError.errorMessages.STOP)
1398
+ }
1399
+
1400
+ /**
1401
+ * Creates a new log in the current environment.
1402
+ */
1403
+ log(data: Uint8Array, numberOfTopics: number, topics: Uint8Array[]): void {
1404
+ if (numberOfTopics < 0 || numberOfTopics > 4) {
1405
+ trap(EVMError.errorMessages.OUT_OF_RANGE)
1406
+ }
1407
+
1408
+ if (topics.length !== numberOfTopics) {
1409
+ trap(EVMError.errorMessages.INTERNAL_ERROR)
1410
+ }
1411
+
1412
+ const log: Log = [this._env.address.bytes, topics, data]
1413
+ this._result.logs.push(log)
1414
+ }
1415
+
1416
+ private _getReturnCode(results: EVMResult, isEOFCreate = false) {
1417
+ if (this._runState.env.eof === undefined || isEOFCreate) {
1418
+ if (results.execResult.exceptionError) {
1419
+ return BIGINT_0
1420
+ } else {
1421
+ return BIGINT_1
1422
+ }
1423
+ } else {
1424
+ // EOF mode, call was either EXTCALL / EXTDELEGATECALL / EXTSTATICCALL
1425
+ if (results.execResult.exceptionError !== undefined) {
1426
+ if (results.execResult.exceptionError.error === EVMError.errorMessages.REVERT) {
1427
+ // Revert
1428
+ return BIGINT_1
1429
+ } else {
1430
+ // Failure
1431
+ return BIGINT_2
1432
+ }
1433
+ }
1434
+ return BIGINT_0
1435
+ }
1436
+ }
1437
+ }