@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,1775 @@
1
+ import { Account, Address, BIGINT_0, BIGINT_1, BIGINT_2, BIGINT_2EXP96, BIGINT_2EXP160, BIGINT_2EXP224, BIGINT_7, BIGINT_8, BIGINT_31, BIGINT_32, BIGINT_96, BIGINT_160, BIGINT_224, BIGINT_255, BIGINT_256, MAX_INTEGER_BIGINT, TWO_POW256, bigIntToAddressBytes, bigIntToBytes, bytesToBigInt, bytesToHex, bytesToInt, concatBytes, equalsBytes, setLengthLeft, setLengthRight, } from '@feelyourprotocol/util';
2
+ import { keccak_256 } from '@noble/hashes/sha3.js';
3
+ import { EOFContainer, EOFContainerMode } from "../eof/container.js";
4
+ import { EOFErrorMessage } from "../eof/errors.js";
5
+ import { EOFBYTES, EOFHASH, isEOF } from "../eof/util.js";
6
+ import { EVMError } from "../errors.js";
7
+ import { createAddressFromStackBigInt, decodeEIP8024PairImmediate, decodeEIP8024SingleImmediate, describeLocation, exponentiation, fromTwos, getDataSlice, jumpIsValid, mod, readImmediateByteOrZero, toTwos, trap, writeCallOutput, } from "./util.js";
8
+ // the opcode functions
9
+ export const handlers = new Map([
10
+ // 0x00: STOP
11
+ [
12
+ 0x00,
13
+ function () {
14
+ trap(EVMError.errorMessages.STOP);
15
+ },
16
+ ],
17
+ // 0x01: ADD
18
+ [
19
+ 0x01,
20
+ function (runState) {
21
+ const [a, b] = runState.stack.popN(2);
22
+ const r = mod(a + b, TWO_POW256);
23
+ runState.stack.push(r);
24
+ },
25
+ ],
26
+ // 0x02: MUL
27
+ [
28
+ 0x02,
29
+ function (runState) {
30
+ const [a, b] = runState.stack.popN(2);
31
+ const r = mod(a * b, TWO_POW256);
32
+ runState.stack.push(r);
33
+ },
34
+ ],
35
+ // 0x03: SUB
36
+ [
37
+ 0x03,
38
+ function (runState) {
39
+ const [a, b] = runState.stack.popN(2);
40
+ const r = mod(a - b, TWO_POW256);
41
+ runState.stack.push(r);
42
+ },
43
+ ],
44
+ // 0x04: DIV
45
+ [
46
+ 0x04,
47
+ function (runState) {
48
+ const [a, b] = runState.stack.popN(2);
49
+ let r;
50
+ if (b === BIGINT_0) {
51
+ r = BIGINT_0;
52
+ }
53
+ else {
54
+ r = mod(a / b, TWO_POW256);
55
+ }
56
+ runState.stack.push(r);
57
+ },
58
+ ],
59
+ // 0x05: SDIV
60
+ [
61
+ 0x05,
62
+ function (runState) {
63
+ const [a, b] = runState.stack.popN(2);
64
+ let r;
65
+ if (b === BIGINT_0) {
66
+ r = BIGINT_0;
67
+ }
68
+ else {
69
+ r = toTwos(fromTwos(a) / fromTwos(b));
70
+ }
71
+ runState.stack.push(r);
72
+ },
73
+ ],
74
+ // 0x06: MOD
75
+ [
76
+ 0x06,
77
+ function (runState) {
78
+ const [a, b] = runState.stack.popN(2);
79
+ let r;
80
+ if (b === BIGINT_0) {
81
+ r = b;
82
+ }
83
+ else {
84
+ r = mod(a, b);
85
+ }
86
+ runState.stack.push(r);
87
+ },
88
+ ],
89
+ // 0x07: SMOD
90
+ [
91
+ 0x07,
92
+ function (runState) {
93
+ const [a, b] = runState.stack.popN(2);
94
+ let r;
95
+ if (b === BIGINT_0) {
96
+ r = b;
97
+ }
98
+ else {
99
+ r = fromTwos(a) % fromTwos(b);
100
+ }
101
+ runState.stack.push(toTwos(r));
102
+ },
103
+ ],
104
+ // 0x08: ADDMOD
105
+ [
106
+ 0x08,
107
+ function (runState) {
108
+ const [a, b, c] = runState.stack.popN(3);
109
+ let r;
110
+ if (c === BIGINT_0) {
111
+ r = BIGINT_0;
112
+ }
113
+ else {
114
+ r = mod(a + b, c);
115
+ }
116
+ runState.stack.push(r);
117
+ },
118
+ ],
119
+ // 0x09: MULMOD
120
+ [
121
+ 0x09,
122
+ function (runState) {
123
+ const [a, b, c] = runState.stack.popN(3);
124
+ let r;
125
+ if (c === BIGINT_0) {
126
+ r = BIGINT_0;
127
+ }
128
+ else {
129
+ r = mod(a * b, c);
130
+ }
131
+ runState.stack.push(r);
132
+ },
133
+ ],
134
+ // 0x0a: EXP
135
+ [
136
+ 0x0a,
137
+ function (runState) {
138
+ const [base, exponent] = runState.stack.popN(2);
139
+ if (base === BIGINT_2) {
140
+ switch (exponent) {
141
+ case BIGINT_96:
142
+ runState.stack.push(BIGINT_2EXP96);
143
+ return;
144
+ case BIGINT_160:
145
+ runState.stack.push(BIGINT_2EXP160);
146
+ return;
147
+ case BIGINT_224:
148
+ runState.stack.push(BIGINT_2EXP224);
149
+ return;
150
+ }
151
+ }
152
+ if (exponent === BIGINT_0) {
153
+ runState.stack.push(BIGINT_1);
154
+ return;
155
+ }
156
+ if (base === BIGINT_0) {
157
+ runState.stack.push(base);
158
+ return;
159
+ }
160
+ const r = exponentiation(base, exponent);
161
+ runState.stack.push(r);
162
+ },
163
+ ],
164
+ // 0x0b: SIGNEXTEND
165
+ [
166
+ 0x0b,
167
+ function (runState) {
168
+ /* eslint-disable-next-line prefer-const */
169
+ let [k, val] = runState.stack.popN(2);
170
+ if (k < BIGINT_31) {
171
+ const signBit = k * BIGINT_8 + BIGINT_7;
172
+ const mask = (BIGINT_1 << signBit) - BIGINT_1;
173
+ if ((val >> signBit) & BIGINT_1) {
174
+ val = val | BigInt.asUintN(256, ~mask);
175
+ }
176
+ else {
177
+ val = val & mask;
178
+ }
179
+ }
180
+ runState.stack.push(val);
181
+ },
182
+ ],
183
+ // 0x10 range - bit ops
184
+ // 0x10: LT
185
+ [
186
+ 0x10,
187
+ function (runState) {
188
+ const [a, b] = runState.stack.popN(2);
189
+ const r = a < b ? BIGINT_1 : BIGINT_0;
190
+ runState.stack.push(r);
191
+ },
192
+ ],
193
+ // 0x11: GT
194
+ [
195
+ 0x11,
196
+ function (runState) {
197
+ const [a, b] = runState.stack.popN(2);
198
+ const r = a > b ? BIGINT_1 : BIGINT_0;
199
+ runState.stack.push(r);
200
+ },
201
+ ],
202
+ // 0x12: SLT
203
+ [
204
+ 0x12,
205
+ function (runState) {
206
+ const [a, b] = runState.stack.popN(2);
207
+ const r = fromTwos(a) < fromTwos(b) ? BIGINT_1 : BIGINT_0;
208
+ runState.stack.push(r);
209
+ },
210
+ ],
211
+ // 0x13: SGT
212
+ [
213
+ 0x13,
214
+ function (runState) {
215
+ const [a, b] = runState.stack.popN(2);
216
+ const r = fromTwos(a) > fromTwos(b) ? BIGINT_1 : BIGINT_0;
217
+ runState.stack.push(r);
218
+ },
219
+ ],
220
+ // 0x14: EQ
221
+ [
222
+ 0x14,
223
+ function (runState) {
224
+ const [a, b] = runState.stack.popN(2);
225
+ const r = a === b ? BIGINT_1 : BIGINT_0;
226
+ runState.stack.push(r);
227
+ },
228
+ ],
229
+ // 0x15: ISZERO
230
+ [
231
+ 0x15,
232
+ function (runState) {
233
+ const a = runState.stack.pop();
234
+ const r = a === BIGINT_0 ? BIGINT_1 : BIGINT_0;
235
+ runState.stack.push(r);
236
+ },
237
+ ],
238
+ // 0x16: AND
239
+ [
240
+ 0x16,
241
+ function (runState) {
242
+ const [a, b] = runState.stack.popN(2);
243
+ const r = a & b;
244
+ runState.stack.push(r);
245
+ },
246
+ ],
247
+ // 0x17: OR
248
+ [
249
+ 0x17,
250
+ function (runState) {
251
+ const [a, b] = runState.stack.popN(2);
252
+ const r = a | b;
253
+ runState.stack.push(r);
254
+ },
255
+ ],
256
+ // 0x18: XOR
257
+ [
258
+ 0x18,
259
+ function (runState) {
260
+ const [a, b] = runState.stack.popN(2);
261
+ const r = a ^ b;
262
+ runState.stack.push(r);
263
+ },
264
+ ],
265
+ // 0x19: NOT
266
+ [
267
+ 0x19,
268
+ function (runState) {
269
+ const a = runState.stack.pop();
270
+ const r = BigInt.asUintN(256, ~a);
271
+ runState.stack.push(r);
272
+ },
273
+ ],
274
+ // 0x1a: BYTE
275
+ [
276
+ 0x1a,
277
+ function (runState) {
278
+ const [pos, word] = runState.stack.popN(2);
279
+ if (pos > BIGINT_32) {
280
+ runState.stack.push(BIGINT_0);
281
+ return;
282
+ }
283
+ const r = (word >> ((BIGINT_31 - pos) * BIGINT_8)) & BIGINT_255;
284
+ runState.stack.push(r);
285
+ },
286
+ ],
287
+ // 0x1b: SHL
288
+ [
289
+ 0x1b,
290
+ function (runState) {
291
+ const [a, b] = runState.stack.popN(2);
292
+ if (a > BIGINT_256) {
293
+ runState.stack.push(BIGINT_0);
294
+ return;
295
+ }
296
+ const r = (b << a) & MAX_INTEGER_BIGINT;
297
+ runState.stack.push(r);
298
+ },
299
+ ],
300
+ // 0x1c: SHR
301
+ [
302
+ 0x1c,
303
+ function (runState) {
304
+ const [a, b] = runState.stack.popN(2);
305
+ if (a > 256) {
306
+ runState.stack.push(BIGINT_0);
307
+ return;
308
+ }
309
+ const r = b >> a;
310
+ runState.stack.push(r);
311
+ },
312
+ ],
313
+ // 0x1d: SAR
314
+ [
315
+ 0x1d,
316
+ function (runState) {
317
+ const [a, b] = runState.stack.popN(2);
318
+ let r;
319
+ const bComp = BigInt.asIntN(256, b);
320
+ const isSigned = bComp < 0;
321
+ if (a > 256) {
322
+ if (isSigned) {
323
+ r = MAX_INTEGER_BIGINT;
324
+ }
325
+ else {
326
+ r = BIGINT_0;
327
+ }
328
+ runState.stack.push(r);
329
+ return;
330
+ }
331
+ const c = b >> a;
332
+ if (isSigned) {
333
+ const shiftedOutWidth = BIGINT_255 - a;
334
+ const mask = (MAX_INTEGER_BIGINT >> shiftedOutWidth) << shiftedOutWidth;
335
+ r = c | mask;
336
+ }
337
+ else {
338
+ r = c;
339
+ }
340
+ runState.stack.push(r);
341
+ },
342
+ ],
343
+ // 0x1e: CLZ
344
+ [
345
+ 0x1e,
346
+ function (runState) {
347
+ const x = runState.stack.pop();
348
+ // If x is zero, return 256
349
+ if (x === BIGINT_0) {
350
+ runState.stack.push(BIGINT_256);
351
+ return;
352
+ }
353
+ // toString(2) yields a binary string with no leading zeros.
354
+ // So 256 - binaryStr.length equals the leading-zero count.
355
+ const binaryStr = x.toString(2);
356
+ const leadingZeros = 256 - binaryStr.length;
357
+ runState.stack.push(BigInt(leadingZeros));
358
+ },
359
+ ],
360
+ // 0x20 range - crypto
361
+ // 0x20: KECCAK256
362
+ [
363
+ 0x20,
364
+ function (runState, common) {
365
+ const [offset, length] = runState.stack.popN(2);
366
+ let data = new Uint8Array(0);
367
+ if (length !== BIGINT_0) {
368
+ data = runState.memory.read(Number(offset), Number(length));
369
+ }
370
+ const r = BigInt(bytesToHex((common.customCrypto.keccak256 ?? keccak_256)(data)));
371
+ runState.stack.push(r);
372
+ },
373
+ ],
374
+ // 0x30 range - closure state
375
+ // 0x30: ADDRESS
376
+ [
377
+ 0x30,
378
+ function (runState) {
379
+ const address = bytesToBigInt(runState.interpreter.getAddress().bytes);
380
+ runState.stack.push(address);
381
+ },
382
+ ],
383
+ // 0x31: BALANCE
384
+ [
385
+ 0x31,
386
+ async function (runState) {
387
+ const addressBigInt = runState.stack.pop();
388
+ const address = createAddressFromStackBigInt(addressBigInt);
389
+ const balance = await runState.interpreter.getExternalBalance(address);
390
+ runState.stack.push(balance);
391
+ },
392
+ ],
393
+ // 0x32: ORIGIN
394
+ [
395
+ 0x32,
396
+ function (runState) {
397
+ runState.stack.push(runState.interpreter.getTxOrigin());
398
+ },
399
+ ],
400
+ // 0x33: CALLER
401
+ [
402
+ 0x33,
403
+ function (runState) {
404
+ runState.stack.push(runState.interpreter.getCaller());
405
+ },
406
+ ],
407
+ // 0x34: CALLVALUE
408
+ [
409
+ 0x34,
410
+ function (runState) {
411
+ runState.stack.push(runState.interpreter.getCallValue());
412
+ },
413
+ ],
414
+ // 0x35: CALLDATALOAD
415
+ [
416
+ 0x35,
417
+ function (runState) {
418
+ const pos = runState.stack.pop();
419
+ if (pos > runState.interpreter.getCallDataSize()) {
420
+ runState.stack.push(BIGINT_0);
421
+ return;
422
+ }
423
+ const i = Number(pos);
424
+ let loaded = runState.interpreter.getCallData().subarray(i, i + 32);
425
+ loaded = loaded.length ? loaded : Uint8Array.from([0]);
426
+ let r = bytesToBigInt(loaded);
427
+ if (loaded.length < 32) {
428
+ r = r << (BIGINT_8 * BigInt(32 - loaded.length));
429
+ }
430
+ runState.stack.push(r);
431
+ },
432
+ ],
433
+ // 0x36: CALLDATASIZE
434
+ [
435
+ 0x36,
436
+ function (runState) {
437
+ const r = runState.interpreter.getCallDataSize();
438
+ runState.stack.push(r);
439
+ },
440
+ ],
441
+ // 0x37: CALLDATACOPY
442
+ [
443
+ 0x37,
444
+ function (runState) {
445
+ const [memOffset, dataOffset, dataLength] = runState.stack.popN(3);
446
+ if (dataLength !== BIGINT_0) {
447
+ const data = getDataSlice(runState.interpreter.getCallData(), dataOffset, dataLength);
448
+ const memOffsetNum = Number(memOffset);
449
+ const dataLengthNum = Number(dataLength);
450
+ runState.memory.write(memOffsetNum, dataLengthNum, data);
451
+ }
452
+ },
453
+ ],
454
+ // 0x38: CODESIZE
455
+ [
456
+ 0x38,
457
+ function (runState) {
458
+ runState.stack.push(runState.interpreter.getCodeSize());
459
+ },
460
+ ],
461
+ // 0x39: CODECOPY
462
+ [
463
+ 0x39,
464
+ function (runState) {
465
+ const [memOffset, codeOffset, dataLength] = runState.stack.popN(3);
466
+ if (dataLength !== BIGINT_0) {
467
+ const data = getDataSlice(runState.interpreter.getCode(), codeOffset, dataLength);
468
+ const memOffsetNum = Number(memOffset);
469
+ const lengthNum = Number(dataLength);
470
+ runState.memory.write(memOffsetNum, lengthNum, data);
471
+ }
472
+ },
473
+ ],
474
+ // 0x3b: EXTCODESIZE
475
+ [
476
+ 0x3b,
477
+ async function (runState) {
478
+ const addressBigInt = runState.stack.pop();
479
+ const address = createAddressFromStackBigInt(addressBigInt);
480
+ // EIP-7928: Track address access in BAL
481
+ if (runState.interpreter._evm.common.isActivatedEIP(7928)) {
482
+ runState.interpreter._evm.blockLevelAccessList?.addAddress(address.toString());
483
+ }
484
+ // EOF check
485
+ const code = await runState.stateManager.getCode(address);
486
+ if (isEOF(code)) {
487
+ // In legacy code, the target code is treated as to be "EOFBYTES" code
488
+ runState.stack.push(BigInt(EOFBYTES.length));
489
+ return;
490
+ }
491
+ const size = BigInt(code.length);
492
+ runState.stack.push(size);
493
+ },
494
+ ],
495
+ // 0x3c: EXTCODECOPY
496
+ [
497
+ 0x3c,
498
+ async function (runState) {
499
+ const [addressBigInt, memOffset, codeOffset, dataLength] = runState.stack.popN(4);
500
+ const address = createAddressFromStackBigInt(addressBigInt);
501
+ // EIP-7928: Track address access in BAL
502
+ if (runState.interpreter._evm.common.isActivatedEIP(7928)) {
503
+ runState.interpreter._evm.blockLevelAccessList?.addAddress(address.toString());
504
+ }
505
+ if (dataLength !== BIGINT_0) {
506
+ let code = await runState.stateManager.getCode(address);
507
+ if (isEOF(code)) {
508
+ // In legacy code, the target code is treated as to be "EOFBYTES" code
509
+ code = EOFBYTES;
510
+ }
511
+ const data = getDataSlice(code, codeOffset, dataLength);
512
+ const memOffsetNum = Number(memOffset);
513
+ const lengthNum = Number(dataLength);
514
+ runState.memory.write(memOffsetNum, lengthNum, data);
515
+ }
516
+ },
517
+ ],
518
+ // 0x3f: EXTCODEHASH
519
+ [
520
+ 0x3f,
521
+ async function (runState) {
522
+ const addressBigInt = runState.stack.pop();
523
+ const address = createAddressFromStackBigInt(addressBigInt);
524
+ // EIP-7928: Track address access in BAL
525
+ if (runState.interpreter._evm.common.isActivatedEIP(7928)) {
526
+ runState.interpreter._evm.blockLevelAccessList?.addAddress(address.toString());
527
+ }
528
+ // EOF check
529
+ const code = await runState.stateManager.getCode(address);
530
+ if (isEOF(code)) {
531
+ // In legacy code, the target code is treated as to be "EOFBYTES" code
532
+ // Therefore, push the hash of EOFBYTES to the stack
533
+ runState.stack.push(bytesToBigInt(EOFHASH));
534
+ return;
535
+ }
536
+ const account = await runState.stateManager.getAccount(address);
537
+ if (!account || account.isEmpty()) {
538
+ runState.stack.push(BIGINT_0);
539
+ return;
540
+ }
541
+ runState.stack.push(BigInt(bytesToHex(account.codeHash)));
542
+ },
543
+ ],
544
+ // 0x3d: RETURNDATASIZE
545
+ [
546
+ 0x3d,
547
+ function (runState) {
548
+ runState.stack.push(runState.interpreter.getReturnDataSize());
549
+ },
550
+ ],
551
+ // 0x3e: RETURNDATACOPY
552
+ [
553
+ 0x3e,
554
+ function (runState) {
555
+ const [memOffset, returnDataOffset, dataLength] = runState.stack.popN(3);
556
+ if (dataLength !== BIGINT_0) {
557
+ const data = getDataSlice(runState.interpreter.getReturnData(), returnDataOffset, dataLength);
558
+ const memOffsetNum = Number(memOffset);
559
+ const lengthNum = Number(dataLength);
560
+ runState.memory.write(memOffsetNum, lengthNum, data);
561
+ }
562
+ },
563
+ ],
564
+ // 0x3a: GASPRICE
565
+ [
566
+ 0x3a,
567
+ function (runState) {
568
+ runState.stack.push(runState.interpreter.getTxGasPrice());
569
+ },
570
+ ],
571
+ // '0x40' range - block operations
572
+ // 0x40: BLOCKHASH
573
+ [
574
+ 0x40,
575
+ async function (runState, common) {
576
+ const number = runState.stack.pop();
577
+ if (common.isActivatedEIP(7709)) {
578
+ if (number >= runState.interpreter.getBlockNumber()) {
579
+ runState.stack.push(BIGINT_0);
580
+ return;
581
+ }
582
+ const diff = runState.interpreter.getBlockNumber() - number;
583
+ // block lookups must be within the original window even if historyStorageAddress's
584
+ // historyServeWindow is much greater than 256
585
+ if (diff > BIGINT_256 || diff <= BIGINT_0) {
586
+ runState.stack.push(BIGINT_0);
587
+ return;
588
+ }
589
+ const historyAddress = new Address(bigIntToAddressBytes(common.param('historyStorageAddress')));
590
+ const historyServeWindow = common.param('historyServeWindow');
591
+ const key = setLengthLeft(bigIntToBytes(number % historyServeWindow), 32);
592
+ if (common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) {
593
+ // create witnesses and charge gas
594
+ const statelessGas = runState.env.accessWitness.readAccountStorage(historyAddress, number);
595
+ runState.interpreter.useGas(statelessGas, `BLOCKHASH`);
596
+ }
597
+ const storage = await runState.stateManager.getStorage(historyAddress, key);
598
+ runState.stack.push(bytesToBigInt(storage));
599
+ }
600
+ else {
601
+ const diff = runState.interpreter.getBlockNumber() - number;
602
+ // block lookups must be within the past 256 blocks
603
+ if (diff > BIGINT_256 || diff <= BIGINT_0) {
604
+ runState.stack.push(BIGINT_0);
605
+ return;
606
+ }
607
+ const block = await runState.blockchain.getBlock(Number(number));
608
+ runState.stack.push(bytesToBigInt(block.hash()));
609
+ }
610
+ },
611
+ ],
612
+ // 0x41: COINBASE
613
+ [
614
+ 0x41,
615
+ function (runState) {
616
+ runState.stack.push(runState.interpreter.getBlockCoinbase());
617
+ },
618
+ ],
619
+ // 0x42: TIMESTAMP
620
+ [
621
+ 0x42,
622
+ function (runState) {
623
+ runState.stack.push(runState.interpreter.getBlockTimestamp());
624
+ },
625
+ ],
626
+ // 0x43: NUMBER
627
+ [
628
+ 0x43,
629
+ function (runState) {
630
+ runState.stack.push(runState.interpreter.getBlockNumber());
631
+ },
632
+ ],
633
+ // 0x44: DIFFICULTY (EIP-4399: supplanted as PREVRANDAO)
634
+ [
635
+ 0x44,
636
+ function (runState, common) {
637
+ if (common.isActivatedEIP(4399)) {
638
+ runState.stack.push(runState.interpreter.getBlockPrevRandao());
639
+ }
640
+ else {
641
+ runState.stack.push(runState.interpreter.getBlockDifficulty());
642
+ }
643
+ },
644
+ ],
645
+ // 0x45: GASLIMIT
646
+ [
647
+ 0x45,
648
+ function (runState) {
649
+ runState.stack.push(runState.interpreter.getBlockGasLimit());
650
+ },
651
+ ],
652
+ // 0x4b: SLOTNUM (EIP-7843)
653
+ [
654
+ 0x4b,
655
+ function (runState) {
656
+ runState.stack.push(runState.interpreter.getBlockSlotNumber());
657
+ },
658
+ ],
659
+ // 0x46: CHAINID
660
+ [
661
+ 0x46,
662
+ function (runState) {
663
+ runState.stack.push(runState.interpreter.getChainId());
664
+ },
665
+ ],
666
+ // 0x47: SELFBALANCE
667
+ [
668
+ 0x47,
669
+ function (runState) {
670
+ runState.stack.push(runState.interpreter.getSelfBalance());
671
+ },
672
+ ],
673
+ // 0x48: BASEFEE
674
+ [
675
+ 0x48,
676
+ function (runState) {
677
+ runState.stack.push(runState.interpreter.getBlockBaseFee());
678
+ },
679
+ ],
680
+ // 0x49: BLOBHASH
681
+ [
682
+ 0x49,
683
+ function (runState) {
684
+ const index = runState.stack.pop();
685
+ if (runState.env.blobVersionedHashes.length > Number(index)) {
686
+ runState.stack.push(BigInt(runState.env.blobVersionedHashes[Number(index)]));
687
+ }
688
+ else {
689
+ runState.stack.push(BIGINT_0);
690
+ }
691
+ },
692
+ ],
693
+ // 0x4a: BLOBBASEFEE
694
+ [
695
+ 0x4a,
696
+ function (runState) {
697
+ runState.stack.push(runState.interpreter.getBlobBaseFee());
698
+ },
699
+ ],
700
+ // 0x50 range - 'storage' and execution
701
+ // 0x50: POP
702
+ [
703
+ 0x50,
704
+ function (runState) {
705
+ runState.stack.pop();
706
+ },
707
+ ],
708
+ // 0x51: MLOAD
709
+ [
710
+ 0x51,
711
+ function (runState) {
712
+ const pos = runState.stack.pop();
713
+ const word = runState.memory.read(Number(pos), 32, true);
714
+ runState.stack.push(bytesToBigInt(word));
715
+ },
716
+ ],
717
+ // 0x52: MSTORE
718
+ [
719
+ 0x52,
720
+ function (runState) {
721
+ const [offset, word] = runState.stack.popN(2);
722
+ const buf = setLengthLeft(bigIntToBytes(word), 32);
723
+ const offsetNum = Number(offset);
724
+ runState.memory.write(offsetNum, 32, buf);
725
+ },
726
+ ],
727
+ // 0x53: MSTORE8
728
+ [
729
+ 0x53,
730
+ function (runState) {
731
+ const [offset, byte] = runState.stack.popN(2);
732
+ const buf = bigIntToBytes(byte & BIGINT_255);
733
+ const offsetNum = Number(offset);
734
+ runState.memory.write(offsetNum, 1, buf);
735
+ },
736
+ ],
737
+ // 0x54: SLOAD
738
+ [
739
+ 0x54,
740
+ async function (runState) {
741
+ const key = runState.stack.pop();
742
+ const keyBuf = setLengthLeft(bigIntToBytes(key), 32);
743
+ const value = await runState.interpreter.storageLoad(keyBuf);
744
+ const valueBigInt = value.length ? bytesToBigInt(value) : BIGINT_0;
745
+ runState.stack.push(valueBigInt);
746
+ },
747
+ ],
748
+ // 0x55: SSTORE
749
+ [
750
+ 0x55,
751
+ async function (runState) {
752
+ const [key, val] = runState.stack.popN(2);
753
+ const keyBuf = setLengthLeft(bigIntToBytes(key), 32);
754
+ // NOTE: this should be the shortest representation
755
+ let value;
756
+ if (val === BIGINT_0) {
757
+ value = Uint8Array.from([]);
758
+ }
759
+ else {
760
+ value = bigIntToBytes(val);
761
+ }
762
+ await runState.interpreter.storageStore(keyBuf, value);
763
+ },
764
+ ],
765
+ // 0x56: JUMP
766
+ [
767
+ 0x56,
768
+ function (runState) {
769
+ const dest = runState.stack.pop();
770
+ if (dest > runState.interpreter.getCodeSize()) {
771
+ trap(EVMError.errorMessages.INVALID_JUMP + ' at ' + describeLocation(runState));
772
+ }
773
+ const destNum = Number(dest);
774
+ if (!jumpIsValid(runState, destNum)) {
775
+ trap(EVMError.errorMessages.INVALID_JUMP + ' at ' + describeLocation(runState));
776
+ }
777
+ runState.programCounter = destNum;
778
+ },
779
+ ],
780
+ // 0x57: JUMPI
781
+ [
782
+ 0x57,
783
+ function (runState) {
784
+ const [dest, cond] = runState.stack.popN(2);
785
+ if (cond !== BIGINT_0) {
786
+ if (dest > runState.interpreter.getCodeSize()) {
787
+ trap(EVMError.errorMessages.INVALID_JUMP + ' at ' + describeLocation(runState));
788
+ }
789
+ const destNum = Number(dest);
790
+ if (!jumpIsValid(runState, destNum)) {
791
+ trap(EVMError.errorMessages.INVALID_JUMP + ' at ' + describeLocation(runState));
792
+ }
793
+ runState.programCounter = destNum;
794
+ }
795
+ },
796
+ ],
797
+ // 0x58: PC
798
+ [
799
+ 0x58,
800
+ function (runState) {
801
+ runState.stack.push(BigInt(runState.programCounter - 1));
802
+ },
803
+ ],
804
+ // 0x59: MSIZE
805
+ [
806
+ 0x59,
807
+ function (runState) {
808
+ runState.stack.push(runState.memoryWordCount * BIGINT_32);
809
+ },
810
+ ],
811
+ // 0x5a: GAS
812
+ [
813
+ 0x5a,
814
+ function (runState) {
815
+ runState.stack.push(runState.interpreter.getGasLeft());
816
+ },
817
+ ],
818
+ // 0x5b: JUMPDEST
819
+ [0x5b, function () { }],
820
+ // 0x5c: TLOAD (EIP 1153)
821
+ [
822
+ 0x5c,
823
+ function (runState) {
824
+ const key = runState.stack.pop();
825
+ const keyBuf = setLengthLeft(bigIntToBytes(key), 32);
826
+ const value = runState.interpreter.transientStorageLoad(keyBuf);
827
+ const valueBN = value.length ? bytesToBigInt(value) : BIGINT_0;
828
+ runState.stack.push(valueBN);
829
+ },
830
+ ],
831
+ // 0x5d: TSTORE (EIP 1153)
832
+ [
833
+ 0x5d,
834
+ function (runState) {
835
+ // TSTORE
836
+ if (runState.interpreter.isStatic()) {
837
+ trap(EVMError.errorMessages.STATIC_STATE_CHANGE);
838
+ }
839
+ const [key, val] = runState.stack.popN(2);
840
+ const keyBuf = setLengthLeft(bigIntToBytes(key), 32);
841
+ // NOTE: this should be the shortest representation
842
+ let value;
843
+ if (val === BIGINT_0) {
844
+ value = Uint8Array.from([]);
845
+ }
846
+ else {
847
+ value = bigIntToBytes(val);
848
+ }
849
+ runState.interpreter.transientStorageStore(keyBuf, value);
850
+ },
851
+ ],
852
+ // 0x5e: MCOPY (5656)
853
+ [
854
+ 0x5e,
855
+ function (runState) {
856
+ const [dst, src, length] = runState.stack.popN(3);
857
+ const data = runState.memory.read(Number(src), Number(length), true);
858
+ runState.memory.write(Number(dst), Number(length), data);
859
+ },
860
+ ],
861
+ // 0x5f: PUSH0
862
+ [
863
+ 0x5f,
864
+ function (runState) {
865
+ runState.stack.push(BIGINT_0);
866
+ },
867
+ ],
868
+ // 0x60: PUSH
869
+ [
870
+ 0x60,
871
+ function (runState, common) {
872
+ const numToPush = runState.opCode - 0x5f;
873
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
874
+ runState.env.chargeCodeAccesses === true) {
875
+ const contract = runState.interpreter.getAddress();
876
+ const startOffset = Math.min(runState.code.length, runState.programCounter + 1);
877
+ const endOffset = Math.min(runState.code.length, startOffset + numToPush - 1);
878
+ const statelessGas = runState.env.accessWitness.readAccountCodeChunks(contract, startOffset, endOffset);
879
+ runState.interpreter.useGas(statelessGas, `PUSH`);
880
+ }
881
+ if (!runState.shouldDoJumpAnalysis) {
882
+ runState.stack.push(runState.cachedPushes[runState.programCounter]);
883
+ runState.programCounter += numToPush;
884
+ }
885
+ else {
886
+ let loadedBytes = runState.code.subarray(runState.programCounter, runState.programCounter + numToPush);
887
+ if (loadedBytes.length < numToPush) {
888
+ loadedBytes = setLengthRight(loadedBytes, numToPush);
889
+ }
890
+ runState.programCounter += numToPush;
891
+ runState.stack.push(bytesToBigInt(loadedBytes));
892
+ }
893
+ },
894
+ ],
895
+ // 0x80: DUP
896
+ [
897
+ 0x80,
898
+ function (runState) {
899
+ const stackPos = runState.opCode - 0x7f;
900
+ runState.stack.dup(stackPos);
901
+ },
902
+ ],
903
+ // 0x90: SWAP
904
+ [
905
+ 0x90,
906
+ function (runState) {
907
+ const stackPos = runState.opCode - 0x8f;
908
+ runState.stack.swap(stackPos);
909
+ },
910
+ ],
911
+ // 0xa0: LOG
912
+ [
913
+ 0xa0,
914
+ function (runState) {
915
+ const [memOffset, memLength] = runState.stack.popN(2);
916
+ const topicsCount = runState.opCode - 0xa0;
917
+ const topics = runState.stack.popN(topicsCount);
918
+ const topicsBuf = topics.map(function (a) {
919
+ return setLengthLeft(bigIntToBytes(a), 32);
920
+ });
921
+ let mem = new Uint8Array(0);
922
+ if (memLength !== BIGINT_0) {
923
+ mem = runState.memory.read(Number(memOffset), Number(memLength));
924
+ }
925
+ runState.interpreter.log(mem, topicsCount, topicsBuf);
926
+ },
927
+ ],
928
+ // 0xd0: DATALOAD
929
+ [
930
+ 0xd0,
931
+ function (runState) {
932
+ if (runState.env.eof === undefined) {
933
+ // Opcode not available in legacy contracts
934
+ trap(EVMError.errorMessages.INVALID_OPCODE);
935
+ }
936
+ const pos = runState.stack.pop();
937
+ if (pos > runState.env.eof.container.body.dataSection.length) {
938
+ runState.stack.push(BIGINT_0);
939
+ return;
940
+ }
941
+ const i = Number(pos);
942
+ let loaded = runState.env.eof.container.body.dataSection.subarray(i, i + 32);
943
+ loaded = loaded.length ? loaded : Uint8Array.from([0]);
944
+ let r = bytesToBigInt(loaded);
945
+ // Pad the loaded length with 0 bytes in case it is smaller than 32
946
+ if (loaded.length < 32) {
947
+ r = r << (BIGINT_8 * BigInt(32 - loaded.length));
948
+ }
949
+ runState.stack.push(r);
950
+ },
951
+ ],
952
+ // 0xd1: DATALOADN
953
+ [
954
+ 0xd1,
955
+ function (runState) {
956
+ if (runState.env.eof === undefined) {
957
+ // Opcode not available in legacy contracts
958
+ trap(EVMError.errorMessages.INVALID_OPCODE);
959
+ }
960
+ const toLoad = Number(bytesToBigInt(runState.code.subarray(runState.programCounter, runState.programCounter + 2)));
961
+ const data = bytesToBigInt(runState.env.eof.container.body.dataSection.subarray(toLoad, toLoad + 32));
962
+ runState.stack.push(data);
963
+ runState.programCounter += 2;
964
+ },
965
+ ],
966
+ // 0xd2: DATASIZE
967
+ [
968
+ 0xd2,
969
+ function (runState) {
970
+ if (runState.env.eof === undefined) {
971
+ // Opcode not available in legacy contracts
972
+ trap(EVMError.errorMessages.INVALID_OPCODE);
973
+ }
974
+ runState.stack.push(BigInt(runState.env.eof.container.body.dataSection.length));
975
+ },
976
+ ],
977
+ // 0xd3: DATACOPY
978
+ [
979
+ 0xd3,
980
+ function (runState) {
981
+ if (runState.env.eof === undefined) {
982
+ // Opcode not available in legacy contracts
983
+ trap(EVMError.errorMessages.INVALID_OPCODE);
984
+ }
985
+ const [memOffset, offset, size] = runState.stack.popN(3);
986
+ if (size !== BIGINT_0) {
987
+ const data = getDataSlice(runState.env.eof.container.body.dataSection, offset, size);
988
+ const memOffsetNum = Number(memOffset);
989
+ const dataLengthNum = Number(size);
990
+ runState.memory.write(memOffsetNum, dataLengthNum, data);
991
+ }
992
+ },
993
+ ],
994
+ // 0xe0: RJUMP
995
+ [
996
+ 0xe0,
997
+ function (runState) {
998
+ if (runState.env.eof === undefined) {
999
+ // Opcode not available in legacy contracts
1000
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1001
+ }
1002
+ else {
1003
+ const code = runState.env.code;
1004
+ const rjumpDest = new DataView(code.buffer).getInt16(runState.programCounter);
1005
+ runState.programCounter += 2 + rjumpDest;
1006
+ }
1007
+ },
1008
+ ],
1009
+ // 0xe1: RJUMPI
1010
+ [
1011
+ 0xe1,
1012
+ function (runState) {
1013
+ if (runState.env.eof === undefined) {
1014
+ // Opcode not available in legacy contracts
1015
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1016
+ }
1017
+ else {
1018
+ const cond = runState.stack.pop();
1019
+ // Move PC to the PC post instruction
1020
+ if (cond > 0) {
1021
+ const code = runState.env.code;
1022
+ const rjumpDest = new DataView(code.buffer).getInt16(runState.programCounter);
1023
+ runState.programCounter += rjumpDest;
1024
+ }
1025
+ // In all cases, increment PC with 2 (also in the case if `cond` is `0`)
1026
+ runState.programCounter += 2;
1027
+ }
1028
+ },
1029
+ ],
1030
+ // 0xe2: RJUMPV
1031
+ [
1032
+ 0xe2,
1033
+ function (runState) {
1034
+ if (runState.env.eof === undefined) {
1035
+ // Opcode not available in legacy contracts
1036
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1037
+ }
1038
+ else {
1039
+ const code = runState.env.code;
1040
+ const jumptableEntries = code[runState.programCounter];
1041
+ // Note: if the size of the immediate is `0`, this thus means that the actual size is `2`
1042
+ // This allows for 256 entries in the table instead of 255
1043
+ const jumptableSize = (jumptableEntries + 1) * 2;
1044
+ // Move PC to start of the jump table
1045
+ runState.programCounter += 1;
1046
+ const jumptableCase = runState.stack.pop();
1047
+ if (jumptableCase <= jumptableEntries) {
1048
+ const rjumpDest = new DataView(code.buffer).getInt16(runState.programCounter + Number(jumptableCase) * 2);
1049
+ runState.programCounter += jumptableSize + rjumpDest;
1050
+ }
1051
+ else {
1052
+ runState.programCounter += jumptableSize;
1053
+ }
1054
+ }
1055
+ },
1056
+ ],
1057
+ // 0xe3: CALLF
1058
+ [
1059
+ 0xe3,
1060
+ function (runState) {
1061
+ if (runState.env.eof === undefined) {
1062
+ // Opcode not available in legacy contracts
1063
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1064
+ }
1065
+ const sectionTarget = bytesToInt(runState.code.slice(runState.programCounter, runState.programCounter + 2));
1066
+ const stackItems = runState.stack.length;
1067
+ const typeSection = runState.env.eof.container.body.typeSections[sectionTarget];
1068
+ if (stackItems > 1024 - typeSection.maxStackHeight + typeSection.inputs) {
1069
+ trap(EOFErrorMessage.STACK_OVERFLOW);
1070
+ }
1071
+ if (runState.env.eof.eofRunState.returnStack.length >= 1024) {
1072
+ trap(EOFErrorMessage.RETURN_STACK_OVERFLOW);
1073
+ }
1074
+ runState.env.eof?.eofRunState.returnStack.push(runState.programCounter + 2);
1075
+ // Find out the opcode we should jump into
1076
+ runState.programCounter = runState.env.eof.container.header.getCodePosition(sectionTarget);
1077
+ },
1078
+ ],
1079
+ // 0xe4: RETF
1080
+ [
1081
+ 0xe4,
1082
+ function (runState) {
1083
+ if (runState.env.eof === undefined) {
1084
+ // Opcode not available in legacy contracts
1085
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1086
+ }
1087
+ const newPc = runState.env.eof.eofRunState.returnStack.pop();
1088
+ if (newPc === undefined) {
1089
+ // This should NEVER happen since it is validated that functions either terminate (the call frame) or return
1090
+ trap(EOFErrorMessage.RETF_NO_RETURN);
1091
+ }
1092
+ runState.programCounter = newPc;
1093
+ },
1094
+ ],
1095
+ // 0xe5: JUMPF
1096
+ [
1097
+ 0xe5,
1098
+ function (runState) {
1099
+ if (runState.env.eof === undefined) {
1100
+ // Opcode not available in legacy contracts
1101
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1102
+ }
1103
+ // NOTE: (and also TODO) this code is exactly the same as CALLF, except pushing to the return stack is now skipped
1104
+ // (and also the return stack overflow check)
1105
+ // It is commented out here
1106
+ const sectionTarget = bytesToInt(runState.code.slice(runState.programCounter, runState.programCounter + 2));
1107
+ const stackItems = runState.stack.length;
1108
+ const typeSection = runState.env.eof.container.body.typeSections[sectionTarget];
1109
+ if (stackItems > 1024 - typeSection.maxStackHeight + typeSection.inputs) {
1110
+ trap(EOFErrorMessage.STACK_OVERFLOW);
1111
+ }
1112
+ /*if (runState.env.eof!.eofRunState.returnStack.length >= 1024) {
1113
+ trap(EOFErrorMessage.ReturnStackOverflow)
1114
+ }
1115
+ runState.env.eof?.eofRunState.returnStack.push(runState.programCounter + 2)*/
1116
+ // Find out the opcode we should jump into
1117
+ runState.programCounter = runState.env.eof.container.header.getCodePosition(sectionTarget);
1118
+ },
1119
+ ],
1120
+ // 0xe6: DUPN
1121
+ [
1122
+ 0xe6,
1123
+ function (runState, common) {
1124
+ if (!common.isActivatedEIP(8024)) {
1125
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1126
+ }
1127
+ const immediate = readImmediateByteOrZero(runState);
1128
+ const toDup = decodeEIP8024SingleImmediate(immediate);
1129
+ runState.stack.dup(toDup);
1130
+ },
1131
+ ],
1132
+ // 0xe7: SWAPN
1133
+ [
1134
+ 0xe7,
1135
+ function (runState, common) {
1136
+ if (!common.isActivatedEIP(8024)) {
1137
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1138
+ }
1139
+ const immediate = readImmediateByteOrZero(runState);
1140
+ const toSwap = decodeEIP8024SingleImmediate(immediate);
1141
+ runState.stack.swap(toSwap);
1142
+ },
1143
+ ],
1144
+ // 0xe8: EXCHANGE
1145
+ [
1146
+ 0xe8,
1147
+ function (runState, common) {
1148
+ if (!common.isActivatedEIP(8024)) {
1149
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1150
+ }
1151
+ const immediate = readImmediateByteOrZero(runState);
1152
+ const [x, y] = decodeEIP8024PairImmediate(immediate);
1153
+ runState.stack.exchange(x, y);
1154
+ },
1155
+ ],
1156
+ // 0xec: EOFCREATE
1157
+ [
1158
+ 0xec,
1159
+ async function (runState) {
1160
+ if (runState.env.eof === undefined) {
1161
+ // Opcode not available in legacy contracts
1162
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1163
+ }
1164
+ else {
1165
+ if (runState.interpreter.isStatic()) {
1166
+ trap(EVMError.errorMessages.STATIC_STATE_CHANGE);
1167
+ }
1168
+ // Read container index
1169
+ const containerIndex = runState.env.code[runState.programCounter];
1170
+ const containerCode = runState.env.eof.container.body.containerSections[containerIndex];
1171
+ // Pop stack values
1172
+ const [value, salt, inputOffset, inputSize] = runState.stack.popN(4);
1173
+ const gasLimit = runState.messageGasLimit;
1174
+ runState.messageGasLimit = undefined;
1175
+ let data = new Uint8Array(0);
1176
+ if (inputSize !== BIGINT_0) {
1177
+ data = runState.memory.read(Number(inputOffset), Number(inputSize), true);
1178
+ }
1179
+ runState.programCounter++; // Jump over the immediate byte
1180
+ const ret = await runState.interpreter.eofcreate(gasLimit, value, containerCode, setLengthLeft(bigIntToBytes(salt), 32), data);
1181
+ runState.stack.push(ret);
1182
+ }
1183
+ },
1184
+ ],
1185
+ // 0xee: RETURNCONTRACT
1186
+ [
1187
+ 0xee,
1188
+ async function (runState) {
1189
+ if (runState.env.eof === undefined) {
1190
+ // Opcode not available in legacy contracts
1191
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1192
+ }
1193
+ else {
1194
+ // Read container index
1195
+ const containerIndex = runState.env.code[runState.programCounter];
1196
+ const containerCode = runState.env.eof.container.body.containerSections[containerIndex];
1197
+ // Read deployContainer as EOFCreate (initcode) container
1198
+ const deployContainer = new EOFContainer(containerCode, EOFContainerMode.Initmode);
1199
+ // Pop stack values
1200
+ const [auxDataOffset, auxDataSize] = runState.stack.popN(2);
1201
+ let auxData = new Uint8Array(0);
1202
+ if (auxDataSize !== BIGINT_0) {
1203
+ auxData = runState.memory.read(Number(auxDataOffset), Number(auxDataSize));
1204
+ }
1205
+ const originalDataSize = deployContainer.header.dataSize;
1206
+ const preDeployDataSectionSize = deployContainer.body.dataSection.length;
1207
+ const actualSectionSize = preDeployDataSectionSize + Number(auxDataSize);
1208
+ if (actualSectionSize < originalDataSize) {
1209
+ trap(EOFErrorMessage.INVALID_RETURN_CONTRACT_DATA_SIZE);
1210
+ }
1211
+ if (actualSectionSize > 0xffff) {
1212
+ // Data section size is now larger than the max data section size
1213
+ // Temp: trap OOG?
1214
+ trap(EVMError.errorMessages.OUT_OF_GAS);
1215
+ }
1216
+ const newSize = setLengthLeft(bigIntToBytes(BigInt(actualSectionSize)), 2);
1217
+ // Write the bytes to the containerCode
1218
+ const dataSizePtr = deployContainer.header.dataSizePtr;
1219
+ containerCode[dataSizePtr] = newSize[0];
1220
+ containerCode[dataSizePtr + 1] = newSize[1];
1221
+ const returnContainer = concatBytes(containerCode, auxData);
1222
+ runState.interpreter.finish(returnContainer);
1223
+ }
1224
+ },
1225
+ ],
1226
+ // '0xf0' range - closures
1227
+ // 0xf0: CREATE
1228
+ [
1229
+ 0xf0,
1230
+ async function (runState, common) {
1231
+ const [value, offset, length] = runState.stack.popN(3);
1232
+ if (common.isActivatedEIP(3860) &&
1233
+ length > Number(common.param('maxInitCodeSize')) &&
1234
+ !runState.interpreter._evm.allowUnlimitedInitCodeSize) {
1235
+ trap(EVMError.errorMessages.INITCODE_SIZE_VIOLATION);
1236
+ }
1237
+ const gasLimit = runState.messageGasLimit;
1238
+ runState.messageGasLimit = undefined;
1239
+ let data = new Uint8Array(0);
1240
+ if (length !== BIGINT_0) {
1241
+ data = runState.memory.read(Number(offset), Number(length), true);
1242
+ }
1243
+ if (isEOF(data)) {
1244
+ // Legacy cannot deploy EOF code
1245
+ runState.stack.push(BIGINT_0);
1246
+ return;
1247
+ }
1248
+ const ret = await runState.interpreter.create(gasLimit, value, data);
1249
+ runState.stack.push(ret);
1250
+ },
1251
+ ],
1252
+ // 0xf5: CREATE2
1253
+ [
1254
+ 0xf5,
1255
+ async function (runState, common) {
1256
+ if (runState.interpreter.isStatic()) {
1257
+ trap(EVMError.errorMessages.STATIC_STATE_CHANGE);
1258
+ }
1259
+ const [value, offset, length, salt] = runState.stack.popN(4);
1260
+ if (common.isActivatedEIP(3860) &&
1261
+ length > Number(common.param('maxInitCodeSize')) &&
1262
+ !runState.interpreter._evm.allowUnlimitedInitCodeSize) {
1263
+ trap(EVMError.errorMessages.INITCODE_SIZE_VIOLATION);
1264
+ }
1265
+ const gasLimit = runState.messageGasLimit;
1266
+ runState.messageGasLimit = undefined;
1267
+ let data = new Uint8Array(0);
1268
+ if (length !== BIGINT_0) {
1269
+ data = runState.memory.read(Number(offset), Number(length), true);
1270
+ }
1271
+ if (isEOF(data)) {
1272
+ // Legacy cannot deploy EOF code
1273
+ runState.stack.push(BIGINT_0);
1274
+ return;
1275
+ }
1276
+ const ret = await runState.interpreter.create2(gasLimit, value, data, setLengthLeft(bigIntToBytes(salt), 32));
1277
+ runState.stack.push(ret);
1278
+ },
1279
+ ],
1280
+ // 0xf1: CALL
1281
+ [
1282
+ 0xf1,
1283
+ async function (runState, common) {
1284
+ const [_currentGasLimit, toAddr, value, inOffset, inLength, outOffset, outLength] = runState.stack.popN(7);
1285
+ const toAddress = createAddressFromStackBigInt(toAddr);
1286
+ let data = new Uint8Array(0);
1287
+ if (inLength !== BIGINT_0) {
1288
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1289
+ }
1290
+ let gasLimit = runState.messageGasLimit;
1291
+ if (value !== BIGINT_0) {
1292
+ const callStipend = common.param('callStipendGas');
1293
+ runState.interpreter.addStipend(callStipend);
1294
+ gasLimit += callStipend;
1295
+ }
1296
+ runState.messageGasLimit = undefined;
1297
+ const ret = await runState.interpreter.call(gasLimit, toAddress, value, data);
1298
+ // Write return data to memory
1299
+ writeCallOutput(runState, outOffset, outLength);
1300
+ runState.stack.push(ret);
1301
+ },
1302
+ ],
1303
+ // 0xf2: CALLCODE
1304
+ [
1305
+ 0xf2,
1306
+ async function (runState, common) {
1307
+ const [_currentGasLimit, toAddr, value, inOffset, inLength, outOffset, outLength] = runState.stack.popN(7);
1308
+ const toAddress = createAddressFromStackBigInt(toAddr);
1309
+ let gasLimit = runState.messageGasLimit;
1310
+ if (value !== BIGINT_0) {
1311
+ const callStipend = common.param('callStipendGas');
1312
+ runState.interpreter.addStipend(callStipend);
1313
+ gasLimit += callStipend;
1314
+ }
1315
+ runState.messageGasLimit = undefined;
1316
+ let data = new Uint8Array(0);
1317
+ if (inLength !== BIGINT_0) {
1318
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1319
+ }
1320
+ const ret = await runState.interpreter.callCode(gasLimit, toAddress, value, data);
1321
+ // Write return data to memory
1322
+ writeCallOutput(runState, outOffset, outLength);
1323
+ runState.stack.push(ret);
1324
+ },
1325
+ ],
1326
+ // 0xf4: DELEGATECALL
1327
+ [
1328
+ 0xf4,
1329
+ async function (runState) {
1330
+ const value = runState.interpreter.getCallValue();
1331
+ const [_currentGasLimit, toAddr, inOffset, inLength, outOffset, outLength] = runState.stack.popN(6);
1332
+ const toAddress = createAddressFromStackBigInt(toAddr);
1333
+ let data = new Uint8Array(0);
1334
+ if (inLength !== BIGINT_0) {
1335
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1336
+ }
1337
+ const gasLimit = runState.messageGasLimit;
1338
+ runState.messageGasLimit = undefined;
1339
+ const ret = await runState.interpreter.callDelegate(gasLimit, toAddress, value, data);
1340
+ // Write return data to memory
1341
+ writeCallOutput(runState, outOffset, outLength);
1342
+ runState.stack.push(ret);
1343
+ },
1344
+ ],
1345
+ // 0xf7: RETURNDATALOAD
1346
+ [
1347
+ 0xf7,
1348
+ function (runState) {
1349
+ if (runState.env.eof === undefined) {
1350
+ // Opcode not available in legacy contracts
1351
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1352
+ }
1353
+ const pos = runState.stack.pop();
1354
+ if (pos > runState.interpreter.getReturnDataSize()) {
1355
+ runState.stack.push(BIGINT_0);
1356
+ return;
1357
+ }
1358
+ const i = Number(pos);
1359
+ let loaded = runState.interpreter.getReturnData().subarray(i, i + 32);
1360
+ loaded = loaded.length ? loaded : Uint8Array.from([0]);
1361
+ let r = bytesToBigInt(loaded);
1362
+ if (loaded.length < 32) {
1363
+ r = r << (BIGINT_8 * BigInt(32 - loaded.length));
1364
+ }
1365
+ runState.stack.push(r);
1366
+ },
1367
+ ],
1368
+ // 0xf8: EXTCALL
1369
+ [
1370
+ 0xf8,
1371
+ async function (runState) {
1372
+ if (runState.env.eof === undefined) {
1373
+ // Opcode not available in legacy contracts
1374
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1375
+ }
1376
+ else {
1377
+ const [toAddr, inOffset, inLength, value] = runState.stack.popN(4);
1378
+ const gasLimit = runState.messageGasLimit;
1379
+ runState.messageGasLimit = undefined;
1380
+ if (gasLimit === -BIGINT_1) {
1381
+ // Special case, abort doing any logic (this logic is defined in `gas.ts`), and put `1` on stack per spec
1382
+ runState.stack.push(BIGINT_1);
1383
+ runState.returnBytes = new Uint8Array(0);
1384
+ return;
1385
+ }
1386
+ const toAddress = createAddressFromStackBigInt(toAddr);
1387
+ let data = new Uint8Array(0);
1388
+ if (inLength !== BIGINT_0) {
1389
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1390
+ }
1391
+ const ret = await runState.interpreter.call(gasLimit, toAddress, value, data);
1392
+ // Write return data to memory
1393
+ runState.stack.push(ret);
1394
+ }
1395
+ },
1396
+ ],
1397
+ // 0xf9: EXTDELEGATECALL
1398
+ [
1399
+ 0xf9,
1400
+ async function (runState) {
1401
+ if (runState.env.eof === undefined) {
1402
+ // Opcode not available in legacy contracts
1403
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1404
+ }
1405
+ else {
1406
+ const value = runState.interpreter.getCallValue();
1407
+ const [toAddr, inOffset, inLength] = runState.stack.popN(3);
1408
+ const gasLimit = runState.messageGasLimit;
1409
+ runState.messageGasLimit = undefined;
1410
+ if (gasLimit === -BIGINT_1) {
1411
+ // Special case, abort doing any logic (this logic is defined in `gas.ts`), and put `1` on stack per spec
1412
+ runState.stack.push(BIGINT_1);
1413
+ runState.returnBytes = new Uint8Array(0);
1414
+ return;
1415
+ }
1416
+ const toAddress = createAddressFromStackBigInt(toAddr);
1417
+ const code = await runState.stateManager.getCode(toAddress);
1418
+ if (!isEOF(code)) {
1419
+ // EXTDELEGATECALL cannot call legacy contracts
1420
+ runState.stack.push(BIGINT_1);
1421
+ runState.returnBytes = new Uint8Array(0);
1422
+ return;
1423
+ }
1424
+ let data = new Uint8Array(0);
1425
+ if (inLength !== BIGINT_0) {
1426
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1427
+ }
1428
+ const ret = await runState.interpreter.callDelegate(gasLimit, toAddress, value, data);
1429
+ runState.stack.push(ret);
1430
+ }
1431
+ },
1432
+ ],
1433
+ // 0xfa: STATICCALL
1434
+ [
1435
+ 0xfa,
1436
+ async function (runState) {
1437
+ const value = BIGINT_0;
1438
+ const [_currentGasLimit, toAddr, inOffset, inLength, outOffset, outLength] = runState.stack.popN(6);
1439
+ const toAddress = createAddressFromStackBigInt(toAddr);
1440
+ const gasLimit = runState.messageGasLimit;
1441
+ runState.messageGasLimit = undefined;
1442
+ let data = new Uint8Array(0);
1443
+ if (inLength !== BIGINT_0) {
1444
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1445
+ }
1446
+ const ret = await runState.interpreter.callStatic(gasLimit, toAddress, value, data);
1447
+ // Write return data to memory
1448
+ writeCallOutput(runState, outOffset, outLength);
1449
+ runState.stack.push(ret);
1450
+ },
1451
+ ],
1452
+ // 0xfb: EXTSTATICCALL
1453
+ [
1454
+ 0xfb,
1455
+ async function (runState) {
1456
+ if (runState.env.eof === undefined) {
1457
+ // Opcode not available in legacy contracts
1458
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1459
+ }
1460
+ else {
1461
+ const value = BIGINT_0;
1462
+ const [toAddr, inOffset, inLength] = runState.stack.popN(3);
1463
+ const gasLimit = runState.messageGasLimit;
1464
+ runState.messageGasLimit = undefined;
1465
+ if (gasLimit === -BIGINT_1) {
1466
+ // Special case, abort doing any logic (this logic is defined in `gas.ts`), and put `1` on stack per spec
1467
+ runState.stack.push(BIGINT_1);
1468
+ runState.returnBytes = new Uint8Array(0);
1469
+ return;
1470
+ }
1471
+ const toAddress = createAddressFromStackBigInt(toAddr);
1472
+ let data = new Uint8Array(0);
1473
+ if (inLength !== BIGINT_0) {
1474
+ data = runState.memory.read(Number(inOffset), Number(inLength), true);
1475
+ }
1476
+ const ret = await runState.interpreter.callStatic(gasLimit, toAddress, value, data);
1477
+ runState.stack.push(ret);
1478
+ }
1479
+ },
1480
+ ],
1481
+ // 0xf3: RETURN
1482
+ [
1483
+ 0xf3,
1484
+ function (runState) {
1485
+ const [offset, length] = runState.stack.popN(2);
1486
+ let returnData = new Uint8Array(0);
1487
+ if (length !== BIGINT_0) {
1488
+ returnData = runState.memory.read(Number(offset), Number(length));
1489
+ }
1490
+ runState.interpreter.finish(returnData);
1491
+ },
1492
+ ],
1493
+ // 0xfd: REVERT
1494
+ [
1495
+ 0xfd,
1496
+ function (runState) {
1497
+ const [offset, length] = runState.stack.popN(2);
1498
+ let returnData = new Uint8Array(0);
1499
+ if (length !== BIGINT_0) {
1500
+ returnData = runState.memory.read(Number(offset), Number(length));
1501
+ }
1502
+ runState.interpreter.revert(returnData);
1503
+ },
1504
+ ],
1505
+ // '0x70', range - other
1506
+ // 0xff: SELFDESTRUCT
1507
+ [
1508
+ 0xff,
1509
+ async function (runState) {
1510
+ const selfdestructToAddressBigInt = runState.stack.pop();
1511
+ const selfdestructToAddress = createAddressFromStackBigInt(selfdestructToAddressBigInt);
1512
+ return runState.interpreter.selfDestruct(selfdestructToAddress);
1513
+ },
1514
+ ],
1515
+ // EIP-8141: Frame Transaction opcodes
1516
+ // 0xaa: APPROVE
1517
+ [
1518
+ 0xaa,
1519
+ async function (runState) {
1520
+ const scope = runState.stack.pop();
1521
+ const evm = runState.interpreter._evm;
1522
+ const fctx = evm.frameExecutionContext;
1523
+ if (fctx === undefined) {
1524
+ return trap(EVMError.errorMessages.REVERT);
1525
+ }
1526
+ const { tx, state } = fctx;
1527
+ const address = runState.env.address;
1528
+ const currentFrame = state.parsedFrames[state.currentFrameIndex];
1529
+ const frameTarget = currentFrame.target ?? tx.sender;
1530
+ if (!equalsBytes(address.bytes, frameTarget.bytes)) {
1531
+ trap(EVMError.errorMessages.REVERT);
1532
+ }
1533
+ if (scope === BIGINT_0) {
1534
+ if (state.senderApproved)
1535
+ trap(EVMError.errorMessages.REVERT);
1536
+ if (!equalsBytes(frameTarget.bytes, tx.sender.bytes)) {
1537
+ trap(EVMError.errorMessages.REVERT);
1538
+ }
1539
+ state.senderApproved = true;
1540
+ }
1541
+ else if (scope === BIGINT_1) {
1542
+ if (state.payerApproved)
1543
+ trap(EVMError.errorMessages.REVERT);
1544
+ if (!state.senderApproved)
1545
+ trap(EVMError.errorMessages.REVERT);
1546
+ let account = await runState.stateManager.getAccount(frameTarget);
1547
+ if (account === undefined)
1548
+ account = new Account();
1549
+ if (account.balance < state.totalGasCost + state.totalBlobGasCost) {
1550
+ trap(EVMError.errorMessages.REVERT);
1551
+ }
1552
+ account.nonce += BIGINT_1;
1553
+ account.balance -= state.totalGasCost + state.totalBlobGasCost;
1554
+ await runState.stateManager.putAccount(frameTarget, account);
1555
+ state.payerApproved = true;
1556
+ state.payer = frameTarget;
1557
+ }
1558
+ else if (scope === BIGINT_2) {
1559
+ if (state.senderApproved || state.payerApproved) {
1560
+ trap(EVMError.errorMessages.REVERT);
1561
+ }
1562
+ if (!equalsBytes(frameTarget.bytes, tx.sender.bytes)) {
1563
+ trap(EVMError.errorMessages.REVERT);
1564
+ }
1565
+ let account = await runState.stateManager.getAccount(frameTarget);
1566
+ if (account === undefined)
1567
+ account = new Account();
1568
+ if (account.balance < state.totalGasCost + state.totalBlobGasCost) {
1569
+ trap(EVMError.errorMessages.REVERT);
1570
+ }
1571
+ state.senderApproved = true;
1572
+ account.nonce += BIGINT_1;
1573
+ account.balance -= state.totalGasCost + state.totalBlobGasCost;
1574
+ await runState.stateManager.putAccount(frameTarget, account);
1575
+ state.payerApproved = true;
1576
+ state.payer = frameTarget;
1577
+ }
1578
+ else {
1579
+ trap(EVMError.errorMessages.REVERT);
1580
+ }
1581
+ state.approveCalledInCurrentFrame = true;
1582
+ runState.interpreter.finish(new Uint8Array(0));
1583
+ },
1584
+ ],
1585
+ // 0xb0: TXPARAM
1586
+ [
1587
+ 0xb0,
1588
+ function (runState) {
1589
+ const [param, in2] = runState.stack.popN(2);
1590
+ const evm = runState.interpreter._evm;
1591
+ const fctx = evm.frameExecutionContext;
1592
+ if (fctx === undefined) {
1593
+ return trap(EVMError.errorMessages.INVALID_OPCODE);
1594
+ }
1595
+ const { tx, state } = fctx;
1596
+ const paramNum = Number(param);
1597
+ switch (paramNum) {
1598
+ case 0x00:
1599
+ if (in2 !== BIGINT_0)
1600
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1601
+ runState.stack.push(BigInt(tx.type));
1602
+ break;
1603
+ case 0x01:
1604
+ if (in2 !== BIGINT_0)
1605
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1606
+ runState.stack.push(tx.nonce);
1607
+ break;
1608
+ case 0x02:
1609
+ if (in2 !== BIGINT_0)
1610
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1611
+ runState.stack.push(bytesToBigInt(tx.sender.bytes));
1612
+ break;
1613
+ case 0x03:
1614
+ if (in2 !== BIGINT_0)
1615
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1616
+ runState.stack.push(tx.maxPriorityFeePerGas);
1617
+ break;
1618
+ case 0x04:
1619
+ if (in2 !== BIGINT_0)
1620
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1621
+ runState.stack.push(tx.maxFeePerGas);
1622
+ break;
1623
+ case 0x05:
1624
+ if (in2 !== BIGINT_0)
1625
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1626
+ runState.stack.push(tx.maxFeePerBlobGas);
1627
+ break;
1628
+ case 0x06:
1629
+ if (in2 !== BIGINT_0)
1630
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1631
+ runState.stack.push(state.totalGasCost + state.totalBlobGasCost);
1632
+ break;
1633
+ case 0x07:
1634
+ if (in2 !== BIGINT_0)
1635
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1636
+ runState.stack.push(BigInt(tx.blobVersionedHashes.length));
1637
+ break;
1638
+ case 0x08:
1639
+ if (in2 !== BIGINT_0)
1640
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1641
+ runState.stack.push(bytesToBigInt(tx.getHashedMessageToSign()));
1642
+ break;
1643
+ case 0x09:
1644
+ if (in2 !== BIGINT_0)
1645
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1646
+ runState.stack.push(BigInt(state.parsedFrames.length));
1647
+ break;
1648
+ case 0x10:
1649
+ if (in2 !== BIGINT_0)
1650
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1651
+ runState.stack.push(BigInt(state.currentFrameIndex));
1652
+ break;
1653
+ case 0x11: {
1654
+ const idx = Number(in2);
1655
+ if (idx >= state.parsedFrames.length)
1656
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1657
+ const t = state.parsedFrames[idx].target;
1658
+ runState.stack.push(t !== null ? bytesToBigInt(t.bytes) : bytesToBigInt(tx.sender.bytes));
1659
+ break;
1660
+ }
1661
+ case 0x12: {
1662
+ const idx = Number(in2);
1663
+ if (idx >= state.parsedFrames.length)
1664
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1665
+ runState.stack.push(state.parsedFrames[idx].gasLimit);
1666
+ break;
1667
+ }
1668
+ case 0x13: {
1669
+ const idx = Number(in2);
1670
+ if (idx >= state.parsedFrames.length)
1671
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1672
+ runState.stack.push(BigInt(state.parsedFrames[idx].mode));
1673
+ break;
1674
+ }
1675
+ case 0x14: {
1676
+ const idx = Number(in2);
1677
+ if (idx >= state.parsedFrames.length)
1678
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1679
+ const frame = state.parsedFrames[idx];
1680
+ if (frame.mode === 1) {
1681
+ runState.stack.push(BIGINT_0);
1682
+ }
1683
+ else {
1684
+ runState.stack.push(BigInt(frame.data.length));
1685
+ }
1686
+ break;
1687
+ }
1688
+ case 0x15: {
1689
+ const idx = Number(in2);
1690
+ if (idx >= state.parsedFrames.length)
1691
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1692
+ if (idx >= state.currentFrameIndex)
1693
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1694
+ const fr = state.frameResults[idx];
1695
+ if (fr === undefined)
1696
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1697
+ runState.stack.push(BigInt(fr.status));
1698
+ break;
1699
+ }
1700
+ default:
1701
+ trap(EVMError.errorMessages.INVALID_OPCODE);
1702
+ }
1703
+ },
1704
+ ],
1705
+ // 0xb1: FRAMEDATALOAD
1706
+ [
1707
+ 0xb1,
1708
+ function (runState) {
1709
+ const [offset, frameIndex] = runState.stack.popN(2);
1710
+ const evm = runState.interpreter._evm;
1711
+ const fctx = evm.frameExecutionContext;
1712
+ if (fctx === undefined)
1713
+ return trap(EVMError.errorMessages.INVALID_OPCODE);
1714
+ const { state } = fctx;
1715
+ const idx = Number(frameIndex);
1716
+ if (idx >= state.parsedFrames.length)
1717
+ return trap(EVMError.errorMessages.INVALID_OPCODE);
1718
+ const frame = state.parsedFrames[idx];
1719
+ if (frame.mode === 1) {
1720
+ runState.stack.push(BIGINT_0);
1721
+ return;
1722
+ }
1723
+ const i = Number(offset);
1724
+ let loaded = frame.data.subarray(i, i + 32);
1725
+ loaded = loaded.length > 0 ? loaded : Uint8Array.from([0]);
1726
+ let r = bytesToBigInt(loaded);
1727
+ if (loaded.length < 32) {
1728
+ r = r << (BIGINT_8 * BigInt(32 - loaded.length));
1729
+ }
1730
+ runState.stack.push(r);
1731
+ },
1732
+ ],
1733
+ // 0xb2: FRAMEDATACOPY
1734
+ [
1735
+ 0xb2,
1736
+ function (runState) {
1737
+ const [memOffset, dataOffset, length, frameIndex] = runState.stack.popN(4);
1738
+ const evm = runState.interpreter._evm;
1739
+ const fctx = evm.frameExecutionContext;
1740
+ if (fctx === undefined)
1741
+ return trap(EVMError.errorMessages.INVALID_OPCODE);
1742
+ const { state } = fctx;
1743
+ const idx = Number(frameIndex);
1744
+ if (idx >= state.parsedFrames.length)
1745
+ return trap(EVMError.errorMessages.INVALID_OPCODE);
1746
+ const frame = state.parsedFrames[idx];
1747
+ if (frame.mode === 1 || length === BIGINT_0) {
1748
+ return;
1749
+ }
1750
+ const data = getDataSlice(frame.data, dataOffset, length);
1751
+ const memOffsetNum = Number(memOffset);
1752
+ const lengthNum = Number(length);
1753
+ runState.memory.extend(memOffsetNum, lengthNum);
1754
+ runState.memory.write(memOffsetNum, lengthNum, data);
1755
+ },
1756
+ ],
1757
+ ]);
1758
+ // Fill in rest of PUSHn, DUPn, SWAPn, LOGn for handlers
1759
+ const pushFn = handlers.get(0x60);
1760
+ for (let i = 0x61; i <= 0x7f; i++) {
1761
+ handlers.set(i, pushFn);
1762
+ }
1763
+ const dupFn = handlers.get(0x80);
1764
+ for (let i = 0x81; i <= 0x8f; i++) {
1765
+ handlers.set(i, dupFn);
1766
+ }
1767
+ const swapFn = handlers.get(0x90);
1768
+ for (let i = 0x91; i <= 0x9f; i++) {
1769
+ handlers.set(i, swapFn);
1770
+ }
1771
+ const logFn = handlers.get(0xa0);
1772
+ for (let i = 0xa1; i <= 0xa4; i++) {
1773
+ handlers.set(i, logFn);
1774
+ }
1775
+ //# sourceMappingURL=functions.js.map