@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,215 @@
1
+ import {
2
+ BIGINT_0,
3
+ BIGINT_1,
4
+ BIGINT_2,
5
+ BIGINT_7,
6
+ BIGINT_8,
7
+ BIGINT_32,
8
+ BIGINT_64,
9
+ BIGINT_96,
10
+ bigIntToBytes,
11
+ bytesToBigInt,
12
+ bytesToHex,
13
+ setLengthLeft,
14
+ setLengthRight,
15
+ } from '@feelyourprotocol/util'
16
+
17
+ import { OOGResult } from '../evm.ts'
18
+
19
+ import { getPrecompileName } from './index.ts'
20
+ import { gasLimitCheck } from './util.ts'
21
+
22
+ import type { ExecResult } from '../types.ts'
23
+ import type { PrecompileInput } from './types.ts'
24
+
25
+ const BIGINT_4 = BigInt(4)
26
+ const BIGINT_16 = BigInt(16)
27
+ const BIGINT_480 = BigInt(480)
28
+ const BIGINT_200 = BigInt(200)
29
+ const BIGINT_500 = BigInt(500)
30
+ const BIGINT_1024 = BigInt(1024)
31
+ const BIGINT_3072 = BigInt(3072)
32
+ const BIGINT_199680 = BigInt(199680)
33
+ const BIGINT_2147483647 = BigInt(2147483647)
34
+
35
+ const maxInt = BigInt(Number.MAX_SAFE_INTEGER)
36
+
37
+ function multiplicationComplexity(x: bigint): bigint {
38
+ let fac1
39
+ let fac2
40
+ if (x <= BIGINT_64) {
41
+ return x ** BIGINT_2
42
+ } else if (x <= BIGINT_1024) {
43
+ // return Math.floor(Math.pow(x, 2) / 4) + 96 * x - 3072
44
+ fac1 = x ** BIGINT_2 / BIGINT_4
45
+ fac2 = x * BIGINT_96
46
+ return fac1 + fac2 - BIGINT_3072
47
+ } else {
48
+ // return Math.floor(Math.pow(x, 2) / 16) + 480 * x - 199680
49
+ fac1 = x ** BIGINT_2 / BIGINT_16
50
+ fac2 = x * BIGINT_480
51
+ return fac1 + fac2 - BIGINT_199680
52
+ }
53
+ }
54
+
55
+ function getAdjustedExponentLength(data: Uint8Array, opts: PrecompileInput): bigint {
56
+ let expBytesStart
57
+ try {
58
+ const baseLen = bytesToBigInt(data.subarray(0, 32))
59
+ expBytesStart = 96 + Number(baseLen) // 96 for base length, then exponent length, and modulus length, then baseLen for the base data, then exponent bytes start
60
+ } catch {
61
+ expBytesStart = Number.MAX_SAFE_INTEGER - 32
62
+ }
63
+ const expLen = bytesToBigInt(data.subarray(32, 64))
64
+ let firstExpBytes = data.subarray(expBytesStart, expBytesStart + 32) // first word of the exponent data
65
+ firstExpBytes = setLengthRight(firstExpBytes, 32) // reading past the data reads virtual zeros
66
+ let firstExpBigInt = bytesToBigInt(firstExpBytes)
67
+ let max32expLen = 0
68
+ if (expLen < BIGINT_32) {
69
+ max32expLen = 32 - Number(expLen)
70
+ }
71
+ firstExpBigInt = firstExpBigInt >> (BIGINT_8 * BigInt(Math.max(max32expLen, 0)))
72
+
73
+ let bitLen = -1
74
+ while (firstExpBigInt > BIGINT_0) {
75
+ bitLen = bitLen + 1
76
+ firstExpBigInt = firstExpBigInt >> BIGINT_1
77
+ }
78
+ let expLenMinus32OrZero = expLen - BIGINT_32
79
+ if (expLenMinus32OrZero < BIGINT_0) {
80
+ expLenMinus32OrZero = BIGINT_0
81
+ }
82
+ let adjustedExpLen =
83
+ expLenMinus32OrZero * (opts.common.isActivatedEIP(7883) === true ? BIGINT_16 : BIGINT_8)
84
+ if (bitLen > 0) {
85
+ adjustedExpLen += BigInt(bitLen)
86
+ }
87
+ return adjustedExpLen
88
+ }
89
+
90
+ export function expMod(a: bigint, power: bigint, modulo: bigint) {
91
+ if (power === BIGINT_0) {
92
+ return BIGINT_1 % modulo
93
+ }
94
+ let res = BIGINT_1
95
+ while (power > BIGINT_0) {
96
+ if (power & BIGINT_1) res = (res * a) % modulo
97
+ a = (a * a) % modulo
98
+ power >>= BIGINT_1
99
+ }
100
+ return res
101
+ }
102
+
103
+ export function precompile05(opts: PrecompileInput): ExecResult {
104
+ const pName = getPrecompileName('05')
105
+ const data = opts.data.length < 96 ? setLengthRight(opts.data, 96) : opts.data
106
+
107
+ let adjustedELen = getAdjustedExponentLength(data, opts)
108
+ if (adjustedELen < BIGINT_1) {
109
+ adjustedELen = BIGINT_1
110
+ }
111
+
112
+ const bLen = bytesToBigInt(data.subarray(0, 32))
113
+ const eLen = bytesToBigInt(data.subarray(32, 64))
114
+ const mLen = bytesToBigInt(data.subarray(64, 96))
115
+
116
+ let maxLen = bLen
117
+ if (maxLen < mLen) {
118
+ maxLen = mLen
119
+ }
120
+ const Gquaddivisor = opts.common.param('modexpGquaddivisorGas')
121
+ let gasUsed
122
+
123
+ const bStart = BIGINT_96
124
+ const bEnd = bStart + bLen
125
+ const eStart = bEnd
126
+ const eEnd = eStart + eLen
127
+ const mStart = eEnd
128
+ const mEnd = mStart + mLen
129
+
130
+ if (opts.common.isActivatedEIP(2565)) {
131
+ const words = (maxLen + BIGINT_7) / BIGINT_8
132
+ if (opts.common.isActivatedEIP(7883)) {
133
+ gasUsed = adjustedELen * (maxLen > BIGINT_32 ? BIGINT_2 * words * words : BIGINT_16)
134
+ if (gasUsed < BIGINT_500) {
135
+ gasUsed = BIGINT_500
136
+ }
137
+ } else {
138
+ gasUsed = (adjustedELen * words * words) / Gquaddivisor
139
+ if (gasUsed < BIGINT_200) {
140
+ gasUsed = BIGINT_200
141
+ }
142
+ }
143
+ } else {
144
+ gasUsed = (adjustedELen * multiplicationComplexity(maxLen)) / Gquaddivisor
145
+ }
146
+
147
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
148
+ return OOGResult(opts.gasLimit)
149
+ }
150
+
151
+ // Upper bounds by EIP-7823 (Osaka and upwards) or otherwise
152
+ // @feelyourprotocol/util setLengthRight limitation
153
+ const maxSize = opts.common.isActivatedEIP(7823) ? BIGINT_1024 : BIGINT_2147483647
154
+
155
+ if (opts._debug !== undefined) {
156
+ // Lengths value debugging
157
+ const total = BigInt(96) + bLen + eLen + mLen
158
+ const data = BigInt(opts.data.length)
159
+ let msg = `${pName} length values: maxSize(b/e/m)=${maxSize} bLen=${bLen} eLen=${eLen} mLen=${mLen} 96+b+e+m=${total} `
160
+ msg += `data=${data} lengthMatch=${total === data}`
161
+ opts._debug(msg)
162
+ }
163
+
164
+ // Optimization: do not compute for b and m being 0 but return early
165
+ if (!opts.common.isActivatedEIP(7823) && bLen === BIGINT_0 && mLen === BIGINT_0) {
166
+ return {
167
+ executionGasUsed: gasUsed,
168
+ returnValue: new Uint8Array(),
169
+ }
170
+ }
171
+
172
+ if (bLen > maxSize || eLen > maxSize || mLen > maxSize) {
173
+ if (opts._debug !== undefined) {
174
+ opts._debug(`${pName} failed: one or more input values too large`)
175
+ }
176
+ return OOGResult(opts.gasLimit)
177
+ }
178
+
179
+ if (mEnd > maxInt) {
180
+ if (opts._debug !== undefined) {
181
+ opts._debug(`${pName} failed: total input too large`)
182
+ }
183
+ return OOGResult(opts.gasLimit)
184
+ }
185
+
186
+ const B = bytesToBigInt(setLengthRight(data.subarray(Number(bStart), Number(bEnd)), Number(bLen)))
187
+ const E = bytesToBigInt(setLengthRight(data.subarray(Number(eStart), Number(eEnd)), Number(eLen)))
188
+ const M = bytesToBigInt(setLengthRight(data.subarray(Number(mStart), Number(mEnd)), Number(mLen)))
189
+
190
+ if (opts._debug !== undefined) {
191
+ opts._debug(`${pName} input: B=${B} E=${E} M=${M}`)
192
+ }
193
+
194
+ let R
195
+ if (M === BIGINT_0) {
196
+ R = new Uint8Array()
197
+ } else {
198
+ R = expMod(B, E, M)
199
+ if (R === BIGINT_0) {
200
+ R = new Uint8Array()
201
+ } else {
202
+ R = bigIntToBytes(R)
203
+ }
204
+ }
205
+
206
+ const res = setLengthLeft(R, Number(mLen))
207
+ if (opts._debug !== undefined) {
208
+ opts._debug(`${pName} return value=${bytesToHex(res)}`)
209
+ }
210
+
211
+ return {
212
+ executionGasUsed: gasUsed,
213
+ returnValue: res,
214
+ }
215
+ }
@@ -0,0 +1,49 @@
1
+ import { bytesToHex, setLengthRight } from '@feelyourprotocol/util'
2
+
3
+ import { EVMErrorResult, OOGResult } from '../evm.ts'
4
+
5
+ import { getPrecompileName } from './index.ts'
6
+ import { gasLimitCheck } from './util.ts'
7
+
8
+ import type { EVM } from '../evm.ts'
9
+ import type { ExecResult } from '../types.ts'
10
+ import type { PrecompileInput } from './types.ts'
11
+
12
+ export function precompile06(opts: PrecompileInput): ExecResult {
13
+ const pName = getPrecompileName('06')
14
+ const gasUsed = opts.common.param('bn254AddGas')
15
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
16
+ return OOGResult(opts.gasLimit)
17
+ }
18
+
19
+ // > 128 bytes: chop off extra bytes
20
+ // < 128 bytes: right-pad with 0-s
21
+ const input = setLengthRight(opts.data.subarray(0, 128), 128)
22
+
23
+ let returnData
24
+ try {
25
+ returnData = (opts._EVM as EVM)['_bn254'].add(input)
26
+ } catch (e: any) {
27
+ if (opts._debug !== undefined) {
28
+ opts._debug(`${pName} failed: ${e.message}`)
29
+ }
30
+ return EVMErrorResult(e, opts.gasLimit)
31
+ }
32
+
33
+ // check ecadd success or failure by comparing the output length
34
+ if (returnData.length !== 64) {
35
+ if (opts._debug !== undefined) {
36
+ opts._debug(`${pName} failed: OOG`)
37
+ }
38
+ return OOGResult(opts.gasLimit)
39
+ }
40
+
41
+ if (opts._debug !== undefined) {
42
+ opts._debug(`${pName} return value=${bytesToHex(returnData)}`)
43
+ }
44
+
45
+ return {
46
+ executionGasUsed: gasUsed,
47
+ returnValue: returnData,
48
+ }
49
+ }
@@ -0,0 +1,50 @@
1
+ import { bytesToHex, setLengthRight } from '@feelyourprotocol/util'
2
+
3
+ import { EVMErrorResult, OOGResult } from '../evm.ts'
4
+
5
+ import { getPrecompileName } from './index.ts'
6
+ import { gasLimitCheck } from './util.ts'
7
+
8
+ import type { EVM } from '../evm.ts'
9
+ import type { ExecResult } from '../types.ts'
10
+ import type { PrecompileInput } from './types.ts'
11
+
12
+ export function precompile07(opts: PrecompileInput): ExecResult {
13
+ const pName = getPrecompileName('07')
14
+ const gasUsed = opts.common.param('bn254MulGas')
15
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
16
+ return OOGResult(opts.gasLimit)
17
+ }
18
+
19
+ // > 128 bytes: chop off extra bytes
20
+ // < 128 bytes: right-pad with 0-s
21
+ const input = setLengthRight(opts.data.subarray(0, 128), 128)
22
+
23
+ let returnData
24
+ try {
25
+ returnData = (opts._EVM as EVM)['_bn254'].mul(input)
26
+ } catch (e: any) {
27
+ if (opts._debug !== undefined) {
28
+ opts._debug(`${pName} failed: ${e.message}`)
29
+ }
30
+ return EVMErrorResult(e, opts.gasLimit)
31
+ }
32
+
33
+ // check ecmul success or failure by comparing the output length
34
+ if (returnData.length !== 64) {
35
+ if (opts._debug !== undefined) {
36
+ opts._debug(`${pName} failed: OOG`)
37
+ }
38
+ // TODO: should this really return OOG?
39
+ return OOGResult(opts.gasLimit)
40
+ }
41
+
42
+ if (opts._debug !== undefined) {
43
+ opts._debug(`${pName} return value=${bytesToHex(returnData)}`)
44
+ }
45
+
46
+ return {
47
+ executionGasUsed: gasUsed,
48
+ returnValue: returnData,
49
+ }
50
+ }
@@ -0,0 +1,54 @@
1
+ import { bytesToHex } from '@feelyourprotocol/util'
2
+
3
+ import { EVMError } from '../errors.ts'
4
+ import { EVMErrorResult, OOGResult } from '../evm.ts'
5
+
6
+ import { getPrecompileName } from './index.ts'
7
+ import { gasLimitCheck, moduloLengthCheck } from './util.ts'
8
+
9
+ import type { EVM } from '../evm.ts'
10
+ import type { ExecResult } from '../types.ts'
11
+ import type { PrecompileInput } from './types.ts'
12
+
13
+ export function precompile08(opts: PrecompileInput): ExecResult {
14
+ const pName = getPrecompileName('08')
15
+ if (!moduloLengthCheck(opts, 192, pName)) {
16
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_INPUT_LENGTH), opts.gasLimit)
17
+ }
18
+
19
+ const inputDataSize = BigInt(Math.floor(opts.data.length / 192))
20
+ const gasUsed =
21
+ opts.common.param('bn254PairingGas') + inputDataSize * opts.common.param('bn254PairingWordGas')
22
+
23
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
24
+ return OOGResult(opts.gasLimit)
25
+ }
26
+
27
+ let returnData
28
+ try {
29
+ returnData = (opts._EVM as EVM)['_bn254'].pairing(opts.data)
30
+ } catch (e: any) {
31
+ if (opts._debug !== undefined) {
32
+ opts._debug(`${pName} failed: ${e.message}`)
33
+ }
34
+ return EVMErrorResult(e, opts.gasLimit)
35
+ }
36
+
37
+ // check ecpairing success or failure by comparing the output length
38
+ if (returnData.length !== 32) {
39
+ if (opts._debug !== undefined) {
40
+ opts._debug(`${pName} failed: OOG`)
41
+ }
42
+ // TODO: should this really return OOG?
43
+ return OOGResult(opts.gasLimit)
44
+ }
45
+
46
+ if (opts._debug !== undefined) {
47
+ opts._debug(`${pName} return value=${bytesToHex(returnData)}`)
48
+ }
49
+
50
+ return {
51
+ executionGasUsed: gasUsed,
52
+ returnValue: returnData,
53
+ }
54
+ }
@@ -0,0 +1,243 @@
1
+ import { bytesToHex } from '@feelyourprotocol/util'
2
+
3
+ import { EVMError } from '../errors.ts'
4
+ import { OOGResult } from '../evm.ts'
5
+
6
+ import { getPrecompileName } from './index.ts'
7
+ import { gasLimitCheck } from './util.ts'
8
+
9
+ import type { ExecResult } from '../types.ts'
10
+ import type { PrecompileInput } from './types.ts'
11
+
12
+ // The following blake2 code has been taken from (license: Creative Commons CC0):
13
+ // https://github.com/dcposch/blakejs/blob/410c640d0f08d3b26904c6d1ab3d81df3619d282/blake2b.js
14
+ // The modifications include:
15
+ // - Avoiding the use of context in F
16
+ // - F accepts number of rounds as parameter
17
+ // - Expect 2 64-byte t values, xor them both
18
+ // - Take modulo 10 for indices of SIGMA
19
+ // - Added type annotations
20
+ // - Moved previously global `v` and `m` variables inside the F function
21
+
22
+ // 64-bit unsigned addition
23
+ // Sets v[a,a+1] += v[b,b+1]
24
+ // v should be a Uint32Array
25
+ function ADD64AA(v: Uint32Array, a: number, b: number) {
26
+ const o0 = v[a] + v[b]
27
+ let o1 = v[a + 1] + v[b + 1]
28
+ if (o0 >= 0x100000000) {
29
+ o1++
30
+ }
31
+ v[a] = o0
32
+ v[a + 1] = o1
33
+ }
34
+
35
+ // 64-bit unsigned addition
36
+ // Sets v[a,a+1] += b
37
+ // b0 is the low 32 bits of b, b1 represents the high 32 bits
38
+ function ADD64AC(v: Uint32Array, a: number, b0: number, b1: number) {
39
+ let o0 = v[a] + b0
40
+ if (b0 < 0) {
41
+ o0 += 0x100000000
42
+ }
43
+ let o1 = v[a + 1] + b1
44
+ if (o0 >= 0x100000000) {
45
+ o1++
46
+ }
47
+ v[a] = o0
48
+ v[a + 1] = o1
49
+ }
50
+
51
+ // G Mixing function
52
+ // The ROTRs are inlined for speed
53
+ function B2B_G(
54
+ v: Uint32Array,
55
+ mw: Uint32Array,
56
+ a: number,
57
+ b: number,
58
+ c: number,
59
+ d: number,
60
+ ix: number,
61
+ iy: number,
62
+ ) {
63
+ const x0 = mw[ix]
64
+ const x1 = mw[ix + 1]
65
+ const y0 = mw[iy]
66
+ const y1 = mw[iy + 1]
67
+
68
+ ADD64AA(v, a, b) // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
69
+ ADD64AC(v, a, x0, x1) // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
70
+
71
+ // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
72
+ let xor0 = v[d] ^ v[a]
73
+ let xor1 = v[d + 1] ^ v[a + 1]
74
+ v[d] = xor1
75
+ v[d + 1] = xor0
76
+
77
+ ADD64AA(v, c, d)
78
+
79
+ // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
80
+ xor0 = v[b] ^ v[c]
81
+ xor1 = v[b + 1] ^ v[c + 1]
82
+ v[b] = (xor0 >>> 24) ^ (xor1 << 8)
83
+ v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8)
84
+
85
+ ADD64AA(v, a, b)
86
+ ADD64AC(v, a, y0, y1)
87
+
88
+ // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
89
+ xor0 = v[d] ^ v[a]
90
+ xor1 = v[d + 1] ^ v[a + 1]
91
+ v[d] = (xor0 >>> 16) ^ (xor1 << 16)
92
+ v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16)
93
+
94
+ ADD64AA(v, c, d)
95
+
96
+ // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
97
+ xor0 = v[b] ^ v[c]
98
+ xor1 = v[b + 1] ^ v[c + 1]
99
+ v[b] = (xor1 >>> 31) ^ (xor0 << 1)
100
+ v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1)
101
+ }
102
+
103
+ // Initialization Vector
104
+ // prettier-ignore
105
+ const BLAKE2B_IV32 = new Uint32Array([
106
+ 0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,
107
+ 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,
108
+ ])
109
+
110
+ // prettier-ignore
111
+ const SIGMA8 = [
112
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11,
113
+ 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6,
114
+ 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8,
115
+ 3, 4, 13, 7, 5, 15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7, 14,
116
+ 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5, 10,
117
+ 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
118
+ 14, 15, 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
119
+ ]
120
+
121
+ // These are offsets into a uint64 buffer.
122
+ // Multiply them all by 2 to make them offsets into a uint32 buffer,
123
+ // because this is Javascript and we don't have uint64s
124
+ const SIGMA82 = new Uint8Array(
125
+ SIGMA8.map(function (x) {
126
+ return x * 2
127
+ }),
128
+ )
129
+
130
+ export function F(h: Uint32Array, m: Uint32Array, t: Uint32Array, f: boolean, rounds: number) {
131
+ const v = new Uint32Array(32)
132
+ let i = 0
133
+
134
+ // init work variables
135
+ for (i = 0; i < 16; i++) {
136
+ v[i] = h[i]
137
+ v[i + 16] = BLAKE2B_IV32[i]
138
+ }
139
+
140
+ // 128 bits of offset
141
+ v[24] = v[24] ^ t[0]
142
+ v[25] = v[25] ^ t[1]
143
+ v[26] = v[26] ^ t[2]
144
+ v[27] = v[27] ^ t[3]
145
+
146
+ // last block flag set ?
147
+ if (f) {
148
+ v[28] = ~v[28]
149
+ v[29] = ~v[29]
150
+ }
151
+
152
+ // twelve rounds of mixing
153
+ // uncomment the DebugPrint calls to log the computation
154
+ // and match the RFC sample documentation
155
+ // util.debugPrint(' m[16]', m, 64)
156
+ for (i = 0; i < rounds; i++) {
157
+ // util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
158
+ const ri = (i % 10) * 16
159
+ B2B_G(v, m, 0, 8, 16, 24, SIGMA82[ri + 0], SIGMA82[ri + 1])
160
+ B2B_G(v, m, 2, 10, 18, 26, SIGMA82[ri + 2], SIGMA82[ri + 3])
161
+ B2B_G(v, m, 4, 12, 20, 28, SIGMA82[ri + 4], SIGMA82[ri + 5])
162
+ B2B_G(v, m, 6, 14, 22, 30, SIGMA82[ri + 6], SIGMA82[ri + 7])
163
+ B2B_G(v, m, 0, 10, 20, 30, SIGMA82[ri + 8], SIGMA82[ri + 9])
164
+ B2B_G(v, m, 2, 12, 22, 24, SIGMA82[ri + 10], SIGMA82[ri + 11])
165
+ B2B_G(v, m, 4, 14, 16, 26, SIGMA82[ri + 12], SIGMA82[ri + 13])
166
+ B2B_G(v, m, 6, 8, 18, 28, SIGMA82[ri + 14], SIGMA82[ri + 15])
167
+ }
168
+
169
+ for (i = 0; i < 16; i++) {
170
+ h[i] = h[i] ^ v[i] ^ v[i + 16]
171
+ }
172
+ }
173
+
174
+ export function precompile09(opts: PrecompileInput): ExecResult {
175
+ const pName = getPrecompileName('09')
176
+ const data = opts.data
177
+ if (data.length !== 213) {
178
+ if (opts._debug !== undefined) {
179
+ opts._debug(`${pName} failed: OUT_OF_RANGE dataLength=${data.length}`)
180
+ }
181
+ return {
182
+ returnValue: new Uint8Array(0),
183
+ executionGasUsed: opts.gasLimit,
184
+ exceptionError: new EVMError(EVMError.errorMessages.OUT_OF_RANGE),
185
+ }
186
+ }
187
+ const lastByte = data.subarray(212, 213)[0]
188
+ if (lastByte !== 1 && lastByte !== 0) {
189
+ if (opts._debug !== undefined) {
190
+ opts._debug(`${pName} failed: OUT_OF_RANGE lastByte=${lastByte}`)
191
+ }
192
+ return {
193
+ returnValue: new Uint8Array(0),
194
+ executionGasUsed: opts.gasLimit,
195
+ exceptionError: new EVMError(EVMError.errorMessages.OUT_OF_RANGE),
196
+ }
197
+ }
198
+
199
+ const rounds = new DataView(data.buffer, data.byteOffset).getUint32(0)
200
+ const hRaw = new DataView(data.buffer, data.byteOffset + 4, 64)
201
+ const mRaw = new DataView(data.buffer, data.byteOffset + 68, 128)
202
+ const tRaw = new DataView(data.buffer, data.byteOffset + 196, 16)
203
+ // final
204
+ const f = lastByte === 1
205
+
206
+ let gasUsed = opts.common.param('blake2RoundGas')
207
+ gasUsed *= BigInt(rounds)
208
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
209
+ return OOGResult(opts.gasLimit)
210
+ }
211
+
212
+ const h = new Uint32Array(16)
213
+ for (let i = 0; i < 16; i++) {
214
+ h[i] = hRaw.getUint32(i * 4, true)
215
+ }
216
+
217
+ const m = new Uint32Array(32)
218
+ for (let i = 0; i < 32; i++) {
219
+ m[i] = mRaw.getUint32(i * 4, true)
220
+ }
221
+
222
+ const t = new Uint32Array(4)
223
+ for (let i = 0; i < 4; i++) {
224
+ t[i] = tRaw.getUint32(i * 4, true)
225
+ }
226
+
227
+ F(h, m, t, f, rounds)
228
+
229
+ const output = new Uint8Array(64)
230
+ const outputView = new DataView(output.buffer)
231
+ for (let i = 0; i < 16; i++) {
232
+ outputView.setUint32(i * 4, h[i], true)
233
+ }
234
+
235
+ if (opts._debug !== undefined) {
236
+ opts._debug(`${pName} return hash=${bytesToHex(output)}`)
237
+ }
238
+
239
+ return {
240
+ executionGasUsed: gasUsed,
241
+ returnValue: output,
242
+ }
243
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ EthereumJSErrorWithoutCode,
3
+ bigIntToBytes,
4
+ bytesToHex,
5
+ computeVersionedHash,
6
+ concatBytes,
7
+ setLengthLeft,
8
+ } from '@feelyourprotocol/util'
9
+
10
+ import { EVMError } from '../errors.ts'
11
+ import { EVMErrorResult, OOGResult } from '../evm.ts'
12
+
13
+ import { getPrecompileName } from './index.ts'
14
+ import { gasLimitCheck } from './util.ts'
15
+
16
+ import type { ExecResult } from '../types.ts'
17
+ import type { PrecompileInput } from './types.ts'
18
+
19
+ export const BLS_MODULUS = BigInt(
20
+ '52435875175126190479447740508185965837690552500527637822603658699938581184513',
21
+ )
22
+
23
+ const modulusBuffer = setLengthLeft(bigIntToBytes(BLS_MODULUS), 32)
24
+
25
+ export async function precompile0a(opts: PrecompileInput): Promise<ExecResult> {
26
+ const pName = getPrecompileName('0a')
27
+ if (opts.common.customCrypto?.kzg === undefined) {
28
+ throw EthereumJSErrorWithoutCode('kzg not initialized')
29
+ }
30
+ const gasUsed = opts.common.param('kzgPointEvaluationPrecompileGas')
31
+ if (!gasLimitCheck(opts, gasUsed, pName)) {
32
+ return OOGResult(opts.gasLimit)
33
+ }
34
+
35
+ if (opts.data.length !== 192) {
36
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_INPUT_LENGTH), opts.gasLimit)
37
+ }
38
+
39
+ const version = Number(opts.common.param('blobCommitmentVersionKzg'))
40
+ const fieldElementsPerBlob = opts.common.param('fieldElementsPerBlob')
41
+ const versionedHash = bytesToHex(opts.data.subarray(0, 32))
42
+ const z = bytesToHex(opts.data.subarray(32, 64))
43
+ const y = bytesToHex(opts.data.subarray(64, 96))
44
+ const commitment = bytesToHex(opts.data.subarray(96, 144))
45
+ const kzgProof = bytesToHex(opts.data.subarray(144, 192))
46
+
47
+ if (computeVersionedHash(commitment, version) !== versionedHash) {
48
+ if (opts._debug !== undefined) {
49
+ opts._debug(`${pName} failed: INVALID_COMMITMENT`)
50
+ }
51
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_COMMITMENT), opts.gasLimit)
52
+ }
53
+
54
+ if (opts._debug !== undefined) {
55
+ opts._debug(
56
+ `${pName}: proof verification with commitment=${
57
+ commitment
58
+ } z=${z} y=${y} kzgProof=${kzgProof}`,
59
+ )
60
+ }
61
+ try {
62
+ const res = opts.common.customCrypto?.kzg?.verifyProof(commitment, z, y, kzgProof)
63
+ if (res === false) {
64
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_PROOF), opts.gasLimit)
65
+ }
66
+ } catch (err: any) {
67
+ if (((err.message.includes('C_KZG_BADARGS') === true) === true) === true) {
68
+ if (opts._debug !== undefined) {
69
+ opts._debug(`${pName} failed: INVALID_INPUTS`)
70
+ }
71
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_INPUTS), opts.gasLimit)
72
+ }
73
+ if (opts._debug !== undefined) {
74
+ opts._debug(`${pName} failed: Unknown error - ${err.message}`)
75
+ }
76
+ return EVMErrorResult(new EVMError(EVMError.errorMessages.REVERT), opts.gasLimit)
77
+ }
78
+
79
+ // Return value - FIELD_ELEMENTS_PER_BLOB and BLS_MODULUS as padded 32 byte big endian values
80
+ const fieldElementsBuffer = setLengthLeft(bigIntToBytes(fieldElementsPerBlob), 32)
81
+
82
+ if (opts._debug !== undefined) {
83
+ opts._debug(
84
+ `${pName} return fieldElements=${bytesToHex(
85
+ fieldElementsBuffer,
86
+ )} modulus=${bytesToHex(modulusBuffer)}`,
87
+ )
88
+ }
89
+
90
+ return {
91
+ executionGasUsed: gasUsed,
92
+ returnValue: concatBytes(fieldElementsBuffer, modulusBuffer),
93
+ }
94
+ }