@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,495 @@
1
+ import { EthereumJSErrorWithoutCode } from '@feelyourprotocol/util'
2
+
3
+ import {
4
+ CODE_MIN,
5
+ CODE_SIZE_MIN,
6
+ CONTAINER_MAX,
7
+ CONTAINER_MIN,
8
+ CONTAINER_SIZE_MIN,
9
+ FORMAT,
10
+ INPUTS_MAX,
11
+ KIND_CODE,
12
+ KIND_CONTAINER,
13
+ KIND_DATA,
14
+ KIND_TYPE,
15
+ MAGIC,
16
+ MAX_HEADER_SIZE,
17
+ MAX_STACK_HEIGHT,
18
+ OUTPUTS_MAX,
19
+ TERMINATOR,
20
+ TYPE_DIVISOR,
21
+ TYPE_MAX,
22
+ TYPE_MIN,
23
+ VERSION,
24
+ } from './constants.ts'
25
+ import { EOFErrorMessage, validationError } from './errors.ts'
26
+ import { ContainerSectionType, verifyCode } from './verify.ts'
27
+
28
+ import type { EVM } from '../evm.ts'
29
+
30
+ /*
31
+ This file creates EOF Containers
32
+ EOF Containers are described in EIP-3540.
33
+ A container consists of a header and a body. The header describes the layout of the body.
34
+ The body has the actual "interesting" contents, such as the bytecode to run, the data section,
35
+ and possibly yet-to-be-deployed containers (via EOFCREATE, to create new EOF contracts from an existing one)
36
+ */
37
+
38
+ // This enum marks the "mode" of a container
39
+ // Depending on this mode, certain extra checks for validity have to be done, or some checks can be skipped
40
+ export type EOFContainerMode = (typeof EOFContainerMode)[keyof typeof EOFContainerMode]
41
+
42
+ export const EOFContainerMode = {
43
+ Default: 'default', // Default container validation
44
+ Initmode: 'initMode', // Initmode container validation (for subcontainers pointed to by EOFCreate)
45
+ TxInitmode: 'txInitMode', // Tx initmode container validation (for txs deploying EOF contracts)
46
+ } as const
47
+
48
+ // The StreamReader is a helper class to help reading byte arrays
49
+ class StreamReader {
50
+ private data: Uint8Array // Stream to read
51
+ private ptr: number // Current pointer to where the stream is being read
52
+ constructor(stream: Uint8Array) {
53
+ this.data = stream
54
+ this.ptr = 0
55
+ }
56
+
57
+ /**
58
+ * Read `amount` bytes from the stream. Throws when trying to read out of bounds with an optional error string.
59
+ * This also updates the internal pointer
60
+ * @param amount Bytes to read
61
+ * @param errorStr Optional error string to throw when trying to read out-of-bounds
62
+ * @returns The byte array with length `amount`
63
+ */
64
+ readBytes(amount: number, errorStr?: string) {
65
+ const end = this.ptr + amount
66
+ if (end > this.data.length) {
67
+ validationError(EOFErrorMessage.OUT_OF_BOUNDS, this.ptr, errorStr)
68
+ }
69
+ const ptr = this.ptr
70
+ this.ptr += amount
71
+ return this.data.slice(ptr, end)
72
+ }
73
+
74
+ /**
75
+ * Reads an Uint8. Also updates the pointer.
76
+ * @param errorStr Optional error string
77
+ * @returns The uint8
78
+ */
79
+ readUint(errorStr?: string) {
80
+ if (this.ptr >= this.data.length) {
81
+ validationError(EOFErrorMessage.OUT_OF_BOUNDS, this.ptr, errorStr)
82
+ }
83
+ return this.data[this.ptr++]
84
+ }
85
+
86
+ /**
87
+ * Verify that the current uint8 pointed to by the pointer is the expected uint8
88
+ * Also updates the pointer
89
+ * @param expect The uint to expect
90
+ * @param errorStr Optional error string when the read uint is not the expected uint
91
+ */
92
+ verifyUint(expect: number, errorStr?: string) {
93
+ if (this.readUint() !== expect) {
94
+ validationError(EOFErrorMessage.VERIFY_UINT, this.ptr - 1, errorStr)
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Same as readUint, except this reads an uint16
100
+ * @param errorStr - Optional error message to include in thrown validation errors
101
+ * @returns Unsigned 16-bit integer read from the stream
102
+ */
103
+ readUint16(errorStr?: string) {
104
+ const end = this.ptr + 2
105
+ if (end > this.data.length) {
106
+ validationError(EOFErrorMessage.OUT_OF_BOUNDS, this.ptr, errorStr)
107
+ }
108
+ const ptr = this.ptr
109
+ this.ptr += 2
110
+ return new DataView(this.data.buffer).getUint16(ptr)
111
+ }
112
+
113
+ /**
114
+ * Get the current pointer of the stream
115
+ * @returns The pointer
116
+ */
117
+ getPtr() {
118
+ return this.ptr
119
+ }
120
+
121
+ // Get the remainder bytes of the current stream
122
+ readRemainder() {
123
+ return this.data.slice(this.ptr)
124
+ }
125
+
126
+ // Returns `true` if the stream is fully read, or false if there are dangling bytes
127
+ isAtEnd() {
128
+ return this.ptr === this.data.length
129
+ }
130
+ }
131
+
132
+ // TODO add initcode flags (isEOFContract)
133
+ // TODO validation: mark sections as either initcode or runtime code to validate
134
+
135
+ /**
136
+ * The EOFHeader, describing the header of the EOF container
137
+ */
138
+ class EOFHeader {
139
+ typeSize: number // Size of types section
140
+ codeSizes: number[] // Sizes of code sections
141
+ containerSizes: number[] // Sizes of containers
142
+ dataSize: number // Size of data section
143
+ dataSizePtr: number // Used to edit the dataSize in RETURNCONTRACT
144
+ buffer: Uint8Array // The raw buffer of the entire header
145
+
146
+ private codeStartPos: number[] // Internal array to track at which byte of the container the code starts (per section)
147
+
148
+ /**
149
+ * Create an EOF header. Performs various validation checks inside the constructor
150
+ * @param input either a raw header or a complete container
151
+ */
152
+ constructor(input: Uint8Array) {
153
+ if (input.length > MAX_HEADER_SIZE) {
154
+ throw EthereumJSErrorWithoutCode('err: container size more than maximum valid size')
155
+ }
156
+ const stream = new StreamReader(input)
157
+ // Verify that the header starts with 0xEF0001
158
+ stream.verifyUint(FORMAT, EOFErrorMessage.FORMAT)
159
+ stream.verifyUint(MAGIC, EOFErrorMessage.MAGIC)
160
+ stream.verifyUint(VERSION, EOFErrorMessage.VERSION)
161
+ if (input.length < 15) {
162
+ throw EthereumJSErrorWithoutCode('err: container size less than minimum valid size')
163
+ }
164
+ // Verify that the types section is present and its length is valid
165
+ stream.verifyUint(KIND_TYPE, EOFErrorMessage.KIND_TYPE)
166
+ const typeSize = stream.readUint16(EOFErrorMessage.TYPE_SIZE)
167
+ if (typeSize < TYPE_MIN) {
168
+ validationError(EOFErrorMessage.INVALID_TYPE_SIZE, typeSize)
169
+ }
170
+ if (typeSize % TYPE_DIVISOR !== 0) {
171
+ validationError(EOFErrorMessage.INVALID_TYPE_SIZE, typeSize)
172
+ }
173
+ if (typeSize > TYPE_MAX) {
174
+ throw EthereumJSErrorWithoutCode(
175
+ `err: number of code sections must not exceed 1024 (got ${typeSize})`,
176
+ )
177
+ }
178
+ // Verify that the code section is present and its size is valid
179
+ stream.verifyUint(KIND_CODE, EOFErrorMessage.KIND_CODE)
180
+ const codeSize = stream.readUint16(EOFErrorMessage.CODE_SIZE)
181
+ if (codeSize < CODE_MIN) {
182
+ validationError(EOFErrorMessage.MIN_CODE_SECTIONS)
183
+ }
184
+ if (codeSize !== typeSize / TYPE_DIVISOR) {
185
+ validationError(EOFErrorMessage.TYPE_SECTIONS, typeSize / TYPE_DIVISOR, codeSize)
186
+ }
187
+ // Read the actual code sizes in the code section and verify that each section has the minimum size
188
+ const codeSizes = []
189
+ for (let i = 0; i < codeSize; i++) {
190
+ const codeSectionSize = stream.readUint16(EOFErrorMessage.CODE_SECTION)
191
+ if (codeSectionSize < CODE_SIZE_MIN) {
192
+ validationError(EOFErrorMessage.CODE_SECTION_SIZE)
193
+ }
194
+ codeSizes.push(codeSectionSize)
195
+ }
196
+
197
+ // Check if there are container sections
198
+ let nextSection = stream.readUint()
199
+ const containerSizes: number[] = []
200
+ if (nextSection === KIND_CONTAINER) {
201
+ // The optional container section is present, validate that the size is within bounds
202
+ const containerSectionSize = stream.readUint16(EOFErrorMessage.CONTAINER_SIZE)
203
+
204
+ if (containerSectionSize < CONTAINER_MIN) {
205
+ validationError(EOFErrorMessage.CONTAINER_SECTION_SIZE)
206
+ }
207
+ if (containerSectionSize > CONTAINER_MAX) {
208
+ validationError(EOFErrorMessage.CONTAINER_SECTION_SIZE)
209
+ }
210
+
211
+ // Read the actual container sections and validate that each section has the minimum size
212
+ for (let i = 0; i < containerSectionSize; i++) {
213
+ const containerSize = stream.readUint16(EOFErrorMessage.CONTAINER_SECTION)
214
+
215
+ if (containerSize < CONTAINER_SIZE_MIN) {
216
+ validationError(EOFErrorMessage.CONTAINER_SECTION_MIN)
217
+ }
218
+
219
+ containerSizes.push(containerSize)
220
+ }
221
+
222
+ nextSection = stream.readUint()
223
+ }
224
+
225
+ // Verify that the next section is of the data type
226
+ if (nextSection !== KIND_DATA) {
227
+ validationError(EOFErrorMessage.KIND_DATA)
228
+ }
229
+
230
+ this.dataSizePtr = stream.getPtr()
231
+
232
+ const dataSize = stream.readUint16(EOFErrorMessage.DATA_SIZE)
233
+
234
+ // Verify that the header ends with the TERMINATOR byte
235
+ stream.verifyUint(TERMINATOR, EOFErrorMessage.TERMINATOR)
236
+
237
+ // Write all values to the header object
238
+ this.typeSize = typeSize
239
+ this.codeSizes = codeSizes
240
+ this.containerSizes = containerSizes
241
+ this.dataSize = dataSize
242
+ // Slice the input such that `this.buffer` is now the complete header
243
+ // If there are dangling bytes in the stream, this is OK: this is the body section of the container
244
+ this.buffer = input.slice(0, stream.getPtr())
245
+ const relativeOffset = this.buffer.length + this.typeSize
246
+ // Write the start of the first code section into `codeStartPos`
247
+ // Note: in EVM, if one would set the Program Counter to this byte, it would start executing the bytecode of the first code section
248
+ this.codeStartPos = [relativeOffset]
249
+ }
250
+
251
+ sections() {
252
+ return [this.typeSize, this.codeSizes, this.containerSizes, this.dataSize]
253
+ }
254
+ sectionSizes() {
255
+ return [1, this.codeSizes.length, this.containerSizes.length, 1]
256
+ }
257
+
258
+ // Returns the code position in the container for the requested section
259
+ // Setting the Program Counter in the EVM to a number of this array would start executing the bytecode of the indexed section
260
+ getCodePosition(section: number) {
261
+ if (this.codeStartPos[section]) {
262
+ return this.codeStartPos[section]
263
+ }
264
+ const start = this.codeStartPos.length
265
+ let offset = this.codeStartPos[start - 1]
266
+ for (let i = start; i <= section; i++) {
267
+ offset += this.codeSizes[i - 1]
268
+ this.codeStartPos[i] = offset
269
+ }
270
+ return offset
271
+ }
272
+
273
+ // Returns the code section for a given program counter position
274
+ getSectionFromProgramCounter(programCounter: number) {
275
+ const lastIndex = this.codeSizes.length - 1
276
+ const lastStart = this.getCodePosition(lastIndex)
277
+ const lastEnd = lastStart + this.codeSizes[lastIndex]
278
+ if (programCounter < 0 || programCounter > lastEnd) {
279
+ // If code position is outside the beginning or end of the code sections, return 0
280
+ throw EthereumJSErrorWithoutCode('program counter out of bounds')
281
+ }
282
+
283
+ if (this.codeStartPos.length < this.codeSizes.length) {
284
+ this.getCodePosition(this.codeSizes.length - 1) // initialize code positions if uninitialized
285
+ }
286
+
287
+ for (let i = 0; i < this.codeSizes.length; i++) {
288
+ if (programCounter < this.codeStartPos[i] + this.codeSizes[i]) {
289
+ // We've found our section if the code position is less than the end of the current code section
290
+ return i
291
+ }
292
+ }
293
+ // This shouldn't happen so just error
294
+ throw EthereumJSErrorWithoutCode(`Invalid program counter value: ${programCounter}`)
295
+ }
296
+ }
297
+
298
+ export interface TypeSection {
299
+ inputs: number
300
+ outputs: number
301
+ maxStackHeight: number
302
+ }
303
+
304
+ /**
305
+ * The EOF body holds the contents of the EOF container, such as the code sections (bytecode),
306
+ * the subcontainers (EOF containers to be deployed via EOFCREATE) and the data section
307
+ */
308
+ class EOFBody {
309
+ typeSections: TypeSection[] // Array of type sections, used to index the inputs/outputs/max stack height of each section
310
+ codeSections: Uint8Array[] // Bytecode of each code section
311
+ containerSections: Uint8Array[] // Raw container bytes of each subcontainer
312
+ entireCode: Uint8Array // The `entireCode` are all code sections concatenated
313
+ dataSection: Uint8Array // Bytes of the data section
314
+ buffer: Uint8Array // Raw bytes of the body
315
+
316
+ txCallData?: Uint8Array // Only available in TxInitmode. The `txCallData` are the dangling bytes after parsing the container,
317
+ // and these are used for the CALLDATA in the EVM when trying to create a contract via a transaction, and the deployment code is an EOF container
318
+
319
+ constructor(
320
+ buf: Uint8Array, // Buffer of the body. This should be the entire body. It is not valid to pass an entire EOF container in here
321
+ header: EOFHeader, // EOFHeader corresponding to this body
322
+ eofMode: EOFContainerMode = EOFContainerMode.Default, // Container mode of EOF
323
+ dataSectionAllowedSmaller = false, // Only for validation: Deployment containers are allowed to have smaller data section size
324
+ ) {
325
+ const stream = new StreamReader(buf)
326
+ const typeSections: TypeSection[] = []
327
+ // Read and parse each type section, and validate that the type section values are within valid bounds
328
+ for (let i = 0; i < header.typeSize / 4; i++) {
329
+ const inputs = stream.readUint(EOFErrorMessage.INPUTS)
330
+ const outputs = stream.readUint(EOFErrorMessage.OUTPUTS)
331
+ const maxStackHeight = stream.readUint16(EOFErrorMessage.MAX_STACK_HEIGHT)
332
+ if (i === 0) {
333
+ if (inputs !== 0) {
334
+ validationError(EOFErrorMessage.CODE0_INPUTS)
335
+ }
336
+ if (outputs !== 0x80) {
337
+ validationError(EOFErrorMessage.CODE0_OUTPUTS)
338
+ }
339
+ }
340
+ if (inputs > INPUTS_MAX) {
341
+ validationError(EOFErrorMessage.MAX_INPUTS, i, inputs)
342
+ }
343
+ if (outputs > OUTPUTS_MAX) {
344
+ validationError(EOFErrorMessage.MAX_OUTPUTS, i, outputs)
345
+ }
346
+ if (maxStackHeight > MAX_STACK_HEIGHT) {
347
+ validationError(EOFErrorMessage.MAX_STACK_HEIGHT_LIMIT, i, maxStackHeight)
348
+ }
349
+ typeSections.push({
350
+ inputs,
351
+ outputs,
352
+ maxStackHeight,
353
+ })
354
+ }
355
+ // Read each code section
356
+ const codeStartPtr = stream.getPtr()
357
+ const codes = []
358
+ for (const [i, codeSize] of header.codeSizes.entries()) {
359
+ try {
360
+ const code = stream.readBytes(codeSize)
361
+ codes.push(code)
362
+ } catch {
363
+ validationError(EOFErrorMessage.CODE_SECTION, i)
364
+ }
365
+ }
366
+ // Write the entire code section to the entireCodeSection
367
+ const entireCodeSection = buf.slice(codeStartPtr, stream.getPtr())
368
+
369
+ // Read all raw subcontainers and push those to the containers array
370
+ const containers = []
371
+ for (const [i, containerSize] of header.containerSizes.entries()) {
372
+ try {
373
+ const container = stream.readBytes(containerSize)
374
+ containers.push(container)
375
+ } catch {
376
+ validationError(EOFErrorMessage.CONTAINER_SECTION, i)
377
+ }
378
+ }
379
+
380
+ // Data section of the body
381
+ // Note: for EOF containers in Initmode (these are Subcontainers) it is allowed
382
+ // to have a data section of size lower than what is written in the header
383
+ // For details, see "Data section lifecycle" of EIP 7620
384
+ let dataSection: Uint8Array
385
+
386
+ // Edge case: deployment code validation
387
+ if (eofMode !== EOFContainerMode.Initmode && !dataSectionAllowedSmaller) {
388
+ dataSection = stream.readBytes(header.dataSize, EOFErrorMessage.DATA_SECTION)
389
+
390
+ if (eofMode === EOFContainerMode.Default) {
391
+ if (!stream.isAtEnd()) {
392
+ // If there are dangling bytes in default container mode, this is invalid
393
+ validationError(EOFErrorMessage.DANGLING_BYTES)
394
+ }
395
+ } else {
396
+ // Tx init mode: the remaining bytes (if any) are used as CALLDATA in the EVM, in case of a Tx init
397
+ this.txCallData = stream.readRemainder()
398
+ }
399
+ } else {
400
+ dataSection = stream.readRemainder()
401
+
402
+ if (dataSection.length > header.dataSize) {
403
+ validationError(EOFErrorMessage.DANGLING_BYTES)
404
+ }
405
+ }
406
+
407
+ // Write all data to the object
408
+ this.typeSections = typeSections
409
+ this.codeSections = codes
410
+ this.containerSections = containers
411
+ this.entireCode = entireCodeSection
412
+ this.dataSection = dataSection
413
+ this.buffer = buf
414
+ }
415
+ sections() {
416
+ return [this.typeSections, this.codeSections, this.dataSection]
417
+ }
418
+ size() {
419
+ return {
420
+ typeSize: this.typeSections.length,
421
+ codeSize: this.codeSections.length,
422
+ dataSize: this.dataSection.length,
423
+ }
424
+ }
425
+ sectionSizes() {
426
+ return [
427
+ this.typeSections.map(() => 4),
428
+ this.codeSections.map((b) => b.length),
429
+ this.dataSection.length,
430
+ ]
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Main constructor for the EOFContainer
436
+ */
437
+ export class EOFContainer {
438
+ header: EOFHeader
439
+ body: EOFBody
440
+ buffer: Uint8Array
441
+ eofMode: EOFContainerMode
442
+
443
+ /**
444
+ *
445
+ * @param buf Entire container buffer
446
+ * @param eofMode Container mode to validate the container on
447
+ * @param dataSectionAllowedSmaller `true` if the data section is allowed to be smaller than the data section size in the header
448
+ */
449
+ constructor(
450
+ buf: Uint8Array,
451
+ eofMode: EOFContainerMode = EOFContainerMode.Default,
452
+ dataSectionAllowedSmaller = false,
453
+ ) {
454
+ this.eofMode = eofMode
455
+ this.header = new EOFHeader(buf)
456
+ this.body = new EOFBody(
457
+ buf.slice(this.header.buffer.length),
458
+ this.header,
459
+ eofMode,
460
+ dataSectionAllowedSmaller,
461
+ )
462
+ this.buffer = buf
463
+ }
464
+ }
465
+
466
+ /**
467
+ * This method validates the EOF. It also performs deeper validation of the body, such as stack/opcode validation
468
+ * This is ONLY necessary when trying to deploy contracts from a transaction: these can submit containers which are invalid
469
+ * Since all deployed EOF containers are valid by definition, `validateEOF` does not need to be called each time an EOF contract is called
470
+ * @param input Full container buffer
471
+ * @param evm EVM, to read opcodes from
472
+ * @param containerMode Container mode to validate on
473
+ * @param eofMode EOF mode to run in
474
+ * @returns The decoded EOF container
475
+ */
476
+ export function validateEOF(
477
+ input: Uint8Array,
478
+ evm: EVM,
479
+ containerMode: ContainerSectionType = ContainerSectionType.RuntimeCode,
480
+ eofMode: EOFContainerMode = EOFContainerMode.Default,
481
+ ) {
482
+ const container = new EOFContainer(
483
+ input,
484
+ eofMode,
485
+ containerMode === ContainerSectionType.DeploymentCode,
486
+ )
487
+ const containerMap = verifyCode(container, evm, containerMode)
488
+ // Recursively validate the containerSections
489
+ for (let i = 0; i < container.body.containerSections.length; i++) {
490
+ const subContainer = container.body.containerSections[i]
491
+ const mode = containerMap.get(i)!
492
+ validateEOF(subContainer, evm, mode)
493
+ }
494
+ return container
495
+ }