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