@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,1016 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dynamicGasHandlers = void 0;
4
+ const common_1 = require("@feelyourprotocol/common");
5
+ const util_1 = require("@feelyourprotocol/util");
6
+ const errors_ts_1 = require("../eof/errors.js");
7
+ const errors_ts_2 = require("../errors.js");
8
+ const types_ts_1 = require("../types.js");
9
+ const EIP1283_ts_1 = require("./EIP1283.js");
10
+ const EIP2200_ts_1 = require("./EIP2200.js");
11
+ const EIP2929_ts_1 = require("./EIP2929.js");
12
+ const util_ts_1 = require("./util.js");
13
+ const EXTCALL_TARGET_MAX = BigInt(2) ** BigInt(8 * 20) - BigInt(1);
14
+ /**
15
+ * Gets the gas cost for EIP-7702 delegation lookup WITHOUT side effects.
16
+ * Returns the gas cost and delegation address so callers can check gas
17
+ * availability before committing to the access.
18
+ */
19
+ async function eip7702GetAccessCost(runState, common, address, charge2929Gas) {
20
+ const code = await runState.stateManager.getCode(address);
21
+ if ((0, util_1.equalsBytes)(code.slice(0, 3), types_ts_1.DELEGATION_7702_FLAG)) {
22
+ const delegationAddress = code.slice(3, 24);
23
+ // Just get the cost, don't warm yet
24
+ const gas = (0, EIP2929_ts_1.getAddressAccessCost)(runState, delegationAddress, common, charge2929Gas);
25
+ return { gas, delegationAddress };
26
+ }
27
+ return { gas: util_1.BIGINT_0, delegationAddress: null };
28
+ }
29
+ /**
30
+ * Warms the delegation address for EIP-7702 (call after verifying sufficient gas).
31
+ */
32
+ function eip7702WarmAddress(runState, delegationAddress) {
33
+ (0, EIP2929_ts_1.warmAddress)(runState, delegationAddress);
34
+ }
35
+ exports.dynamicGasHandlers = new Map([
36
+ [
37
+ /* EXP */
38
+ 0x0a,
39
+ async function (runState, gas, common) {
40
+ const [_base, exponent] = runState.stack.peek(2);
41
+ if (exponent === util_1.BIGINT_0) {
42
+ return gas;
43
+ }
44
+ let byteLength = exponent.toString(2).length / 8;
45
+ if (byteLength > Math.trunc(byteLength)) {
46
+ byteLength = Math.trunc(byteLength) + 1;
47
+ }
48
+ if (byteLength < 1 || byteLength > 32) {
49
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_RANGE);
50
+ }
51
+ const expPricePerByte = common.param('expByteGas');
52
+ gas += BigInt(byteLength) * expPricePerByte;
53
+ return gas;
54
+ },
55
+ ],
56
+ [
57
+ /* KECCAK256 */
58
+ 0x20,
59
+ async function (runState, gas, common) {
60
+ const [offset, length] = runState.stack.peek(2);
61
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, length, common);
62
+ gas += common.param('keccak256WordGas') * (0, util_ts_1.divCeil)(length, util_1.BIGINT_32);
63
+ return gas;
64
+ },
65
+ ],
66
+ [
67
+ /* BALANCE */
68
+ 0x31,
69
+ async function (runState, gas, common) {
70
+ const address = (0, util_ts_1.createAddressFromStackBigInt)(runState.stack.peek()[0]);
71
+ let charge2929Gas = true;
72
+ if (common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) {
73
+ const coldAccessGas = runState.env.accessWitness.readAccountBasicData(address);
74
+ gas += coldAccessGas;
75
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
76
+ }
77
+ if (common.isActivatedEIP(2929)) {
78
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, address.bytes, common, charge2929Gas);
79
+ }
80
+ return gas;
81
+ },
82
+ ],
83
+ [
84
+ /* CALLDATACOPY */
85
+ 0x37,
86
+ async function (runState, gas, common) {
87
+ const [memOffset, _dataOffset, dataLength] = runState.stack.peek(3);
88
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
89
+ if (dataLength !== util_1.BIGINT_0) {
90
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
91
+ }
92
+ return gas;
93
+ },
94
+ ],
95
+ [
96
+ /* CODECOPY */
97
+ 0x39,
98
+ async function (runState, gas, common) {
99
+ const [memOffset, _codeOffset, dataLength] = runState.stack.peek(3);
100
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
101
+ if (dataLength !== util_1.BIGINT_0) {
102
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
103
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
104
+ runState.env.chargeCodeAccesses === true) {
105
+ const contract = runState.interpreter.getAddress();
106
+ let codeEnd = _codeOffset + dataLength;
107
+ const codeSize = runState.interpreter.getCodeSize();
108
+ if (codeEnd > codeSize) {
109
+ codeEnd = codeSize;
110
+ }
111
+ gas += runState.env.accessWitness.readAccountCodeChunks(contract, Number(_codeOffset), Number(codeEnd));
112
+ }
113
+ }
114
+ return gas;
115
+ },
116
+ ],
117
+ [
118
+ /* EXTCODESIZE */
119
+ 0x3b,
120
+ async function (runState, gas, common) {
121
+ const address = (0, util_ts_1.createAddressFromStackBigInt)(runState.stack.peek()[0]);
122
+ let charge2929Gas = true;
123
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
124
+ runState.interpreter._evm.getPrecompile(address) === undefined &&
125
+ !address.equals((0, util_ts_1.createAddressFromStackBigInt)(common.param('systemAddress')))) {
126
+ let coldAccessGas = util_1.BIGINT_0;
127
+ coldAccessGas += runState.env.accessWitness.readAccountBasicData(address);
128
+ gas += coldAccessGas;
129
+ // if cold access gas has been charged 2929 gas shouldn't be charged
130
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
131
+ }
132
+ if (common.isActivatedEIP(2929)) {
133
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, address.bytes, common, charge2929Gas);
134
+ }
135
+ return gas;
136
+ },
137
+ ],
138
+ [
139
+ /* EXTCODECOPY */
140
+ 0x3c,
141
+ async function (runState, gas, common) {
142
+ const [addressBigInt, memOffset, _codeOffset, dataLength] = runState.stack.peek(4);
143
+ const address = (0, util_ts_1.createAddressFromStackBigInt)(addressBigInt);
144
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
145
+ let charge2929Gas = true;
146
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
147
+ runState.interpreter._evm.getPrecompile(address) === undefined &&
148
+ !address.equals((0, util_ts_1.createAddressFromStackBigInt)(common.param('systemAddress')))) {
149
+ let coldAccessGas = util_1.BIGINT_0;
150
+ coldAccessGas += runState.env.accessWitness.readAccountBasicData(address);
151
+ gas += coldAccessGas;
152
+ // if cold access gas has been charged 2929 gas shouldn't be charged
153
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
154
+ }
155
+ if (common.isActivatedEIP(2929)) {
156
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, address.bytes, common, charge2929Gas);
157
+ }
158
+ if (dataLength !== util_1.BIGINT_0) {
159
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
160
+ if (common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) {
161
+ let codeEnd = _codeOffset + dataLength;
162
+ const codeSize = BigInt((await runState.stateManager.getCode(address)).length);
163
+ if (codeEnd > codeSize) {
164
+ codeEnd = codeSize;
165
+ }
166
+ gas += runState.env.accessWitness.readAccountCodeChunks(address, Number(_codeOffset), Number(codeEnd));
167
+ }
168
+ }
169
+ return gas;
170
+ },
171
+ ],
172
+ [
173
+ /* RETURNDATACOPY */
174
+ 0x3e,
175
+ async function (runState, gas, common) {
176
+ const [memOffset, returnDataOffset, dataLength] = runState.stack.peek(3);
177
+ if (returnDataOffset + dataLength > runState.interpreter.getReturnDataSize()) {
178
+ // For an EOF contract, the behavior is changed (see EIP 7069)
179
+ // RETURNDATACOPY in that case does not throw OOG when reading out-of-bounds
180
+ if (runState.env.eof === undefined) {
181
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
182
+ }
183
+ }
184
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
185
+ if (dataLength !== util_1.BIGINT_0) {
186
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
187
+ }
188
+ return gas;
189
+ },
190
+ ],
191
+ [
192
+ /* EXTCODEHASH */
193
+ 0x3f,
194
+ async function (runState, gas, common) {
195
+ const address = (0, util_ts_1.createAddressFromStackBigInt)(runState.stack.peek()[0]);
196
+ let charge2929Gas = true;
197
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
198
+ runState.interpreter._evm.getPrecompile(address) === undefined &&
199
+ !address.equals((0, util_ts_1.createAddressFromStackBigInt)(common.param('systemAddress')))) {
200
+ let coldAccessGas = util_1.BIGINT_0;
201
+ coldAccessGas += runState.env.accessWitness.readAccountCodeHash(address);
202
+ gas += coldAccessGas;
203
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
204
+ }
205
+ if (common.isActivatedEIP(2929)) {
206
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, address.bytes, common, charge2929Gas);
207
+ }
208
+ return gas;
209
+ },
210
+ ],
211
+ [
212
+ /* MLOAD */
213
+ 0x51,
214
+ async function (runState, gas, common) {
215
+ const pos = runState.stack.peek()[0];
216
+ gas += (0, util_ts_1.subMemUsage)(runState, pos, util_1.BIGINT_32, common);
217
+ return gas;
218
+ },
219
+ ],
220
+ [
221
+ /* MSTORE */
222
+ 0x52,
223
+ async function (runState, gas, common) {
224
+ const offset = runState.stack.peek()[0];
225
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, util_1.BIGINT_32, common);
226
+ return gas;
227
+ },
228
+ ],
229
+ [
230
+ /* MSTORE8 */
231
+ 0x53,
232
+ async function (runState, gas, common) {
233
+ const offset = runState.stack.peek()[0];
234
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, util_1.BIGINT_1, common);
235
+ return gas;
236
+ },
237
+ ],
238
+ [
239
+ /* SLOAD */
240
+ 0x54,
241
+ async function (runState, gas, common) {
242
+ const key = runState.stack.peek()[0];
243
+ const keyBuf = (0, util_1.setLengthLeft)((0, util_1.bigIntToBytes)(key), 32);
244
+ let charge2929Gas = true;
245
+ if (common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) {
246
+ const address = runState.interpreter.getAddress();
247
+ const coldAccessGas = runState.env.accessWitness.readAccountStorage(address, key);
248
+ gas += coldAccessGas;
249
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
250
+ }
251
+ if (common.isActivatedEIP(2929)) {
252
+ gas += (0, EIP2929_ts_1.accessStorageEIP2929)(runState, keyBuf, false, common, charge2929Gas);
253
+ }
254
+ return gas;
255
+ },
256
+ ],
257
+ [
258
+ /* SSTORE */
259
+ 0x55,
260
+ async function (runState, gas, common) {
261
+ if (runState.interpreter.isStatic()) {
262
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
263
+ }
264
+ const [key, val] = runState.stack.peek(2);
265
+ const keyBytes = (0, util_1.setLengthLeft)((0, util_1.bigIntToBytes)(key), 32);
266
+ // NOTE: this should be the shortest representation
267
+ let value;
268
+ if (val === util_1.BIGINT_0) {
269
+ value = Uint8Array.from([]);
270
+ }
271
+ else {
272
+ value = (0, util_1.bigIntToBytes)(val);
273
+ }
274
+ // Read current and original storage for gas calculation.
275
+ // Pass trackBAL=false because we'll track the read manually below,
276
+ // but ONLY if the EIP-2200 sentry check passes (per EIP-7928).
277
+ const currentStorage = (0, util_ts_1.setLengthLeftStorage)(await runState.interpreter.storageLoad(keyBytes, false, false));
278
+ const originalStorage = (0, util_ts_1.setLengthLeftStorage)(await runState.interpreter.storageLoad(keyBytes, true, false));
279
+ if (common.hardfork() === common_1.Hardfork.Constantinople) {
280
+ gas += (0, EIP1283_ts_1.updateSstoreGasEIP1283)(runState, currentStorage, originalStorage, (0, util_ts_1.setLengthLeftStorage)(value), common);
281
+ }
282
+ else if (common.gteHardfork(common_1.Hardfork.Istanbul)) {
283
+ if (!common.isActivatedEIP(6800) && !common.isActivatedEIP(7864)) {
284
+ gas += (0, EIP2200_ts_1.updateSstoreGasEIP2200)(runState, currentStorage, originalStorage, (0, util_ts_1.setLengthLeftStorage)(value), keyBytes, common);
285
+ }
286
+ }
287
+ else {
288
+ gas += (0, util_ts_1.updateSstoreGas)(runState, currentStorage, (0, util_ts_1.setLengthLeftStorage)(value), common);
289
+ }
290
+ // If we reach here, the EIP-2200 sentry check passed (didn't trap).
291
+ // Per EIP-7928, now track the storage read for BAL. If the SSTORE
292
+ // succeeds later, the write will remove this read (see addStorageWrite).
293
+ // If SSTORE fails with OOG after the sentry, the read remains in BAL.
294
+ if (common.isActivatedEIP(7928)) {
295
+ runState.interpreter._evm.blockLevelAccessList?.addStorageRead(runState.interpreter.getAddress().toString(), keyBytes);
296
+ }
297
+ let charge2929Gas = true;
298
+ if (common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) {
299
+ const contract = runState.interpreter.getAddress();
300
+ const coldAccessGas = runState.env.accessWitness.writeAccountStorage(contract, key);
301
+ gas += coldAccessGas;
302
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
303
+ }
304
+ if (common.isActivatedEIP(2929)) {
305
+ // We have to do this after the Istanbul (EIP2200) checks.
306
+ // Otherwise, we might run out of gas, due to "sentry check" of 2300 gas,
307
+ // if we deduct extra gas first.
308
+ gas += (0, EIP2929_ts_1.accessStorageEIP2929)(runState, keyBytes, true, common, charge2929Gas);
309
+ }
310
+ return gas;
311
+ },
312
+ ],
313
+ [
314
+ /* MCOPY */
315
+ 0x5e,
316
+ async function (runState, gas, common) {
317
+ const [dst, src, length] = runState.stack.peek(3);
318
+ const wordsCopied = (length + util_1.BIGINT_31) / util_1.BIGINT_32;
319
+ gas += util_1.BIGINT_3 * wordsCopied;
320
+ gas += (0, util_ts_1.subMemUsage)(runState, src, length, common);
321
+ gas += (0, util_ts_1.subMemUsage)(runState, dst, length, common);
322
+ return gas;
323
+ },
324
+ ],
325
+ [
326
+ /* LOG */
327
+ 0xa0,
328
+ async function (runState, gas, common) {
329
+ if (runState.interpreter.isStatic()) {
330
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
331
+ }
332
+ const [memOffset, memLength] = runState.stack.peek(2);
333
+ const topicsCount = runState.opCode - 0xa0;
334
+ if (topicsCount < 0 || topicsCount > 4) {
335
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_RANGE);
336
+ }
337
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, memLength, common);
338
+ gas +=
339
+ common.param('logTopicGas') * BigInt(topicsCount) + memLength * common.param('logDataGas');
340
+ return gas;
341
+ },
342
+ ],
343
+ /* DATACOPY */
344
+ [
345
+ 0xd3,
346
+ async function (runState, gas, common) {
347
+ if (runState.env.eof === undefined) {
348
+ // Opcode not available in legacy contracts
349
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.INVALID_OPCODE);
350
+ }
351
+ const [memOffset, _dataOffset, dataLength] = runState.stack.peek(3);
352
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
353
+ if (dataLength !== util_1.BIGINT_0) {
354
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
355
+ }
356
+ return gas;
357
+ },
358
+ ],
359
+ /* EOFCREATE */
360
+ [
361
+ 0xec,
362
+ async function (runState, gas, common) {
363
+ if (runState.env.eof === undefined) {
364
+ // Opcode not available in legacy contracts
365
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.INVALID_OPCODE);
366
+ }
367
+ // Note: TX_CREATE_COST is in the base fee (this is 32000 and same as CREATE / CREATE2)
368
+ // Note: in `gas.ts` programCounter is not yet incremented (which it is in `functions.ts`)
369
+ // So have to manually add to programCounter here to get the right container index
370
+ // Read container index
371
+ const containerIndex = runState.env.code[runState.programCounter + 1];
372
+ // Pop stack values
373
+ const [_value, _salt, inputOffset, inputSize] = runState.stack.peek(4);
374
+ //if (common.isActivatedEIP(2929)) {
375
+ // TODO: adding or not adding this makes test
376
+ // --test=tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py::test_eofcreate_then_call[fork_CancunEIP7692-blockchain_test]
377
+ // still succeed. This only warms the current address?? This is also in CREATE/CREATE2
378
+ // Can this be removed in both?
379
+ /*gas += accessAddressEIP2929(
380
+ runState,
381
+ runState.interpreter.getAddress().bytes,
382
+ common,
383
+ false
384
+ )
385
+ }*/
386
+ // Expand memory
387
+ gas += (0, util_ts_1.subMemUsage)(runState, inputOffset, inputSize, common);
388
+ // Read container
389
+ const container = runState.env.eof.container.body.containerSections[containerIndex];
390
+ // Charge for hashing cost
391
+ gas += common.param('keccak256WordGas') * (0, util_ts_1.divCeil)(BigInt(container.length), util_1.BIGINT_32);
392
+ const gasLeft = runState.interpreter.getGasLeft() - gas;
393
+ runState.messageGasLimit = (0, util_ts_1.maxCallGas)(gasLeft, gasLeft, runState, common);
394
+ return gas;
395
+ },
396
+ ],
397
+ /* RETURNCONTRACT */
398
+ [
399
+ 0xee,
400
+ async function (runState, gas, common) {
401
+ // Pop stack values
402
+ const [auxDataOffset, auxDataSize] = runState.stack.peek(2);
403
+ // Expand memory
404
+ gas += (0, util_ts_1.subMemUsage)(runState, auxDataOffset, auxDataSize, common);
405
+ return gas;
406
+ },
407
+ ],
408
+ [
409
+ /* CREATE */
410
+ 0xf0,
411
+ async function (runState, gas, common) {
412
+ if (runState.interpreter.isStatic()) {
413
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
414
+ }
415
+ const [_value, offset, length] = runState.stack.peek(3);
416
+ if (common.isActivatedEIP(2929)) {
417
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, runState.interpreter.getAddress().bytes, common, false);
418
+ }
419
+ if (common.isActivatedEIP(3860)) {
420
+ gas += ((length + util_1.BIGINT_31) / util_1.BIGINT_32) * common.param('initCodeWordGas');
421
+ }
422
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, length, common);
423
+ let gasLimit = BigInt(runState.interpreter.getGasLeft()) - gas;
424
+ gasLimit = (0, util_ts_1.maxCallGas)(gasLimit, gasLimit, runState, common);
425
+ runState.messageGasLimit = gasLimit;
426
+ return gas;
427
+ },
428
+ ],
429
+ [
430
+ /* CALL */
431
+ 0xf1,
432
+ async function (runState, gas, common) {
433
+ const [currentGasLimit, toAddr, value, inOffset, inLength, outOffset, outLength] = runState.stack.peek(7);
434
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
435
+ if (runState.interpreter.isStatic() && value !== util_1.BIGINT_0) {
436
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
437
+ }
438
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
439
+ gas += (0, util_ts_1.subMemUsage)(runState, outOffset, outLength, common);
440
+ // EIP-7928: Early OOG check before address access
441
+ // If we don't have enough gas to proceed, trap before adding to BAL
442
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
443
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
444
+ }
445
+ let charge2929Gas = true;
446
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
447
+ runState.interpreter._evm.getPrecompile(toAddress) === undefined) {
448
+ const coldAccessGas = runState.env.accessWitness.readAccountBasicData(toAddress);
449
+ if (value !== util_1.BIGINT_0) {
450
+ const contractAddress = runState.interpreter.getAddress();
451
+ gas += runState.env.accessWitness.writeAccountBasicData(contractAddress);
452
+ gas += runState.env.accessWitness.writeAccountBasicData(toAddress);
453
+ }
454
+ gas += coldAccessGas;
455
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
456
+ }
457
+ // EIP-2929/7928: Get target access cost first (no side effects)
458
+ let targetAccessCost = util_1.BIGINT_0;
459
+ if (common.isActivatedEIP(2929)) {
460
+ targetAccessCost = (0, EIP2929_ts_1.getAddressAccessCost)(runState, toAddress.bytes, common, charge2929Gas);
461
+ gas += targetAccessCost;
462
+ }
463
+ // EIP-7928: Check gas before committing target access.
464
+ // Include value transfer gas in this boundary, but defer new-account gas
465
+ // until after target access commit so OOG can still happen after target
466
+ // access for account-creation cases.
467
+ let valueTransferGas = util_1.BIGINT_0;
468
+ let newAccountGas = util_1.BIGINT_0;
469
+ if (value !== util_1.BIGINT_0 && !common.isActivatedEIP(6800) && !common.isActivatedEIP(7864)) {
470
+ valueTransferGas = common.param('callValueTransferGas');
471
+ }
472
+ // For BAL eligibility check: compute new account gas upfront only when needed
473
+ // (SpuriousDragon+ with value transfer)
474
+ if (value !== util_1.BIGINT_0 && common.gteHardfork(common_1.Hardfork.SpuriousDragon)) {
475
+ const account = await runState.stateManager.getAccount(toAddress);
476
+ if (account === undefined || account.isEmpty()) {
477
+ newAccountGas = common.param('callNewAccountGas');
478
+ }
479
+ }
480
+ // EIP-7928: Check gas before committing target access
481
+ const gasForTargetAccess = gas + valueTransferGas;
482
+ if (common.isActivatedEIP(7928) && gasForTargetAccess > runState.interpreter.getGasLeft()) {
483
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
484
+ }
485
+ // Now commit target access: warm the address and add to BAL
486
+ if (common.isActivatedEIP(2929)) {
487
+ (0, EIP2929_ts_1.warmAddress)(runState, toAddress.bytes);
488
+ }
489
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, toAddress.bytes, common);
490
+ // Add the value-related gas costs (already computed above for value transfers)
491
+ gas += valueTransferGas + newAccountGas;
492
+ // For pre-SpuriousDragon: check new account gas regardless of value
493
+ if (!common.gteHardfork(common_1.Hardfork.SpuriousDragon)) {
494
+ if ((await runState.stateManager.getAccount(toAddress)) === undefined) {
495
+ gas += common.param('callNewAccountGas');
496
+ }
497
+ }
498
+ // EIP-7702: Get delegation access cost (no side effects)
499
+ let delegationAddress = null;
500
+ if (common.isActivatedEIP(7702)) {
501
+ const { gas: delegationGas, delegationAddress: delAddr } = await eip7702GetAccessCost(runState, common, toAddress, charge2929Gas);
502
+ delegationAddress = delAddr;
503
+ gas += delegationGas;
504
+ // EIP-7928: Check gas before committing delegation access
505
+ if (common.isActivatedEIP(7928) && delegationAddress !== null) {
506
+ if (gas > runState.interpreter.getGasLeft()) {
507
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
508
+ }
509
+ // Commit delegation access: warm and add to BAL
510
+ eip7702WarmAddress(runState, delegationAddress);
511
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, delegationAddress, common);
512
+ }
513
+ else if (delegationAddress !== null) {
514
+ // No BAL check needed, just warm the address
515
+ eip7702WarmAddress(runState, delegationAddress);
516
+ }
517
+ }
518
+ const gasLimit = (0, util_ts_1.maxCallGas)(currentGasLimit, runState.interpreter.getGasLeft() - gas, runState, common);
519
+ // note that TangerineWhistle or later this cannot happen
520
+ // (it could have ran out of gas prior to getting here though)
521
+ if (gasLimit > runState.interpreter.getGasLeft() - gas) {
522
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
523
+ }
524
+ if (gas > runState.interpreter.getGasLeft()) {
525
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
526
+ }
527
+ runState.messageGasLimit = gasLimit;
528
+ return gas;
529
+ },
530
+ ],
531
+ [
532
+ /* CALLCODE */
533
+ 0xf2,
534
+ async function (runState, gas, common) {
535
+ const [currentGasLimit, toAddr, value, inOffset, inLength, outOffset, outLength] = runState.stack.peek(7);
536
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
537
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
538
+ gas += (0, util_ts_1.subMemUsage)(runState, outOffset, outLength, common);
539
+ // EIP-7928: Early OOG check before address access
540
+ // If we don't have enough gas to proceed, trap before adding to BAL
541
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
542
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
543
+ }
544
+ let charge2929Gas = true;
545
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
546
+ runState.interpreter._evm.getPrecompile(toAddress) === undefined) {
547
+ const coldAccessGas = runState.env.accessWitness.readAccountBasicData(toAddress);
548
+ gas += coldAccessGas;
549
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
550
+ }
551
+ // EIP-2929/7928: Get target access cost first (no side effects)
552
+ let targetAccessCost = util_1.BIGINT_0;
553
+ if (common.isActivatedEIP(2929)) {
554
+ targetAccessCost = (0, EIP2929_ts_1.getAddressAccessCost)(runState, toAddress.bytes, common, charge2929Gas);
555
+ gas += targetAccessCost;
556
+ }
557
+ // For CALLCODE with value, compute value transfer cost before checking BAL eligibility
558
+ let valueTransferGas = util_1.BIGINT_0;
559
+ if (value !== util_1.BIGINT_0) {
560
+ valueTransferGas = common.param('callValueTransferGas');
561
+ }
562
+ // EIP-7928: Check gas before committing target access
563
+ // For value transfers, include value transfer gas in the check
564
+ const gasForTargetAccess = gas + valueTransferGas;
565
+ if (common.isActivatedEIP(7928) && gasForTargetAccess > runState.interpreter.getGasLeft()) {
566
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
567
+ }
568
+ // Now commit target access: warm the address and add to BAL
569
+ if (common.isActivatedEIP(2929)) {
570
+ (0, EIP2929_ts_1.warmAddress)(runState, toAddress.bytes);
571
+ }
572
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, toAddress.bytes, common);
573
+ // Add the value transfer gas (already computed above)
574
+ gas += valueTransferGas;
575
+ // EIP-7702: Get delegation access cost (no side effects)
576
+ let delegationAddress = null;
577
+ if (common.isActivatedEIP(7702)) {
578
+ const { gas: delegationGas, delegationAddress: delAddr } = await eip7702GetAccessCost(runState, common, toAddress, charge2929Gas);
579
+ delegationAddress = delAddr;
580
+ gas += delegationGas;
581
+ // EIP-7928: Check gas before committing delegation access
582
+ if (common.isActivatedEIP(7928) && delegationAddress !== null) {
583
+ if (gas > runState.interpreter.getGasLeft()) {
584
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
585
+ }
586
+ // Commit delegation access: warm and add to BAL
587
+ eip7702WarmAddress(runState, delegationAddress);
588
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, delegationAddress, common);
589
+ }
590
+ else if (delegationAddress !== null) {
591
+ // No BAL check needed, just warm the address
592
+ eip7702WarmAddress(runState, delegationAddress);
593
+ }
594
+ }
595
+ const gasLimit = (0, util_ts_1.maxCallGas)(currentGasLimit, runState.interpreter.getGasLeft() - gas, runState, common);
596
+ // note that TangerineWhistle or later this cannot happen
597
+ // (it could have ran out of gas prior to getting here though)
598
+ if (gasLimit > runState.interpreter.getGasLeft() - gas) {
599
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
600
+ }
601
+ if (gas > runState.interpreter.getGasLeft()) {
602
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
603
+ }
604
+ runState.messageGasLimit = gasLimit;
605
+ return gas;
606
+ },
607
+ ],
608
+ [
609
+ /* RETURN */
610
+ 0xf3,
611
+ async function (runState, gas, common) {
612
+ const [offset, length] = runState.stack.peek(2);
613
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, length, common);
614
+ return gas;
615
+ },
616
+ ],
617
+ [
618
+ /* DELEGATECALL */
619
+ 0xf4,
620
+ async function (runState, gas, common) {
621
+ const [currentGasLimit, toAddr, inOffset, inLength, outOffset, outLength] = runState.stack.peek(6);
622
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
623
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
624
+ gas += (0, util_ts_1.subMemUsage)(runState, outOffset, outLength, common);
625
+ // EIP-7928: Early OOG check before address access
626
+ // If we don't have enough gas to proceed, trap before adding to BAL
627
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
628
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
629
+ }
630
+ let charge2929Gas = true;
631
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
632
+ runState.interpreter._evm.getPrecompile(toAddress) === undefined) {
633
+ const coldAccessGas = runState.env.accessWitness.readAccountBasicData(toAddress);
634
+ gas += coldAccessGas;
635
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
636
+ }
637
+ // EIP-2929/7928: Get target access cost first (no side effects)
638
+ let targetAccessCost = util_1.BIGINT_0;
639
+ if (common.isActivatedEIP(2929)) {
640
+ targetAccessCost = (0, EIP2929_ts_1.getAddressAccessCost)(runState, toAddress.bytes, common, charge2929Gas);
641
+ gas += targetAccessCost;
642
+ }
643
+ // EIP-7928: Check gas before committing target access
644
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
645
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
646
+ }
647
+ // Now commit target access: warm the address and add to BAL
648
+ if (common.isActivatedEIP(2929)) {
649
+ (0, EIP2929_ts_1.warmAddress)(runState, toAddress.bytes);
650
+ }
651
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, toAddress.bytes, common);
652
+ // EIP-7702: Get delegation access cost (no side effects)
653
+ let delegationAddress = null;
654
+ if (common.isActivatedEIP(7702)) {
655
+ const { gas: delegationGas, delegationAddress: delAddr } = await eip7702GetAccessCost(runState, common, toAddress, charge2929Gas);
656
+ delegationAddress = delAddr;
657
+ gas += delegationGas;
658
+ // EIP-7928: Check gas before committing delegation access
659
+ if (common.isActivatedEIP(7928) && delegationAddress !== null) {
660
+ if (gas > runState.interpreter.getGasLeft()) {
661
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
662
+ }
663
+ // Commit delegation access: warm and add to BAL
664
+ eip7702WarmAddress(runState, delegationAddress);
665
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, delegationAddress, common);
666
+ }
667
+ else if (delegationAddress !== null) {
668
+ // No BAL check needed, just warm the address
669
+ eip7702WarmAddress(runState, delegationAddress);
670
+ }
671
+ }
672
+ const gasLimit = (0, util_ts_1.maxCallGas)(currentGasLimit, runState.interpreter.getGasLeft() - gas, runState, common);
673
+ // note that TangerineWhistle or later this cannot happen
674
+ // (it could have ran out of gas prior to getting here though)
675
+ if (gasLimit > runState.interpreter.getGasLeft() - gas) {
676
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
677
+ }
678
+ if (gas > runState.interpreter.getGasLeft()) {
679
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
680
+ }
681
+ runState.messageGasLimit = gasLimit;
682
+ return gas;
683
+ },
684
+ ],
685
+ [
686
+ /* CREATE2 */
687
+ 0xf5,
688
+ async function (runState, gas, common) {
689
+ if (runState.interpreter.isStatic()) {
690
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
691
+ }
692
+ const [_value, offset, length, _salt] = runState.stack.peek(4);
693
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, length, common);
694
+ if (common.isActivatedEIP(2929)) {
695
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, runState.interpreter.getAddress().bytes, common, false);
696
+ }
697
+ if (common.isActivatedEIP(3860)) {
698
+ gas += ((length + util_1.BIGINT_31) / util_1.BIGINT_32) * common.param('initCodeWordGas');
699
+ }
700
+ gas += common.param('keccak256WordGas') * (0, util_ts_1.divCeil)(length, util_1.BIGINT_32);
701
+ let gasLimit = runState.interpreter.getGasLeft() - gas;
702
+ gasLimit = (0, util_ts_1.maxCallGas)(gasLimit, gasLimit, runState, common); // CREATE2 is only available after TangerineWhistle (Constantinople introduced this opcode)
703
+ runState.messageGasLimit = gasLimit;
704
+ return gas;
705
+ },
706
+ ],
707
+ /* EXTCALL */
708
+ [
709
+ 0xf8,
710
+ async function (runState, gas, common) {
711
+ if (runState.env.eof === undefined) {
712
+ // Opcode not available in legacy contracts
713
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.INVALID_OPCODE);
714
+ }
715
+ // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929
716
+ // Peek stack values
717
+ const [toAddr, inOffset, inLength, value] = runState.stack.peek(4);
718
+ // If value is nonzero and in static mode, throw:
719
+ if (runState.interpreter.isStatic() && value !== util_1.BIGINT_0) {
720
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
721
+ }
722
+ // If value > 0, charge CALL_VALUE_COST
723
+ if (value > util_1.BIGINT_0) {
724
+ gas += common.param('callValueTransferGas');
725
+ }
726
+ // Check if the target address > 20 bytes
727
+ if (toAddr > EXTCALL_TARGET_MAX) {
728
+ (0, util_ts_1.trap)(errors_ts_1.EOFErrorMessage.INVALID_EXTCALL_TARGET);
729
+ }
730
+ // Charge for memory expansion
731
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
732
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
733
+ // Charge to make address warm (2600 gas)
734
+ // (in case if address is already warm, this charges the 100 gas)
735
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, toAddress.bytes, common);
736
+ // Charge account creation cost if value is nonzero
737
+ if (value > util_1.BIGINT_0) {
738
+ const account = await runState.stateManager.getAccount(toAddress);
739
+ const deadAccount = account === undefined || account.isEmpty();
740
+ if (deadAccount) {
741
+ gas += common.param('callNewAccountGas');
742
+ }
743
+ }
744
+ const minRetainedGas = common.param('minRetainedGas');
745
+ const minCalleeGas = common.param('minCalleeGas');
746
+ const currentGasAvailable = runState.interpreter.getGasLeft() - gas;
747
+ const reducedGas = currentGasAvailable / util_1.BIGINT_64;
748
+ // Calculate the gas limit for the callee
749
+ // (this is the gas available for the next call frame)
750
+ let gasLimit;
751
+ if (reducedGas < minRetainedGas) {
752
+ gasLimit = currentGasAvailable - minRetainedGas;
753
+ }
754
+ else {
755
+ gasLimit = currentGasAvailable - reducedGas;
756
+ }
757
+ if (runState.env.depth >= Number(common.param('stackLimit')) ||
758
+ runState.env.contract.balance < value ||
759
+ gasLimit < minCalleeGas) {
760
+ // Note: this is a hack, TODO: get around this hack and clean this up
761
+ // This special case will ensure that the actual EXT*CALL is being ran,
762
+ // But, the code in `function.ts` will note that `runState.messageGasLimit` is set to a negative number
763
+ // This special number signals that `1` should be put on the stack (per spec)
764
+ gasLimit = -util_1.BIGINT_1;
765
+ }
766
+ runState.messageGasLimit = gasLimit;
767
+ return gas;
768
+ },
769
+ ],
770
+ /* EXTDELEGATECALL */
771
+ [
772
+ 0xf9,
773
+ async function (runState, gas, common) {
774
+ if (runState.env.eof === undefined) {
775
+ // Opcode not available in legacy contracts
776
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.INVALID_OPCODE);
777
+ }
778
+ // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929
779
+ // Peek stack values
780
+ const [toAddr, inOffset, inLength] = runState.stack.peek(3);
781
+ // Check if the target address > 20 bytes
782
+ if (toAddr > EXTCALL_TARGET_MAX) {
783
+ (0, util_ts_1.trap)(errors_ts_1.EOFErrorMessage.INVALID_EXTCALL_TARGET);
784
+ }
785
+ // Charge for memory expansion
786
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
787
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
788
+ // Charge to make address warm (2600 gas)
789
+ // (in case if address is already warm, this charges the 100 gas)
790
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, toAddress.bytes, common);
791
+ const minRetainedGas = common.param('minRetainedGas');
792
+ const minCalleeGas = common.param('minCalleeGas');
793
+ const currentGasAvailable = runState.interpreter.getGasLeft() - gas;
794
+ const reducedGas = currentGasAvailable / util_1.BIGINT_64;
795
+ // Calculate the gas limit for the callee
796
+ // (this is the gas available for the next call frame)
797
+ let gasLimit;
798
+ if (reducedGas < minRetainedGas) {
799
+ gasLimit = currentGasAvailable - minRetainedGas;
800
+ }
801
+ else {
802
+ gasLimit = currentGasAvailable - reducedGas;
803
+ }
804
+ if (runState.env.depth >= Number(common.param('stackLimit')) || gasLimit < minCalleeGas) {
805
+ // Note: this is a hack, TODO: get around this hack and clean this up
806
+ // This special case will ensure that the actual EXT*CALL is being ran,
807
+ // But, the code in `function.ts` will note that `runState.messageGasLimit` is set to a negative number
808
+ // This special number signals that `1` should be put on the stack (per spec)
809
+ gasLimit = -util_1.BIGINT_1;
810
+ }
811
+ runState.messageGasLimit = gasLimit;
812
+ return gas;
813
+ },
814
+ ],
815
+ [
816
+ /* STATICCALL */
817
+ 0xfa,
818
+ async function (runState, gas, common) {
819
+ const [currentGasLimit, toAddr, inOffset, inLength, outOffset, outLength] = runState.stack.peek(6);
820
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
821
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
822
+ gas += (0, util_ts_1.subMemUsage)(runState, outOffset, outLength, common);
823
+ // EIP-7928: Early OOG check before address access
824
+ // If we don't have enough gas to proceed, trap before adding to BAL
825
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
826
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
827
+ }
828
+ let charge2929Gas = true;
829
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
830
+ runState.interpreter._evm.getPrecompile(toAddress) === undefined) {
831
+ const coldAccessGas = runState.env.accessWitness.readAccountBasicData(toAddress);
832
+ gas += coldAccessGas;
833
+ charge2929Gas = coldAccessGas === util_1.BIGINT_0;
834
+ }
835
+ // EIP-2929/7928: Get target access cost first (no side effects)
836
+ let targetAccessCost = util_1.BIGINT_0;
837
+ if (common.isActivatedEIP(2929)) {
838
+ targetAccessCost = (0, EIP2929_ts_1.getAddressAccessCost)(runState, toAddress.bytes, common, charge2929Gas);
839
+ gas += targetAccessCost;
840
+ }
841
+ // EIP-7928: Check gas before committing target access
842
+ if (common.isActivatedEIP(7928) && gas > runState.interpreter.getGasLeft()) {
843
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
844
+ }
845
+ // Now commit target access: warm the address and add to BAL
846
+ if (common.isActivatedEIP(2929)) {
847
+ (0, EIP2929_ts_1.warmAddress)(runState, toAddress.bytes);
848
+ }
849
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, toAddress.bytes, common);
850
+ // EIP-7702: Get delegation access cost (no side effects)
851
+ let delegationAddress = null;
852
+ if (common.isActivatedEIP(7702)) {
853
+ const { gas: delegationGas, delegationAddress: delAddr } = await eip7702GetAccessCost(runState, common, toAddress, charge2929Gas);
854
+ delegationAddress = delAddr;
855
+ gas += delegationGas;
856
+ // EIP-7928: Check gas before committing delegation access
857
+ if (common.isActivatedEIP(7928) && delegationAddress !== null) {
858
+ if (gas > runState.interpreter.getGasLeft()) {
859
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.OUT_OF_GAS);
860
+ }
861
+ // Commit delegation access: warm and add to BAL
862
+ eip7702WarmAddress(runState, delegationAddress);
863
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, delegationAddress, common);
864
+ }
865
+ else if (delegationAddress !== null) {
866
+ // No BAL check needed, just warm the address
867
+ eip7702WarmAddress(runState, delegationAddress);
868
+ }
869
+ }
870
+ const gasLimit = (0, util_ts_1.maxCallGas)(currentGasLimit, runState.interpreter.getGasLeft() - gas, runState, common); // we set TangerineWhistle or later to true here, as STATICCALL was available from Byzantium (which is after TangerineWhistle)
871
+ runState.messageGasLimit = gasLimit;
872
+ return gas;
873
+ },
874
+ ],
875
+ /* EXTSTATICCALL */
876
+ [
877
+ 0xfb,
878
+ async function (runState, gas, common) {
879
+ if (runState.env.eof === undefined) {
880
+ // Opcode not available in legacy contracts
881
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.INVALID_OPCODE);
882
+ }
883
+ // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929
884
+ // Peek stack values
885
+ const [toAddr, inOffset, inLength] = runState.stack.peek(3);
886
+ // Check if the target address > 20 bytes
887
+ if (toAddr > EXTCALL_TARGET_MAX) {
888
+ (0, util_ts_1.trap)(errors_ts_1.EOFErrorMessage.INVALID_EXTCALL_TARGET);
889
+ }
890
+ // Charge for memory expansion
891
+ gas += (0, util_ts_1.subMemUsage)(runState, inOffset, inLength, common);
892
+ const toAddress = (0, util_ts_1.createAddressFromStackBigInt)(toAddr);
893
+ // Charge to make address warm (2600 gas)
894
+ // (in case if address is already warm, this charges the 100 gas)
895
+ gas += (0, EIP2929_ts_1.accessAddressEIP2929)(runState, toAddress.bytes, common);
896
+ const minRetainedGas = common.param('minRetainedGas');
897
+ const minCalleeGas = common.param('minCalleeGas');
898
+ const currentGasAvailable = runState.interpreter.getGasLeft() - gas;
899
+ const reducedGas = currentGasAvailable / util_1.BIGINT_64;
900
+ // Calculate the gas limit for the callee
901
+ // (this is the gas available for the next call frame)
902
+ let gasLimit;
903
+ if (reducedGas < minRetainedGas) {
904
+ gasLimit = currentGasAvailable - minRetainedGas;
905
+ }
906
+ else {
907
+ gasLimit = currentGasAvailable - reducedGas;
908
+ }
909
+ if (runState.env.depth >= Number(common.param('stackLimit')) || gasLimit < minCalleeGas) {
910
+ // Note: this is a hack, TODO: get around this hack and clean this up
911
+ // This special case will ensure that the actual EXT*CALL is being ran,
912
+ // But, the code in `function.ts` will note that `runState.messageGasLimit` is set to a negative number
913
+ // This special number signals that `1` should be put on the stack (per spec)
914
+ gasLimit = -util_1.BIGINT_1;
915
+ }
916
+ runState.messageGasLimit = gasLimit;
917
+ return gas;
918
+ },
919
+ ],
920
+ [
921
+ /* REVERT */
922
+ 0xfd,
923
+ async function (runState, gas, common) {
924
+ const [offset, length] = runState.stack.peek(2);
925
+ gas += (0, util_ts_1.subMemUsage)(runState, offset, length, common);
926
+ return gas;
927
+ },
928
+ ],
929
+ [
930
+ /* SELFDESTRUCT */
931
+ 0xff,
932
+ async function (runState, gas, common) {
933
+ if (runState.interpreter.isStatic()) {
934
+ (0, util_ts_1.trap)(errors_ts_2.EVMError.errorMessages.STATIC_STATE_CHANGE);
935
+ }
936
+ const selfdestructToaddressBigInt = runState.stack.peek()[0];
937
+ const selfdestructToAddress = (0, util_ts_1.createAddressFromStackBigInt)(selfdestructToaddressBigInt);
938
+ const contractAddress = runState.interpreter.getAddress();
939
+ const balance = await runState.interpreter.getExternalBalance(contractAddress);
940
+ // Calculate new account gas first (needed for checkpoint ordering)
941
+ let newAccountGas = util_1.BIGINT_0;
942
+ if (common.gteHardfork(common_1.Hardfork.SpuriousDragon)) {
943
+ // EIP-161: State Trie Clearing
944
+ if (balance > util_1.BIGINT_0) {
945
+ // This technically checks if account is empty or non-existent
946
+ const account = await runState.stateManager.getAccount(selfdestructToAddress);
947
+ if (account === undefined || account.isEmpty()) {
948
+ newAccountGas = common.param('callNewAccountGas');
949
+ }
950
+ }
951
+ }
952
+ else if (common.gteHardfork(common_1.Hardfork.TangerineWhistle)) {
953
+ // EIP-150 (Tangerine Whistle) gas semantics
954
+ const exists = (await runState.stateManager.getAccount(selfdestructToAddress)) !== undefined;
955
+ if (!exists) {
956
+ newAccountGas = common.param('callNewAccountGas');
957
+ }
958
+ }
959
+ let selfDestructToCharge2929Gas = true;
960
+ if ((common.isActivatedEIP(6800) || common.isActivatedEIP(7864)) &&
961
+ runState.env.chargeCodeAccesses === true) {
962
+ gas += runState.env.accessWitness.readAccountBasicData(contractAddress);
963
+ if (balance > util_1.BIGINT_0) {
964
+ gas += runState.env.accessWitness.writeAccountBasicData(contractAddress);
965
+ }
966
+ let selfDestructToColdAccessGas = runState.env.accessWitness.readAccountBasicData(selfdestructToAddress);
967
+ if (balance > util_1.BIGINT_0) {
968
+ selfDestructToColdAccessGas +=
969
+ runState.env.accessWitness.writeAccountBasicData(selfdestructToAddress);
970
+ }
971
+ gas += selfDestructToColdAccessGas;
972
+ selfDestructToCharge2929Gas = selfDestructToColdAccessGas === util_1.BIGINT_0;
973
+ }
974
+ // EIP-2929/7928: Get cold access cost first (no side effects)
975
+ let coldAccessCost = util_1.BIGINT_0;
976
+ if (common.isActivatedEIP(2929)) {
977
+ coldAccessCost = (0, EIP2929_ts_1.getAddressAccessCost)(runState, selfdestructToAddress.bytes, common, selfDestructToCharge2929Gas, true);
978
+ gas += coldAccessCost;
979
+ }
980
+ // EIP-7928: Check if we have enough gas for the cold access (checkpoint 1)
981
+ // If yes, add beneficiary to BAL - this is the "state access" point
982
+ // The newAccountGas (checkpoint 2) is added after, so OOG there still records BAL
983
+ if (common.isActivatedEIP(7928)) {
984
+ // Only add to BAL if we have enough gas for the current accumulated cost
985
+ // (base gas + cold access). newAccountGas is NOT included here because
986
+ // per EIP-7928, if we pass the cold access check but fail at new account
987
+ // creation, the beneficiary should still be in BAL.
988
+ if (gas <= runState.interpreter.getGasLeft()) {
989
+ (0, EIP2929_ts_1.addAddressToBAL)(runState, selfdestructToAddress.bytes, common);
990
+ }
991
+ }
992
+ // Now commit the address warming (EIP-2929)
993
+ if (common.isActivatedEIP(2929)) {
994
+ (0, EIP2929_ts_1.warmAddress)(runState, selfdestructToAddress.bytes);
995
+ }
996
+ // Add new account gas (checkpoint 2)
997
+ gas += newAccountGas;
998
+ return gas;
999
+ },
1000
+ ],
1001
+ ]);
1002
+ // Set the range [0xa0, 0xa4] to the LOG handler
1003
+ const logDynamicFunc = exports.dynamicGasHandlers.get(0xa0);
1004
+ for (let i = 0xa1; i <= 0xa4; i++) {
1005
+ exports.dynamicGasHandlers.set(i, logDynamicFunc);
1006
+ }
1007
+ // EIP-8141: FRAMEDATACOPY dynamic gas (matches CALLDATACOPY)
1008
+ exports.dynamicGasHandlers.set(0xb2, async function (runState, gas, common) {
1009
+ const [memOffset, _dataOffset, dataLength] = runState.stack.peek(4);
1010
+ gas += (0, util_ts_1.subMemUsage)(runState, memOffset, dataLength, common);
1011
+ if (dataLength !== util_1.BIGINT_0) {
1012
+ gas += common.param('copyGas') * (0, util_ts_1.divCeil)(dataLength, util_1.BIGINT_32);
1013
+ }
1014
+ return gas;
1015
+ });
1016
+ //# sourceMappingURL=gas.js.map