@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,531 @@
1
+ import { EOFErrorMessage, validationError } from './errors.ts'
2
+ import { stackDelta } from './stackDelta.ts'
3
+
4
+ import type { EVM } from '../evm.ts'
5
+ import type { EOFContainer } from './container.ts'
6
+
7
+ /**
8
+ * Note for reviewers regarding these flags: these only reside inside `verify.ts` (this file)
9
+ * and `container.ts`. For `container.ts`, the only behavior which ever changes is in the `DeploymentCode` mode
10
+ * This `DeploymentCode` mode means that the subcontainer is flagged in such way that this container is launched
11
+ * in a "deployment" mode. This means, that the data section of the body is actually allowed to contain
12
+ * less data than is written in the header. However, once the target container (by the container in deployment)
13
+ * mode is returned by RETURNCONTRACT it should have at least the header amount of data.
14
+ * See also "data section lifecycle"
15
+ * Note: the subcontainers of a container can be marked "InitCode" or "DeploymentCode".
16
+ * InitCode cannot contain the instructions RETURN / STOP
17
+ * InitCode is the only container type which can contain RETURNCONTRACT
18
+ * A container can also be marked DeploymentCode, this is a subcontainer targeted by RETURNCONTRACT
19
+ * A container cannot be marked both InitCode and DeploymentCode
20
+ * This flag is thus to distinguish between subcontainers, and also thus also allows for data section sizes
21
+ * lower than the size in the header in case of `InitCode`
22
+ */
23
+ export type ContainerSectionType = (typeof ContainerSectionType)[keyof typeof ContainerSectionType]
24
+
25
+ export const ContainerSectionType = {
26
+ InitCode: 'initCode', // Targeted by EOFCreate
27
+ DeploymentCode: 'deploymentCode', // Targeted by RETURNCONTRACT
28
+ RuntimeCode: 'runtimeCode', // "Default" runtime code
29
+ } as const
30
+
31
+ /**
32
+ * This method validates an EOF container deeply. It will validate the opcodes, validate the stack, and performs
33
+ * various checks such as checking for forbidden opcodes in certain modes, jumps to invalid places, etc.
34
+ * For more information, see "Code validation" of https://github.com/ipsilon/eof/blob/main/spec/eof.md
35
+ * This is a compilation of all the extra validation rules introduced by the various EIPs
36
+ * In particular, the stack validation EIP https://eips.ethereum.org/EIPS/eip-5450 is a big part here
37
+ * @param container EOFContainer to verify
38
+ * @param evm The EVM to run in (pulls opcodes from here)
39
+ * @param mode The validation mode to run in
40
+ * @returns Returns a Map which marks what ContainerSectionType each container is
41
+ * NOTE: this should likely not be a map, since a container section can only be of a single type, not multiple
42
+ */
43
+ export function verifyCode(
44
+ container: EOFContainer,
45
+ evm: EVM,
46
+ mode: ContainerSectionType = ContainerSectionType.RuntimeCode,
47
+ ) {
48
+ return validateOpcodes(container, evm, mode)
49
+ }
50
+
51
+ // Helper methods to read Int16s / Uint16s
52
+ function readInt16(code: Uint8Array, start: number) {
53
+ return new DataView(code.buffer).getInt16(start)
54
+ }
55
+
56
+ function readUint16(code: Uint8Array, start: number) {
57
+ return new DataView(code.buffer).getUint16(start)
58
+ }
59
+
60
+ function validateOpcodes(
61
+ container: EOFContainer,
62
+ evm: EVM,
63
+ mode: ContainerSectionType = ContainerSectionType.RuntimeCode,
64
+ ) {
65
+ // Track the type of the container targets
66
+ // Should at the end of the analysis have all the containers
67
+ const containerTypeMap = new Map<number, ContainerSectionType>()
68
+ // TODO (?) -> stackDelta currently only has active EOF opcodes, can use it directly (?)
69
+ // (so no need to generate the valid opcodeNumbers)
70
+
71
+ // Validate each code section
72
+ const opcodes = evm.getActiveOpcodes()
73
+
74
+ const opcodeNumbers = new Set<number>()
75
+
76
+ for (const [key] of opcodes) {
77
+ opcodeNumbers.add(key)
78
+ }
79
+
80
+ // Add INVALID as valid
81
+ opcodeNumbers.add(0xfe)
82
+
83
+ // Remove CODESIZE, CODECOPY, EXTCODESIZE, EXTCODECOPY, EXTCODEHASH, GAS
84
+ opcodeNumbers.delete(0x38)
85
+ opcodeNumbers.delete(0x39)
86
+ opcodeNumbers.delete(0x5a)
87
+ opcodeNumbers.delete(0x3b)
88
+ opcodeNumbers.delete(0x3c)
89
+ opcodeNumbers.delete(0x3f)
90
+
91
+ // Remove CALLCODE and SELFDESTRUCT
92
+ opcodeNumbers.delete(0xf2)
93
+ opcodeNumbers.delete(0xff)
94
+
95
+ // TODO omnibus https://github.com/ipsilon/eof/blob/main/spec/eof.md states
96
+ // JUMP / JUMPI / PC / CREATE / CREATE2 also banned
97
+ // This is not in the EIPs yet
98
+ // Add these opcodes here
99
+
100
+ opcodeNumbers.delete(0x56) // JUMP
101
+ opcodeNumbers.delete(0x57) // JUMPI
102
+
103
+ opcodeNumbers.delete(0x58) // PC
104
+
105
+ opcodeNumbers.delete(0xf0) // CREATE
106
+ opcodeNumbers.delete(0xf5) // CREATE2
107
+
108
+ // Note: Name might be misleading since this is the list of opcodes which are OK as final opcodes in a code section
109
+ // TODO if using stackDelta for EOF it is possible to add a "termination" boolean for the opcode to mark it as terminating
110
+ // (so no need to generate this set here)
111
+ const terminatingOpcodes = new Set<number>()
112
+
113
+ terminatingOpcodes.add(0x00) // STOP
114
+ terminatingOpcodes.add(0xf3) // RETURN
115
+ terminatingOpcodes.add(0xfd) // REVERT
116
+ terminatingOpcodes.add(0xfe) // INVALID
117
+
118
+ terminatingOpcodes.add(0xee) // RETURNCONTRACT
119
+
120
+ terminatingOpcodes.add(0xe4) // RETF
121
+ terminatingOpcodes.add(0xe5) // JUMPF
122
+
123
+ terminatingOpcodes.add(0xe0) // RJUMPing back into code section is OK
124
+
125
+ for (const opcode of terminatingOpcodes) {
126
+ if (!opcodeNumbers.has(opcode)) {
127
+ terminatingOpcodes.delete(opcode)
128
+ }
129
+ }
130
+
131
+ const validJumps = new Set<number>()
132
+
133
+ // Add all reachable code sections
134
+ const reachableSections: { [key: number]: Set<number> } = {}
135
+
136
+ let codeSection = -1
137
+ for (const code of container.body.codeSections) {
138
+ // Track the intermediate bytes
139
+ const intermediateBytes = new Set<number>()
140
+ // Track the jump locations (for forward jumps it is unknown at the first pass if the byte is intermediate)
141
+ const jumpLocations = new Set<number>()
142
+
143
+ function addJump(location: number) {
144
+ if (intermediateBytes.has(location)) {
145
+ // When trying to JUMP into an intermediate byte: this is invalid
146
+ validationError(EOFErrorMessage.INVALID_RJUMP)
147
+ }
148
+ jumpLocations.add(location)
149
+ }
150
+
151
+ function addIntermediate(location: number) {
152
+ if (jumpLocations.has(location)) {
153
+ // When trying to add an intermediate to a location already JUMPed to: this is invalid
154
+ validationError(EOFErrorMessage.INVALID_RJUMP)
155
+ }
156
+ intermediateBytes.add(location)
157
+ }
158
+
159
+ codeSection++
160
+
161
+ reachableSections[codeSection] = new Set()
162
+
163
+ // Section is marked as "non-returning": it does never "return" to another code section
164
+ // it rather exits the current EVM call frame
165
+ const nonReturningFunction = container.body.typeSections[codeSection].outputs === 0x80
166
+
167
+ // Boolean flag to mark if this section has a returning opcode:
168
+ // RETF
169
+ // Or JUMPF into a returning section
170
+ // Each returning section should contain a returning opcode
171
+ let sectionHasReturningOpcode = false
172
+
173
+ // Tracking set of reachable opcodes
174
+ const reachableOpcodes = new Set<number>()
175
+ reachableOpcodes.add(0)
176
+
177
+ // Validate that each opcode is defined
178
+ let ptr = 0
179
+ let lastOpcode: number = 0 // Note: code sections cannot be empty, so this number will always be set
180
+
181
+ // Implement the EIP 5450 stack validation algorithm
182
+ const inputs = container.body.typeSections[codeSection].inputs
183
+ let maxStackHeight = inputs
184
+ // These arrays track the min/max stack height **before** executing the instruction
185
+ const stackHeightMin: number[] = [inputs]
186
+ const stackHeightMax: number[] = [inputs]
187
+
188
+ // Loop over the entire code section and validate various rules
189
+ // For (most) validation rules, see https://github.com/ipsilon/eof/blob/main/spec/eof.md
190
+ // For all validation rules per opcode, find the corresponding EIP, the rules are there
191
+ while (ptr < code.length) {
192
+ // Tracks the successor opcodes of this opcode (for stack purposes)
193
+ const successorSet = new Set<number>()
194
+
195
+ // ReachableOpcodes: this can likely be deleted after implementing the 5450 algorithm
196
+ if (!reachableOpcodes.has(ptr)) {
197
+ validationError(EOFErrorMessage.UNREACHABLE_CODE)
198
+ }
199
+
200
+ if (stackHeightMin[ptr] === undefined || stackHeightMax[ptr] === undefined) {
201
+ // Code is either unreachable or only reachable via a backwards jump
202
+ validationError(EOFErrorMessage.UNREACHABLE_CODE)
203
+ }
204
+
205
+ validJumps.add(ptr)
206
+ const opcode = code[ptr]
207
+
208
+ const minStackCurrent = stackHeightMin[ptr]
209
+ const maxStackCurrent = stackHeightMax[ptr]
210
+
211
+ const opcodeInputs = stackDelta[opcode].inputs
212
+ const opcodeOutputs = stackDelta[opcode].outputs
213
+
214
+ if (minStackCurrent - opcodeInputs < 0) {
215
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
216
+ }
217
+
218
+ const delta = opcodeOutputs - opcodeInputs
219
+
220
+ let minStackNext = minStackCurrent + delta
221
+ let maxStackNext = maxStackCurrent + delta
222
+
223
+ if (maxStackNext > 1024) {
224
+ // TODO verify if 1023 or 1024 is the right constant
225
+ validationError(EOFErrorMessage.STACK_OVERFLOW)
226
+ }
227
+
228
+ if (nonReturningFunction && opcode === 0xe4) {
229
+ validationError(EOFErrorMessage.INVALID_RETURNING_SECTION)
230
+ }
231
+
232
+ lastOpcode = opcode
233
+ if (!opcodeNumbers.has(opcode)) {
234
+ validationError(EOFErrorMessage.INVALID_OPCODE)
235
+ }
236
+
237
+ if (opcode === 0xe0 || opcode === 0xe1) {
238
+ // RJUMP / RJUMPI
239
+ const target = readInt16(code, ptr + 1) + ptr + 3
240
+ if (target < 0 || target >= code.length) {
241
+ validationError(EOFErrorMessage.INVALID_RJUMP)
242
+ }
243
+
244
+ successorSet.add(target)
245
+
246
+ addJump(target)
247
+ reachableOpcodes.add(target)
248
+
249
+ if (opcode === 0xe0) {
250
+ // For RJUMP check that the instruction after RJUMP is reachable
251
+ // If not the case then it is not yet targeted by a forward jump
252
+ // and hence violates the spec
253
+ if (!reachableOpcodes.has(ptr + 3) && ptr + 3 < code.length) {
254
+ // Note: the final condition above ensures that the bytes after ptr are there
255
+ // This is an edge case, if the container ends with RJUMP (which is valid)
256
+ validationError(EOFErrorMessage.UNREACHABLE_CODE)
257
+ }
258
+ }
259
+ } else if (opcode === 0xe2) {
260
+ // RJUMPV
261
+ const tableSize = code[ptr + 1] + 1
262
+
263
+ if (tableSize === undefined) {
264
+ validationError(EOFErrorMessage.OPCODE_INTERMEDIATES_OOB)
265
+ } else if (tableSize === 0) {
266
+ validationError(EOFErrorMessage.RJUMPV_TABLE_SIZE0)
267
+ }
268
+
269
+ if (ptr + tableSize * 2 + 2 >= code.length) {
270
+ // Fall-through case
271
+ validationError(EOFErrorMessage.OPCODE_INTERMEDIATES_OOB)
272
+ }
273
+
274
+ const newPc = ptr + 2 + tableSize * 2
275
+
276
+ for (let i = 0; i < tableSize; i++) {
277
+ const newPtr = ptr + 2 + i * 2
278
+ // Add the table bytes to intermediates
279
+ addIntermediate(newPtr)
280
+ addIntermediate(newPtr + 1)
281
+ const target = readInt16(code, newPtr) + newPc
282
+ if (target < 0 || target >= code.length) {
283
+ validationError(EOFErrorMessage.OPCODE_INTERMEDIATES_OOB)
284
+ }
285
+
286
+ successorSet.add(target)
287
+
288
+ addJump(target)
289
+ reachableOpcodes.add(target)
290
+ }
291
+
292
+ // Special case for RJUMPV: move ptr over the table (the immediate starting byte will be added later)
293
+ // In this special case, add the immediate starting byte
294
+ addIntermediate(ptr + 1)
295
+ ptr += 2 * tableSize + 1
296
+ } else if (opcode === 0xe3 || opcode === 0xe5) {
297
+ // CALLF / JUMPF
298
+ const target = readUint16(code, ptr + 1)
299
+ reachableSections[codeSection].add(target)
300
+ if (target >= container.header.codeSizes.length) {
301
+ validationError(EOFErrorMessage.INVALID_CALL_TARGET)
302
+ }
303
+ if (opcode === 0xe3) {
304
+ // CALLF
305
+ const targetOutputs = container.body.typeSections[target].outputs
306
+ const targetInputs = container.body.typeSections[target].inputs
307
+ if (targetOutputs === 0x80) {
308
+ // CALLF points to non-returning function which is not allowed
309
+ validationError(EOFErrorMessage.INVALID_CALLF_RETURNING)
310
+ }
311
+
312
+ if (minStackCurrent < targetInputs) {
313
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
314
+ }
315
+
316
+ if (
317
+ maxStackCurrent + container.body.typeSections[target].maxStackHeight - targetInputs >
318
+ 1024
319
+ ) {
320
+ validationError(EOFErrorMessage.STACK_OVERFLOW)
321
+ }
322
+
323
+ minStackNext += targetOutputs - targetInputs
324
+ maxStackNext += targetOutputs - targetInputs
325
+ } else {
326
+ // JUMPF
327
+ const currentOutputs = container.body.typeSections[codeSection].outputs
328
+ const targetOutputs = container.body.typeSections[target].outputs
329
+ const targetInputs = container.body.typeSections[target].inputs
330
+ const targetNonReturning = targetOutputs === 0x80
331
+
332
+ if (targetOutputs > currentOutputs && !targetNonReturning) {
333
+ // Spec rule:
334
+ // JUMPF operand must point to a code section with equal or fewer number of outputs as
335
+ // the section in which it resides, or to a section with 0x80 as outputs (non-returning)
336
+ validationError(EOFErrorMessage.INVALID_JUMPF)
337
+ }
338
+
339
+ if (nonReturningFunction && targetOutputs <= 0x7f) {
340
+ // Current function is returning, but target is not, cannot jump into this
341
+ validationError(EOFErrorMessage.INVALID_RETURNING_SECTION)
342
+ }
343
+
344
+ if (targetNonReturning) {
345
+ // Target is returning
346
+ if (minStackCurrent < targetInputs) {
347
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
348
+ }
349
+ } else {
350
+ // Target is returning
351
+ const expectedStack = currentOutputs + targetInputs - targetOutputs
352
+ if (!(minStackCurrent === maxStackCurrent && maxStackCurrent === expectedStack)) {
353
+ validationError(EOFErrorMessage.INVALID_STACK_HEIGHT)
354
+ }
355
+ sectionHasReturningOpcode = true
356
+ }
357
+ if (
358
+ maxStackCurrent + container.body.typeSections[target].maxStackHeight - targetInputs >
359
+ 1024
360
+ ) {
361
+ validationError(EOFErrorMessage.STACK_OVERFLOW)
362
+ }
363
+ }
364
+ } else if (opcode === 0xe4) {
365
+ // RETF
366
+ // Stack height must match the outputs of current code section
367
+ const outputs = container.body.typeSections[codeSection].outputs
368
+ if (!(minStackCurrent === maxStackCurrent && maxStackCurrent === outputs)) {
369
+ validationError(EOFErrorMessage.INVALID_STACK_HEIGHT)
370
+ }
371
+ sectionHasReturningOpcode = true
372
+ } else if (opcode === 0xe6) {
373
+ // DUPN
374
+ const toDup = code[ptr + 1]
375
+ if (toDup + 1 > minStackCurrent) {
376
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
377
+ }
378
+ } else if (opcode === 0xe7) {
379
+ // SWAPN
380
+ const toSwap = code[ptr + 1]
381
+ if (toSwap + 2 > minStackCurrent) {
382
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
383
+ }
384
+ } else if (opcode === 0xe8) {
385
+ // EXCHANGE
386
+ const exchangeRaw = code[ptr + 1]
387
+ const n = (exchangeRaw >> 4) + 1
388
+ const m = (exchangeRaw & 0x0f) + 1
389
+ if (n + m + 1 > minStackCurrent) {
390
+ validationError(EOFErrorMessage.STACK_UNDERFLOW)
391
+ }
392
+ } else if (opcode === 0xec) {
393
+ // EOFCREATE
394
+ const target = code[ptr + 1]
395
+ if (target >= container.header.containerSizes.length) {
396
+ validationError(EOFErrorMessage.INVALID_EOF_CREATE_TARGET)
397
+ }
398
+ if (containerTypeMap.has(target)) {
399
+ if (containerTypeMap.get(target) !== ContainerSectionType.InitCode) {
400
+ validationError(EOFErrorMessage.CONTAINER_DOUBLE_TYPE)
401
+ }
402
+ }
403
+ containerTypeMap.set(target, ContainerSectionType.InitCode)
404
+ } else if (opcode === 0xee) {
405
+ // RETURNCONTRACT
406
+
407
+ if (mode !== ContainerSectionType.InitCode) {
408
+ validationError(EOFErrorMessage.CONTAINER_TYPE_ERROR)
409
+ }
410
+
411
+ const target = code[ptr + 1]
412
+ if (target >= container.header.containerSizes.length) {
413
+ validationError(EOFErrorMessage.INVALID_RETURN_CONTRACT_TARGET)
414
+ }
415
+ if (containerTypeMap.has(target)) {
416
+ if (containerTypeMap.get(target) !== ContainerSectionType.DeploymentCode) {
417
+ validationError(EOFErrorMessage.CONTAINER_DOUBLE_TYPE)
418
+ }
419
+ }
420
+ containerTypeMap.set(target, ContainerSectionType.DeploymentCode)
421
+ } else if (opcode === 0xd1) {
422
+ // DATALOADN
423
+ const dataTarget = readUint16(code, ptr + 1)
424
+ const endOfSlice = dataTarget + 32
425
+ if (container.header.dataSize < endOfSlice) {
426
+ validationError(EOFErrorMessage.DATALOADN_OOB)
427
+ }
428
+ } else if (opcode === 0x00 || opcode === 0xf3) {
429
+ // STOP / RETURN
430
+
431
+ if (mode === ContainerSectionType.InitCode) {
432
+ validationError(EOFErrorMessage.CONTAINER_TYPE_ERROR)
433
+ }
434
+ }
435
+
436
+ // Move ptr forward over any intermediates (if any)
437
+ // Note: for EOF this stackDelta is guaranteed to exist
438
+ const intermediates = stackDelta[opcode].intermediates
439
+ if (intermediates > 0) {
440
+ for (let i = 1; i <= intermediates; i++) {
441
+ addIntermediate(ptr + i)
442
+ }
443
+ ptr += intermediates // If the opcode has any intermediates, jump over it
444
+ }
445
+ if (ptr >= code.length) {
446
+ validationError(EOFErrorMessage.OPCODE_INTERMEDIATES_OOB)
447
+ }
448
+ ptr++ // Move to next opcode
449
+ if (stackDelta[opcode].terminating === undefined) {
450
+ // If the opcode is not terminating we can add the next opcode to the reachable opcodes
451
+ // It can be reached by sequential instruction flow
452
+ reachableOpcodes.add(ptr)
453
+
454
+ // Add next opcode to successorSet
455
+ // NOTE: these are all opcodes except RJUMP
456
+ if (opcode !== 0xe0) {
457
+ successorSet.add(ptr)
458
+ }
459
+ }
460
+
461
+ // TODO here validate stack / reachability and stack overflow check
462
+
463
+ for (const successor of successorSet) {
464
+ if (successor < ptr) {
465
+ // Reached via backwards jump
466
+ if (
467
+ stackHeightMin[successor] !== minStackNext ||
468
+ stackHeightMax[successor] !== maxStackNext
469
+ ) {
470
+ validationError(EOFErrorMessage.UNSTABLE_STACK)
471
+ }
472
+ }
473
+
474
+ if (stackHeightMax[successor] === undefined) {
475
+ // Target is seen for first time
476
+ stackHeightMin[successor] = minStackNext
477
+ stackHeightMax[successor] = maxStackNext
478
+ } else {
479
+ stackHeightMin[successor] = Math.min(stackHeightMin[successor], minStackNext)
480
+ stackHeightMax[successor] = Math.max(stackHeightMax[successor], maxStackNext)
481
+ }
482
+ }
483
+
484
+ maxStackHeight = Math.max(maxStackNext, maxStackHeight)
485
+ }
486
+
487
+ // Validate that the final opcode terminates
488
+ if (!terminatingOpcodes.has(lastOpcode)) {
489
+ validationError(EOFErrorMessage.INVALID_TERMINATOR)
490
+ }
491
+
492
+ if (container.body.typeSections[codeSection].maxStackHeight !== maxStackHeight) {
493
+ validationError(EOFErrorMessage.MAX_STACK_HEIGHT_VIOLATION)
494
+ }
495
+ if (maxStackHeight > 1024) {
496
+ // TODO verify if 1023 or 1024 is the right constant
497
+ validationError(EOFErrorMessage.MAX_STACK_HEIGHT_LIMIT)
498
+ }
499
+
500
+ // Validate that if the section is returning, there is a returning opcode
501
+ if (!sectionHasReturningOpcode && !nonReturningFunction) {
502
+ validationError(EOFErrorMessage.RETURNING_NO_RETURN)
503
+ }
504
+ }
505
+
506
+ // Verify that each code section can be reached from code section 0
507
+ const sectionAccumulator = new Set<number>()
508
+ sectionAccumulator.add(0) // 0 is always reachable
509
+ const toCheck = [0]
510
+
511
+ while (toCheck.length > 0) {
512
+ const checkArray = reachableSections[toCheck.pop()!]
513
+ for (const checkSection of checkArray) {
514
+ if (!sectionAccumulator.has(checkSection)) {
515
+ // Only check the reachable section if
516
+ sectionAccumulator.add(checkSection)
517
+ toCheck.push(checkSection)
518
+ }
519
+ }
520
+ }
521
+
522
+ if (sectionAccumulator.size !== container.header.codeSizes.length) {
523
+ validationError(EOFErrorMessage.UNREACHABLE_CODE_SECTIONS)
524
+ }
525
+
526
+ if (containerTypeMap.size !== container.header.containerSizes.length) {
527
+ validationError(EOFErrorMessage.UNREACHABLE_CONTAINER_SECTIONS)
528
+ }
529
+
530
+ return containerTypeMap
531
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,45 @@
1
+ export type EVMErrorType = (typeof EVMErrorMessage)[keyof typeof EVMErrorMessage]
2
+
3
+ export const EVMErrorTypeString = 'EVMError'
4
+
5
+ const EVMErrorMessage = {
6
+ OUT_OF_GAS: 'out of gas',
7
+ CODESTORE_OUT_OF_GAS: 'code store out of gas',
8
+ CODESIZE_EXCEEDS_MAXIMUM: 'code size to deposit exceeds maximum code size',
9
+ STACK_UNDERFLOW: 'stack underflow',
10
+ STACK_OVERFLOW: 'stack overflow',
11
+ INVALID_JUMP: 'invalid JUMP',
12
+ INVALID_OPCODE: 'invalid opcode',
13
+ OUT_OF_RANGE: 'value out of range',
14
+ REVERT: 'revert',
15
+ STATIC_STATE_CHANGE: 'static state change',
16
+ INTERNAL_ERROR: 'internal error',
17
+ CREATE_COLLISION: 'create collision',
18
+ STOP: 'stop',
19
+ REFUND_EXHAUSTED: 'refund exhausted',
20
+ VALUE_OVERFLOW: 'value overflow',
21
+ INSUFFICIENT_BALANCE: 'insufficient balance',
22
+ INVALID_BYTECODE_RESULT: 'invalid bytecode deployed',
23
+ INITCODE_SIZE_VIOLATION: 'initcode exceeds max initcode size',
24
+ INVALID_INPUT_LENGTH: 'invalid input length',
25
+ INVALID_EOF_FORMAT: 'invalid EOF format',
26
+ BLS_12_381_INVALID_INPUT_LENGTH: 'invalid input length',
27
+ BLS_12_381_POINT_NOT_ON_CURVE: 'point not on curve',
28
+ BLS_12_381_INPUT_EMPTY: 'input is empty',
29
+ BLS_12_381_FP_NOT_IN_FIELD: 'fp point not in field',
30
+ BN254_FP_NOT_IN_FIELD: 'fp point not in field',
31
+ INVALID_COMMITMENT: 'kzg commitment does not match versioned hash',
32
+ INVALID_INPUTS: 'kzg inputs invalid',
33
+ INVALID_PROOF: 'kzg proof invalid',
34
+ } as const
35
+
36
+ export class EVMError {
37
+ error: EVMErrorType
38
+ errorType: string
39
+ static errorMessages: Record<keyof typeof EVMErrorMessage, EVMErrorType> = EVMErrorMessage
40
+
41
+ constructor(error: EVMErrorType) {
42
+ this.error = error
43
+ this.errorType = EVMErrorTypeString
44
+ }
45
+ }