From e1123be5a3363da4e19ddbe137a34ef9dbc8c9ed Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 1 Aug 2023 15:51:48 -0300 Subject: [PATCH 1/3] Bump ts eslint versions --- yarn-project/circuits.js/package.json | 2 - yarn-project/foundation/package.json | 4 +- yarn-project/yarn.lock | 201 ++++++++++++-------------- 3 files changed, 93 insertions(+), 114 deletions(-) diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index a5b6add6bdb..2a3dee75f1b 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -63,8 +63,6 @@ "@types/lodash.chunk": "^4.2.7", "@types/lodash.mapvalues": "^4.6.7", "@types/node": "^18.7.23", - "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.54.1", "jest": "^29.5.0", "prettier": "^2.8.4", "ts-dedent": "^2.2.0", diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 0bf838f28f5..1441e2eb85d 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -81,8 +81,8 @@ "@types/memdown": "^3.0.1", "@types/node": "^18.7.23", "@types/supertest": "^2.0.12", - "@typescript-eslint/eslint-plugin": "^5.38.0", - "@typescript-eslint/parser": "^5.38.0", + "@typescript-eslint/eslint-plugin": "^6.2.1", + "@typescript-eslint/parser": "^6.2.1", "comlink": "^4.4.1", "eslint": "^8.21.0", "eslint-config-prettier": "^8.5.0", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index a7bdfcf2f7e..0fd2ac5053c 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -260,8 +260,6 @@ __metadata: "@types/lodash.mapvalues": ^4.6.7 "@types/lodash.times": ^4.3.7 "@types/node": ^18.7.23 - "@typescript-eslint/eslint-plugin": ^5.54.1 - "@typescript-eslint/parser": ^5.54.1 cross-fetch: ^3.1.5 detect-node: ^2.1.0 eslint: ^8.35.0 @@ -396,8 +394,8 @@ __metadata: "@types/memdown": ^3.0.1 "@types/node": ^18.7.23 "@types/supertest": ^2.0.12 - "@typescript-eslint/eslint-plugin": ^5.38.0 - "@typescript-eslint/parser": ^5.38.0 + "@typescript-eslint/eslint-plugin": ^6.2.1 + "@typescript-eslint/parser": ^6.2.1 comlink: ^4.4.1 debug: ^4.3.4 detect-node: ^2.1.0 @@ -1414,7 +1412,7 @@ __metadata: languageName: node linkType: hard -"@eslint-community/eslint-utils@npm:^4.2.0": +"@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" dependencies: @@ -1432,6 +1430,13 @@ __metadata: languageName: node linkType: hard +"@eslint-community/regexpp@npm:^4.5.1": + version: 4.6.2 + resolution: "@eslint-community/regexpp@npm:4.6.2" + checksum: a3c341377b46b54fa228f455771b901d1a2717f95d47dcdf40199df30abc000ba020f747f114f08560d119e979d882a94cf46cfc51744544d54b00319c0f2724 + languageName: node + linkType: hard + "@eslint/eslintrc@npm:^2.1.0": version: 2.1.0 resolution: "@eslint/eslintrc@npm:2.1.0" @@ -3090,7 +3095,7 @@ __metadata: languageName: node linkType: hard -"@types/json-schema@npm:^7.0.9": +"@types/json-schema@npm:^7.0.12": version: 7.0.12 resolution: "@types/json-schema@npm:7.0.12" checksum: 00239e97234eeb5ceefb0c1875d98ade6e922bfec39dd365ec6bd360b5c2f825e612ac4f6e5f1d13601b8b30f378f15e6faa805a3a732f4a1bbe61915163d293 @@ -3447,7 +3452,7 @@ __metadata: languageName: node linkType: hard -"@types/semver@npm:^7.3.12": +"@types/semver@npm:^7.5.0": version: 7.5.0 resolution: "@types/semver@npm:7.5.0" checksum: 0a64b9b9c7424d9a467658b18dd70d1d781c2d6f033096a6e05762d20ebbad23c1b69b0083b0484722aabf35640b78ccc3de26368bcae1129c87e9df028a22e2 @@ -3551,124 +3556,126 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^5.38.0, @typescript-eslint/eslint-plugin@npm:^5.54.1": - version: 5.62.0 - resolution: "@typescript-eslint/eslint-plugin@npm:5.62.0" +"@typescript-eslint/eslint-plugin@npm:^6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/eslint-plugin@npm:6.2.1" dependencies: - "@eslint-community/regexpp": ^4.4.0 - "@typescript-eslint/scope-manager": 5.62.0 - "@typescript-eslint/type-utils": 5.62.0 - "@typescript-eslint/utils": 5.62.0 + "@eslint-community/regexpp": ^4.5.1 + "@typescript-eslint/scope-manager": 6.2.1 + "@typescript-eslint/type-utils": 6.2.1 + "@typescript-eslint/utils": 6.2.1 + "@typescript-eslint/visitor-keys": 6.2.1 debug: ^4.3.4 graphemer: ^1.4.0 - ignore: ^5.2.0 + ignore: ^5.2.4 + natural-compare: ^1.4.0 natural-compare-lite: ^1.4.0 - semver: ^7.3.7 - tsutils: ^3.21.0 + semver: ^7.5.4 + ts-api-utils: ^1.0.1 peerDependencies: - "@typescript-eslint/parser": ^5.0.0 - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + "@typescript-eslint/parser": ^6.0.0 || ^6.0.0-alpha + eslint: ^7.0.0 || ^8.0.0 peerDependenciesMeta: typescript: optional: true - checksum: fc104b389c768f9fa7d45a48c86d5c1ad522c1d0512943e782a56b1e3096b2cbcc1eea3fcc590647bf0658eef61aac35120a9c6daf979bf629ad2956deb516a1 + checksum: e73f3fe36519d895037d223f3ddf200b97e17bcde9390984118c38733add1edf996357c809ec2db92cec61bc7c9e5a3d9a583e0d0f92fa9c3919b68716a27b37 languageName: node linkType: hard -"@typescript-eslint/parser@npm:^5.38.0, @typescript-eslint/parser@npm:^5.54.1": - version: 5.62.0 - resolution: "@typescript-eslint/parser@npm:5.62.0" +"@typescript-eslint/parser@npm:^6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/parser@npm:6.2.1" dependencies: - "@typescript-eslint/scope-manager": 5.62.0 - "@typescript-eslint/types": 5.62.0 - "@typescript-eslint/typescript-estree": 5.62.0 + "@typescript-eslint/scope-manager": 6.2.1 + "@typescript-eslint/types": 6.2.1 + "@typescript-eslint/typescript-estree": 6.2.1 + "@typescript-eslint/visitor-keys": 6.2.1 debug: ^4.3.4 peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + eslint: ^7.0.0 || ^8.0.0 peerDependenciesMeta: typescript: optional: true - checksum: d168f4c7f21a7a63f47002e2d319bcbb6173597af5c60c1cf2de046b46c76b4930a093619e69faf2d30214c29ab27b54dcf1efc7046a6a6bd6f37f59a990e752 + checksum: cf4768cbfc696ce1d4b15ae55b3d2b52761e91a4a80e738cf3a75c501c2257d735cd6e462567965069d0d693a8cf5463ab9e8b97c36c6ed1fccd3c1c09855bdb languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/scope-manager@npm:5.62.0" +"@typescript-eslint/scope-manager@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/scope-manager@npm:6.2.1" dependencies: - "@typescript-eslint/types": 5.62.0 - "@typescript-eslint/visitor-keys": 5.62.0 - checksum: 6062d6b797fe1ce4d275bb0d17204c827494af59b5eaf09d8a78cdd39dadddb31074dded4297aaf5d0f839016d601032857698b0e4516c86a41207de606e9573 + "@typescript-eslint/types": 6.2.1 + "@typescript-eslint/visitor-keys": 6.2.1 + checksum: 3bb461678c7e729895c5ac16781ec7d66efc6ffa944bb49693ce8e9560f9a6cac70929157c0fc0875b2829ae19a5cdabb97973ddcfb7e81c16e22cdd5d39e3fd languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/type-utils@npm:5.62.0" +"@typescript-eslint/type-utils@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/type-utils@npm:6.2.1" dependencies: - "@typescript-eslint/typescript-estree": 5.62.0 - "@typescript-eslint/utils": 5.62.0 + "@typescript-eslint/typescript-estree": 6.2.1 + "@typescript-eslint/utils": 6.2.1 debug: ^4.3.4 - tsutils: ^3.21.0 + ts-api-utils: ^1.0.1 peerDependencies: - eslint: "*" + eslint: ^7.0.0 || ^8.0.0 peerDependenciesMeta: typescript: optional: true - checksum: fc41eece5f315dfda14320be0da78d3a971d650ea41300be7196934b9715f3fe1120a80207551eb71d39568275dbbcf359bde540d1ca1439d8be15e9885d2739 + checksum: 7f8d80f03e6ddc1838307a2a4df61dc4bd8400efb9dcc7316063ae293fce54afad238404a0c25cd2cdaceee73ae514f254b850bd7ff11e2def700d5d6b90af05 languageName: node linkType: hard -"@typescript-eslint/types@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/types@npm:5.62.0" - checksum: 48c87117383d1864766486f24de34086155532b070f6264e09d0e6139449270f8a9559cfef3c56d16e3bcfb52d83d42105d61b36743626399c7c2b5e0ac3b670 +"@typescript-eslint/types@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/types@npm:6.2.1" + checksum: 388d32f15a9db8ad5d80794caf9ab280d6e5a428efdf4f6a6dfc4069afe4d19da32d628acf638e4c5b92ee77a9a18eecf728a778a3b91cc8a24484af579fc9cf languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.62.0" +"@typescript-eslint/typescript-estree@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/typescript-estree@npm:6.2.1" dependencies: - "@typescript-eslint/types": 5.62.0 - "@typescript-eslint/visitor-keys": 5.62.0 + "@typescript-eslint/types": 6.2.1 + "@typescript-eslint/visitor-keys": 6.2.1 debug: ^4.3.4 globby: ^11.1.0 is-glob: ^4.0.3 - semver: ^7.3.7 - tsutils: ^3.21.0 + semver: ^7.5.4 + ts-api-utils: ^1.0.1 peerDependenciesMeta: typescript: optional: true - checksum: 3624520abb5807ed8f57b1197e61c7b1ed770c56dfcaca66372d584ff50175225798bccb701f7ef129d62c5989070e1ee3a0aa2d84e56d9524dcf011a2bb1a52 + checksum: 3d9beeb5e36b8827de5c160ed8e5c111dd66ca00671b183409b051e242b291480679b900bb74aaf4895dcae49497037567d3fcbbe67fa9930786ddd01c685f04 languageName: node linkType: hard -"@typescript-eslint/utils@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/utils@npm:5.62.0" - dependencies: - "@eslint-community/eslint-utils": ^4.2.0 - "@types/json-schema": ^7.0.9 - "@types/semver": ^7.3.12 - "@typescript-eslint/scope-manager": 5.62.0 - "@typescript-eslint/types": 5.62.0 - "@typescript-eslint/typescript-estree": 5.62.0 - eslint-scope: ^5.1.1 - semver: ^7.3.7 +"@typescript-eslint/utils@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/utils@npm:6.2.1" + dependencies: + "@eslint-community/eslint-utils": ^4.4.0 + "@types/json-schema": ^7.0.12 + "@types/semver": ^7.5.0 + "@typescript-eslint/scope-manager": 6.2.1 + "@typescript-eslint/types": 6.2.1 + "@typescript-eslint/typescript-estree": 6.2.1 + semver: ^7.5.4 peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: ee9398c8c5db6d1da09463ca7bf36ed134361e20131ea354b2da16a5fdb6df9ba70c62a388d19f6eebb421af1786dbbd79ba95ddd6ab287324fc171c3e28d931 + eslint: ^7.0.0 || ^8.0.0 + checksum: d16356a633f39d988a9af159da15e28c6a28fa47abce372061c79cf186d193d148e1c32862c9702ff87e2a06f7a2f82773e4b56320a39f432f4b1a989f8005ad languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.62.0" +"@typescript-eslint/visitor-keys@npm:6.2.1": + version: 6.2.1 + resolution: "@typescript-eslint/visitor-keys@npm:6.2.1" dependencies: - "@typescript-eslint/types": 5.62.0 - eslint-visitor-keys: ^3.3.0 - checksum: 976b05d103fe8335bef5c93ad3f76d781e3ce50329c0243ee0f00c0fcfb186c81df50e64bfdd34970148113f8ade90887f53e3c4938183afba830b4ba8e30a35 + "@typescript-eslint/types": 6.2.1 + eslint-visitor-keys: ^3.4.1 + checksum: c05a1c45129f2cf9a8c49dadc3da10b675232e59b69dfe9fdc0bfb45d3be077ceff78097baf50e502dab3e71ce9fd799d2015e356a4be2787ee10c6c7a44ea8a languageName: node linkType: hard @@ -5456,16 +5463,6 @@ __metadata: languageName: node linkType: hard -"eslint-scope@npm:^5.1.1": - version: 5.1.1 - resolution: "eslint-scope@npm:5.1.1" - dependencies: - esrecurse: ^4.3.0 - estraverse: ^4.1.1 - checksum: 47e4b6a3f0cc29c7feedee6c67b225a2da7e155802c6ea13bbef4ac6b9e10c66cd2dcb987867ef176292bf4e64eccc680a49e35e9e9c669f4a02bac17e86abdb - languageName: node - linkType: hard - "eslint-scope@npm:^7.2.0": version: 7.2.0 resolution: "eslint-scope@npm:7.2.0" @@ -5571,13 +5568,6 @@ __metadata: languageName: node linkType: hard -"estraverse@npm:^4.1.1": - version: 4.3.0 - resolution: "estraverse@npm:4.3.0" - checksum: a6299491f9940bb246124a8d44b7b7a413a8336f5436f9837aaa9330209bd9ee8af7e91a654a3545aee9c54b3308e78ee360cef1d777d37cfef77d2fa33b5827 - languageName: node - linkType: hard - "estraverse@npm:^5.1.0, estraverse@npm:^5.2.0": version: 5.3.0 resolution: "estraverse@npm:5.3.0" @@ -9668,7 +9658,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3": +"semver@npm:^7.3.5, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": version: 7.5.4 resolution: "semver@npm:7.5.4" dependencies: @@ -10322,6 +10312,15 @@ __metadata: languageName: node linkType: hard +"ts-api-utils@npm:^1.0.1": + version: 1.0.1 + resolution: "ts-api-utils@npm:1.0.1" + peerDependencies: + typescript: ">=4.2.0" + checksum: 78794fc7270d295b36c1ac613465b5dc7e7226907a533125b30f177efef9dd630d4e503b00be31b44335eb2ebf9e136ebe97353f8fc5d383885d5fead9d54c09 + languageName: node + linkType: hard + "ts-dedent@npm:^2.2.0": version: 2.2.0 resolution: "ts-dedent@npm:2.2.0" @@ -10437,13 +10436,6 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^1.8.1": - version: 1.14.1 - resolution: "tslib@npm:1.14.1" - checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd - languageName: node - linkType: hard - "tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.5.0, tslib@npm:^2.6.0": version: 2.6.0 resolution: "tslib@npm:2.6.0" @@ -10458,17 +10450,6 @@ __metadata: languageName: node linkType: hard -"tsutils@npm:^3.21.0": - version: 3.21.0 - resolution: "tsutils@npm:3.21.0" - dependencies: - tslib: ^1.8.1 - peerDependencies: - typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 - languageName: node - linkType: hard - "type-check@npm:^0.4.0, type-check@npm:~0.4.0": version: 0.4.0 resolution: "type-check@npm:0.4.0" From 0516205133c9e30c42547acd0f50fdb5a784ec53 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 1 Aug 2023 15:52:03 -0300 Subject: [PATCH 2/3] Tweak eslintrc jsdoc settings --- yarn-project/foundation/.eslintrc.cjs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/yarn-project/foundation/.eslintrc.cjs b/yarn-project/foundation/.eslintrc.cjs index df1649afae8..66f3a26f721 100644 --- a/yarn-project/foundation/.eslintrc.cjs +++ b/yarn-project/foundation/.eslintrc.cjs @@ -1,6 +1,12 @@ +// See https://typescript-eslint.io/play/#ts=5.1.6&showAST=es&fileType=.ts const contexts = [ - 'TSMethodDefinition[accessibility=public]', - 'MethodDefinition[accessibility=public]', + // All methods in an interface + 'TSInterfaceDeclaration TSMethodSignature', + // All public methods in a class that does not implement an interface + 'ClassDeclaration[implements.length=0] MethodDefinition[accessibility=public]', + // TODO: All methods public by default in a class that does not implement an interface + // 'ClassDeclaration[implements.length=0] MethodDefinition[accessibility=undefined][key.type=Identifier]', + // Legacy contexts (needs review) 'TSParameterProperty[accessibility=public]', 'TSPropertySignature', 'PropertySignature', @@ -120,8 +126,7 @@ module.exports = { 'jsdoc/require-property': [JSDOC_RULES_LEVEL, { contexts }], 'jsdoc/require-property-description': [JSDOC_RULES_LEVEL, { contexts }], 'jsdoc/require-property-name': [JSDOC_RULES_LEVEL, { contexts }], - 'jsdoc/require-returns': [JSDOC_RULES_LEVEL, { contexts }], - 'jsdoc/require-returns-description': [JSDOC_RULES_LEVEL, { contexts }], + 'jsdoc/require-returns': 'off', }, ignorePatterns: ['node_modules', 'dest*', 'dist', '*.js', '.eslintrc.cjs'], }; From 64fcda1e5aa98c1950c6ef6d7ec9df24eebff7ec Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 1 Aug 2023 15:52:12 -0300 Subject: [PATCH 3/3] Move docs around! --- .../acir-simulator/src/client/db_oracle.ts | 43 ++++++ yarn-project/acir-simulator/src/public/db.ts | 19 +++ .../src/aztec_rpc_server/aztec_rpc_server.ts | 139 ----------------- .../aztec-rpc/src/database/database.ts | 110 +++++++++++++ .../aztec-rpc/src/database/memory_db.ts | 81 ---------- .../aztec-rpc/src/kernel_oracle/index.ts | 39 ----- .../src/kernel_prover/proof_creator.ts | 57 +++---- .../src/kernel_prover/proving_data_oracle.ts | 43 ++++++ .../aztec-rpc/src/simulator_oracle/index.ts | 39 ----- .../src/account_impl/account_collection.ts | 6 - .../aztec.js/src/account_impl/index.ts | 12 +- .../barretenberg/crypto/signature/index.ts | 14 ++ .../foundation/src/mutex/mutex_database.ts | 3 + .../src/transport/interface/connector.ts | 1 + .../src/transport/interface/listener.ts | 5 +- .../src/transport/interface/socket.ts | 3 + .../src/transport/transport_client.ts | 6 +- .../foundation/src/wasm/worker/data_store.ts | 12 ++ .../src/wasm/worker/node/node_data_store.ts | 10 -- yarn-project/key-store/src/key_pair.ts | 12 -- yarn-project/key-store/src/test_key_store.ts | 27 ---- yarn-project/merkle-tree/src/pedersen.ts | 27 ---- yarn-project/p2p/src/client/p2p_client.ts | 5 +- .../global_variable_builder/global_builder.ts | 17 ++ .../global_variable_builder/viem-reader.ts | 12 -- .../sequencer-client/src/prover/index.ts | 26 ++++ .../sequencer-client/src/simulator/index.ts | 4 +- .../src/simulator/public_executor.ts | 16 -- yarn-project/types/src/contract_database.ts | 15 ++ .../types/src/interfaces/aztec-node.ts | 1 + .../types/src/interfaces/aztec_rpc.ts | 145 +++++++++++++++++- yarn-project/types/src/interfaces/hasher.ts | 30 ++++ yarn-project/types/src/keys/key_pair.ts | 10 ++ yarn-project/types/src/keys/key_store.ts | 27 ++++ .../server_world_state_synchroniser.ts | 19 --- .../synchroniser/world_state_synchroniser.ts | 23 +++ 36 files changed, 596 insertions(+), 462 deletions(-) diff --git a/yarn-project/acir-simulator/src/client/db_oracle.ts b/yarn-project/acir-simulator/src/client/db_oracle.ts index 7110525be8c..37a6270f579 100644 --- a/yarn-project/acir-simulator/src/client/db_oracle.ts +++ b/yarn-project/acir-simulator/src/client/db_oracle.ts @@ -71,9 +71,52 @@ export interface CommitmentDataOracleInputs { * The database oracle interface. */ export interface DBOracle extends CommitmentsDB { + /** + * Retrieve the public key associated to a given address. + * @param address - Address to fetch the pubkey for. + * @returns A public key and the corresponding partial contract address, such that the hash of the two resolves to the input address. + */ getPublicKey(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]>; + + /** + * Retrieve the secret key associated with a specific public key. + * The function only allows access to the secret keys of the transaction creator, + * and throws an error if the address does not match the public key address of the key pair. + * + * @param contractAddress - The contract address. Ignored here. But we might want to return different keys for different contracts. + * @param pubKey - The public key of an account. + * @returns A Promise that resolves to the secret key as a Buffer. + * @throws An Error if the input address does not match the public key address of the key pair. + */ getSecretKey(contractAddress: AztecAddress, pubKey: PublicKey): Promise; + + /** + * Retrieves a set of notes stored in the database for a given contract address and storage slot. + * The query result is paginated using 'limit' and 'offset' values. + * Returns an object containing an array of note data, including preimage, nonce, and index for each note. + * + * @param contractAddress - The AztecAddress instance representing the contract address. + * @param storageSlot - The Fr instance representing the storage slot of the notes. + * @returns A Promise that resolves to an array of note data. + */ getNotes(contractAddress: AztecAddress, storageSlot: Fr): Promise; + + /** + * Retrieve the ABI information of a specific function within a contract. + * The function is identified by its selector, which is a unique identifier generated from the function signature. + * + * @param contractAddress - The contract address. + * @param functionSelector - The Buffer containing the function selector bytes. + * @returns A Promise that resolves to a FunctionAbi object containing the ABI information of the target function. + */ getFunctionABI(contractAddress: AztecAddress, functionSelector: Buffer): Promise; + + /** + * Retrieves the portal contract address associated with the given contract address. + * Throws an error if the input contract address is not found or invalid. + * + * @param contractAddress - The address of the contract whose portal address is to be fetched. + * @returns A Promise that resolves to an EthAddress instance, representing the portal contract address. + */ getPortalContractAddress(contractAddress: AztecAddress): Promise; } diff --git a/yarn-project/acir-simulator/src/public/db.ts b/yarn-project/acir-simulator/src/public/db.ts index dd3f94a2ae7..f03c075b424 100644 --- a/yarn-project/acir-simulator/src/public/db.ts +++ b/yarn-project/acir-simulator/src/public/db.ts @@ -21,6 +21,7 @@ export interface PublicStateDB { * @param contract - Owner of the storage. * @param slot - Slot to read in the contract storage. * @param newValue - The new value to store. + * @returns Nothing. */ storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise; } @@ -55,7 +56,25 @@ export interface PublicContractsDB { /** Database interface for providing access to commitment tree and l1 to l2 messages tree (append only data trees). */ export interface CommitmentsDB { + /** + * Gets a confirmed L1 to L2 message for the given message key. + * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. + * @param msgKey - The message Key. + * @returns - The l1 to l2 message object + */ getL1ToL2Message(msgKey: Fr): Promise; + + /** + * Gets a message index and sibling path to some commitment in the private data tree. + * @param address - The contract address owning storage. + * @param commitment - The preimage of the siloed data. + * @returns - The Commitment data oracle object + */ getCommitmentOracle(address: AztecAddress, commitment: Fr): Promise; + + /** + * Gets the current tree roots from the merkle db. + * @returns current tree roots. + */ getTreeRoots(): PrivateHistoricTreeRoots; } diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index 5ee354b04d5..5a02b94fb85 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -86,14 +86,6 @@ export class AztecRPCServer implements AztecRPC { this.log.info('Stopped'); } - /** - * Registers an account backed by an account contract. - * - * @param privKey - Private key of the corresponding user master public key. - * @param address - Address of the account contract. - * @param partialContractAddress - The partially computed address of the account contract. - * @returns The address of the account contract. - */ public async addAccount(privKey: PrivateKey, address: AztecAddress, partialContractAddress: PartialContractAddress) { const pubKey = this.keyStore.addAccount(privKey); // TODO(#1007): ECDSA contract breaks this check, since the ecdsa public key does not match the one derived from the keystore. @@ -111,13 +103,6 @@ export class AztecRPCServer implements AztecRPC { return address; } - /** - * Adds public key and partial address to a database. - * @param address - Address of the account to add public key and partial address for. - * @param publicKey - Public key of the corresponding user. - * @param partialAddress - The partially computed address of the account contract. - * @returns A Promise that resolves once the public key has been added to the database. - */ public async addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, @@ -127,13 +112,6 @@ export class AztecRPCServer implements AztecRPC { this.log.info(`Added public key for ${address.toString()}`); } - /** - * Add an array of deployed contracts to the database. - * Each contract should contain ABI, address, and portalContract information. - * - * @param contracts - An array of DeployedContract objects containing contract ABI, address, and portalContract. - * @returns A Promise that resolves once all the contracts have been added to the database. - */ public async addContracts(contracts: DeployedContract[]) { const contractDaos = contracts.map(c => toContractDao(c.abi, c.address, c.portalContract)); await Promise.all(contractDaos.map(c => this.db.addContract(c))); @@ -144,23 +122,10 @@ export class AztecRPCServer implements AztecRPC { } } - /** - * Retrieves the list of Aztec addresses added to this rpc server - * The addresses are returned as a promise that resolves to an array of AztecAddress objects. - * - * @returns A promise that resolves to an array of AztecAddress instances. - */ public async getAccounts(): Promise { return await this.db.getAccounts(); } - /** - * Retrieve the public key associated with an address. - * Throws an error if the account is not found in the key store. - * - * @param address - The AztecAddress instance representing the account to get public key for. - * @returns A Promise resolving to the PublicKey instance representing the public key. - */ public async getPublicKey(address: AztecAddress): Promise { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) { @@ -169,13 +134,6 @@ export class AztecRPCServer implements AztecRPC { return Promise.resolve(result[0]); } - /** - * Retrieve the public key and partial contract address associated with an address. - * Throws an error if the account is not found in the key store. - * - * @param address - The AztecAddress instance representing the account to get public key and partial address for. - * @returns A Promise resolving to the PublicKey instance representing the public key. - */ public async getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]> { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) { @@ -184,27 +142,11 @@ export class AztecRPCServer implements AztecRPC { return Promise.resolve(result); } - /** - * Retrieves the preimage data at a specified contract address and storage slot. - * The returned data is an array of note preimage items, with each item containing its value. - * - * @param contract - The AztecAddress of the target contract. - * @param storageSlot - The Fr representing the storage slot to be fetched. - * @returns A promise that resolves to an array of note preimage items, each containing its value. - */ public async getPreimagesAt(contract: AztecAddress, storageSlot: Fr) { const noteSpendingInfo = await this.db.getNoteSpendingInfo(contract, storageSlot); return noteSpendingInfo.map(d => d.notePreimage.items.map(item => item.value)); } - /** - * Retrieves the public storage data at a specified contract address and storage slot. - * The returned data is data at the storage slot or throws an error if the contract is not deployed. - * - * @param contract - The AztecAddress of the target contract. - * @param storageSlot - The Fr representing the storage slot to be fetched. - * @returns A buffer containing the public storage data at the storage slot. - */ public async getPublicStorageAt(contract: AztecAddress, storageSlot: Fr) { if (!(await this.isContractDeployed(contract))) { throw new Error(`Contract ${contract.toString()} is not deployed`); @@ -212,23 +154,10 @@ export class AztecRPCServer implements AztecRPC { return await this.node.getPublicStorageAt(contract, storageSlot.value); } - /** - * Is an L2 contract deployed at this address? - * @param contractAddress - The contract data address. - * @returns Whether the contract was deployed. - */ public async isContractDeployed(contractAddress: AztecAddress): Promise { return !!(await this.node.getContractInfo(contractAddress)); } - /** - * Create a transaction for a contract function call with the provided arguments. - * Throws an error if the contract or function is unknown. - * - * @param txRequest - An authenticated tx request ready for simulation - * @param optionalFromAddress - The address to simulate from - * @returns A Tx ready to send to the p2p pool for execution. - */ public async simulateTx(txRequest: TxExecutionRequest) { if (!txRequest.functionData.isPrivate) { throw new Error(`Public entrypoints are not allowed`); @@ -256,11 +185,6 @@ export class AztecRPCServer implements AztecRPC { return tx; } - /** - * Send a transaction. - * @param tx - The transaction. - * @returns A hash of the transaction, used to identify it. - */ public async sendTx(tx: Tx): Promise { const txHash = await tx.getTxHash(); this.log.info(`Sending transaction ${txHash}`); @@ -268,18 +192,6 @@ export class AztecRPCServer implements AztecRPC { return txHash; } - /** - * Simulate the execution of a view (read-only) function on a deployed contract without actually modifying state. - * This is useful to inspect contract state, for example fetching a variable value or calling a getter function. - * The function takes function name and arguments as parameters, along with the contract address - * and optionally the sender's address. - * - * @param functionName - The name of the function to be called in the contract. - * @param args - The arguments to be provided to the function. - * @param to - The address of the contract to be called. - * @param from - (Optional) The caller of the transaction. - * @returns The result of the view function call, structured based on the function ABI. - */ public async viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress) { const txRequest = await this.#getExecutionRequest(functionName, args, to, from ?? AztecAddress.ZERO); @@ -289,11 +201,6 @@ export class AztecRPCServer implements AztecRPC { return executionResult; } - /** - * Fetches a transaction receipt for a tx. - * @param txHash - The transaction hash. - * @returns A receipt of the transaction. - */ public async getTxReceipt(txHash: TxHash): Promise { const localTx = await this.#getTxByHash(txHash); const partialReceipt = new TxReceipt( @@ -331,40 +238,18 @@ export class AztecRPCServer implements AztecRPC { return partialReceipt; } - /** - * Get latest L2 block number. - * @returns The latest block number. - */ async getBlockNum(): Promise { return await this.node.getBlockHeight(); } - /** - * Lookup the L2 contract data for this contract. - * Contains the ethereum portal address and bytecode. - * @param contractAddress - The contract data address. - * @returns The complete contract data including portal address & bytecode (if we didn't throw an error). - */ public async getContractData(contractAddress: AztecAddress): Promise { return await this.node.getContractData(contractAddress); } - /** - * Lookup the L2 contract info for this contract. - * Contains the ethereum portal address . - * @param contractAddress - The contract data address. - * @returns The contract's address & portal address. - */ public async getContractInfo(contractAddress: AztecAddress): Promise { return await this.node.getContractInfo(contractAddress); } - /** - * Gets L2 block unencrypted logs. - * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned. - * @param take - The number of unencrypted logs to return. - * @returns The requested unencrypted logs. - */ public async getUnencryptedLogs(from: number, take: number): Promise { return await this.node.getLogs(from, take, LogType.UNENCRYPTED); } @@ -393,10 +278,6 @@ export class AztecRPCServer implements AztecRPC { }; } - /** - * Returns the information about the server's node - * @returns - The node information. - */ public async getNodeInfo(): Promise { const [version, chainId] = await Promise.all([this.node.getVersion(), this.node.getChainId()]); @@ -458,16 +339,6 @@ export class AztecRPCServer implements AztecRPC { }; } - /** - * Simulate the execution of a transaction request. - * This function computes the expected state changes resulting from the transaction - * without actually submitting it to the blockchain. The result will be used for creating the kernel proofs, - * as well as for estimating gas costs. - * - * @param txRequest - The transaction request object containing the necessary data for simulation. - * @param contractDataOracle - Optional parameter, an instance of ContractDataOracle class for retrieving contract data. - * @returns A promise that resolves to an object containing the simulation results, including expected output notes and any error messages. - */ async #simulate(txRequest: TxExecutionRequest, contractDataOracle?: ContractDataOracle) { // TODO - Pause syncing while simulating. if (!contractDataOracle) { @@ -567,20 +438,10 @@ export class AztecRPCServer implements AztecRPC { ); } - /** - * Return true if the top level block synchronisation is up to date - * This indicates that blocks and transactions are synched even if notes are not - * @returns True if there are no outstanding blocks to be synched - */ public async isSynchronised() { return await this.synchroniser.isSynchronised(); } - /** - * Returns true if the account specified by the given address is synched to the latest block - * @param account - The aztec address for which to query the sync status - * @returns True if the account is fully synched, false otherwise - */ public async isAccountSynchronised(account: AztecAddress) { return await this.synchroniser.isAccountSynchronised(account); } diff --git a/yarn-project/aztec-rpc/src/database/database.ts b/yarn-project/aztec-rpc/src/database/database.ts index 1da0ad3ef9b..069f27ee7d4 100644 --- a/yarn-project/aztec-rpc/src/database/database.ts +++ b/yarn-project/aztec-rpc/src/database/database.ts @@ -11,24 +11,134 @@ import { TxDao } from './tx_dao.js'; * addresses, storage slots, and nullifiers. */ export interface Database extends ContractDatabase { + /** + * Retrieve a transaction from the MemoryDB using its transaction hash. + * The function searches for the transaction with the given hash in the txTable and returns it as a Promise. + * Returns 'undefined' if the transaction is not found in the database. + * + * @param txHash - The TxHash of the transaction to be retrieved. + * @returns A Promise that resolves to the found TxDao instance, or undefined if not found. + */ getTx(txHash: TxHash): Promise; + + /** + * Retrieve all transactions associated with a given AztecAddress. + * + * @param origin - The sender's address. + * @returns A Promise resolving to an array of TxDao objects associated with the sender. + */ getTxsByAddress(origin: AztecAddress): Promise; + + /** + * Adds a TxDao instance to the transaction table. + * If a transaction with the same hash already exists in the table, it replaces the existing one. + * Otherwise, it pushes the new transaction to the table. + * + * @param tx - The TxDao instance representing the transaction to be added. + * @returns A Promise that resolves when the transaction is successfully added/updated in the table. + */ addTx(tx: TxDao): Promise; + + /** + * Add an array of transaction data objects. + * If a transaction with the same hash already exists in the database, it will be updated + * with the new transaction data. Otherwise, the new transaction will be added to the database. + * + * @param txs - An array of TxDao instances representing the transactions to be added to the database. + * @returns A Promise that resolves when all the transactions have been added or updated. + */ addTxs(txs: TxDao[]): Promise; + /** + * Get auxiliary transaction data based on contract address and storage slot. + * It searches for matching NoteSpendingInfoDao objects in the MemoryDB's noteSpendingInfoTable + * where both the contractAddress and storageSlot properties match the given inputs. + * + * @param contract - The contract address. + * @param storageSlot - A Fr object representing the storage slot to search for in the auxiliary data. + * @returns An array of NoteSpendingInfoDao objects that fulfill the contract address and storage slot criteria. + */ getNoteSpendingInfo(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Add a NoteSpendingInfoDao instance to the noteSpendingInfoTable. + * This function is used to store auxiliary data related to a transaction, + * such as contract address and storage slot, in the database. + * + * @param noteSpendingInfoDao - The NoteSpendingInfoDao instance containing the auxiliary data of a transaction. + * @returns A promise that resolves when the auxiliary data is added to the database. + */ addNoteSpendingInfo(noteSpendingInfoDao: NoteSpendingInfoDao): Promise; + + /** + * Adds an array of NoteSpendingInfoDaos to the noteSpendingInfoTable. + * This function is used to insert multiple transaction auxiliary data objects into the database at once, + * which can improve performance when dealing with large numbers of transactions. + * + * @param noteSpendingInfoDaos - An array of NoteSpendingInfoDao instances representing the auxiliary data of transactions. + * @returns A Promise that resolves when all NoteSpendingInfoDaos have been successfully added to the noteSpendingInfoTable. + */ addNoteSpendingInfoBatch(noteSpendingInfoDaos: NoteSpendingInfoDao[]): Promise; + + /** + * Remove nullified transaction auxiliary data records associated with the given account and nullifiers. + * The function filters the records based on matching account and nullifier values, and updates the + * noteSpendingInfoTable with the remaining records. It returns an array of removed NoteSpendingInfoDao instances. + * + * @param nullifiers - An array of Fr instances representing nullifiers to be matched. + * @param account - A PublicKey instance representing the account for which the records are being removed. + * @returns A Promise resolved with an array of removed NoteSpendingInfoDao instances. + */ removeNullifiedNoteSpendingInfo(nullifiers: Fr[], account: PublicKey): Promise; + /** + * Retrieve the stored Merkle tree roots from the database. + * The function returns a Promise that resolves to an object containing the MerkleTreeId as keys + * and their corresponding Fr values as roots. Throws an error if the tree roots are not set in the + * memory database. + * + * @returns An object containing the Merkle tree roots for each merkle tree id. + */ getTreeRoots(): Record; + + /** + * Set the tree roots for the Merkle trees in the database. + * This function updates the 'treeRoots' property of the instance + * with the provided 'roots' object containing MerkleTreeId and Fr pairs. + * Note that this will overwrite any existing tree roots in the database. + * + * @param roots - A Record object mapping MerkleTreeIds to their corresponding Fr root values. + * @returns A Promise that resolves when the tree roots have been successfully updated in the database. + */ setTreeRoots(roots: Record): Promise; + /** + * Adds public key and partial address to a database. + * @param address - Address of the account to add public key and partial address for. + * @param publicKey - Public key of the corresponding user. + * @param partialAddress - The partially computed address of the account contract. + * @returns A Promise that resolves once the public key has been added to the database. + */ addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, partialAddress: PartialContractAddress, ): Promise; + + /** + * Retrieve the public key and partial contract address associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key and partial address for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress] | undefined>; + + /** + * Retrieves the list of Aztec addresses added to this database + * The addresses are returned as a promise that resolves to an array of AztecAddress objects. + * + * @returns A promise that resolves to an array of AztecAddress instances. + */ getAccounts(): Promise; } diff --git a/yarn-project/aztec-rpc/src/database/memory_db.ts b/yarn-project/aztec-rpc/src/database/memory_db.ts index 949c31bde47..756e7b6c8a0 100644 --- a/yarn-project/aztec-rpc/src/database/memory_db.ts +++ b/yarn-project/aztec-rpc/src/database/memory_db.ts @@ -25,36 +25,14 @@ export class MemoryDB extends MemoryContractDatabase implements Database { super(createDebugLogger(logSuffix ? 'aztec:memory_db_' + logSuffix : 'aztec:memory_db')); } - /** - * Retrieve a transaction from the MemoryDB using its transaction hash. - * The function searches for the transaction with the given hash in the txTable and returns it as a Promise. - * Returns 'undefined' if the transaction is not found in the database. - * - * @param txHash - The TxHash of the transaction to be retrieved. - * @returns A Promise that resolves to the found TxDao instance, or undefined if not found. - */ public getTx(txHash: TxHash) { return Promise.resolve(this.txTable.find(tx => tx.txHash.equals(txHash))); } - /** - * Retrieve all transactions associated with a given AztecAddress. - * - * @param origin - The sender's address. - * @returns A Promise resolving to an array of TxDao objects associated with the sender. - */ public getTxsByAddress(origin: AztecAddress) { return Promise.resolve(this.txTable.filter(tx => tx.origin.equals(origin))); } - /** - * Adds a TxDao instance to the transaction table. - * If a transaction with the same hash already exists in the table, it replaces the existing one. - * Otherwise, it pushes the new transaction to the table. - * - * @param tx - The TxDao instance representing the transaction to be added. - * @returns A Promise that resolves when the transaction is successfully added/updated in the table. - */ public addTx(tx: TxDao) { const index = this.txTable.findIndex(t => t.txHash.equals(tx.txHash)); if (index === -1) { @@ -65,53 +43,20 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(); } - /** - * Add an array of transaction data objects. - * If a transaction with the same hash already exists in the database, it will be updated - * with the new transaction data. Otherwise, the new transaction will be added to the database. - * - * @param txs - An array of TxDao instances representing the transactions to be added to the database. - * @returns A Promise that resolves when all the transactions have been added or updated. - */ public async addTxs(txs: TxDao[]) { await Promise.all(txs.map(tx => this.addTx(tx))); } - /** - * Add a NoteSpendingInfoDao instance to the noteSpendingInfoTable. - * This function is used to store auxiliary data related to a transaction, - * such as contract address and storage slot, in the database. - * - * @param noteSpendingInfoDao - The NoteSpendingInfoDao instance containing the auxiliary data of a transaction. - * @returns A promise that resolves when the auxiliary data is added to the database. - */ public addNoteSpendingInfo(noteSpendingInfoDao: NoteSpendingInfoDao) { this.noteSpendingInfoTable.push(noteSpendingInfoDao); return Promise.resolve(); } - /** - * Adds an array of NoteSpendingInfoDaos to the noteSpendingInfoTable. - * This function is used to insert multiple transaction auxiliary data objects into the database at once, - * which can improve performance when dealing with large numbers of transactions. - * - * @param noteSpendingInfoDaos - An array of NoteSpendingInfoDao instances representing the auxiliary data of transactions. - * @returns A Promise that resolves when all NoteSpendingInfoDaos have been successfully added to the noteSpendingInfoTable. - */ public addNoteSpendingInfoBatch(noteSpendingInfoDaos: NoteSpendingInfoDao[]) { this.noteSpendingInfoTable.push(...noteSpendingInfoDaos); return Promise.resolve(); } - /** - * Get auxiliary transaction data based on contract address and storage slot. - * It searches for matching NoteSpendingInfoDao objects in the MemoryDB's noteSpendingInfoTable - * where both the contractAddress and storageSlot properties match the given inputs. - * - * @param contract - The contract address. - * @param storageSlot - A Fr object representing the storage slot to search for in the auxiliary data. - * @returns An array of NoteSpendingInfoDao objects that fulfill the contract address and storage slot criteria. - */ public getNoteSpendingInfo(contract: AztecAddress, storageSlot: Fr) { const res = this.noteSpendingInfoTable.filter( noteSpendingInfo => @@ -121,15 +66,6 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(res); } - /** - * Remove nullified transaction auxiliary data records associated with the given account and nullifiers. - * The function filters the records based on matching account and nullifier values, and updates the - * noteSpendingInfoTable with the remaining records. It returns an array of removed NoteSpendingInfoDao instances. - * - * @param nullifiers - An array of Fr instances representing nullifiers to be matched. - * @param account - A PublicKey instance representing the account for which the records are being removed. - * @returns A Promise resolved with an array of removed NoteSpendingInfoDao instances. - */ public removeNullifiedNoteSpendingInfo(nullifiers: Fr[], account: PublicKey) { const nullifierSet = new Set(nullifiers.map(nullifier => nullifier.toString())); const [remaining, removed] = this.noteSpendingInfoTable.reduce( @@ -150,29 +86,12 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(removed); } - /** - * Retrieve the stored Merkle tree roots from the database. - * The function returns a Promise that resolves to an object containing the MerkleTreeId as keys - * and their corresponding Fr values as roots. Throws an error if the tree roots are not set in the - * memory database. - * - * @returns An object containing the Merkle tree roots for each merkle tree id. - */ public getTreeRoots(): Record { const roots = this.treeRoots; if (!roots) throw new Error(`Tree roots not set in memory database`); return roots; } - /** - * Set the tree roots for the Merkle trees in the database. - * This function updates the 'treeRoots' property of the instance - * with the provided 'roots' object containing MerkleTreeId and Fr pairs. - * Note that this will overwrite any existing tree roots in the database. - * - * @param roots - A Record object mapping MerkleTreeIds to their corresponding Fr root values. - * @returns A Promise that resolves when the tree roots have been successfully updated in the database. - */ public setTreeRoots(roots: Record) { this.treeRoots = roots; return Promise.resolve(); diff --git a/yarn-project/aztec-rpc/src/kernel_oracle/index.ts b/yarn-project/aztec-rpc/src/kernel_oracle/index.ts index 778a25dd230..a52a160f029 100644 --- a/yarn-project/aztec-rpc/src/kernel_oracle/index.ts +++ b/yarn-project/aztec-rpc/src/kernel_oracle/index.ts @@ -11,52 +11,18 @@ import { ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js'; export class KernelOracle implements ProvingDataOracle { constructor(private contractDataOracle: ContractDataOracle, private node: AztecNode) {} - /** - * Retrieves the contract membership witness for a given contract address. - * A contract membership witness is a cryptographic proof that the contract exists in the Aztec network. - * This function will search for an existing contract tree associated with the contract address and obtain its - * membership witness. If no such contract tree exists, it will throw an error. - * - * @param contractAddress - The contract address. - * @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness. - * @throws Error if the contract address is unknown or not found. - */ public async getContractMembershipWitness(contractAddress: AztecAddress) { return await this.contractDataOracle.getContractMembershipWitness(contractAddress); } - /** - * Retrieve the function membership witness for the given contract address and function selector. - * The function membership witness represents a proof that the function belongs to the specified contract. - * Throws an error if the contract address or function selector is unknown. - * - * @param contractAddress - The contract address. - * @param functionSelector - The buffer containing the function selector. - * @returns A promise that resolves with the MembershipWitness instance for the specified contract's function. - */ public async getFunctionMembershipWitness(contractAddress: AztecAddress, functionSelector: Buffer) { return await this.contractDataOracle.getFunctionMembershipWitness(contractAddress, functionSelector); } - /** - * Retrieve the membership witness corresponding to a verification key. - * This function currently returns a random membership witness of the specified height, - * which is a placeholder implementation until a concrete membership witness calculation - * is implemented. - * - * @param vk - The VerificationKey for which the membership witness is needed. - * @returns A Promise that resolves to the MembershipWitness instance. - */ public async getVkMembershipWitness() { return await this.contractDataOracle.getVkMembershipWitness(); } - /** - * Get the note membership witness for a note in the private data tree at the given leaf index. - * - * @param leafIndex - The leaf index of the note in the private data tree. - * @returns the MembershipWitness for the note. - */ async getNoteMembershipWitness(leafIndex: bigint): Promise> { const path = await this.node.getDataTreePath(leafIndex); return new MembershipWitness( @@ -66,11 +32,6 @@ export class KernelOracle implements ProvingDataOracle { ); } - /** - * Get the root of the private data tree. - * - * @returns the root of the private data tree. - */ async getPrivateDataRoot(): Promise { const roots = await this.node.getTreeRoots(); return roots[MerkleTreeId.PRIVATE_DATA_TREE]; diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts index d7ae36ee982..fe6ce191bd8 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts @@ -36,9 +36,38 @@ export interface ProofOutput { * siloed commitments necessary for maintaining transaction privacy and security on the network. */ export interface ProofCreator { + /** + * Computes the siloed commitments for a given set of public inputs. + * + * @param publicInputs - The public inputs containing the contract address and new commitments to be used in generating siloed commitments. + * @returns An array of Fr (finite field) elements representing the siloed commitments. + */ getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs): Promise; + + /** + * Creates a proof output for a given signed transaction request and private call data for the first iteration. + * + * @param txRequest - The signed transaction request object. + * @param privateCallData - The private call data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofInit(txRequest: TxRequest, privateCallData: PrivateCallData): Promise; + + /** + * Creates a proof output for a given previous kernel data and private call data for an inner iteration. + * + * @param previousKernelData - The previous kernel data object. + * @param privateCallData - The private call data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofInner(previousKernelData: PreviousKernelData, privateCallData: PrivateCallData): Promise; + + /** + * Creates a proof output based on the last inner kernel iteration kernel data for the final ordering iteration. + * + * @param previousKernelData - The previous kernel data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofOrdering(previousKernelData: PreviousKernelData): Promise; } @@ -49,15 +78,9 @@ export interface ProofCreator { * based on the given public inputs and to generate proofs based on signed transaction requests, previous kernel * data, private call data, and a flag indicating whether it's the first iteration or not. */ -export class KernelProofCreator { +export class KernelProofCreator implements ProofCreator { constructor(private log = createDebugLogger('aztec:kernel_proof_creator')) {} - /** - * Computes the siloed commitments for a given set of public inputs. - * - * @param publicInputs - The public inputs containing the contract address and new commitments to be used in generating siloed commitments. - * @returns An array of Fr (finite field) elements representing the siloed commitments. - */ public async getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { const wasm = await CircuitsWasm.get(); const contractAddress = publicInputs.callContext.storageContractAddress; @@ -65,13 +88,6 @@ export class KernelProofCreator { return publicInputs.newCommitments.map(commitment => siloCommitment(wasm, contractAddress, commitment)); } - /** - * Creates a proof output for a given signed transaction request and private call data for the first iteration. - * - * @param txRequest - The signed transaction request object. - * @param privateCallData - The private call data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofInit(txRequest: TxRequest, privateCallData: PrivateCallData): Promise { const wasm = await CircuitsWasm.get(); this.log('Executing private kernel simulation init...'); @@ -87,13 +103,6 @@ export class KernelProofCreator { }; } - /** - * Creates a proof output for a given previous kernel data and private call data for an inner iteration. - * - * @param previousKernelData - The previous kernel data object. - * @param privateCallData - The private call data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofInner( previousKernelData: PreviousKernelData, privateCallData: PrivateCallData, @@ -112,12 +121,6 @@ export class KernelProofCreator { }; } - /** - * Creates a proof output based on the last inner kernel iteration kernel data for the final ordering iteration. - * - * @param previousKernelData - The previous kernel data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofOrdering(previousKernelData: PreviousKernelData): Promise { const wasm = await CircuitsWasm.get(); this.log('Executing private kernel simulation ordering...'); diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts b/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts index 9df4bdcf602..16e90f9ca1a 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts @@ -14,12 +14,55 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; * contract addresses, and function selectors in their respective merkle trees. */ export interface ProvingDataOracle { + /** + * Retrieves the contract membership witness for a given contract address. + * A contract membership witness is a cryptographic proof that the contract exists in the Aztec network. + * This function will search for an existing contract tree associated with the contract address and obtain its + * membership witness. If no such contract tree exists, it will throw an error. + * + * @param contractAddress - The contract address. + * @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness. + * @throws Error if the contract address is unknown or not found. + */ getContractMembershipWitness(contractAddress: AztecAddress): Promise>; + + /** + * Retrieve the function membership witness for the given contract address and function selector. + * The function membership witness represents a proof that the function belongs to the specified contract. + * Throws an error if the contract address or function selector is unknown. + * + * @param contractAddress - The contract address. + * @param functionSelector - The buffer containing the function selector. + * @returns A promise that resolves with the MembershipWitness instance for the specified contract's function. + */ getFunctionMembershipWitness( contractAddress: AztecAddress, functionSelector: Buffer, ): Promise>; + + /** + * Retrieve the membership witness corresponding to a verification key. + * This function currently returns a random membership witness of the specified height, + * which is a placeholder implementation until a concrete membership witness calculation + * is implemented. + * + * @param vk - The VerificationKey for which the membership witness is needed. + * @returns A Promise that resolves to the MembershipWitness instance. + */ getVkMembershipWitness(vk: VerificationKey): Promise>; + + /** + * Get the note membership witness for a note in the private data tree at the given leaf index. + * + * @param leafIndex - The leaf index of the note in the private data tree. + * @returns the MembershipWitness for the note. + */ getNoteMembershipWitness(leafIndex: bigint): Promise>; + + /** + * Get the root of the private data tree. + * + * @returns the root of the private data tree. + */ getPrivateDataRoot(): Promise; } diff --git a/yarn-project/aztec-rpc/src/simulator_oracle/index.ts b/yarn-project/aztec-rpc/src/simulator_oracle/index.ts index aafe648eceb..267ea532c16 100644 --- a/yarn-project/aztec-rpc/src/simulator_oracle/index.ts +++ b/yarn-project/aztec-rpc/src/simulator_oracle/index.ts @@ -28,25 +28,10 @@ export class SimulatorOracle implements DBOracle { private dataTreeProvider: DataCommitmentProvider, ) {} - /** - * Retrieve the secret key associated with a specific public key. - * The function only allows access to the secret keys of the transaction creator, - * and throws an error if the address does not match the public key address of the key pair. - * - * @param _contractAddress - The contract address. Ignored here. But we might want to return different keys for different contracts. - * @param pubKey - The public key of an account. - * @returns A Promise that resolves to the secret key as a Buffer. - * @throws An Error if the input address does not match the public key address of the key pair. - */ getSecretKey(_contractAddress: AztecAddress, pubKey: PublicKey): Promise { return this.keyStore.getAccountPrivateKey(pubKey); } - /** - * Retrieve the public key associated to a given address. - * @param address - Address to fetch the pubkey for. - * @returns A public key and the corresponding partial contract address, such that the hash of the two resolves to the input address. - */ async getPublicKey(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]> { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) @@ -56,15 +41,6 @@ export class SimulatorOracle implements DBOracle { return result; } - /** - * Retrieves a set of notes stored in the database for a given contract address and storage slot. - * The query result is paginated using 'limit' and 'offset' values. - * Returns an object containing an array of note data, including preimage, nonce, and index for each note. - * - * @param contractAddress - The AztecAddress instance representing the contract address. - * @param storageSlot - The Fr instance representing the storage slot of the notes. - * @returns A Promise that resolves to an array of note data. - */ async getNotes(contractAddress: AztecAddress, storageSlot: Fr) { const noteDaos = await this.db.getNoteSpendingInfo(contractAddress, storageSlot); return noteDaos.map(({ contractAddress, storageSlot, nonce, notePreimage, nullifier, index }) => ({ @@ -78,25 +54,10 @@ export class SimulatorOracle implements DBOracle { })); } - /** - * Retrieve the ABI information of a specific function within a contract. - * The function is identified by its selector, which is a unique identifier generated from the function signature. - * - * @param contractAddress - The contract address. - * @param functionSelector - The Buffer containing the function selector bytes. - * @returns A Promise that resolves to a FunctionAbi object containing the ABI information of the target function. - */ async getFunctionABI(contractAddress: AztecAddress, functionSelector: Buffer): Promise { return await this.contractDataOracle.getFunctionAbi(contractAddress, functionSelector); } - /** - * Retrieves the portal contract address associated with the given contract address. - * Throws an error if the input contract address is not found or invalid. - * - * @param contractAddress - The address of the contract whose portal address is to be fetched. - * @returns A Promise that resolves to an EthAddress instance, representing the portal contract address. - */ async getPortalContractAddress(contractAddress: AztecAddress): Promise { return await this.contractDataOracle.getPortalContractAddress(contractAddress); } diff --git a/yarn-project/aztec.js/src/account_impl/account_collection.ts b/yarn-project/aztec.js/src/account_impl/account_collection.ts index b7d606db2c5..29309d027d0 100644 --- a/yarn-project/aztec.js/src/account_impl/account_collection.ts +++ b/yarn-project/aztec.js/src/account_impl/account_collection.ts @@ -23,12 +23,6 @@ export class AccountCollection implements AccountImplementation { return AztecAddress.fromString(this.accounts.keys().next().value as string); } - /** - * Uses a registered account implementation to generate an authenticated request - * @param executions - The execution intent to be authenticated. - * @param txContext - The tx context under with the execution is to be made. - * @returns - The authenticated transaction execution request. - */ public createAuthenticatedTxRequest( executions: ExecutionRequest[], txContext: TxContext, diff --git a/yarn-project/aztec.js/src/account_impl/index.ts b/yarn-project/aztec.js/src/account_impl/index.ts index fef49cc8096..9d9858d49fb 100644 --- a/yarn-project/aztec.js/src/account_impl/index.ts +++ b/yarn-project/aztec.js/src/account_impl/index.ts @@ -7,7 +7,17 @@ export * from './account_collection.js'; /** Represents an implementation for a user account contract. Knows how to encode and sign a tx for that particular implementation. */ export interface AccountImplementation { + /** + * Returns the address for the account contract used by this implementation. + * @returns The address. + */ getAddress(): AztecAddress; - /** Creates a tx to be sent from a given account contract given a set of execution requests. */ + + /** + * Generates an authenticated request out of set of intents + * @param executions - The execution intent to be authenticated. + * @param txContext - The tx context under with the execution is to be made. + * @returns The authenticated transaction execution request. + */ createAuthenticatedTxRequest(executions: ExecutionRequest[], txContext: TxContext): Promise; } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts index 842d606d118..506fc08c57a 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts @@ -6,7 +6,15 @@ import { PrivateKey } from '../../../types/private_key.js'; * Interface to represent a signature. */ export interface Signature { + /** + * Serializes to a buffer. + * @returns A buffer. + */ toBuffer(): Buffer; + /** + * Serializes to an array of fields. + * @returns Fields. + */ toFields(): Fr[]; } @@ -14,5 +22,11 @@ export interface Signature { * Interface to represent a signer. */ export interface Signer { + /** + * Signs the given message with the given private key. + * @param message - What to sign. + * @param privateKey - The private key. + * @returns A signature. + */ constructSignature(message: Uint8Array, privateKey: PrivateKey): Signature; } diff --git a/yarn-project/foundation/src/mutex/mutex_database.ts b/yarn-project/foundation/src/mutex/mutex_database.ts index a6b3c2cbf64..a3b1d053bad 100644 --- a/yarn-project/foundation/src/mutex/mutex_database.ts +++ b/yarn-project/foundation/src/mutex/mutex_database.ts @@ -3,7 +3,10 @@ * Provides functionality for acquiring, extending, and releasing locks on resources to ensure exclusive access and prevent conflicts in concurrent applications. */ export interface MutexDatabase { + // eslint-disable-next-line jsdoc/require-jsdoc acquireLock(name: string, timeout: number): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc extendLock(name: string, timeout: number): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc releaseLock(name: string): Promise; } diff --git a/yarn-project/foundation/src/transport/interface/connector.ts b/yarn-project/foundation/src/transport/interface/connector.ts index 9d72f6574f7..af01fd19520 100644 --- a/yarn-project/foundation/src/transport/interface/connector.ts +++ b/yarn-project/foundation/src/transport/interface/connector.ts @@ -4,5 +4,6 @@ import { Socket } from './socket.js'; * Opens a socket with corresponding TransportListener. */ export interface Connector { + // eslint-disable-next-line jsdoc/require-jsdoc createSocket(): Promise; } diff --git a/yarn-project/foundation/src/transport/interface/listener.ts b/yarn-project/foundation/src/transport/interface/listener.ts index f4e31e928b8..d71b3ffb1a8 100644 --- a/yarn-project/foundation/src/transport/interface/listener.ts +++ b/yarn-project/foundation/src/transport/interface/listener.ts @@ -7,9 +7,10 @@ import { Socket } from './socket.js'; * Possible implementations could include MessageChannels or WebSockets. */ export interface Listener extends EventEmitter { + // eslint-disable-next-line jsdoc/require-jsdoc open(): void; - + // eslint-disable-next-line jsdoc/require-jsdoc close(): void; - + // eslint-disable-next-line jsdoc/require-jsdoc on(name: 'new_socket', cb: (client: Socket) => void): this; } diff --git a/yarn-project/foundation/src/transport/interface/socket.ts b/yarn-project/foundation/src/transport/interface/socket.ts index 6da7ca436ed..a862ad4eb2d 100644 --- a/yarn-project/foundation/src/transport/interface/socket.ts +++ b/yarn-project/foundation/src/transport/interface/socket.ts @@ -6,7 +6,10 @@ * If `registerHandler` callback receives `undefined` that signals the other end closed. */ export interface Socket { + // eslint-disable-next-line jsdoc/require-jsdoc send(msg: any, transfer?: Transferable[]): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc registerHandler(cb: (msg: any) => any): void; + // eslint-disable-next-line jsdoc/require-jsdoc close(): void; } diff --git a/yarn-project/foundation/src/transport/transport_client.ts b/yarn-project/foundation/src/transport/transport_client.ts index 373d0f74f87..5fc5b631da2 100644 --- a/yarn-project/foundation/src/transport/transport_client.ts +++ b/yarn-project/foundation/src/transport/transport_client.ts @@ -17,7 +17,9 @@ interface PendingRequest { * The unique message identifier used for tracking and matching request/response pairs. */ msgId: number; + // eslint-disable-next-line jsdoc/require-jsdoc resolve(data: any): void; + // eslint-disable-next-line jsdoc/require-jsdoc reject(error: Error): void; } @@ -26,8 +28,10 @@ interface PendingRequest { * Provides request/response functionality, event handling, and multiplexing support * for efficient and concurrent communication with a corresponding TransportServer. */ -export interface TransportClient extends EventEmitter { +export interface ITransportClient extends EventEmitter { + // eslint-disable-next-line jsdoc/require-jsdoc on(name: 'event_msg', handler: (payload: Payload) => void): this; + // eslint-disable-next-line jsdoc/require-jsdoc emit(name: 'event_msg', payload: Payload): boolean; } diff --git a/yarn-project/foundation/src/wasm/worker/data_store.ts b/yarn-project/foundation/src/wasm/worker/data_store.ts index 4390b2775ee..afa4b4d4758 100644 --- a/yarn-project/foundation/src/wasm/worker/data_store.ts +++ b/yarn-project/foundation/src/wasm/worker/data_store.ts @@ -2,6 +2,18 @@ * Simple read/write interface for wasm modules. */ export interface DataStore { + /** + * Get a value from our DB. + * @param key - The key to look up. + * @returns The value. + */ get(key: string): Promise; + + /** + * Set a value in our DB. + * @param key - The key to update. + * @param value - The value to set. + * @returns Nothing. + */ set(key: string, value: Buffer): Promise; } diff --git a/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts b/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts index 007e4bc643d..24bb39747bf 100644 --- a/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts +++ b/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts @@ -17,20 +17,10 @@ export class NodeDataStore implements DataStore { this.db = levelup(path ? (leveldown as any)(path) : (memdown as any)()); } - /** - * Get a value from our DB. - * @param key - The key to look up. - * @returns The value. - */ async get(key: string): Promise { return await this.db.get(key).catch(() => {}); } - /** - * Set a value in our DB. - * @param key - The key to update. - * @param value - The value to set. - */ async set(key: string, value: Buffer): Promise { await this.db.put(key, value); } diff --git a/yarn-project/key-store/src/key_pair.ts b/yarn-project/key-store/src/key_pair.ts index 59960d0753b..2a27127707f 100644 --- a/yarn-project/key-store/src/key_pair.ts +++ b/yarn-project/key-store/src/key_pair.ts @@ -35,22 +35,10 @@ export class ConstantKeyPair implements KeyPair { constructor(private publicKey: PublicKey, private privateKey: PrivateKey) {} - /** - * Retrieve the public key from the KeyPair instance. - * The returned public key is a PublicKey object which represents a point on the elliptic curve secp256k1. - * - * @returns The public key as an elliptic curve point. - */ public getPublicKey(): PublicKey { return this.publicKey; } - /** - * Retrieves the private key of the KeyPair instance. - * The function returns a Promise that resolves to a Buffer containing the private key. - * - * @returns A Promise that resolves to a Buffer containing the private key. - */ public getPrivateKey() { return Promise.resolve(this.privateKey); } diff --git a/yarn-project/key-store/src/test_key_store.ts b/yarn-project/key-store/src/test_key_store.ts index 85e93ecc4d1..cea6fc3a3b8 100644 --- a/yarn-project/key-store/src/test_key_store.ts +++ b/yarn-project/key-store/src/test_key_store.ts @@ -12,12 +12,6 @@ export class TestKeyStore implements KeyStore { private accounts: KeyPair[] = []; constructor(private curve: Grumpkin) {} - /** - * Adds an account to the key store from the provided private key. - * @param curve - The curve to use for generating the public key. - * @param privKey - The private key of the account. - * @returns - The account's public key. - */ public addAccount(privKey: PrivateKey): PublicKey { const keyPair = ConstantKeyPair.fromPrivateKey(this.curve, privKey); @@ -31,37 +25,16 @@ export class TestKeyStore implements KeyStore { return keyPair.getPublicKey(); } - /** - * Adds a new account to the TestKeyStore with a randomly generated ConstantKeyPair. - * The account will have its own private and public key pair, which can be used for signing transactions. - * @param curve - The curve to use for generating the public key. - * @returns A promise that resolves to the newly created account's AztecAddress. - */ public createAccount(): Promise { const keyPair = ConstantKeyPair.random(this.curve); this.accounts.push(keyPair); return Promise.resolve(keyPair.getPublicKey()); } - /** - * Retrieves the public keys of all accounts stored in the TestKeyStore. - * The returned addresses are instances of `PublicKey` and can be used for subsequent operations - * such as signing transactions or fetching public/private keys. - * - * @returns A Promise that resolves to an array of public keys instances. - */ public getAccounts(): Promise { return Promise.resolve(this.accounts.map(a => a.getPublicKey())); } - /** - * Retrieves the private key of the account associated with the specified AztecAddress. - * Throws an error if the provided address is not found in the list of registered accounts. - * - * @param pubKey - The AztecAddress instance representing the account for which the private key is requested. - * @returns A Promise that resolves to a Buffer containing the private key. - * @deprecated We should not require a keystore to expose private keys in plain. - */ public getAccountPrivateKey(pubKey: PublicKey): Promise { const account = this.getAccount(pubKey); return account.getPrivateKey(); diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index b4c3b19124d..376f2708d3a 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -13,45 +13,18 @@ import { Hasher } from '@aztec/types'; export class Pedersen implements Hasher { constructor(private wasm: IWasmModule) {} - /** - * Compresses two 32-byte hashes. - * @param lhs - The first hash. - * @param rhs - The second hash. - * @returns The new 32-byte hash. - */ public compress(lhs: Uint8Array, rhs: Uint8Array): Buffer { return pedersenCompress(this.wasm, lhs, rhs); } - /** - * Compresses an array of buffers. - * @param inputs - The array of buffers to compress. - * @returns The resulting 32-byte hash. - */ public compressInputs(inputs: Buffer[]): Buffer { return pedersenHashInputs(this.wasm, inputs); } - /** - * Get a 32-byte pedersen hash from a buffer. - * @param data - The data buffer. - * @returns The resulting hash buffer. - */ public hashToField(data: Uint8Array): Buffer { return pedersenGetHash(this.wasm, Buffer.from(data)); } - /** - * Given a buffer containing 32 byte pedersen leaves, return a new buffer containing the leaves and all pairs of - * nodes that define a merkle tree. - * - * E.g. - * Input: [1][2][3][4] - * Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]. - * - * @param leaves - The 32 byte pedersen leaves. - * @returns A tree represented by an array. - */ public hashToTree(leaves: Buffer[]): Promise { return Promise.resolve(pedersenGetHashTree(this.wasm, leaves)); } diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index a390a4c7024..009efca161b 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -35,12 +35,14 @@ export interface P2PSyncState { export interface P2P { /** * Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers. + * @param tx - The transaction. **/ sendTx(tx: Tx): Promise; /** * Deletes 'txs' from the pool, given hashes. * NOT used if we use sendTx as reconcileTxPool will handle this. + * @param txHashes - Hashes to check. **/ deleteTxs(txHashes: TxHash[]): Promise; @@ -52,6 +54,7 @@ export interface P2P { /** * Returns a transaction in the transaction pool by its hash. + * @param txHash - Hash of tx to return. * @returns A single tx or undefined. */ getTxByhash(txHash: TxHash): Promise; @@ -74,7 +77,7 @@ export interface P2P { */ isReady(): Promise; - /* + /** * Returns the current status of the p2p client. */ getStatus(): Promise; diff --git a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts index 26ddbd28b9a..4b878107284 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts @@ -5,8 +5,20 @@ import { createDebugLogger } from '@aztec/foundation/log'; * Reads values from L1 state that is used for the global values. */ export interface L1GlobalReader { + /** + * Fetches the last timestamp that a block was processed by the contract. + * @returns The last timestamp that a block was processed by the contract. + */ getLastTimestamp(): Promise; + /** + * Fetches the version of the rollup contract. + * @returns The version of the rollup contract. + */ getVersion(): Promise; + /** + * Gets the chain id. + * @returns The chain id. + */ getChainId(): Promise; } @@ -14,6 +26,11 @@ export interface L1GlobalReader { * Builds global variables from L1 state. */ export interface GlobalVariableBuilder { + /** + * Builds global variables. + * @param blockNumber - The block number to build global variables for. + * @returns The global variables for the given block number. + */ buildGlobalVariables(blockNumber: Fr): Promise; } diff --git a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts index d7ffbad0f40..54328f78c3a 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts @@ -39,26 +39,14 @@ export class ViemReader implements L1GlobalReader { }); } - /** - * Fetches the last timestamp that a block was processed by the contract. - * @returns The last timestamp that a block was processed by the contract. - */ public async getLastTimestamp(): Promise { return BigInt(await this.rollupContract.read.lastBlockTs()); } - /** - * Fetches the version of the rollup contract. - * @returns The version of the rollup contract. - */ public async getVersion(): Promise { return BigInt(await this.rollupContract.read.VERSION()); } - /** - * Gets the chain id. - * @returns The chain id. - */ public async getChainId(): Promise { return await Promise.resolve(BigInt(this.publicClient.chain.id)); } diff --git a/yarn-project/sequencer-client/src/prover/index.ts b/yarn-project/sequencer-client/src/prover/index.ts index 984cd01682d..02125db9dff 100644 --- a/yarn-project/sequencer-client/src/prover/index.ts +++ b/yarn-project/sequencer-client/src/prover/index.ts @@ -13,8 +13,25 @@ import { * Generates proofs for the base, merge, and root rollup circuits. */ export interface RollupProver { + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getBaseRollupProof(input: BaseRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getMergeRollupProof(input: MergeRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getRootRollupProof(input: RootRollupInputs, publicInputs: RootRollupPublicInputs): Promise; } @@ -22,6 +39,15 @@ export interface RollupProver { * Generates proofs for the public and public kernel circuits. */ export interface PublicProver { + /** + * Creates a proof for the given input. + * @param publicInputs - Public inputs obtained via simulation. + */ getPublicCircuitProof(publicInputs: PublicCircuitPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param publicInputs - Public inputs obtained via simulation. + */ getPublicKernelCircuitProof(publicInputs: PublicKernelPublicInputs): Promise; } diff --git a/yarn-project/sequencer-client/src/simulator/index.ts b/yarn-project/sequencer-client/src/simulator/index.ts index 35cff20445f..a9ede566376 100644 --- a/yarn-project/sequencer-client/src/simulator/index.ts +++ b/yarn-project/sequencer-client/src/simulator/index.ts @@ -38,13 +38,13 @@ export interface RollupSimulator { export interface PublicKernelCircuitSimulator { /** * Simulates the public kernel circuit (with a previous private kernel circuit run) from its inputs. - * @param input - Inputs to the circuit. + * @param inputs - Inputs to the circuit. * @returns The public inputs as outputs of the simulation. */ publicKernelCircuitPrivateInput(inputs: PublicKernelInputs): Promise; /** * Simulates the public kernel circuit (with no previous public kernel circuit run) from its inputs. - * @param input - Inputs to the circuit. + * @param inputs - Inputs to the circuit. * @returns The public inputs as outputs of the simulation. */ publicKernelCircuitNonFirstIteration(inputs: PublicKernelInputs): Promise; diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 0a96592344e..1949f13b9c3 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -85,12 +85,6 @@ class WorldStatePublicDB implements PublicStateDB { export class WorldStateDB implements CommitmentsDB { constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {} - /** - * Gets a confirmed L1 to L2 message for the given message key. - * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. - * @param messageKey - The message Key. - * @returns - The l1 to l2 message object - */ public async getL1ToL2Message(messageKey: Fr): Promise { // todo: #697 - make this one lookup. const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); @@ -104,12 +98,6 @@ export class WorldStateDB implements CommitmentsDB { }; } - /** - * Gets a message index and sibling path to some commitment in the private data tree. - * @param address - The contract address owning storage. - * @param commitment - The preimage of the siloed data. - * @returns - The Commitment data oracle object - */ public async getCommitmentOracle(address: AztecAddress, commitment: Fr): Promise { const siloedCommitment = siloCommitment(await CircuitsWasm.get(), address, commitment); const index = (await this.db.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, siloedCommitment.toBuffer()))!; @@ -122,10 +110,6 @@ export class WorldStateDB implements CommitmentsDB { }; } - /** - * Gets the current tree roots from the merkle db. - * @returns current tree roots. - */ public getTreeRoots(): PrivateHistoricTreeRoots { const roots = this.db.getCommitmentTreeRoots(); diff --git a/yarn-project/types/src/contract_database.ts b/yarn-project/types/src/contract_database.ts index c2928be91a7..3a8a81bb01a 100644 --- a/yarn-project/types/src/contract_database.ts +++ b/yarn-project/types/src/contract_database.ts @@ -7,6 +7,21 @@ import { ContractDao } from './contract_dao.js'; * Provides methods for adding and retrieving ContractDao objects by their associated addresses. */ export interface ContractDatabase { + /** + * Adds a new ContractDao instance to the contract database. + * The function stores the contract in an array and returns a resolved promise indicating successful addition. + * + * @param contract - The ContractDao instance to be added. + * @returns A Promise that resolves when the contract is successfully added. + */ addContract(contract: ContractDao): Promise; + + /** + * Retrieve a ContractDao instance with the specified AztecAddress. + * Returns the first match found or undefined if no contract with the given address is found. + * + * @param address - The AztecAddress to search for in the stored contracts. + * @returns A Promise resolving to the ContractDao instance matching the given address or undefined. + */ getContract(address: AztecAddress): Promise; } diff --git a/yarn-project/types/src/interfaces/aztec-node.ts b/yarn-project/types/src/interfaces/aztec-node.ts index 8f6203ce85a..f2e91687b9a 100644 --- a/yarn-project/types/src/interfaces/aztec-node.ts +++ b/yarn-project/types/src/interfaces/aztec-node.ts @@ -80,6 +80,7 @@ export interface AztecNode extends DataCommitmentProvider, L1ToL2MessageProvider /** * Method to submit a transaction to the p2p pool. * @param tx - The transaction to be submitted. + * @returns Nothing. */ sendTx(tx: Tx): Promise; diff --git a/yarn-project/types/src/interfaces/aztec_rpc.ts b/yarn-project/types/src/interfaces/aztec_rpc.ts index f3a4d235302..8e0c2d039ee 100644 --- a/yarn-project/types/src/interfaces/aztec_rpc.ts +++ b/yarn-project/types/src/interfaces/aztec_rpc.ts @@ -50,37 +50,180 @@ export type NodeInfo = { * as well as storage and view functions for smart contracts. */ export interface AztecRPC { + /** + * Registers an account backed by an account contract. + * + * @param privKey - Private key of the corresponding user master public key. + * @param address - Address of the account contract. + * @param partialContractAddress - The partially computed address of the account contract. + * @returns The address of the account contract. + */ addAccount( privKey: PrivateKey, address: AztecAddress, partialContractAddress: PartialContractAddress, ): Promise; + + /** + * Retrieves the list of Aztec addresses added to this rpc server + * The addresses are returned as a promise that resolves to an array of AztecAddress objects. + * + * @returns A promise that resolves to an array of AztecAddress instances. + */ getAccounts(): Promise; + + /** + * Retrieve the public key associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKey(address: AztecAddress): Promise; + + /** + * Add an array of deployed contracts to the database. + * Each contract should contain ABI, address, and portalContract information. + * + * @param contracts - An array of DeployedContract objects containing contract ABI, address, and portalContract. + * @returns A Promise that resolves once all the contracts have been added to the database. + */ addContracts(contracts: DeployedContract[]): Promise; + /** * Is an L2 contract deployed at this address? - * @param contractAddress - The contract data address. + * @param contract - The contract data address. * @returns Whether the contract was deployed. */ isContractDeployed(contract: AztecAddress): Promise; + + /** + * Create a transaction for a contract function call with the provided arguments. + * Throws an error if the contract or function is unknown. + * + * @param txRequest - An authenticated tx request ready for simulation + * @param optionalFromAddress - The address to simulate from + * @returns A Tx ready to send to the p2p pool for execution. + */ simulateTx(txRequest: TxExecutionRequest): Promise; + + /** + * Send a transaction. + * @param tx - The transaction. + * @returns A hash of the transaction, used to identify it. + */ sendTx(tx: Tx): Promise; + + /** + * Fetches a transaction receipt for a tx. + * @param txHash - The transaction hash. + * @returns A receipt of the transaction. + */ getTxReceipt(txHash: TxHash): Promise; + + /** + * Retrieves the preimage data at a specified contract address and storage slot. + * The returned data is an array of note preimage items, with each item containing its value. + * + * @param contract - The AztecAddress of the target contract. + * @param storageSlot - The Fr representing the storage slot to be fetched. + * @returns A promise that resolves to an array of note preimage items, each containing its value. + */ getPreimagesAt(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Retrieves the public storage data at a specified contract address and storage slot. + * The returned data is data at the storage slot or throws an error if the contract is not deployed. + * + * @param contract - The AztecAddress of the target contract. + * @param storageSlot - The Fr representing the storage slot to be fetched. + * @returns A buffer containing the public storage data at the storage slot. + */ getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Simulate the execution of a view (read-only) function on a deployed contract without actually modifying state. + * This is useful to inspect contract state, for example fetching a variable value or calling a getter function. + * The function takes function name and arguments as parameters, along with the contract address + * and optionally the sender's address. + * + * @param functionName - The name of the function to be called in the contract. + * @param args - The arguments to be provided to the function. + * @param to - The address of the contract to be called. + * @param from - (Optional) The caller of the transaction. + * @returns The result of the view function call, structured based on the function ABI. + */ viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress): Promise; + + /** + * Lookup the L2 contract data for this contract. + * Contains the ethereum portal address and bytecode. + * @param contractAddress - The contract data address. + * @returns The complete contract data including portal address & bytecode (if we didn't throw an error). + */ getContractData(contractAddress: AztecAddress): Promise; + + /** + * Lookup the L2 contract info for this contract. + * Contains the ethereum portal address . + * @param contractAddress - The contract data address. + * @returns The contract's address & portal address. + */ getContractInfo(contractAddress: AztecAddress): Promise; + + /** + * Gets L2 block unencrypted logs. + * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned. + * @param take - The number of unencrypted logs to return. + * @returns The requested unencrypted logs. + */ getUnencryptedLogs(from: number, take: number): Promise; + + /** + * Get latest L2 block number. + * @returns The latest block number. + */ getBlockNum(): Promise; + + /** + * Returns the information about the server's node + * @returns - The node information. + */ getNodeInfo(): Promise; + + /** + * Adds public key and partial address to a database. + * @param address - Address of the account to add public key and partial address for. + * @param publicKey - Public key of the corresponding user. + * @param partialAddress - The partially computed address of the account contract. + * @returns A Promise that resolves once the public key has been added to the database. + */ addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, partialAddress: PartialContractAddress, ): Promise; + + /** + * Retrieve the public key and partial contract address associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key and partial address for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]>; + + /** + * Return true if the top level block synchronisation is up to date + * This indicates that blocks and transactions are synched even if notes are not + * @returns True if there are no outstanding blocks to be synched + */ isSynchronised(): Promise; + + /** + * Returns true if the account specified by the given address is synched to the latest block + * @param account - The aztec address for which to query the sync status + * @returns True if the account is fully synched, false otherwise + */ isAccountSynchronised(account: AztecAddress): Promise; } diff --git a/yarn-project/types/src/interfaces/hasher.ts b/yarn-project/types/src/interfaces/hasher.ts index f457839d9ff..aea50dc0ae1 100644 --- a/yarn-project/types/src/interfaces/hasher.ts +++ b/yarn-project/types/src/interfaces/hasher.ts @@ -2,8 +2,38 @@ * Defines hasher interface used by Merkle trees. */ export interface Hasher { + /** + * Compresses two 32-byte hashes. + * @param lhs - The first hash. + * @param rhs - The second hash. + * @returns The new 32-byte hash. + */ compress(lhs: Uint8Array, rhs: Uint8Array): Buffer; + + /** + * Compresses an array of buffers. + * @param inputs - The array of buffers to compress. + * @returns The resulting 32-byte hash. + */ compressInputs(inputs: Buffer[]): Buffer; + + /** + * Get a 32-byte hash from a buffer. + * @param data - The data buffer. + * @returns The resulting hash buffer. + */ hashToField(data: Uint8Array): Buffer; + + /** + * Given a buffer containing 32 byte leaves, return a new buffer containing the leaves and all pairs of + * nodes that define a merkle tree. + * + * E.g. + * Input: [1][2][3][4] + * Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]. + * + * @param leaves - The 32 byte leaves. + * @returns A tree represented by an array. + */ hashToTree(leaves: Buffer[]): Promise; } diff --git a/yarn-project/types/src/keys/key_pair.ts b/yarn-project/types/src/keys/key_pair.ts index 9a59b455026..63c8994ff14 100644 --- a/yarn-project/types/src/keys/key_pair.ts +++ b/yarn-project/types/src/keys/key_pair.ts @@ -5,6 +5,16 @@ import { PrivateKey, PublicKey } from '@aztec/circuits.js'; * Provides functionality to generate, access, and sign messages using the key pair. */ export interface KeyPair { + /** + * Retrieve the public key from the KeyPair instance. + * The returned public key is a PublicKey object which represents a point on an elliptic curve. + * @returns The public key as an elliptic curve point. + */ getPublicKey(): PublicKey; + /** + * Retrieves the private key of the KeyPair instance. + * The function returns a Promise that resolves to a Buffer containing the private key. + * @returns A Promise that resolves to a Buffer containing the private key. + */ getPrivateKey(): Promise; } diff --git a/yarn-project/types/src/keys/key_store.ts b/yarn-project/types/src/keys/key_store.ts index 4826dc0f41c..f39c43b4ae8 100644 --- a/yarn-project/types/src/keys/key_store.ts +++ b/yarn-project/types/src/keys/key_store.ts @@ -5,8 +5,35 @@ import { PrivateKey, PublicKey } from '@aztec/circuits.js'; * Provides functionality to create and retrieve accounts, private and public keys, */ export interface KeyStore { + /** + * Adds a new account with a randomly generated key pair. + * The account will have its own private and public key pair, which can be used for signing transactions. + * @returns A promise that resolves to the newly created account's AztecAddress. + */ createAccount(): Promise; + + /** + * Adds an account to the key store from the provided private key. + * @param curve - The curve to use for generating the public key. + * @param privKey - The private key of the account. + * @returns - The account's public key. + */ addAccount(privKey: PrivateKey): PublicKey; + + /** + * Retrieves the public keys of all accounts stored. + * The returned addresses are instances of `PublicKey` and can be used for subsequent operations + * such as signing transactions or fetching public/private keys. + * @returns A Promise that resolves to an array of public keys instances. + */ getAccounts(): Promise; + + /** + * Retrieves the private key of the account associated with the specified AztecAddress. + * Throws an error if the provided address is not found in the list of registered accounts. + * @param pubKey - The AztecAddress instance representing the account for which the private key is requested. + * @returns A Promise that resolves to a Buffer containing the private key. + * @deprecated We should not require a keystore to expose private keys in plain. + */ getAccountPrivateKey(pubKey: PublicKey): Promise; } diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts index 79fda0599c9..a1665ec17c2 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts @@ -34,26 +34,14 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { ); } - /** - * Returns an instance of MerkleTreeOperations that will include uncommitted data. - * @returns An instance of MerkleTreeOperations that will include uncommitted data. - */ public getLatest(): MerkleTreeOperations { return new MerkleTreeOperationsFacade(this.merkleTreeDb, true); } - /** - * Returns an instance of MerkleTreeOperations that will not include uncommitted data. - * @returns An instance of MerkleTreeOperations that will not include uncommitted data. - */ public getCommitted(): MerkleTreeOperations { return new MerkleTreeOperationsFacade(this.merkleTreeDb, false); } - /** - * Starts the synchroniser. - * @returns A promise that resolves once the initial sync is completed. - */ public async start() { if (this.currentState === WorldStateRunningState.STOPPED) { throw new Error('Synchroniser already stopped'); @@ -94,9 +82,6 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { return this.syncPromise; } - /** - * Stops the synchroniser. - */ public async stop() { this.log('Stopping world state...'); this.stopping = true; @@ -105,10 +90,6 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { this.setCurrentState(WorldStateRunningState.STOPPED); } - /** - * Returns the current status of the synchroniser. - * @returns The current status of the synchroniser. - */ public status(): Promise { const status = { syncedToL2Block: this.currentL2BlockNum, diff --git a/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts index c760bfd1ce3..e7a14ee6d4e 100644 --- a/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts @@ -28,9 +28,32 @@ export interface WorldStateStatus { * Defines the interface for a world state synchroniser. */ export interface WorldStateSynchroniser { + /** + * Starts the synchroniser. + * @returns A promise that resolves once the initial sync is completed. + */ start(): void; + + /** + * Returns the current status of the synchroniser. + * @returns The current status of the synchroniser. + */ status(): Promise; + + /** + * Stops the synchroniser. + */ stop(): Promise; + + /** + * Returns an instance of MerkleTreeOperations that will include uncommitted data. + * @returns An instance of MerkleTreeOperations that will include uncommitted data. + */ getLatest(): MerkleTreeOperations; + + /** + * Returns an instance of MerkleTreeOperations that will not include uncommitted data. + * @returns An instance of MerkleTreeOperations that will not include uncommitted data. + */ getCommitted(): MerkleTreeOperations; }