@aztec/stdlib 0.0.1-commit.f504929 → 0.0.1-commit.f5d02921e

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 (305) hide show
  1. package/dest/abi/abi.d.ts +138 -1
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +10 -2
  4. package/dest/abi/buffer.d.ts +14 -4
  5. package/dest/abi/buffer.d.ts.map +1 -1
  6. package/dest/abi/buffer.js +25 -4
  7. package/dest/abi/decoder.d.ts +5 -44
  8. package/dest/abi/decoder.d.ts.map +1 -1
  9. package/dest/abi/decoder.js +12 -67
  10. package/dest/abi/function_selector.js +1 -1
  11. package/dest/abi/function_signature_decoder.d.ts +43 -0
  12. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  13. package/dest/abi/function_signature_decoder.js +66 -0
  14. package/dest/abi/index.d.ts +2 -1
  15. package/dest/abi/index.d.ts.map +1 -1
  16. package/dest/abi/index.js +1 -0
  17. package/dest/avm/avm.d.ts +300 -300
  18. package/dest/block/l2_block.d.ts +9 -1
  19. package/dest/block/l2_block.d.ts.map +1 -1
  20. package/dest/block/l2_block.js +12 -2
  21. package/dest/block/l2_block_source.d.ts +95 -10
  22. package/dest/block/l2_block_source.d.ts.map +1 -1
  23. package/dest/block/l2_block_source.js +1 -0
  24. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  25. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  26. package/dest/block/l2_block_stream/l2_tips_store_base.js +17 -4
  27. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  28. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  29. package/dest/block/test/l2_tips_store_test_suite.js +3 -2
  30. package/dest/checkpoint/checkpoint.d.ts +8 -1
  31. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  32. package/dest/checkpoint/checkpoint.js +18 -5
  33. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  34. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  35. package/dest/checkpoint/checkpoint_data.js +10 -0
  36. package/dest/checkpoint/index.d.ts +2 -1
  37. package/dest/checkpoint/index.d.ts.map +1 -1
  38. package/dest/checkpoint/index.js +1 -0
  39. package/dest/checkpoint/validate.d.ts +36 -0
  40. package/dest/checkpoint/validate.d.ts.map +1 -0
  41. package/dest/checkpoint/validate.js +120 -0
  42. package/dest/config/index.d.ts +2 -1
  43. package/dest/config/index.d.ts.map +1 -1
  44. package/dest/config/index.js +1 -0
  45. package/dest/config/pipelining-config.d.ts +19 -0
  46. package/dest/config/pipelining-config.d.ts.map +1 -0
  47. package/dest/config/pipelining-config.js +18 -0
  48. package/dest/config/sequencer-config.d.ts +2 -2
  49. package/dest/config/sequencer-config.d.ts.map +1 -1
  50. package/dest/config/sequencer-config.js +1 -2
  51. package/dest/contract/contract_address.d.ts +3 -3
  52. package/dest/contract/contract_address.js +3 -3
  53. package/dest/contract/contract_class_id.d.ts +2 -2
  54. package/dest/contract/contract_class_id.js +2 -2
  55. package/dest/contract/index.d.ts +1 -3
  56. package/dest/contract/index.d.ts.map +1 -1
  57. package/dest/contract/index.js +0 -2
  58. package/dest/contract/interfaces/contract_class.d.ts +3 -156
  59. package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
  60. package/dest/contract/interfaces/contract_class.js +1 -28
  61. package/dest/epoch-helpers/index.d.ts +11 -1
  62. package/dest/epoch-helpers/index.d.ts.map +1 -1
  63. package/dest/epoch-helpers/index.js +16 -2
  64. package/dest/file-store/factory.d.ts +4 -3
  65. package/dest/file-store/factory.d.ts.map +1 -1
  66. package/dest/file-store/factory.js +2 -2
  67. package/dest/file-store/http.d.ts +9 -2
  68. package/dest/file-store/http.d.ts.map +1 -1
  69. package/dest/file-store/http.js +20 -9
  70. package/dest/file-store/index.d.ts +2 -1
  71. package/dest/file-store/index.d.ts.map +1 -1
  72. package/dest/ha-signing/config.d.ts +49 -14
  73. package/dest/ha-signing/config.d.ts.map +1 -1
  74. package/dest/ha-signing/config.js +20 -15
  75. package/dest/ha-signing/index.d.ts +3 -2
  76. package/dest/ha-signing/index.d.ts.map +1 -1
  77. package/dest/ha-signing/index.js +2 -1
  78. package/dest/ha-signing/local_config.d.ts +63 -0
  79. package/dest/ha-signing/local_config.d.ts.map +1 -0
  80. package/dest/ha-signing/local_config.js +24 -0
  81. package/dest/hash/hash.d.ts +19 -1
  82. package/dest/hash/hash.d.ts.map +1 -1
  83. package/dest/hash/hash.js +29 -0
  84. package/dest/interfaces/allowed_element.d.ts +25 -1
  85. package/dest/interfaces/allowed_element.d.ts.map +1 -1
  86. package/dest/interfaces/allowed_element.js +8 -2
  87. package/dest/interfaces/archiver.d.ts +1 -1
  88. package/dest/interfaces/archiver.d.ts.map +1 -1
  89. package/dest/interfaces/archiver.js +6 -3
  90. package/dest/interfaces/aztec-node-admin.d.ts +70 -13
  91. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  92. package/dest/interfaces/aztec-node.d.ts +12 -6
  93. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  94. package/dest/interfaces/aztec-node.js +5 -2
  95. package/dest/interfaces/block-builder.d.ts +38 -11
  96. package/dest/interfaces/block-builder.d.ts.map +1 -1
  97. package/dest/interfaces/block-builder.js +12 -5
  98. package/dest/interfaces/configs.d.ts +47 -7
  99. package/dest/interfaces/configs.d.ts.map +1 -1
  100. package/dest/interfaces/configs.js +3 -1
  101. package/dest/interfaces/l2_logs_source.d.ts +5 -3
  102. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  103. package/dest/interfaces/merkle_tree_operations.d.ts +9 -19
  104. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  105. package/dest/interfaces/prover-client.d.ts +6 -1
  106. package/dest/interfaces/prover-client.d.ts.map +1 -1
  107. package/dest/interfaces/prover-client.js +7 -1
  108. package/dest/interfaces/proving-job.d.ts +200 -200
  109. package/dest/interfaces/validator.d.ts +101 -30
  110. package/dest/interfaces/validator.d.ts.map +1 -1
  111. package/dest/interfaces/validator.js +7 -5
  112. package/dest/interfaces/world_state.d.ts +5 -4
  113. package/dest/interfaces/world_state.d.ts.map +1 -1
  114. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts +2 -1
  115. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts.map +1 -1
  116. package/dest/kernel/private_kernel_tail_circuit_public_inputs.js +4 -0
  117. package/dest/kv-store/config.d.ts +17 -0
  118. package/dest/kv-store/config.d.ts.map +1 -0
  119. package/dest/kv-store/config.js +26 -0
  120. package/dest/kv-store/index.d.ts +2 -0
  121. package/dest/kv-store/index.d.ts.map +1 -0
  122. package/dest/kv-store/index.js +1 -0
  123. package/dest/logs/index.d.ts +2 -1
  124. package/dest/logs/index.d.ts.map +1 -1
  125. package/dest/logs/index.js +1 -0
  126. package/dest/logs/log_filter.d.ts +4 -1
  127. package/dest/logs/log_filter.d.ts.map +1 -1
  128. package/dest/logs/log_filter.js +2 -1
  129. package/dest/logs/message_context.d.ts +4 -7
  130. package/dest/logs/message_context.d.ts.map +1 -1
  131. package/dest/logs/message_context.js +23 -9
  132. package/dest/logs/pending_tagged_log.d.ts +2 -3
  133. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  134. package/dest/logs/pending_tagged_log.js +2 -2
  135. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  136. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  137. package/dest/logs/shared_secret_derivation.js +15 -9
  138. package/dest/logs/siloed_tag.d.ts +4 -1
  139. package/dest/logs/siloed_tag.d.ts.map +1 -1
  140. package/dest/logs/siloed_tag.js +7 -3
  141. package/dest/logs/tagging_index_range.d.ts +40 -0
  142. package/dest/logs/tagging_index_range.d.ts.map +1 -0
  143. package/dest/logs/tagging_index_range.js +8 -0
  144. package/dest/logs/tx_scoped_l2_log.d.ts +3 -1
  145. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  146. package/dest/logs/tx_scoped_l2_log.js +7 -0
  147. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  148. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  149. package/dest/messaging/l1_to_l2_message.js +11 -13
  150. package/dest/messaging/l1_to_l2_message_source.d.ts +4 -2
  151. package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
  152. package/dest/messaging/l2_to_l1_membership.d.ts +32 -6
  153. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  154. package/dest/messaging/l2_to_l1_membership.js +69 -26
  155. package/dest/noir/index.d.ts +3 -3
  156. package/dest/noir/index.d.ts.map +1 -1
  157. package/dest/note/note_dao.d.ts +1 -1
  158. package/dest/note/note_dao.d.ts.map +1 -1
  159. package/dest/note/note_dao.js +1 -4
  160. package/dest/p2p/checkpoint_proposal.d.ts +1 -6
  161. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  162. package/dest/p2p/checkpoint_proposal.js +13 -23
  163. package/dest/p2p/peer_error.d.ts +3 -1
  164. package/dest/p2p/peer_error.d.ts.map +1 -1
  165. package/dest/p2p/peer_error.js +5 -0
  166. package/dest/proofs/chonk_proof.d.ts +46 -2
  167. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  168. package/dest/proofs/chonk_proof.js +85 -10
  169. package/dest/slashing/tally.d.ts +5 -6
  170. package/dest/slashing/tally.d.ts.map +1 -1
  171. package/dest/slashing/tally.js +19 -10
  172. package/dest/tests/factories.d.ts +2 -4
  173. package/dest/tests/factories.d.ts.map +1 -1
  174. package/dest/tests/factories.js +10 -27
  175. package/dest/tests/mocks.d.ts +4 -2
  176. package/dest/tests/mocks.d.ts.map +1 -1
  177. package/dest/tests/mocks.js +13 -8
  178. package/dest/tx/block_header.d.ts +3 -1
  179. package/dest/tx/block_header.d.ts.map +1 -1
  180. package/dest/tx/block_header.js +4 -0
  181. package/dest/tx/capsule.d.ts +6 -2
  182. package/dest/tx/capsule.d.ts.map +1 -1
  183. package/dest/tx/capsule.js +9 -3
  184. package/dest/tx/global_variable_builder.d.ts +14 -2
  185. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  186. package/dest/tx/private_execution_result.d.ts +6 -6
  187. package/dest/tx/private_execution_result.d.ts.map +1 -1
  188. package/dest/tx/private_execution_result.js +6 -6
  189. package/dest/tx/profiling.d.ts +14 -2
  190. package/dest/tx/profiling.d.ts.map +1 -1
  191. package/dest/tx/profiling.js +13 -3
  192. package/dest/tx/simulated_tx.d.ts +109 -1
  193. package/dest/tx/simulated_tx.d.ts.map +1 -1
  194. package/dest/tx/tx.d.ts +6 -5
  195. package/dest/tx/tx.d.ts.map +1 -1
  196. package/dest/tx/tx.js +18 -6
  197. package/dest/tx/tx_receipt.d.ts +7 -2
  198. package/dest/tx/tx_receipt.d.ts.map +1 -1
  199. package/dest/tx/tx_receipt.js +6 -3
  200. package/dest/tx/validator/error_texts.d.ts +8 -1
  201. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  202. package/dest/tx/validator/error_texts.js +9 -0
  203. package/dest/update-checker/index.d.ts +3 -2
  204. package/dest/update-checker/index.d.ts.map +1 -1
  205. package/dest/update-checker/index.js +2 -1
  206. package/dest/update-checker/package_version.d.ts +3 -0
  207. package/dest/update-checker/package_version.d.ts.map +1 -0
  208. package/dest/update-checker/package_version.js +24 -0
  209. package/dest/update-checker/version_checker.d.ts +25 -0
  210. package/dest/update-checker/version_checker.d.ts.map +1 -0
  211. package/dest/update-checker/version_checker.js +50 -0
  212. package/dest/validators/errors.d.ts +6 -1
  213. package/dest/validators/errors.d.ts.map +1 -1
  214. package/dest/validators/errors.js +7 -0
  215. package/dest/versioning/versioning.d.ts +4 -2
  216. package/dest/versioning/versioning.d.ts.map +1 -1
  217. package/dest/versioning/versioning.js +4 -1
  218. package/package.json +10 -9
  219. package/src/abi/abi.ts +25 -2
  220. package/src/abi/buffer.ts +25 -4
  221. package/src/abi/decoder.ts +23 -78
  222. package/src/abi/function_selector.ts +1 -1
  223. package/src/abi/function_signature_decoder.ts +77 -0
  224. package/src/abi/index.ts +1 -0
  225. package/src/block/l2_block.ts +13 -1
  226. package/src/block/l2_block_source.ts +26 -9
  227. package/src/block/l2_block_stream/l2_tips_store_base.ts +24 -12
  228. package/src/block/test/l2_tips_store_test_suite.ts +8 -1
  229. package/src/checkpoint/checkpoint.ts +23 -4
  230. package/src/checkpoint/checkpoint_data.ts +40 -4
  231. package/src/checkpoint/index.ts +1 -0
  232. package/src/checkpoint/validate.ts +230 -0
  233. package/src/config/index.ts +1 -0
  234. package/src/config/pipelining-config.ts +31 -0
  235. package/src/config/sequencer-config.ts +2 -2
  236. package/src/contract/contract_address.ts +3 -3
  237. package/src/contract/contract_class_id.ts +2 -2
  238. package/src/contract/index.ts +0 -2
  239. package/src/contract/interfaces/contract_class.ts +2 -82
  240. package/src/epoch-helpers/index.ts +27 -0
  241. package/src/file-store/factory.ts +13 -4
  242. package/src/file-store/http.ts +29 -10
  243. package/src/file-store/index.ts +1 -0
  244. package/src/gas/README.md +123 -0
  245. package/src/ha-signing/config.ts +45 -38
  246. package/src/ha-signing/index.ts +9 -0
  247. package/src/ha-signing/local_config.ts +46 -0
  248. package/src/hash/hash.ts +34 -0
  249. package/src/interfaces/allowed_element.ts +28 -4
  250. package/src/interfaces/archiver.ts +6 -3
  251. package/src/interfaces/aztec-node.ts +24 -5
  252. package/src/interfaces/block-builder.ts +56 -13
  253. package/src/interfaces/configs.ts +15 -4
  254. package/src/interfaces/l2_logs_source.ts +4 -1
  255. package/src/interfaces/merkle_tree_operations.ts +8 -18
  256. package/src/interfaces/prover-client.ts +8 -0
  257. package/src/interfaces/validator.ts +46 -29
  258. package/src/interfaces/world_state.ts +4 -3
  259. package/src/kernel/private_kernel_tail_circuit_public_inputs.ts +9 -0
  260. package/src/kv-store/config.ts +36 -0
  261. package/src/kv-store/index.ts +1 -0
  262. package/src/logs/index.ts +1 -0
  263. package/src/logs/log_filter.ts +5 -0
  264. package/src/logs/message_context.ts +17 -7
  265. package/src/logs/pending_tagged_log.ts +1 -3
  266. package/src/logs/shared_secret_derivation.ts +21 -10
  267. package/src/logs/siloed_tag.ts +7 -2
  268. package/src/logs/tagging_index_range.ts +24 -0
  269. package/src/logs/tx_scoped_l2_log.ts +16 -0
  270. package/src/messaging/l1_to_l2_message.ts +12 -9
  271. package/src/messaging/l1_to_l2_message_source.ts +3 -1
  272. package/src/messaging/l2_to_l1_membership.ts +98 -33
  273. package/src/noir/index.ts +2 -2
  274. package/src/note/note_dao.ts +1 -4
  275. package/src/p2p/checkpoint_proposal.ts +23 -37
  276. package/src/p2p/peer_error.ts +7 -0
  277. package/src/proofs/chonk_proof.ts +91 -5
  278. package/src/slashing/tally.ts +22 -4
  279. package/src/tests/factories.ts +4 -33
  280. package/src/tests/mocks.ts +18 -7
  281. package/src/tx/block_header.ts +6 -0
  282. package/src/tx/capsule.ts +10 -2
  283. package/src/tx/global_variable_builder.ts +15 -0
  284. package/src/tx/private_execution_result.ts +5 -5
  285. package/src/tx/profiling.ts +11 -2
  286. package/src/tx/tx.ts +20 -11
  287. package/src/tx/tx_receipt.ts +7 -2
  288. package/src/tx/validator/error_texts.ts +11 -0
  289. package/src/update-checker/index.ts +2 -1
  290. package/src/update-checker/package_version.ts +30 -0
  291. package/src/update-checker/version_checker.ts +65 -0
  292. package/src/validators/errors.ts +9 -0
  293. package/src/versioning/versioning.ts +4 -1
  294. package/dest/contract/private_function_membership_proof.d.ts +0 -32
  295. package/dest/contract/private_function_membership_proof.d.ts.map +0 -1
  296. package/dest/contract/private_function_membership_proof.js +0 -124
  297. package/dest/contract/utility_function_membership_proof.d.ts +0 -27
  298. package/dest/contract/utility_function_membership_proof.d.ts.map +0 -1
  299. package/dest/contract/utility_function_membership_proof.js +0 -87
  300. package/dest/update-checker/update-checker.d.ts +0 -49
  301. package/dest/update-checker/update-checker.d.ts.map +0 -1
  302. package/dest/update-checker/update-checker.js +0 -130
  303. package/src/contract/private_function_membership_proof.ts +0 -167
  304. package/src/contract/utility_function_membership_proof.ts +0 -118
  305. package/src/update-checker/update-checker.ts +0 -166
