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