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