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