@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
package/src/journal.ts ADDED
@@ -0,0 +1,317 @@
1
+ import { Hardfork } from '@feelyourprotocol/common'
2
+ import {
3
+ Address,
4
+ EthereumJSErrorWithoutCode,
5
+ RIPEMD160_ADDRESS_STRING,
6
+ bytesToHex,
7
+ bytesToUnprefixedHex,
8
+ hexToBytes,
9
+ isDebugEnabled,
10
+ stripHexPrefix,
11
+ unprefixedHexToBytes,
12
+ } from '@feelyourprotocol/util'
13
+ import debugDefault from 'debug'
14
+
15
+ import type { Common, StateManagerInterface } from '@feelyourprotocol/common'
16
+ import type { Account, PrefixedHexString } from '@feelyourprotocol/util'
17
+ import type { Debugger } from 'debug'
18
+
19
+ type AddressString = string
20
+ type SlotString = string
21
+ type WarmSlots = Set<SlotString>
22
+
23
+ type JournalType = Map<AddressString, WarmSlots>
24
+
25
+ /**
26
+ * Journal Diff Item:
27
+ * Index 0: remove warm address
28
+ * Index 1: remove warm slots for this warm address
29
+ * Index 2: remove touched
30
+ */
31
+
32
+ type JournalDiffItem = [Set<AddressString>, Map<AddressString, Set<SlotString>>, Set<AddressString>]
33
+
34
+ type JournalHeight = number
35
+
36
+ export class Journal {
37
+ private stateManager: StateManagerInterface
38
+ private common: Common
39
+ private DEBUG: boolean
40
+ private _debug: Debugger
41
+
42
+ private journal!: JournalType
43
+ private alwaysWarmJournal!: Map<AddressString, Set<SlotString>>
44
+ private touched!: Set<AddressString>
45
+ private journalDiff!: [JournalHeight, JournalDiffItem][]
46
+
47
+ private journalHeight: JournalHeight
48
+
49
+ public accessList?: Map<AddressString, Set<SlotString>>
50
+ public preimages?: Map<PrefixedHexString, Uint8Array>
51
+
52
+ constructor(stateManager: StateManagerInterface, common: Common) {
53
+ // Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables
54
+ this.DEBUG = isDebugEnabled('ethjs')
55
+
56
+ this._debug = debugDefault('evm:journal')
57
+
58
+ // TODO maybe call into this.clearJournal
59
+ this.cleanJournal()
60
+ this.journalHeight = 0
61
+
62
+ this.stateManager = stateManager
63
+ this.common = common
64
+ }
65
+
66
+ /**
67
+ * Clears the internal `accessList` map, and mark this journal to start reporting
68
+ * which addresses and storages have been accessed
69
+ */
70
+ startReportingAccessList() {
71
+ this.accessList = new Map()
72
+ }
73
+
74
+ /**
75
+ * Clears the internal `preimages` map, and marks this journal to start reporting
76
+ * the images (hashed addresses) of the accounts that have been accessed
77
+ */
78
+ startReportingPreimages() {
79
+ this.preimages = new Map()
80
+ }
81
+
82
+ async putAccount(address: Address, account: Account | undefined) {
83
+ this.touchAddress(address)
84
+ return this.stateManager.putAccount(address, account)
85
+ }
86
+
87
+ async deleteAccount(address: Address) {
88
+ this.touchAddress(address)
89
+ await this.stateManager.deleteAccount(address)
90
+ }
91
+
92
+ private touchAddress(address: Address): void {
93
+ const str = address.toString().slice(2)
94
+ this.touchAccount(str)
95
+ }
96
+
97
+ private touchAccount(address: string) {
98
+ // If preimages are being reported, add the address to the preimages map
99
+ if (this.preimages !== undefined) {
100
+ const bytesAddress = unprefixedHexToBytes(address)
101
+ if (this.stateManager.getAppliedKey === undefined) {
102
+ throw EthereumJSErrorWithoutCode(
103
+ 'touchAccount: stateManager.getAppliedKey can not be undefined if preimage storing is enabled',
104
+ )
105
+ }
106
+ const hashedKey = this.stateManager.getAppliedKey(bytesAddress)
107
+ this.preimages.set(bytesToHex(hashedKey), bytesAddress)
108
+ }
109
+
110
+ if (!this.touched.has(address)) {
111
+ this.touched.add(address)
112
+ const diffArr = this.journalDiff[this.journalDiff.length - 1][1]
113
+ diffArr[2].add(address)
114
+ }
115
+ }
116
+ async commit() {
117
+ this.journalHeight--
118
+ this.journalDiff.push([this.journalHeight, [new Set(), new Map(), new Set()]])
119
+ await this.stateManager.commit()
120
+ }
121
+
122
+ async checkpoint() {
123
+ this.journalHeight++
124
+ this.journalDiff.push([this.journalHeight, [new Set(), new Map(), new Set()]])
125
+ await this.stateManager.checkpoint()
126
+ }
127
+
128
+ async revert() {
129
+ // Loop backwards over the journal diff and stop if we are at a lower height than current journal height
130
+ // During this process, delete all items.
131
+ // TODO check this logic, if there is this array: height [4,3,4] and we revert height 4, then the final
132
+ // diff arr will be reverted, but it will stop at height 3, so [4,3] are both not reverted..?
133
+ let finalI: number
134
+ for (let i = this.journalDiff.length - 1; i >= 0; i--) {
135
+ finalI = i
136
+ const [height, diff] = this.journalDiff[i]
137
+ if (height < this.journalHeight) {
138
+ break
139
+ }
140
+
141
+ const addressSet = diff[0]
142
+ const slotsMap = diff[1]
143
+ const touchedSet = diff[2]
144
+
145
+ for (const address of addressSet) {
146
+ // Sanity check, journal should have the item
147
+ if (this.journal.has(address)) {
148
+ this.journal.delete(address)
149
+ }
150
+ }
151
+
152
+ for (const [address, delSlots] of slotsMap) {
153
+ // Sanity check, the address SHOULD be in the journal
154
+ if (this.journal.has(address)) {
155
+ const slots = this.journal.get(address)!
156
+ for (const delSlot of delSlots) {
157
+ slots.delete(delSlot)
158
+ }
159
+ }
160
+ }
161
+
162
+ for (const address of touchedSet) {
163
+ // Delete the address from the journal
164
+ if (address !== RIPEMD160_ADDRESS_STRING) {
165
+ // If RIPEMD160 is touched, keep it touched.
166
+ // Default behavior for others.
167
+ this.touched.delete(address)
168
+ }
169
+ }
170
+ }
171
+
172
+ // the final diffs are reverted and we can dispose those
173
+ this.journalDiff = this.journalDiff.slice(0, finalI! + 1)
174
+
175
+ this.journalHeight--
176
+
177
+ await this.stateManager.revert()
178
+ }
179
+
180
+ public cleanJournal() {
181
+ this.journalHeight = 0
182
+ this.journal = new Map()
183
+ this.alwaysWarmJournal = new Map()
184
+ this.touched = new Set()
185
+ this.journalDiff = [[0, [new Set(), new Map(), new Set()]]]
186
+ }
187
+
188
+ /**
189
+ * Removes accounts from the state trie that have been touched,
190
+ * as defined in EIP-161 (https://eips.ethereum.org/EIPS/eip-161).
191
+ * Also cleanups any other internal fields
192
+ */
193
+ async cleanup(): Promise<void> {
194
+ if (this.common.gteHardfork(Hardfork.SpuriousDragon)) {
195
+ for (const addressHex of this.touched) {
196
+ const address = new Address(hexToBytes(`0x${addressHex}`))
197
+ const account = await this.stateManager.getAccount(address)
198
+ if (account === undefined || account.isEmpty()) {
199
+ await this.deleteAccount(address)
200
+ if (this.DEBUG) {
201
+ this._debug(`Cleanup touched account address=${address} (>= SpuriousDragon)`)
202
+ }
203
+ }
204
+ }
205
+ }
206
+ this.cleanJournal()
207
+ delete this.accessList
208
+ delete this.preimages
209
+ }
210
+
211
+ addAlwaysWarmAddress(addressStr: string, addToAccessList: boolean = false) {
212
+ const address = stripHexPrefix(addressStr)
213
+ if (!this.alwaysWarmJournal.has(address)) {
214
+ this.alwaysWarmJournal.set(address, new Set())
215
+ }
216
+ if (addToAccessList && this.accessList !== undefined) {
217
+ if (!this.accessList.has(address)) {
218
+ this.accessList.set(address, new Set())
219
+ }
220
+ }
221
+ }
222
+
223
+ addAlwaysWarmSlot(addressStr: string, slotStr: string, addToAccessList: boolean = false) {
224
+ const address = stripHexPrefix(addressStr)
225
+ this.addAlwaysWarmAddress(address, addToAccessList)
226
+ const slotsSet = this.alwaysWarmJournal.get(address)!
227
+ const slot = stripHexPrefix(slotStr)
228
+ slotsSet.add(slot)
229
+ if (addToAccessList && this.accessList !== undefined) {
230
+ this.accessList.get(address)!.add(slot)
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Returns true if the address is warm in the current context
236
+ * @param address - The address (as a Uint8Array) to check
237
+ */
238
+ isWarmedAddress(address: Uint8Array): boolean {
239
+ // Using deprecated bytesToUnprefixedHex for performance: this is a hot path used in Map/Set lookups.
240
+ const addressHex = bytesToUnprefixedHex(address)
241
+ const warm = this.journal.has(addressHex) || this.alwaysWarmJournal.has(addressHex)
242
+ return warm
243
+ }
244
+
245
+ /**
246
+ * Add a warm address in the current context
247
+ * @param addressArr - The address (as a Uint8Array) to check
248
+ */
249
+ addWarmedAddress(addressArr: Uint8Array): void {
250
+ // Using deprecated bytesToUnprefixedHex for performance: this is a hot path used in Map/Set operations.
251
+ const address = bytesToUnprefixedHex(addressArr)
252
+ if (!this.journal.has(address)) {
253
+ this.journal.set(address, new Set())
254
+ const diffArr = this.journalDiff[this.journalDiff.length - 1][1]
255
+ diffArr[0].add(address)
256
+ }
257
+ if (this.accessList !== undefined) {
258
+ if (!this.accessList.has(address)) {
259
+ this.accessList.set(address, new Set())
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Returns true if the slot of the address is warm
266
+ * @param address - The address (as a Uint8Array) to check
267
+ * @param slot - The slot (as a Uint8Array) to check
268
+ */
269
+ isWarmedStorage(address: Uint8Array, slot: Uint8Array): boolean {
270
+ // Using deprecated bytesToUnprefixedHex for performance: this is a hot path used in Map/Set lookups.
271
+ const addressHex = bytesToUnprefixedHex(address)
272
+ const slots = this.journal.get(addressHex)
273
+ if (slots === undefined) {
274
+ if (this.alwaysWarmJournal.has(addressHex)) {
275
+ return this.alwaysWarmJournal.get(addressHex)!.has(bytesToUnprefixedHex(slot))
276
+ }
277
+ return false
278
+ }
279
+ if (slots.has(bytesToUnprefixedHex(slot))) {
280
+ return true
281
+ } else if (this.alwaysWarmJournal.has(addressHex)) {
282
+ return this.alwaysWarmJournal.get(addressHex)!.has(bytesToUnprefixedHex(slot))
283
+ }
284
+ return false
285
+ }
286
+
287
+ /**
288
+ * Mark the storage slot in the address as warm in the current context
289
+ * @param address - The address (as a Uint8Array) to check
290
+ * @param slot - The slot (as a Uint8Array) to check
291
+ */
292
+ addWarmedStorage(address: Uint8Array, slot: Uint8Array): void {
293
+ // Using deprecated bytesToUnprefixedHex for performance: this is a hot path used in Map/Set operations.
294
+ const addressHex = bytesToUnprefixedHex(address)
295
+ let slots = this.journal.get(addressHex)
296
+ if (slots === undefined) {
297
+ this.addWarmedAddress(address)
298
+ slots = this.journal.get(addressHex)
299
+ }
300
+ const slotStr = bytesToUnprefixedHex(slot)
301
+ if (!slots!.has(slotStr)) {
302
+ slots!.add(slotStr)
303
+ const diff = this.journalDiff[this.journalDiff.length - 1][1]
304
+ const addressSlotMap = diff[1]
305
+ if (!addressSlotMap.has(addressHex)) {
306
+ addressSlotMap.set(addressHex, new Set())
307
+ }
308
+ const slotsSet = addressSlotMap.get(addressHex)!
309
+ slotsSet.add(slotStr)
310
+ }
311
+ if (this.accessList !== undefined) {
312
+ // Note: in `addWarmedAddress` the address is added to warm addresses
313
+ const addrSet = this.accessList.get(addressHex)!
314
+ addrSet.add(slotStr)
315
+ }
316
+ }
317
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,180 @@
1
+ import { EthereumJSErrorWithoutCode } from '@feelyourprotocol/util'
2
+
3
+ type EVMPerformanceLogEntry = {
4
+ calls: number
5
+ time: number
6
+ gasUsed: number
7
+ staticGas?: number
8
+ dynamicGasUsed?: number
9
+ }
10
+
11
+ export type EVMPerformanceLogOutput = {
12
+ calls: number // Amount this opcode/precompile was called
13
+ totalTime: number // Amount of seconds taken for this opcode/precompile (rounded to 3 digits)
14
+ avgTimePerCall: number // Avg time per call of this opcode/precompile (rounded to 3 digits)
15
+ gasUsed: number // Total amount of gas used by this opcode/precompile
16
+ millionGasPerSecond: number // How much million gas is executed per second (rounded to 3 digits)
17
+ blocksPerSlot: number // How many blocks is executed per beacon chain slot (rounded to 3 digits)
18
+ tag: string // opcode/precompile tag
19
+ staticGasUsed?: number // total static gas units spent
20
+ dynamicGasUsed?: number // total dynamic gas units spent
21
+ staticGas?: number // static gas of the opcode
22
+ }
23
+
24
+ type EVMPerformanceLogs = {
25
+ [tag: string]: EVMPerformanceLogEntry
26
+ }
27
+
28
+ const blockGasLimit = 30_000_000 // Block gas limit
29
+ const slotTime = 12 // Time in seconds per slot
30
+
31
+ // Normalize constant to check if execution time is above one block per slot (>=1) or not (<1)
32
+ const bpsNormalizer = blockGasLimit / slotTime
33
+
34
+ export class Timer {
35
+ private startTime: number
36
+ private runTime = 0
37
+ tag: string
38
+
39
+ constructor(tag: string) {
40
+ this.tag = tag
41
+ this.startTime = performance.now()
42
+ }
43
+
44
+ pause() {
45
+ this.runTime = this.runTime + performance.now() - this.startTime
46
+ }
47
+
48
+ unpause() {
49
+ this.startTime = performance.now()
50
+ }
51
+
52
+ time() {
53
+ return (performance.now() - this.startTime + this.runTime) / 1000
54
+ }
55
+ }
56
+
57
+ export class EVMPerformanceLogger {
58
+ private opcodes!: EVMPerformanceLogs
59
+ private precompiles!: EVMPerformanceLogs
60
+
61
+ private currentTimer?: Timer
62
+
63
+ constructor() {
64
+ this.clear()
65
+ }
66
+
67
+ clear() {
68
+ this.opcodes = {}
69
+ this.precompiles = {}
70
+ }
71
+
72
+ getLogs() {
73
+ // Return nicely formatted logs
74
+ function getLogsFor(obj: EVMPerformanceLogs) {
75
+ const output: EVMPerformanceLogOutput[] = []
76
+ for (const key in obj) {
77
+ const field = obj[key]
78
+ const gasPerSecond = field.gasUsed / field.time
79
+ const entry: EVMPerformanceLogOutput = {
80
+ calls: field.calls,
81
+ totalTime: Math.round(field.time * 1e6) / 1e3,
82
+ avgTimePerCall: Math.round((field.time / field.calls) * 1e6) / 1e3,
83
+ gasUsed: field.gasUsed,
84
+ millionGasPerSecond: Math.round(gasPerSecond / 1e3) / 1e3,
85
+ blocksPerSlot: Math.round((gasPerSecond / bpsNormalizer) * 1e3) / 1e3,
86
+ tag: key,
87
+ }
88
+ if (field.dynamicGasUsed !== undefined) {
89
+ // This is an opcode entry
90
+ entry.staticGas = field.staticGas
91
+ entry.staticGasUsed = field.staticGas! * field.calls
92
+ entry.dynamicGasUsed = field.dynamicGasUsed
93
+ }
94
+ output.push(entry)
95
+ }
96
+
97
+ output.sort((a, b) => {
98
+ return b.millionGasPerSecond - a.millionGasPerSecond
99
+ })
100
+
101
+ return output
102
+ }
103
+
104
+ return {
105
+ opcodes: getLogsFor(this.opcodes),
106
+ precompiles: getLogsFor(this.precompiles),
107
+ }
108
+ }
109
+
110
+ hasTimer() {
111
+ return this.currentTimer !== undefined
112
+ }
113
+
114
+ // Start a new timer
115
+ // Only one timer can be timing at the same time
116
+ startTimer(tag: string) {
117
+ if (this.currentTimer !== undefined) {
118
+ throw EthereumJSErrorWithoutCode('Cannot have two timers running at the same time')
119
+ }
120
+
121
+ this.currentTimer = new Timer(tag)
122
+ return this.currentTimer
123
+ }
124
+
125
+ // Pauses current timer and returns that timer
126
+ pauseTimer() {
127
+ const timer = this.currentTimer
128
+ if (timer === undefined) {
129
+ throw EthereumJSErrorWithoutCode('No timer to pause')
130
+ }
131
+ timer.pause()
132
+ this.currentTimer = undefined
133
+ return timer
134
+ }
135
+
136
+ // Unpauses current timer and returns that timer
137
+ unpauseTimer(timer: Timer) {
138
+ if (this.currentTimer !== undefined) {
139
+ throw EthereumJSErrorWithoutCode('Cannot unpause timer: another timer is already running')
140
+ }
141
+ timer.unpause()
142
+ this.currentTimer = timer
143
+ }
144
+
145
+ // Stops a timer from running
146
+ stopTimer(
147
+ timer: Timer,
148
+ gasUsed: number,
149
+ targetTimer: 'precompiles' | 'opcodes' = 'opcodes',
150
+ staticGas?: number,
151
+ dynamicGas?: number,
152
+ ) {
153
+ if (this.currentTimer === undefined || this.currentTimer !== timer) {
154
+ throw EthereumJSErrorWithoutCode('Cannot stop timer: another timer is already running')
155
+ }
156
+ const time = timer.time()
157
+ const tag = timer.tag
158
+ this.currentTimer = undefined
159
+
160
+ // Update the fields
161
+ const target = this[targetTimer]
162
+ if (target[tag] === undefined) {
163
+ target[tag] = {
164
+ calls: 0,
165
+ time: 0,
166
+ gasUsed: 0,
167
+ }
168
+ }
169
+ const obj = target[tag]
170
+
171
+ obj.calls++
172
+ obj.time += time
173
+ obj.gasUsed += gasUsed
174
+
175
+ if (targetTimer === 'opcodes') {
176
+ obj.staticGas = staticGas
177
+ obj.dynamicGasUsed = (obj.dynamicGasUsed ?? 0) + dynamicGas!
178
+ }
179
+ }
180
+ }
package/src/memory.ts ADDED
@@ -0,0 +1,82 @@
1
+ import { EthereumJSErrorWithoutCode, concatBytes } from '@feelyourprotocol/util'
2
+
3
+ const ceil = (value: number, ceiling: number): number => {
4
+ const r = value % ceiling
5
+ if (r === 0) {
6
+ return value
7
+ } else {
8
+ return value + ceiling - r
9
+ }
10
+ }
11
+
12
+ const CONTAINER_SIZE = 8192
13
+
14
+ /**
15
+ * Memory implements a simple memory model
16
+ * for the ethereum virtual machine.
17
+ */
18
+ export class Memory {
19
+ _store: Uint8Array
20
+
21
+ constructor() {
22
+ this._store = new Uint8Array(CONTAINER_SIZE)
23
+ }
24
+
25
+ /**
26
+ * Extends the memory given an offset and size. Rounds extended
27
+ * memory to word-size.
28
+ */
29
+ extend(offset: number, size: number) {
30
+ if (size === 0) {
31
+ return
32
+ }
33
+
34
+ const newSize = ceil(offset + size, 32)
35
+ const sizeDiff = newSize - this._store.length
36
+ if (sizeDiff > 0) {
37
+ const expandBy = Math.ceil(sizeDiff / CONTAINER_SIZE) * CONTAINER_SIZE
38
+ this._store = concatBytes(this._store, new Uint8Array(expandBy))
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Writes a byte array with length `size` to memory, starting from `offset`.
44
+ * @param offset - Starting position
45
+ * @param size - How many bytes to write
46
+ * @param value - Value
47
+ */
48
+ write(offset: number, size: number, value: Uint8Array) {
49
+ if (size === 0) {
50
+ return
51
+ }
52
+
53
+ this.extend(offset, size)
54
+
55
+ if (value.length !== size) throw EthereumJSErrorWithoutCode('Invalid value size')
56
+ if (offset + size > this._store.length)
57
+ throw EthereumJSErrorWithoutCode('Value exceeds memory capacity')
58
+
59
+ this._store.set(value, offset)
60
+ }
61
+
62
+ /**
63
+ * Reads a slice of memory from `offset` till `offset + size` as a `Uint8Array`.
64
+ * It fills up the difference between memory's length and `offset + size` with zeros.
65
+ * @param offset - Starting position
66
+ * @param size - How many bytes to read
67
+ * @param avoidCopy - Avoid memory copy if possible for performance reasons (optional)
68
+ */
69
+ read(offset: number, size: number, avoidCopy?: boolean): Uint8Array<ArrayBuffer> {
70
+ this.extend(offset, size)
71
+
72
+ const loaded = this._store.subarray(offset, offset + size) as Uint8Array<ArrayBuffer>
73
+ if (avoidCopy === true) {
74
+ return loaded
75
+ }
76
+ const returnBytes = new Uint8Array(size)
77
+ // Copy the stored "buffer" from memory into the return Uint8Array
78
+ returnBytes.set(loaded)
79
+
80
+ return returnBytes
81
+ }
82
+ }
package/src/message.ts ADDED
@@ -0,0 +1,114 @@
1
+ import { BIGINT_0, EthereumJSErrorWithoutCode, createZeroAddress } from '@feelyourprotocol/util'
2
+
3
+ import type { BinaryTreeAccessWitnessInterface } from '@feelyourprotocol/common'
4
+ import type { Address, PrefixedHexString } from '@feelyourprotocol/util'
5
+ import type { PrecompileFunc } from './precompiles/index.ts'
6
+ import type { EOFEnv, SelfdestructMap } from './types.ts'
7
+
8
+ const defaults = {
9
+ value: BIGINT_0,
10
+ caller: createZeroAddress(),
11
+ data: new Uint8Array(0),
12
+ depth: 0,
13
+ isStatic: false,
14
+ isCompiled: false,
15
+ delegatecall: false,
16
+ gasRefund: BIGINT_0,
17
+ }
18
+
19
+ interface MessageOpts {
20
+ to?: Address
21
+ value?: bigint
22
+ caller?: Address
23
+ gasLimit: bigint
24
+ data?: Uint8Array
25
+ eofCallData?: Uint8Array
26
+ depth?: number
27
+ code?: Uint8Array | PrecompileFunc
28
+ codeAddress?: Address
29
+ isStatic?: boolean
30
+ isCompiled?: boolean
31
+ salt?: Uint8Array
32
+ /**
33
+ * Selfdestructed addresses mapped to their beneficiary, see {@link Message.selfdestruct}
34
+ */
35
+ selfdestruct?: SelfdestructMap
36
+ /**
37
+ * Map of addresses which were created (used in EIP 6780)
38
+ */
39
+ createdAddresses?: Set<PrefixedHexString>
40
+ delegatecall?: boolean
41
+ gasRefund?: bigint
42
+ blobVersionedHashes?: PrefixedHexString[]
43
+ accessWitness?: BinaryTreeAccessWitnessInterface
44
+ }
45
+
46
+ export class Message {
47
+ to?: Address
48
+ value: bigint
49
+ caller: Address
50
+ gasLimit: bigint
51
+ data: Uint8Array
52
+ eofCallData?: Uint8Array // Only used in EOFCreate to signal an EOF contract to be created with this calldata (via EOFCreate)
53
+ isCreate?: boolean
54
+ depth: number
55
+ code?: Uint8Array | PrecompileFunc
56
+ _codeAddress?: Address
57
+ isStatic: boolean
58
+ isCompiled: boolean
59
+ salt?: Uint8Array
60
+ eof?: EOFEnv
61
+ chargeCodeAccesses?: boolean
62
+ /**
63
+ * Selfdestructed addresses mapped to their beneficiary.
64
+ */
65
+ selfdestruct?: SelfdestructMap
66
+ /**
67
+ * Map of addresses which were created (used in EIP 6780)
68
+ */
69
+ createdAddresses?: Set<PrefixedHexString>
70
+ delegatecall: boolean
71
+ gasRefund: bigint // Keeps track of the gasRefund at the start of the frame (used for journaling purposes)
72
+ /**
73
+ * List of versioned hashes if message is a blob transaction in the outer VM
74
+ */
75
+ blobVersionedHashes?: PrefixedHexString[]
76
+ accessWitness?: BinaryTreeAccessWitnessInterface
77
+
78
+ constructor(opts: MessageOpts) {
79
+ this.to = opts.to
80
+ this.value = opts.value ?? defaults.value
81
+ this.caller = opts.caller ?? defaults.caller
82
+ this.gasLimit = opts.gasLimit
83
+ this.data = opts.data ?? defaults.data
84
+ this.eofCallData = opts.eofCallData
85
+ this.depth = opts.depth ?? defaults.depth
86
+ this.code = opts.code
87
+ this._codeAddress = opts.codeAddress
88
+ this.isStatic = opts.isStatic ?? defaults.isStatic
89
+ this.isCompiled = opts.isCompiled ?? defaults.isCompiled
90
+ this.salt = opts.salt
91
+ this.selfdestruct = opts.selfdestruct
92
+ this.createdAddresses = opts.createdAddresses
93
+ this.delegatecall = opts.delegatecall ?? defaults.delegatecall
94
+ this.gasRefund = opts.gasRefund ?? defaults.gasRefund
95
+ this.blobVersionedHashes = opts.blobVersionedHashes
96
+ this.accessWitness = opts.accessWitness
97
+ if (this.value < 0) {
98
+ throw EthereumJSErrorWithoutCode(`value field cannot be negative, received ${this.value}`)
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Note: should only be called in instances where `_codeAddress` or `to` is defined.
104
+ */
105
+ get codeAddress(): Address {
106
+ const codeAddress = this._codeAddress ?? this.to
107
+ if (!codeAddress) {
108
+ throw EthereumJSErrorWithoutCode('Missing codeAddress')
109
+ }
110
+ return codeAddress
111
+ }
112
+ }
113
+
114
+ export type MessageWithTo = Message & Pick<Required<MessageOpts>, 'to'>