@@ -1,87 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
4
- import { FunctionSelector, FunctionType } from '../abi/index.js';
5
- import { computeArtifactFunctionTree, computeArtifactHash, computeArtifactHashPreimage, computeFunctionArtifactHash, computeFunctionMetadataHash, getArtifactMerkleTreeHasher } from './artifact_hash.js';
6
- /**
7
- * Creates a membership proof for a utility function in a contract class, to be verified via `isValidUtilityFunctionMembershipProof`.
8
- * @param selector - Selector of the function to create the proof for.
9
- * @param artifact - Artifact of the contract class where the function is defined.
10
- */ export async function createUtilityFunctionMembershipProof(selector, artifact) {
11
- const log = createLogger('circuits:function_membership_proof');
12
- // Locate function artifact
13
- const utilityFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.UTILITY);
14
- const utilityFunctionsAndSelectors = await Promise.all(utilityFunctions.map(async (fn)=>({
15
- fn,
16
- selector: await FunctionSelector.fromNameAndParameters(fn)
17
- })));
18
- const fn = utilityFunctionsAndSelectors.find((fnAndSelector)=>selector.equals(fnAndSelector.selector))?.fn;
19
- if (!fn) {
20
- throw new Error(`Utility function with selector ${selector.toString()} not found`);
21
- }
22
- // Compute preimage for the artifact hash
23
- const { privateFunctionRoot: privateFunctionsArtifactTreeRoot, metadataHash: artifactMetadataHash } = await computeArtifactHashPreimage(artifact);
24
- // Compute the sibling path for the "artifact tree"
25
- const functionMetadataHash = computeFunctionMetadataHash(fn);
26
- const functionArtifactHash = await computeFunctionArtifactHash({
27
- ...fn,
28
- functionMetadataHash
29
- });
30
- const artifactTree = await computeArtifactFunctionTree(artifact, FunctionType.UTILITY);
31
- const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
32
- const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
33
- log.debug(`Computed proof for utility function with selector ${selector.toString()}`, {
34
- functionArtifactHash,
35
- functionMetadataHash,
36
- artifactMetadataHash,
37
- artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map((fr)=>fr.toString()).join(','),
38
- privateFunctionsArtifactTreeRoot
39
- });
40
- return {
41
- artifactTreeSiblingPath,
42
- artifactTreeLeafIndex,
43
- artifactMetadataHash,
44
- functionMetadataHash,
45
- privateFunctionsArtifactTreeRoot
46
- };
47
- }
48
- /**
49
- * Verifies that a utility function with a membership proof as emitted by the ClassRegistry contract is valid,
50
- * as defined in the protocol specs at contract-deployment/classes:
51
- *
52
- * ```
53
- * // Load contract class from local db
54
- * contract_class = db.get_contract_class(contract_class_id)
55
- *
56
- * // Compute artifact leaf and assert it belongs to the artifact
57
- * artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
58
- * computed_artifact_utility_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path, artifact_function_tree_leaf_index)
59
- * computed_artifact_hash = sha256(private_functions_artifact_tree_root, computed_artifact_utility_function_tree_root, artifact_metadata_hash)
60
- * assert computed_artifact_hash == contract_class.artifact_hash
61
- * ```
62
- * @param fn - Function to check membership proof for.
63
- * @param contractClass - In which contract class the function is expected to be.
64
- */ export async function isValidUtilityFunctionMembershipProof(fn, contractClass) {
65
- const log = createLogger('circuits:function_membership_proof');
66
- const functionArtifactHash = await computeFunctionArtifactHash(fn);
67
- const computedArtifactFunctionTreeRootBuffer = await computeRootFromSiblingPath(functionArtifactHash.toBuffer(), fn.artifactTreeSiblingPath.map((fr)=>fr.toBuffer()), fn.artifactTreeLeafIndex, getArtifactMerkleTreeHasher());
68
- const computedArtifactFunctionTreeRoot = Fr.fromBuffer(computedArtifactFunctionTreeRootBuffer);
69
- const computedArtifactHash = await computeArtifactHash({
70
- privateFunctionRoot: fn.privateFunctionsArtifactTreeRoot,
71
- utilityFunctionRoot: computedArtifactFunctionTreeRoot,
72
- metadataHash: fn.artifactMetadataHash
73
- });
74
- if (!contractClass.artifactHash.equals(computedArtifactHash)) {
75
- log.debug(`Artifact hash mismatch`, {
76
- expected: contractClass.artifactHash,
77
- computedArtifactHash,
78
- computedFunctionArtifactHash: functionArtifactHash,
79
- computedArtifactFunctionTreeRoot,
80
- privateFunctionsArtifactTreeRoot: fn.privateFunctionsArtifactTreeRoot,
81
- metadataHash: fn.artifactMetadataHash,
82
- artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map((fr)=>fr.toString()).join(',')
83
- });
84
- return false;
85
- }
86
- return true;
87
- }
@@ -1,49 +0,0 @@
1
- import type { ViemClient } from '@aztec/ethereum/types';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { EventEmitter } from 'events';
4
- export type EventMap = {
5
- newRollupVersion: [{
6
- currentVersion: bigint;
7
- latestVersion: bigint;
8
- }];
9
- newNodeVersion: [{
10
- currentVersion: string;
11
- latestVersion: string;
12
- }];
13
- updateNodeConfig: [object];
14
- updatePublicTelemetryConfig: [object];
15
- };
16
- type Config = {
17
- baseURL: URL;
18
- nodeVersion?: string;
19
- checkIntervalMs?: number;
20
- registryContractAddress: EthAddress;
21
- publicClient: ViemClient;
22
- fetch?: typeof fetch;
23
- };
24
- export declare class UpdateChecker extends EventEmitter<EventMap> {
25
- private updatesUrl;
26
- private nodeVersion;
27
- private rollupVersion;
28
- private fetch;
29
- private getLatestRollupVersion;
30
- private checkIntervalMs;
31
- private log;
32
- private runningPromise;
33
- private lastPatchedConfig;
34
- private lastPatchedPublicTelemetryConfig;
35
- constructor(updatesUrl: URL, nodeVersion: string | undefined, rollupVersion: bigint, fetch: typeof globalThis.fetch, getLatestRollupVersion: () => Promise<bigint>, checkIntervalMs?: number, log?: import("@aztec/foundation/log").Logger);
36
- static new(config: Config): Promise<UpdateChecker>;
37
- start(): void;
38
- stop(): Promise<void>;
39
- trigger(): Promise<void>;
40
- private runChecks;
41
- private checkRollupVersion;
42
- private checkConfig;
43
- }
44
- /**
45
- * Returns package version.
46
- */
47
- export decl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a,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,sBAAsB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAC7C,eAAe,SAAc,EAC7B,GAAG,yCAA0C,EAItD;IAED,OAAoB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAY9D;IAEM,KAAK,IAAI,IAAI,CAWnB;IAEM,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3B;IAEM,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9B;IAED,OAAO,CAAC,SAAS,CAEf;YAEY,kBAAkB;YAelB,WAAW;CAsC1B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAWtD"}
@@ -1,130 +0,0 @@
1
- import { RegistryContract } from '@aztec/ethereum/contracts';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { RunningPromise } from '@aztec/foundation/running-promise';
4
- import { fileURLToPath } from '@aztec/foundation/url';
5
- import { EventEmitter } from 'events';
6
- import { readFileSync } from 'fs';
7
- import { dirname, resolve } from 'path';
8
- import { isDeepStrictEqual } from 'util';
9
- import { z } from 'zod';
10
- const updateConfigSchema = z.object({
11
- version: z.string().optional(),
12
- publicTelemetry: z.any().optional(),
13
- config: z.any().optional()
14
- });
15
- export class UpdateChecker extends EventEmitter {
16
- updatesUrl;
17
- nodeVersion;
18
- rollupVersion;
19
- fetch;
20
- getLatestRollupVersion;
21
- checkIntervalMs;
22
- log;
23
- runningPromise;
24
- lastPatchedConfig;
25
- lastPatchedPublicTelemetryConfig;
26
- constructor(updatesUrl, nodeVersion, rollupVersion, fetch1, getLatestRollupVersion, checkIntervalMs = 10 * 60_000, log = createLogger('foundation:update-check')){
27
- super(), this.updatesUrl = updatesUrl, this.nodeVersion = nodeVersion, this.rollupVersion = rollupVersion, this.fetch = fetch1, this.getLatestRollupVersion = getLatestRollupVersion, this.checkIntervalMs = checkIntervalMs, this.log = log, this.lastPatchedConfig = {}, this.lastPatchedPublicTelemetryConfig = {}, this.runChecks = async ()=>{
28
- await Promise.all([
29
- this.checkRollupVersion(),
30
- this.checkConfig()
31
- ]);
32
- };
33
- this.runningPromise = new RunningPromise(this.runChecks, this.log, this.checkIntervalMs);
34
- }
35
- static async new(config) {
36
- const registryContract = new RegistryContract(config.publicClient, config.registryContractAddress);
37
- const getLatestRollupVersion = ()=>registryContract.getRollupVersions().then((versions)=>versions.at(-1));
38
- return new UpdateChecker(config.baseURL, config.nodeVersion ?? getPackageVersion(), await getLatestRollupVersion(), config.fetch ?? fetch, getLatestRollupVersion, config.checkIntervalMs);
39
- }
40
- start() {
41
- if (this.runningPromise.isRunning()) {
42
- this.log.debug(`Can't start update checker again`);
43
- return;
44
- }
45
- this.log.info('Starting update checker', {
46
- nodeVersion: this.nodeVersion,
47
- rollupVersion: this.rollupVersion
48
- });
49
- this.runningPromise.start();
50
- }
51
- stop() {
52
- if (!this.runningPromise.isRunning()) {
53
- this.log.debug(`Can't stop update checker because it is not running`);
54
- return Promise.resolve();
55
- }
56
- return this.runningPromise.stop();
57
- }
58
- trigger() {
59
- return this.runningPromise.trigger();
60
- }
61
- runChecks;
62
- async checkRollupVersion() {
63
- try {
64
- const canonicalRollupVersion = await this.getLatestRollupVersion();
65
- if (canonicalRollupVersion !== this.rollupVersion) {
66
- this.log.debug('New canonical rollup version', {
67
- currentVersion: this.rollupVersion,
68
- latestVersion: canonicalRollupVersion
69
- });
70
- this.emit('newRollupVersion', {
71
- currentVersion: this.rollupVersion,
72
- latestVersion: canonicalRollupVersion
73
- });
74
- }
75
- } catch (err) {
76
- this.log.warn(`Failed to check if there is a new rollup`, err);
77
- }
78
- }
79
- async checkConfig() {
80
- try {
81
- const response = await this.fetch(this.updatesUrl);
82
- const body = await response.json();
83
- if (!response.ok) {
84
- this.log.warn(`Unexpected HTTP response checking for updates`, {
85
- status: response.status,
86
- body: await response.text(),
87
- url: this.updatesUrl
88
- });
89
- }
90
- const { version, config, publicTelemetry } = updateConfigSchema.parse(body);
91
- if (this.nodeVersion && version && version !== this.nodeVersion) {
92
- this.log.debug('New node version', {
93
- currentVersion: this.nodeVersion,
94
- latestVersion: version
95
- });
96
- this.emit('newNodeVersion', {
97
- currentVersion: this.nodeVersion,
98
- latestVersion: version
99
- });
100
- }
101
- if (config && Object.keys(config).length > 0 && !isDeepStrictEqual(config, this.lastPatchedConfig)) {
102
- this.log.debug('New node config', {
103
- config
104
- });
105
- this.lastPatchedConfig = config;
106
- this.emit('updateNodeConfig', config);
107
- }
108
- if (publicTelemetry && Object.keys(publicTelemetry).length > 0 && !isDeepStrictEqual(publicTelemetry, this.lastPatchedPublicTelemetryConfig)) {
109
- this.log.debug('New metrics config', {
110
- config
111
- });
112
- this.lastPatchedPublicTelemetryConfig = publicTelemetry;
113
- this.emit('updatePublicTelemetryConfig', publicTelemetry);
114
- }
115
- } catch (err) {
116
- this.log.warn(`Failed to check if there is an update`, err);
117
- }
118
- }
119
- }
120
- /**
121
- * Returns package version.
122
- */ export function getPackageVersion() {
123
- try {
124
- const releasePleaseManifestPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../../../.release-please-manifest.json');
125
- const version = JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
126
- return version;
127
- } catch {
128
- return undefined;
129
- }
130
- }
@@ -1,167 +0,0 @@
1
- import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
2
- import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
5
-
6
- import { type ContractArtifact, FunctionSelector, FunctionType } from '../abi/index.js';
7
- import {
8
- computeArtifactFunctionTree,
9
- computeArtifactHash,
10
- computeArtifactHashPreimage,
11
- computeFunctionArtifactHash,
12
- computeFunctionMetadataHash,
13
- getArtifactMerkleTreeHasher,
14
- } from './artifact_hash.js';
15
- import { getContractClassPrivateFunctionFromArtifact } from './contract_class.js';
16
- import type {
17
- ContractClassPublic,
18
- ExecutablePrivateFunctionWithMembershipProof,
19
- PrivateFunctionMembershipProof,
20
- } from './interfaces/index.js';
21
- import { computePrivateFunctionLeaf, computePrivateFunctionsTree } from './private_function.js';
22
-
23
- /**
24
- * Creates a membership proof for a private function in a contract class, to be verified via `isValidPrivateFunctionMembershipProof`.
25
- * @param selector - Selector of the function to create the proof for.
26
- * @param artifact - Artifact of the contract class where the function is defined.
27
- */
28
- export async function createPrivateFunctionMembershipProof(
29
- selector: FunctionSelector,
30
- artifact: ContractArtifact,
31
- ): Promise<PrivateFunctionMembershipProof> {
32
- const log = createLogger('circuits:function_membership_proof');
33
-
34
- // Locate private function definition and artifact
35
- const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
36
- const privateFunctionsFromArtifact = await Promise.all(
37
- privateFunctions.map(getContractClassPrivateFunctionFromArtifact),
38
- );
39
- const privateFunction = privateFunctionsFromArtifact.find(fn => fn.selector.equals(selector));
40
- const privateFunctionsAndSelectors = await Promise.all(
41
- privateFunctions.map(async fn => ({
42
- fn,
43
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
44
- })),
45
- );
46
- const privateFunctionArtifact = privateFunctionsAndSelectors.find(fnAndSelector =>
47
- selector.equals(fnAndSelector.selector),
48
- )?.fn;
49
- if (!privateFunction || !privateFunctionArtifact) {
50
- throw new Error(`Private function with selector ${selector.toString()} not found`);
51
- }
52
-
53
- // Compute preimage for the artifact hash
54
- const { utilityFunctionRoot: utilityFunctionsTreeRoot, metadataHash: artifactMetadataHash } =
55
- await computeArtifactHashPreimage(artifact);
56
-
57
- // We need two sibling paths because private function information is split across two trees:
58
- // The "private function tree" captures the selectors and verification keys, and is used in the kernel circuit for verifying the proof generated by the app circuit.
59
- const functionLeaf = await computePrivateFunctionLeaf(privateFunction);
60
- const functionsTree = await computePrivateFunctionsTree(privateFunctionsFromArtifact);
61
- const functionsTreeLeafIndex = functionsTree.getIndex(functionLeaf);
62
- const functionsTreeSiblingPath = functionsTree.getSiblingPath(functionsTreeLeafIndex).map(Fr.fromBuffer);
63
-
64
- // And the "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits.
65
- const functionMetadataHash = computeFunctionMetadataHash(privateFunctionArtifact);
66
- const functionArtifactHash = await computeFunctionArtifactHash({ ...privateFunctionArtifact, functionMetadataHash });
67
- const artifactTree = (await computeArtifactFunctionTree(artifact, FunctionType.PRIVATE))!;
68
- const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
69
- const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
70
-
71
- log.debug(`Computed proof for private function with selector ${selector.toString()}`, {
72
- functionArtifactHash,
73
- functionMetadataHash,
74
- functionLeaf: '0x' + functionLeaf.toString('hex'),
75
- artifactMetadataHash,
76
- privateFunctionsTreeRoot: '0x' + functionsTree.root.toString('hex'),
77
- utilityFunctionsTreeRoot,
78
- artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
79
- privateFunctionTreeSiblingPath: functionsTreeSiblingPath.map(fr => fr.toString()).join(','),
80
- });
81
-
82
- return {
83
- artifactTreeSiblingPath,
84
- artifactTreeLeafIndex,
85
- artifactMetadataHash,
86
- functionMetadataHash,
87
- utilityFunctionsTreeRoot,
88
- privateFunctionTreeSiblingPath: functionsTreeSiblingPath,
89
- privateFunctionTreeLeafIndex: functionsTreeLeafIndex,
90
- };
91
- }
92
-
93
- /**
94
- * Verifies that a private function with a membership proof as emitted by the ClassRegistry contract is valid,
95
- * as defined in the protocol specs at contract-deployment/classes:
96
- *
97
- * ```
98
- * // Load contract class from local db
99
- * contract_class = db.get_contract_class(contract_class_id)
100
- *
101
- * // Compute function leaf and assert it belongs to the private functions tree
102
- * function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
103
- * computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
104
- * assert computed_private_function_tree_root == contract_class.private_functions_root
105
- *
106
- * // Compute artifact leaf and assert it belongs to the artifact
107
- * artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
108
- * computed_artifact_private_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path)
109
- * computed_artifact_hash = sha256(computed_artifact_private_function_tree_root, utility_functions_artifact_tree_root, artifact_metadata_hash)
110
- * assert computed_artifact_hash == contract_class.artifact_hash
111
- * ```
112
- * @param fn - Function to check membership proof for.
113
- * @param contractClass - In which contract class the function is expected to be.
114
- */
115
- export async function isValidPrivateFunctionMembershipProof(
116
- fn: ExecutablePrivateFunctionWithMembershipProof,
117
- contractClass: Pick<ContractClassPublic, 'privateFunctionsRoot' | 'artifactHash'>,
118
- ) {
119
- const log = createLogger('circuits:function_membership_proof');
120
-
121
- // Check private function tree membership
122
- const functionLeaf = await computePrivateFunctionLeaf(fn);
123
- const rootBuffer = await computeRootFromSiblingPath(
124
- functionLeaf,
125
- fn.privateFunctionTreeSiblingPath.map(fr => fr.toBuffer()),
126
- fn.privateFunctionTreeLeafIndex,
127
- async (left, right) => (await poseidon2Hash([left, right])).toBuffer(),
128
- );
129
- const computedPrivateFunctionTreeRoot = Fr.fromBuffer(rootBuffer);
130
- if (!contractClass.privateFunctionsRoot.equals(computedPrivateFunctionTreeRoot)) {
131
- log.debug(`Private function tree root mismatch`, {
132
- expectedPrivateFunctionTreeRoot: contractClass.privateFunctionsRoot,
133
- computedPrivateFunctionTreeRoot: computedPrivateFunctionTreeRoot,
134
- computedFunctionLeaf: '0x' + functionLeaf.toString('hex'),
135
- });
136
- return false;
137
- }
138
-
139
- // Check artifact hash
140
- const functionArtifactHash = await computeFunctionArtifactHash(fn);
141
- const computedArtifactPrivateFunctionTreeRootBuffer = await computeRootFromSiblingPath(
142
- functionArtifactHash.toBuffer(),
143
- fn.artifactTreeSiblingPath.map(fr => fr.toBuffer()),
144
- fn.artifactTreeLeafIndex,
145
- getArtifactMerkleTreeHasher(),
146
- );
147
- const computedArtifactPrivateFunctionTreeRoot = Fr.fromBuffer(computedArtifactPrivateFunctionTreeRootBuffer);
148
- const computedArtifactHash = await computeArtifactHash({
149
- privateFunctionRoot: computedArtifactPrivateFunctionTreeRoot,
150
- utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
151
- metadataHash: fn.artifactMetadataHash,
152
- });
153
- if (!contractClass.artifactHash.equals(computedArtifactHash)) {
154
- log.debug(`Artifact hash mismatch`, {
155
- expected: contractClass.artifactHash,
156
- computedArtifactHash,
157
- computedFunctionArtifactHash: functionArtifactHash,
158
- computedArtifactPrivateFunctionTreeRoot,
159
- utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
160
- metadataHash: fn.artifactMetadataHash,
161
- artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
162
- });
163
- return false;
164
- }
165
-
166
- return true;
167
- }
@@ -1,118 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
4
-
5
- import { type ContractArtifact, FunctionSelector, FunctionType } from '../abi/index.js';
6
- import {
7
- computeArtifactFunctionTree,
8
- computeArtifactHash,
9
- computeArtifactHashPreimage,
10
- computeFunctionArtifactHash,
11
- computeFunctionMetadataHash,
12
- getArtifactMerkleTreeHasher,
13
- } from './artifact_hash.js';
14
- import type {
15
- ContractClassPublic,
16
- UtilityFunctionMembershipProof,
17
- UtilityFunctionWithMembershipProof,
18
- } from './interfaces/index.js';
19
-
20
- /**
21
- * Creates a membership proof for a utility function in a contract class, to be verified via `isValidUtilityFunctionMembershipProof`.
22
- * @param selector - Selector of the function to create the proof for.
23
- * @param artifact - Artifact of the contract class where the function is defined.
24
- */
25
- export async function createUtilityFunctionMembershipProof(
26
- selector: FunctionSelector,
27
- artifact: ContractArtifact,
28
- ): Promise<UtilityFunctionMembershipProof> {
29
- const log = createLogger('circuits:function_membership_proof');
30
-
31
- // Locate function artifact
32
- const utilityFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.UTILITY);
33
- const utilityFunctionsAndSelectors = await Promise.all(
34
- utilityFunctions.map(async fn => ({ fn, selector: await FunctionSelector.fromNameAndParameters(fn) })),
35
- );
36
- const fn = utilityFunctionsAndSelectors.find(fnAndSelector => selector.equals(fnAndSelector.selector))?.fn;
37
- if (!fn) {
38
- throw new Error(`Utility function with selector ${selector.toString()} not found`);
39
- }
40
- // Compute preimage for the artifact hash
41
- const { privateFunctionRoot: privateFunctionsArtifactTreeRoot, metadataHash: artifactMetadataHash } =
42
- await computeArtifactHashPreimage(artifact);
43
-
44
- // Compute the sibling path for the "artifact tree"
45
- const functionMetadataHash = computeFunctionMetadataHash(fn);
46
- const functionArtifactHash = await computeFunctionArtifactHash({ ...fn, functionMetadataHash });
47
- const artifactTree = (await computeArtifactFunctionTree(artifact, FunctionType.UTILITY))!;
48
- const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
49
- const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
50
-
51
- log.debug(`Computed proof for utility function with selector ${selector.toString()}`, {
52
- functionArtifactHash,
53
- functionMetadataHash,
54
- artifactMetadataHash,
55
- artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
56
- privateFunctionsArtifactTreeRoot,
57
- });
58
-
59
- return {
60
- artifactTreeSiblingPath,
61
- artifactTreeLeafIndex,
62
- artifactMetadataHash,
63
- functionMetadataHash,
64
- privateFunctionsArtifactTreeRoot,
65
- };
66
- }
67
-
68
- /**
69
- * Verifies that a utility function with a membership proof as emitted by the ClassRegistry contract is valid,
70
- * as defined in the protocol specs at contract-deployment/classes:
71
- *
72
- * ```
73
- * // Load contract class from local db
74
- * contract_class = db.get_contract_class(contract_class_id)
75
- *
76
- * // Compute artifact leaf and assert it belongs to the artifact
77
- * artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
78
- * computed_artifact_utility_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path, artifact_function_tree_leaf_index)
79
- * computed_artifact_hash = sha256(private_functions_artifact_tree_root, computed_artifact_utility_function_tree_root, artifact_metadata_hash)
80
- * assert computed_artifact_hash == contract_class.artifact_hash
81
- * ```
82
- * @param fn - Function to check membership proof for.
83
- * @param contractClass - In which contract class the function is expected to be.
84
- */
85
- export async function isValidUtilityFunctionMembershipProof(
86
- fn: UtilityFunctionWithMembershipProof,
87
- contractClass: Pick<ContractClassPublic, 'artifactHash'>,
88
- ) {
89
- const log = createLogger('circuits:function_membership_proof');
90
-
91
- const functionArtifactHash = await computeFunctionArtifactHash(fn);
92
- const computedArtifactFunctionTreeRootBuffer = await computeRootFromSiblingPath(
93
- functionArtifactHash.toBuffer(),
94
- fn.artifactTreeSiblingPath.map(fr => fr.toBuffer()),
95
- fn.artifactTreeLeafIndex,
96
- getArtifactMerkleTreeHasher(),
97
- );
98
- const computedArtifactFunctionTreeRoot = Fr.fromBuffer(computedArtifactFunctionTreeRootBuffer);
99
- const computedArtifactHash = await computeArtifactHash({
100
- privateFunctionRoot: fn.privateFunctionsArtifactTreeRoot,
101
- utilityFunctionRoot: computedArtifactFunctionTreeRoot,
102
- metadataHash: fn.artifactMetadataHash,
103
- });
104
- if (!contractClass.artifactHash.equals(computedArtifactHash)) {
105
- log.debug(`Artifact hash mismatch`, {
106
- expected: contractClass.artifactHash,
107
- computedArtifactHash,
108
- computedFunctionArtifactHash: functionArtifactHash,
109
- computedArtifactFunctionTreeRoot,
110
- privateFunctionsArtifactTreeRoot: fn.privateFunctionsArtifactTreeRoot,
111
- metadataHash: fn.artifactMetadataHash,
112
- artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
113
- });
114
- return false;
115
- }
116
-
117
- return true;
118
- }