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