From 35594ef70d89557c51687169035cb4943c6831cf Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 13 Mar 2023 14:52:41 +0000 Subject: [PATCH 01/10] test(fixtures): added TS compilation of fixtures --- yarn-project/.pnp.cjs | 43 ++++++ yarn-project/acir-simulator/package.json | 3 + .../acir-simulator/src/declarations.d.ts | 1 + .../{ => src}/fixtures/.gitignore | 0 .../fixtures/circuits}/abi/Nargo.toml | 0 .../fixtures/circuits}/abi/src/lib.nr | 0 .../fixtures/circuits}/constructor/Nargo.toml | 0 .../circuits}/constructor/src/main.nr | 0 .../acir-simulator/src/fixtures/index.test.ts | 9 ++ .../acir-simulator/src/fixtures/index.ts | 123 ++++++++++++++++++ yarn-project/yarn.lock | 26 ++++ 11 files changed, 205 insertions(+) create mode 100644 yarn-project/acir-simulator/src/declarations.d.ts rename yarn-project/acir-simulator/{ => src}/fixtures/.gitignore (100%) rename yarn-project/acir-simulator/{fixtures => src/fixtures/circuits}/abi/Nargo.toml (100%) rename yarn-project/acir-simulator/{fixtures => src/fixtures/circuits}/abi/src/lib.nr (100%) rename yarn-project/acir-simulator/{fixtures => src/fixtures/circuits}/constructor/Nargo.toml (100%) rename yarn-project/acir-simulator/{fixtures => src/fixtures/circuits}/constructor/src/main.nr (100%) create mode 100644 yarn-project/acir-simulator/src/fixtures/index.test.ts create mode 100644 yarn-project/acir-simulator/src/fixtures/index.ts diff --git a/yarn-project/.pnp.cjs b/yarn-project/.pnp.cjs index bf6c68ea2540..13e7ab97ee58 100755 --- a/yarn-project/.pnp.cjs +++ b/yarn-project/.pnp.cjs @@ -149,10 +149,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@aztec/acir-simulator", "workspace:acir-simulator"],\ ["@aztec/eslint-config", "workspace:eslint-config"],\ ["@jest/globals", "npm:29.5.0"],\ + ["@noir-lang/noir-source-resolver", "npm:1.0.0"],\ + ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ ["@rushstack/eslint-patch", "npm:1.2.0"],\ ["@types/jest", "npm:29.4.0"],\ ["@types/node", "npm:18.14.6"],\ ["jest", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:28.1.3"],\ + ["toml", "npm:3.0.0"],\ ["ts-jest", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:28.0.8"],\ ["ts-node", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:10.9.1"],\ ["tslib", "npm:2.5.0"],\ @@ -2072,6 +2075,37 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD"\ }]\ ]],\ + ["@noir-lang/noir-source-resolver", [\ + ["npm:1.0.0", {\ + "packageLocation": "./.yarn/cache/@noir-lang-noir-source-resolver-npm-1.0.0-8371ae11eb-08cb6b145b.zip/node_modules/@noir-lang/noir-source-resolver/",\ + "packageDependencies": [\ + ["@noir-lang/noir-source-resolver", "npm:1.0.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@noir-lang/noir_wasm", [\ + ["npm:0.2.0-9bec92a", {\ + "packageLocation": "./.yarn/cache/@noir-lang-noir_wasm-npm-0.2.0-9bec92a-bf50bab9b9-3fc84a13f3.zip/node_modules/@noir-lang/noir_wasm/",\ + "packageDependencies": [\ + ["@noir-lang/noir_wasm", "npm:0.2.0-9bec92a"]\ + ],\ + "linkType": "SOFT"\ + }],\ + ["virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a", {\ + "packageLocation": "./.yarn/__virtual__/@noir-lang-noir_wasm-virtual-89aedf68ea/0/cache/@noir-lang-noir_wasm-npm-0.2.0-9bec92a-bf50bab9b9-3fc84a13f3.zip/node_modules/@noir-lang/noir_wasm/",\ + "packageDependencies": [\ + ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ + ["@noir-lang/noir-source-resolver", "npm:1.0.0"],\ + ["@types/noir-lang__noir-source-resolver", null]\ + ],\ + "packagePeers": [\ + "@noir-lang/noir-source-resolver",\ + "@types/noir-lang__noir-source-resolver"\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["@npmcli/fs", [\ ["npm:2.1.2", {\ "packageLocation": "./.yarn/cache/@npmcli-fs-npm-2.1.2-08d434e77b-405074965e.zip/node_modules/@npmcli/fs/",\ @@ -6982,6 +7016,15 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD"\ }]\ ]],\ + ["toml", [\ + ["npm:3.0.0", {\ + "packageLocation": "./.yarn/cache/toml-npm-3.0.0-f993270804-5d7f1d8413.zip/node_modules/toml/",\ + "packageDependencies": [\ + ["toml", "npm:3.0.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["ts-essentials", [\ ["npm:7.0.3", {\ "packageLocation": "./.yarn/cache/ts-essentials-npm-7.0.3-dbefe5cb3b-74d75868ac.zip/node_modules/ts-essentials/",\ diff --git a/yarn-project/acir-simulator/package.json b/yarn-project/acir-simulator/package.json index 07eacfa8b1d6..bdcb26222a1b 100644 --- a/yarn-project/acir-simulator/package.json +++ b/yarn-project/acir-simulator/package.json @@ -34,10 +34,13 @@ "devDependencies": { "@aztec/eslint-config": "workspace:^", "@jest/globals": "^29.4.3", + "@noir-lang/noir-source-resolver": "^1.0.0", + "@noir-lang/noir_wasm": "0.2.0-9bec92a", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.4.0", "@types/node": "^18.7.23", "jest": "^28.1.3", + "toml": "^3.0.0", "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.9.5" diff --git a/yarn-project/acir-simulator/src/declarations.d.ts b/yarn-project/acir-simulator/src/declarations.d.ts new file mode 100644 index 000000000000..11de551bde2d --- /dev/null +++ b/yarn-project/acir-simulator/src/declarations.d.ts @@ -0,0 +1 @@ +declare module '@noir-lang/noir-source-resolver'; diff --git a/yarn-project/acir-simulator/fixtures/.gitignore b/yarn-project/acir-simulator/src/fixtures/.gitignore similarity index 100% rename from yarn-project/acir-simulator/fixtures/.gitignore rename to yarn-project/acir-simulator/src/fixtures/.gitignore diff --git a/yarn-project/acir-simulator/fixtures/abi/Nargo.toml b/yarn-project/acir-simulator/src/fixtures/circuits/abi/Nargo.toml similarity index 100% rename from yarn-project/acir-simulator/fixtures/abi/Nargo.toml rename to yarn-project/acir-simulator/src/fixtures/circuits/abi/Nargo.toml diff --git a/yarn-project/acir-simulator/fixtures/abi/src/lib.nr b/yarn-project/acir-simulator/src/fixtures/circuits/abi/src/lib.nr similarity index 100% rename from yarn-project/acir-simulator/fixtures/abi/src/lib.nr rename to yarn-project/acir-simulator/src/fixtures/circuits/abi/src/lib.nr diff --git a/yarn-project/acir-simulator/fixtures/constructor/Nargo.toml b/yarn-project/acir-simulator/src/fixtures/circuits/constructor/Nargo.toml similarity index 100% rename from yarn-project/acir-simulator/fixtures/constructor/Nargo.toml rename to yarn-project/acir-simulator/src/fixtures/circuits/constructor/Nargo.toml diff --git a/yarn-project/acir-simulator/fixtures/constructor/src/main.nr b/yarn-project/acir-simulator/src/fixtures/circuits/constructor/src/main.nr similarity index 100% rename from yarn-project/acir-simulator/fixtures/constructor/src/main.nr rename to yarn-project/acir-simulator/src/fixtures/circuits/constructor/src/main.nr diff --git a/yarn-project/acir-simulator/src/fixtures/index.test.ts b/yarn-project/acir-simulator/src/fixtures/index.test.ts new file mode 100644 index 000000000000..70ccce0a8905 --- /dev/null +++ b/yarn-project/acir-simulator/src/fixtures/index.test.ts @@ -0,0 +1,9 @@ +import { compileCircuit } from './index.js'; + +test('it should compile the constructor circuit', () => { + const { circuit, abi } = compileCircuit('constructor'); + + expect(circuit.length).toBeGreaterThan(0); + expect(abi.parameters.length).toBe(4); + expect(abi.return_type).toBe(null); +}); diff --git a/yarn-project/acir-simulator/src/fixtures/index.ts b/yarn-project/acir-simulator/src/fixtures/index.ts new file mode 100644 index 000000000000..2bcabae22704 --- /dev/null +++ b/yarn-project/acir-simulator/src/fixtures/index.ts @@ -0,0 +1,123 @@ +import { compile } from '@noir-lang/noir_wasm'; +import { dirname, join as pathJoin } from 'path'; +import { fileURLToPath } from 'url'; +import fs from 'fs'; +import Resolver from '@noir-lang/noir-source-resolver'; +import toml from 'toml'; + +const initialiseResolver = Resolver.default; + +const circuitsPath = pathJoin(dirname(fileURLToPath(import.meta.url)), 'circuits'); + +/** + * A dependency entry of Nargo.toml. + */ +interface Dependency { + /** + * Path to the dependency. + */ + path?: string; + /** + * Git repository of the dependency. + */ + git?: string; +} + +/** + * A circuit type. + */ +interface CircuitType { + /** + * The actual type. + */ + kind: any; +} + +/** + * A parameter to the circuit. + */ +interface Parameter { + /** + * The name of the parameter. + */ + name: string; + /** + * The type of the parameter. + */ + type: CircuitType; + /** + * The visibility of the parameter. + */ + visibility: 'private' | 'public'; +} + +/** + * The representation of a compiled circuit. + */ +interface CompiledCircuit { + /** + * The bytecode of the circuit. + */ + circuit: Array; + /** + * The Noir ABI of the circuit. + */ + abi: { + /** + * The circuit parameters. + */ + parameters: Array; + /** + * The witness indices for the parameters. + */ + param_witnesses: Record>; + /** + * The circuit return type. + */ + return_type: CircuitType | null; + /** + * The witness indices for the return value. + */ + return_witnesses: Array; + }; +} + +/** + * + * @param circuitPath - Path to the circuit crate. + * @returns The dependencies of the circuit as a map of name to dependency entry. + */ +function readDependencies(circuitPath: string) { + const { dependencies } = toml.parse(fs.readFileSync(pathJoin(circuitPath, 'Nargo.toml'), { encoding: 'utf8' })); + return dependencies as Record; +} + +/** + * Compiles a noir circuit fixture by name. + * @param circuitName - Name of the circuit fixture to compile. + * @returns The compiled circuit. + */ +export function compileCircuit(circuitName: string) { + const circuitPath = pathJoin(circuitsPath, circuitName); + const dependenciesMap = readDependencies(circuitPath); + + initialiseResolver((id: `${string}/lib.nr` | 'main.nr') => { + let path; + if (id === 'main.nr') { + path = pathJoin(circuitPath, 'src/main.nr'); + } else { + const [dependencyName] = id.split('/'); + const dependency = dependenciesMap[dependencyName]; + if (!dependency.path) { + throw new Error(`Don't know how to resolve dependency ${dependencyName}`); + } + path = pathJoin(circuitPath, dependency.path, 'src/lib.nr'); + } + const result = fs.readFileSync(path, { encoding: 'utf8' }); + return result; + }); + + return compile({ + optional_dependencies_set: Object.keys(dependenciesMap), // eslint-disable-line camelcase + }) as CompiledCircuit; +} diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 4021c9bb42f9..b990600d1693 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -21,10 +21,13 @@ __metadata: dependencies: "@aztec/eslint-config": "workspace:^" "@jest/globals": ^29.4.3 + "@noir-lang/noir-source-resolver": ^1.0.0 + "@noir-lang/noir_wasm": 0.2.0-9bec92a "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.4.0 "@types/node": ^18.7.23 jest: ^28.1.3 + toml: ^3.0.0 ts-jest: ^28.0.7 ts-node: ^10.9.1 tslib: ^2.4.0 @@ -1436,6 +1439,22 @@ __metadata: languageName: node linkType: hard +"@noir-lang/noir-source-resolver@npm:^1.0.0": + version: 1.0.0 + resolution: "@noir-lang/noir-source-resolver@npm:1.0.0" + checksum: 08cb6b145bccc521bb56cfe0af2a25369558b8266098b79bc432eb3cb653d3085cce8d7b5dacedf8c6f455a25128c709e5255bf54c69d0c435fb75c07d39b8db + languageName: node + linkType: hard + +"@noir-lang/noir_wasm@npm:0.2.0-9bec92a": + version: 0.2.0-9bec92a + resolution: "@noir-lang/noir_wasm@npm:0.2.0-9bec92a" + peerDependencies: + "@noir-lang/noir-source-resolver": 1.0.0 + checksum: 3fc84a13f3e43e2589fa48e039207efedee3f16a261b83af8000a57a45f77d73638547e7c6b86d7ab3a29a7542ff34a5bafd356d758bc82255f4e92b5222baee + languageName: node + linkType: hard + "@npmcli/fs@npm:^2.1.0": version: 2.1.2 resolution: "@npmcli/fs@npm:2.1.2" @@ -5700,6 +5719,13 @@ __metadata: languageName: node linkType: hard +"toml@npm:^3.0.0": + version: 3.0.0 + resolution: "toml@npm:3.0.0" + checksum: 5d7f1d8413ad7780e9bdecce8ea4c3f5130dd53b0a4f2e90b93340979a137739879d7b9ce2ce05c938b8cc828897fe9e95085197342a1377dd8850bf5125f15f + languageName: node + linkType: hard + "ts-essentials@npm:^7.0.3": version: 7.0.3 resolution: "ts-essentials@npm:7.0.3" From c0f8058245d0032f766e780bcf44d5a0f9f307e2 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 13 Mar 2023 15:49:22 +0000 Subject: [PATCH 02/10] chore(ci): added acir-simulator to circleci --- .circleci/config.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2660d81af42d..db1756b9f166 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -97,6 +97,17 @@ jobs: name: "Build and test" command: build aztec.js + acir-simulator: + machine: + image: ubuntu-2004:202010-01 + resource_class: large + steps: + - *checkout + - *setup_env + - run: + name: "Build and test" + command: build acir-simulator + end-to-end: machine: image: ubuntu-2004:202010-01 @@ -151,11 +162,13 @@ workflows: filters: *tag_filter - ethereum-js: *yarn_project - aztec-js: *yarn_project + - acir-simulator: *yarn_project - end-to-end: *yarn_project - e2e-join: requires: - ethereum-js - aztec-js + - acir-simulator - end-to-end filters: *tag_filter - e2e-deploy-contract: *e2e_test From a1dd417934d643962fb123344d1358ddfae81543 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 16 Mar 2023 10:52:12 -0400 Subject: [PATCH 03/10] feat(eslint): Force public field comments --- yarn-project/eslint-config/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yarn-project/eslint-config/index.js b/yarn-project/eslint-config/index.js index 33833650a8c4..d60ce0f4d32c 100644 --- a/yarn-project/eslint-config/index.js +++ b/yarn-project/eslint-config/index.js @@ -5,6 +5,8 @@ const contexts = [ 'PropertySignature', 'TSInterfaceDeclaration', 'InterfaceDeclaration', + 'TSPropertyDefinition[accessibility=public]', + 'PropertyDefinition[accessibility=public]', 'TSTypeAliasDeclaration', 'TypeAliasDeclaration', 'TSTypeDeclaration', From 5513004dd5f79e306e3e9e6ddfe7433de77b9770 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 17 Mar 2023 14:58:55 +0000 Subject: [PATCH 04/10] Use cci build context. Remove unneeded options from eip712. (#58) --- .circleci/config.yml | 17 +++--- .../ethereum.js/src/contract/contract.ts | 6 -- .../src/eth_typed_data/eip-712.test.ts | 16 ++---- .../ethereum.js/src/eth_typed_data/eip-712.ts | 57 ++++++------------- yarn-project/ethereum.js/tsconfig.json | 2 +- 5 files changed, 35 insertions(+), 63 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2660d81af42d..b73056eefd72 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -130,17 +130,20 @@ jobs: # Repeatable config for defining the workflow below. tag_regex: &tag_regex /v[0-9]+(\.[0-9]+)*(-[a-zA-Z-]+\.[0-9]+)?/ -tag_filter: &tag_filter - tags: - only: *tag_regex +defaults: &defaults + filters: + tags: + only: *tag_regex + context: + - build yarn_project: &yarn_project requires: - yarn-project-base - filters: *tag_filter + <<: *defaults e2e_test: &e2e_test requires: - e2e-join - filters: *tag_filter + <<: *defaults workflows: system: @@ -148,7 +151,7 @@ workflows: equal: [system, << pipeline.parameters.workflow >>] jobs: - yarn-project-base: - filters: *tag_filter + <<: *defaults - ethereum-js: *yarn_project - aztec-js: *yarn_project - end-to-end: *yarn_project @@ -157,5 +160,5 @@ workflows: - ethereum-js - aztec-js - end-to-end - filters: *tag_filter + <<: *defaults - e2e-deploy-contract: *e2e_test diff --git a/yarn-project/ethereum.js/src/contract/contract.ts b/yarn-project/ethereum.js/src/contract/contract.ts index 9040f4173101..3d9b46dd6750 100644 --- a/yarn-project/ethereum.js/src/contract/contract.ts +++ b/yarn-project/ethereum.js/src/contract/contract.ts @@ -120,12 +120,6 @@ export class Contract { return this.executorFactory([new ContractFunctionEntry(abiEntry)]); } - // public async getTransactionReceipt(txHash: TxHash) - - // public async getError(txHash: TxHash) { - // return await decodeErrorFromContractByTxHash(this.contractAbi, txHash, this.eth); - // } - // PRIVATE METHODS private executorFactory(functions: ContractFunctionEntry[]): TxFactory { diff --git a/yarn-project/ethereum.js/src/eth_typed_data/eip-712.test.ts b/yarn-project/ethereum.js/src/eth_typed_data/eip-712.test.ts index 572b8b63205f..c3d061cc4aed 100644 --- a/yarn-project/ethereum.js/src/eth_typed_data/eip-712.test.ts +++ b/yarn-project/ethereum.js/src/eth_typed_data/eip-712.test.ts @@ -29,9 +29,7 @@ describe('getDependencies', () => { expect(getDependencies(arrayTypedData, 'Person')).toStrictEqual(['Person']); expect(getDependencies(arrayTypedData, 'Mail')).toStrictEqual(['Mail', 'Person']); - expect(getDependencies(customTypedData, 'FooBarDomain', { domain: 'FooBarDomain' })).toStrictEqual([ - 'FooBarDomain', - ]); + expect(getDependencies(customTypedData, 'FooBarDomain')).toStrictEqual(['FooBarDomain']); }); it.skip('throws for invalid JSON data', () => { @@ -65,7 +63,7 @@ describe('encodeType', () => { 'TransactionApproval(address owner,Transaction transaction)Transaction(address to,uint256 amount,bytes data,uint256 nonce)', ); - expect(encodeType(customTypedData, 'FooBarDomain', { domain: 'FooBarDomain' })).toBe( + expect(encodeType(customTypedData, 'FooBarDomain')).toBe( 'FooBarDomain(string name,string version,uint256 chainId,address verifyingContract)', ); }); @@ -113,7 +111,7 @@ describe('getTypeHash', () => { 'b9d8c78acf9b987311de6c7b45bb6a9c8e1bf361fa7fd3467a2163f994c79500', ); - expect(bytesToHex(getTypeHash(customTypedData, 'FooBarDomain', { domain: 'FooBarDomain' }))).toBe( + expect(bytesToHex(getTypeHash(customTypedData, 'FooBarDomain'))).toBe( '85b412c5db9e26aa4f6bf794e72b1557f463a0978ceef9acaff7f6ff1eb24e57', ); }); @@ -149,9 +147,7 @@ describe('encodeData', () => { 'c81112a69b6596b8bc0678e67d97fbf9bed619811fc781419323ec02d1c7290dafd2599280d009dcb3e261f4bccebec901d67c3f54b56d49bf8327359fc69cd7392bb8ab5338a9075ce8fec1b431e334007d4de1e5e83201ca35762e24428e24b7c4150525d88db452c5f08f93f4593daa458ab6280b012532183aed3a8e4a01', ); - expect( - bytesToHex(encodeData(customTypedData, 'FooBarDomain', customTypedData.domain, { domain: 'FooBarDomain' })), - ).toBe( + expect(bytesToHex(encodeData(customTypedData, 'FooBarDomain', customTypedData.domain))).toBe( '85b412c5db9e26aa4f6bf794e72b1557f463a0978ceef9acaff7f6ff1eb24e57c70ef06638535b4881fafcac8287e210e3769ff1a8e91f1b95d6246e61e4d3c6c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000cccccccccccccccccccccccccccccccccccccccc', ); }); @@ -228,7 +224,7 @@ describe('getMessage', () => { expect(bytesToHex(getMessage(arrayTypedData))).toBe( '1901f2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f6757567025d2ba15d5ebb228ea677055b8b601007e60e9463f6ed7c68f918189', ); - expect(bytesToHex(getMessage(customTypedData, false, { domain: 'FooBarDomain' }))).toBe( + expect(bytesToHex(getMessage(customTypedData, false, 'FooBarDomain'))).toBe( '19016ff4505ed33bedaadf3491aa039d9ccb91a3114eeab940e69fdecb809fb268826757567025d2ba15d5ebb228ea677055b8b601007e60e9463f6ed7c68f918189', ); }); @@ -243,7 +239,7 @@ describe('getMessage', () => { expect(bytesToHex(getMessage(arrayTypedData, true))).toBe( 'c6f6c8028eadb17bc5c9e2ea2f738e92e49cfa627d19896c250fd2eac653e4e0', ); - expect(bytesToHex(getMessage(customTypedData, true, { domain: 'FooBarDomain' }))).toBe( + expect(bytesToHex(getMessage(customTypedData, true, 'FooBarDomain'))).toBe( 'e028c0622beef9bde70e78a98c1d09a95ffe0cd9cfa5ff6a99f7db7c9245e103', ); }); diff --git a/yarn-project/ethereum.js/src/eth_typed_data/eip-712.ts b/yarn-project/ethereum.js/src/eth_typed_data/eip-712.ts index af914fa78012..63f8ef1cc9da 100644 --- a/yarn-project/ethereum.js/src/eth_typed_data/eip-712.ts +++ b/yarn-project/ethereum.js/src/eth_typed_data/eip-712.ts @@ -4,18 +4,11 @@ import { abiCoder } from '../contract/index.js'; const EIP_191_PREFIX = Buffer.from('1901', 'hex'); -type Options = any; - /** * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once * in the resulting array. */ -export const getDependencies = ( - typedData: TypedData, - type: string, - options?: Options, - dependencies: string[] = [], -): string[] => { +export const getDependencies = (typedData: TypedData, type: string, dependencies: string[] = []): string[] => { const TYPE_REGEX = /^\w+/; const match = type.match(TYPE_REGEX)!; const actualType = match[0]; @@ -32,9 +25,7 @@ export const getDependencies = ( ...typedData.types[actualType].reduce( (previous, type) => [ ...previous, - ...getDependencies(typedData, type.type, options, previous).filter( - dependency => !previous.includes(dependency), - ), + ...getDependencies(typedData, type.type, previous).filter(dependency => !previous.includes(dependency)), ], [], ), @@ -49,8 +40,8 @@ export const getDependencies = ( * @param {Options} [options] * @return {string} */ -export const encodeType = (typedData: TypedData, type: string, options?: Options): string => { - const [primary, ...dependencies] = getDependencies(typedData, type, options); +export const encodeType = (typedData: TypedData, type: string): string => { + const [primary, ...dependencies] = getDependencies(typedData, type); const types = [primary, ...dependencies.sort()]; return types @@ -63,20 +54,15 @@ export const encodeType = (typedData: TypedData, type: string, options?: Options /** * Get a type string as hash. */ -export const getTypeHash = (typedData: TypedData, type: string, options?: Options) => { - return keccak256(Buffer.from(encodeType(typedData, type, options))); +export const getTypeHash = (typedData: TypedData, type: string) => { + return keccak256(Buffer.from(encodeType(typedData, type))); }; /** * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of * an array of ABI compatible types, and an array of corresponding values. */ -const encodeValue = ( - typedData: TypedData, - type: string, - data: unknown, - options?: Options, -): [string, Buffer | string] => { +const encodeValue = (typedData: TypedData, type: string, data: unknown): [string, Buffer | string] => { // Checks for array types const ARRAY_REGEX = /^(.*)\[([0-9]*?)]$/; const match = type.match(ARRAY_REGEX); @@ -92,7 +78,7 @@ const encodeValue = ( throw new Error(`Cannot encode data: expected length of ${length}, but got ${data.length}`); } - const encodedData = data.map(item => encodeValue(typedData, arrayType, item, options)); + const encodedData = data.map(item => encodeValue(typedData, arrayType, item)); const types = encodedData.map(item => item[0]); const values = encodedData.map(item => item[1]); @@ -100,7 +86,7 @@ const encodeValue = ( } if (typedData.types[type]) { - return ['bytes32', getStructHash(typedData, type, data as Record, options)]; + return ['bytes32', getStructHash(typedData, type, data as Record)]; } // Strings and arbitrary byte arrays are hashed to bytes32 @@ -119,12 +105,7 @@ const encodeValue = ( * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All * dependant types are automatically encoded. */ -export const encodeData = ( - typedData: TypedData, - type: string, - data: Record, - options?: Options, -): Buffer => { +export const encodeData = (typedData: TypedData, type: string, data: Record): Buffer => { const [types, values] = typedData.types[type].reduce<[string[], unknown[]]>( ([types, values], field) => { if (data[field.name] === undefined || data[field.name] === null) { @@ -132,14 +113,14 @@ export const encodeData = ( } const value = data[field.name]; - const [type, encodedValue] = encodeValue(typedData, field.type, value, options); + const [type, encodedValue] = encodeValue(typedData, field.type, value); return [ [...types, type], [...values, encodedValue], ]; }, - [['bytes32'], [getTypeHash(typedData, type, options)]], + [['bytes32'], [getTypeHash(typedData, type)]], ); return abiCoder.encodeParameters(types, values); @@ -149,20 +130,19 @@ export const encodeData = ( * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant * types are automatically encoded. */ -export const getStructHash = (typedData: TypedData, type: string, data: Record, options?: Options) => { - return keccak256(encodeData(typedData, type, data, options)); +export const getStructHash = (typedData: TypedData, type: string, data: Record) => { + return keccak256(encodeData(typedData, type, data)); }; /** * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed * with Keccak256. */ -export const getMessage = (typedData: TypedData, hash?: boolean, options?: Options) => { - const { domain } = options || { domain: 'EIP712Domain', verifyDomain: true }; +export const getMessage = (typedData: TypedData, hash?: boolean, domain = 'EIP712Domain') => { const message = Buffer.concat([ EIP_191_PREFIX, - getStructHash(typedData, domain, typedData.domain as Record, options), - getStructHash(typedData, typedData.primaryType, typedData.message, options), + getStructHash(typedData, domain, typedData.domain as Record), + getStructHash(typedData, typedData.primaryType, typedData.message), ]); if (hash) { @@ -179,7 +159,6 @@ export const asArray = ( typedData: TypedData, type: string = typedData.primaryType, data: Record = typedData.message, - options?: Options, ): unknown[] => { if (!typedData.types[type]) { throw new Error('Cannot get data as array: type does not exist'); @@ -191,7 +170,7 @@ export const asArray = ( throw new Error(`Cannot get data as array: missing data for '${name}'`); } - return [...array, asArray(typedData, type, data[name] as Record, options)]; + return [...array, asArray(typedData, type, data[name] as Record)]; } const value = data[name]; diff --git a/yarn-project/ethereum.js/tsconfig.json b/yarn-project/ethereum.js/tsconfig.json index 7df38b51bfd2..33a248f3824c 100644 --- a/yarn-project/ethereum.js/tsconfig.json +++ b/yarn-project/ethereum.js/tsconfig.json @@ -6,5 +6,5 @@ "rootDir": "src", "tsBuildInfoFile": ".tsbuildinfo" }, - "include": ["src"] + "include": ["src", "src/eth_typed_data/fixtures/*.json"] } From fe4768a3900f083f8dfdb447fd28201f6d3e1f28 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Sat, 18 Mar 2023 08:45:33 +0000 Subject: [PATCH 05/10] Remove redundant packages. --- .circleci/config.yml | 5 --- README.md | 2 - bootstrap.sh | 2 - build_manifest.json | 14 ------ build_manifest.sh | 2 - yarn-project/barretenberg.js/.eslintrc.cjs | 6 --- yarn-project/barretenberg.js/Dockerfile | 12 ----- yarn-project/barretenberg.js/README.md | 1 - yarn-project/barretenberg.js/package.json | 45 ------------------- yarn-project/barretenberg.js/src/index.ts | 4 -- .../barretenberg.js/tsconfig.dest.json | 4 -- yarn-project/barretenberg.js/tsconfig.json | 9 ---- yarn-project/circuit.js/.eslintrc.cjs | 6 --- yarn-project/circuit.js/Dockerfile | 12 ----- yarn-project/circuit.js/README.md | 1 - yarn-project/circuit.js/package.json | 45 ------------------- yarn-project/circuit.js/src/index.ts | 4 -- yarn-project/circuit.js/tsconfig.dest.json | 4 -- yarn-project/circuit.js/tsconfig.json | 9 ---- yarn-project/package.json | 2 - yarn-project/typedoc.json | 2 - yarn-project/yarn-project-base/Dockerfile | 2 - yarn-project/yarn.lock | 34 -------------- 23 files changed, 227 deletions(-) delete mode 100644 yarn-project/barretenberg.js/.eslintrc.cjs delete mode 100644 yarn-project/barretenberg.js/Dockerfile delete mode 100644 yarn-project/barretenberg.js/README.md delete mode 100644 yarn-project/barretenberg.js/package.json delete mode 100644 yarn-project/barretenberg.js/src/index.ts delete mode 100644 yarn-project/barretenberg.js/tsconfig.dest.json delete mode 100644 yarn-project/barretenberg.js/tsconfig.json delete mode 100644 yarn-project/circuit.js/.eslintrc.cjs delete mode 100644 yarn-project/circuit.js/Dockerfile delete mode 100644 yarn-project/circuit.js/README.md delete mode 100644 yarn-project/circuit.js/package.json delete mode 100644 yarn-project/circuit.js/src/index.ts delete mode 100644 yarn-project/circuit.js/tsconfig.dest.json delete mode 100644 yarn-project/circuit.js/tsconfig.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 2660d81af42d..2ee75b33f112 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,11 +19,6 @@ parameters: workflow: type: string default: "system" - target: - type: enum - default: "dev" - description: The environment to trigger redeploys to - enum: ["dev", "stage", "testnet"] # This build step checks out the code from the repository. It has a hardcoded readonly key to allow the checkout. # Initially it just fetches the repo metadata for the current commit hash to a depth of 50 commits. diff --git a/README.md b/README.md index 780509fdc567..4b17b0aa5981 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ The Aztec 3 system consists of the following sub projects. - `archiver` - `aztec-cli` - `aztec.js` -- `barretenberg.js` -- `circuit.js` - `ethereum.js` - `kernel-simulator` - `key-store` diff --git a/bootstrap.sh b/bootstrap.sh index e210bada8813..e127219de253 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -46,8 +46,6 @@ PROJECTS=( # "yarn-project/acir-simulator:yarn build" # "yarn-project/aztec-cli:yarn build" "yarn-project/aztec.js:yarn build" - # "yarn-project/barretenberg.js:yarn build" - # "yarn-project/circuit.js:yarn build" "yarn-project/archiver:yarn build" # "yarn-project/ethereum.js:yarn build" # "yarn-project/kernel-simulator:yarn build" diff --git a/build_manifest.json b/build_manifest.json index 4027e470ba92..2ede9a8eceef 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -66,20 +66,6 @@ "rebuildPatterns": ["^yarn-project/aztec.js/"], "dependencies": ["yarn-project-base"] }, - "barretenberg.js": { - "buildDir": "yarn-project", - "projectDir": "yarn-project/barretenberg.js", - "dockerfile": "barretenberg.js/Dockerfile", - "rebuildPatterns": ["^yarn-project/barretenberg.js/"], - "dependencies": ["yarn-project-base"] - }, - "circuit.js": { - "buildDir": "yarn-project", - "projectDir": "yarn-project/circuit.js", - "dockerfile": "circuit.js/Dockerfile", - "rebuildPatterns": ["^yarn-project/circuit.js/"], - "dependencies": ["yarn-project-base"] - }, "end-to-end": { "buildDir": "yarn-project", "projectDir": "yarn-project/end-to-end", diff --git a/build_manifest.sh b/build_manifest.sh index c562657fb00a..a376b9a2a47e 100755 --- a/build_manifest.sh +++ b/build_manifest.sh @@ -15,8 +15,6 @@ PROJECTS=( # archiver:yarn-project # aztec-cli:yarn-project # aztec.js:yarn-project - # barretenberg.js:yarn-project - # circuit.js:yarn-project # end-to-end:yarn-project # ethereum.js:yarn-project # kernel-simulator:yarn-project diff --git a/yarn-project/barretenberg.js/.eslintrc.cjs b/yarn-project/barretenberg.js/.eslintrc.cjs deleted file mode 100644 index 9cf806b1500f..000000000000 --- a/yarn-project/barretenberg.js/.eslintrc.cjs +++ /dev/null @@ -1,6 +0,0 @@ -require('@rushstack/eslint-patch/modern-module-resolution'); - -module.exports = { - extends: ['@aztec/eslint-config'], - parserOptions: { tsconfigRootDir: __dirname }, -}; diff --git a/yarn-project/barretenberg.js/Dockerfile b/yarn-project/barretenberg.js/Dockerfile deleted file mode 100644 index 3cf5bdf942ab..000000000000 --- a/yarn-project/barretenberg.js/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder - -COPY barretenberg.js barretenberg.js -WORKDIR /usr/src/yarn-project/barretenberg.js -RUN yarn build && yarn formatting && yarn test - -# Prune dev dependencies. See comment in base image. -RUN yarn cache clean -RUN yarn workspaces focus --production > /dev/null - -FROM alpine:latest -COPY --from=builder /usr/src/yarn-project/barretenberg.js /usr/src/yarn-project/barretenberg.js \ No newline at end of file diff --git a/yarn-project/barretenberg.js/README.md b/yarn-project/barretenberg.js/README.md deleted file mode 100644 index d8576f560677..000000000000 --- a/yarn-project/barretenberg.js/README.md +++ /dev/null @@ -1 +0,0 @@ -# Barretenberg.js diff --git a/yarn-project/barretenberg.js/package.json b/yarn-project/barretenberg.js/package.json deleted file mode 100644 index 30e1fede8370..000000000000 --- a/yarn-project/barretenberg.js/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "@aztec/barretenberg.js", - "version": "0.0.0", - "type": "module", - "exports": "./dest/index.js", - "typedoc": { - "entryPoint": "./src/index.ts", - "displayName": "Barretenberg.js", - "tsconfig": "./tsconfig.dest.json" - }, - "scripts": { - "build": "yarn clean && yarn formatting && tsc -b tsconfig.dest.json", - "build:dev": "tsc -b tsconfig.dest.json --watch", - "clean": "rm -rf ./dest .tsbuildinfo", - "formatting": "run -T prettier --check ./src && run -T eslint --max-warnings 0 ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests" - }, - "jest": { - "preset": "ts-jest/presets/default-esm", - "globals": { - "ts-jest": { - "useESM": true - } - }, - "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" - }, - "testRegex": "./src/.*\\.test\\.ts$", - "rootDir": "./src" - }, - "dependencies": { - "tslib": "^2.4.0" - }, - "devDependencies": { - "@aztec/eslint-config": "workspace:^", - "@jest/globals": "^29.4.3", - "@rushstack/eslint-patch": "^1.1.4", - "@types/jest": "^29.4.0", - "@types/node": "^18.7.23", - "jest": "^28.1.3", - "ts-jest": "^28.0.7", - "ts-node": "^10.9.1", - "typescript": "^4.9.5" - } -} diff --git a/yarn-project/barretenberg.js/src/index.ts b/yarn-project/barretenberg.js/src/index.ts deleted file mode 100644 index 5a3071801bc0..000000000000 --- a/yarn-project/barretenberg.js/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * A placeholder for the Barretenberg Wasm. - */ -export class BarretenbergWasm {} diff --git a/yarn-project/barretenberg.js/tsconfig.dest.json b/yarn-project/barretenberg.js/tsconfig.dest.json deleted file mode 100644 index 965aaa1c433e..000000000000 --- a/yarn-project/barretenberg.js/tsconfig.dest.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ".", - "exclude": ["**/*.test.*", "**/fixtures/*"] -} diff --git a/yarn-project/barretenberg.js/tsconfig.json b/yarn-project/barretenberg.js/tsconfig.json deleted file mode 100644 index f67ddec9fd6b..000000000000 --- a/yarn-project/barretenberg.js/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "..", - "compilerOptions": { - "outDir": "dest", - "rootDir": "src", - "tsBuildInfoFile": ".tsbuildinfo" - }, - "include": ["src"] -} diff --git a/yarn-project/circuit.js/.eslintrc.cjs b/yarn-project/circuit.js/.eslintrc.cjs deleted file mode 100644 index 9cf806b1500f..000000000000 --- a/yarn-project/circuit.js/.eslintrc.cjs +++ /dev/null @@ -1,6 +0,0 @@ -require('@rushstack/eslint-patch/modern-module-resolution'); - -module.exports = { - extends: ['@aztec/eslint-config'], - parserOptions: { tsconfigRootDir: __dirname }, -}; diff --git a/yarn-project/circuit.js/Dockerfile b/yarn-project/circuit.js/Dockerfile deleted file mode 100644 index 8d9608bd9af0..000000000000 --- a/yarn-project/circuit.js/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder - -COPY circuit.js circuit.js -WORKDIR /usr/src/yarn-project/circuit.js -RUN yarn build && yarn formatting && yarn test - -# Prune dev dependencies. See comment in base image. -RUN yarn cache clean -RUN yarn workspaces focus --production > /dev/null - -FROM alpine:latest -COPY --from=builder /usr/src/yarn-project/circuit.js /usr/src/yarn-project/circuit.js \ No newline at end of file diff --git a/yarn-project/circuit.js/README.md b/yarn-project/circuit.js/README.md deleted file mode 100644 index 47d37e83d0f3..000000000000 --- a/yarn-project/circuit.js/README.md +++ /dev/null @@ -1 +0,0 @@ -# Circuit.js diff --git a/yarn-project/circuit.js/package.json b/yarn-project/circuit.js/package.json deleted file mode 100644 index 8f5eddcc3cc5..000000000000 --- a/yarn-project/circuit.js/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "@aztec/circuit.js", - "version": "0.0.0", - "type": "module", - "exports": "./dest/index.js", - "typedoc": { - "entryPoint": "./src/index.ts", - "displayName": "Circuit.js", - "tsconfig": "./tsconfig.dest.json" - }, - "scripts": { - "build": "yarn clean && yarn formatting && tsc -b tsconfig.dest.json", - "build:dev": "tsc -b tsconfig.dest.json --watch", - "clean": "rm -rf ./dest .tsbuildinfo", - "formatting": "run -T prettier --check ./src && run -T eslint --max-warnings 0 ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests" - }, - "jest": { - "preset": "ts-jest/presets/default-esm", - "globals": { - "ts-jest": { - "useESM": true - } - }, - "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" - }, - "testRegex": "./src/.*\\.test\\.ts$", - "rootDir": "./src" - }, - "dependencies": { - "tslib": "^2.4.0" - }, - "devDependencies": { - "@aztec/eslint-config": "workspace:^", - "@jest/globals": "^29.4.3", - "@rushstack/eslint-patch": "^1.1.4", - "@types/jest": "^29.4.0", - "@types/node": "^18.7.23", - "jest": "^28.1.3", - "ts-jest": "^28.0.7", - "ts-node": "^10.9.1", - "typescript": "^4.9.5" - } -} diff --git a/yarn-project/circuit.js/src/index.ts b/yarn-project/circuit.js/src/index.ts deleted file mode 100644 index c6a087e63bf4..000000000000 --- a/yarn-project/circuit.js/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * A placeholder for the Circuit Wasm. - */ -export class CircuitWasm {} diff --git a/yarn-project/circuit.js/tsconfig.dest.json b/yarn-project/circuit.js/tsconfig.dest.json deleted file mode 100644 index 965aaa1c433e..000000000000 --- a/yarn-project/circuit.js/tsconfig.dest.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ".", - "exclude": ["**/*.test.*", "**/fixtures/*"] -} diff --git a/yarn-project/circuit.js/tsconfig.json b/yarn-project/circuit.js/tsconfig.json deleted file mode 100644 index f67ddec9fd6b..000000000000 --- a/yarn-project/circuit.js/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "..", - "compilerOptions": { - "outDir": "dest", - "rootDir": "src", - "tsBuildInfoFile": ".tsbuildinfo" - }, - "include": ["src"] -} diff --git a/yarn-project/package.json b/yarn-project/package.json index 1d740434c1f1..a7227ce1661c 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -11,8 +11,6 @@ "archiver", "aztec-cli", "aztec.js", - "barretenberg.js", - "circuit.js", "docs", "end-to-end", "eslint-config", diff --git a/yarn-project/typedoc.json b/yarn-project/typedoc.json index c659782bda14..f47cf8e806c1 100644 --- a/yarn-project/typedoc.json +++ b/yarn-project/typedoc.json @@ -6,8 +6,6 @@ "archiver", "aztec-cli", "aztec.js", - "barretenberg.js", - "circuit.js", "ethereum.js", "kernel-simulator", "key-store", diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 9749868649fd..a923fb77eed6 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -15,8 +15,6 @@ COPY acir-simulator/package.json acir-simulator/package.json COPY archiver/package.json archiver/package.json COPY aztec-cli/package.json aztec-cli/package.json COPY aztec.js/package.json aztec.js/package.json -COPY barretenberg.js/package.json barretenberg.js/package.json -COPY circuit.js/package.json circuit.js/package.json COPY docs/package.json docs/package.json COPY end-to-end/package.json end-to-end/package.json COPY ethereum.js/example/package.json ethereum.js/example/package.json diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index c5ee1791c805..21612e72af48 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -103,40 +103,6 @@ __metadata: languageName: unknown linkType: soft -"@aztec/barretenberg.js@workspace:barretenberg.js": - version: 0.0.0-use.local - resolution: "@aztec/barretenberg.js@workspace:barretenberg.js" - dependencies: - "@aztec/eslint-config": "workspace:^" - "@jest/globals": ^29.4.3 - "@rushstack/eslint-patch": ^1.1.4 - "@types/jest": ^29.4.0 - "@types/node": ^18.7.23 - jest: ^28.1.3 - ts-jest: ^28.0.7 - ts-node: ^10.9.1 - tslib: ^2.4.0 - typescript: ^4.9.5 - languageName: unknown - linkType: soft - -"@aztec/circuit.js@workspace:circuit.js": - version: 0.0.0-use.local - resolution: "@aztec/circuit.js@workspace:circuit.js" - dependencies: - "@aztec/eslint-config": "workspace:^" - "@jest/globals": ^29.4.3 - "@rushstack/eslint-patch": ^1.1.4 - "@types/jest": ^29.4.0 - "@types/node": ^18.7.23 - jest: ^28.1.3 - ts-jest: ^28.0.7 - ts-node: ^10.9.1 - tslib: ^2.4.0 - typescript: ^4.9.5 - languageName: unknown - linkType: soft - "@aztec/docs@workspace:docs": version: 0.0.0-use.local resolution: "@aztec/docs@workspace:docs" From 3c510ef7483cb2856dfd7cc5e605a668ce41977a Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Mon, 20 Mar 2023 17:09:31 +0000 Subject: [PATCH 06/10] Update e2e test. --- .../src/e2e_deploy_contract.test.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index 1586d67858aa..33d951b92cd7 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -1,7 +1,31 @@ -import { Aztec } from '@aztec/aztec.js'; +import { AztecAddress, AztecRPCClient, ContractDeployer } from '@aztec/aztec.js'; +import { createAztecNode } from '@aztec/aztec-node'; +import { createAztecRPCServer } from '@aztec/aztec-rpc'; +import { abi } from './fixtures/test_contract.json'; describe('e2e_deploy_contract', () => { - it('should deploy a contract', () => { - expect(() => new Aztec()).not.toThrow(); + let arc: AztecRPCClient; + let accounts: AztecAddress[]; + + beforeAll(async () => { + const node = await createAztecNode(); + arc = await createAztecRPCServer({ node }); + await arc.addAccount(); + accounts = await arc.getAccounts(); + }); + + it('should deploy a contract', async () => { + const deployer = new ContractDeployer(abi, arc); + const receipt = await deployer.deploy().send().getReceipt(); + expect(receipt).toEqual( + expect.objectContaining({ + from: accounts[0], + status: 1, + }), + ); + + const { contractAddress } = receipt; + const bytecode = await arc.getCode(contractAddress); + expect(bytecode).toEqual(abi.bytecode); }); }); From 3bb4cf6c0e7c17b0a809853ae229aa47e0dc1676 Mon Sep 17 00:00:00 2001 From: ludamad Date: Mon, 20 Mar 2023 15:05:57 -0400 Subject: [PATCH 07/10] feat(eslint-config): new rule --- yarn-project/eslint-config/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn-project/eslint-config/index.js b/yarn-project/eslint-config/index.js index d60ce0f4d32c..54550e5de21f 100644 --- a/yarn-project/eslint-config/index.js +++ b/yarn-project/eslint-config/index.js @@ -1,6 +1,7 @@ const contexts = [ 'TSMethodDefinition', 'MethodDefinition', + 'TSParameterProperty[accessibility=public]', 'TSPropertySignature', 'PropertySignature', 'TSInterfaceDeclaration', From 50d70c85bd3f6a2aa7dc8f2b2fe229f346951d71 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 21 Mar 2023 14:05:44 +0000 Subject: [PATCH 08/10] chore: updated resolver version --- yarn-project/.pnp.cjs | 10 +++++----- yarn-project/acir-simulator/package.json | 2 +- yarn-project/acir-simulator/src/fixtures/index.ts | 4 +--- yarn-project/yarn.lock | 10 +++++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/yarn-project/.pnp.cjs b/yarn-project/.pnp.cjs index 13e7ab97ee58..0f7255adb29f 100755 --- a/yarn-project/.pnp.cjs +++ b/yarn-project/.pnp.cjs @@ -149,7 +149,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@aztec/acir-simulator", "workspace:acir-simulator"],\ ["@aztec/eslint-config", "workspace:eslint-config"],\ ["@jest/globals", "npm:29.5.0"],\ - ["@noir-lang/noir-source-resolver", "npm:1.0.0"],\ + ["@noir-lang/noir-source-resolver", "npm:1.1.0"],\ ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ ["@rushstack/eslint-patch", "npm:1.2.0"],\ ["@types/jest", "npm:29.4.0"],\ @@ -2076,10 +2076,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { }]\ ]],\ ["@noir-lang/noir-source-resolver", [\ - ["npm:1.0.0", {\ - "packageLocation": "./.yarn/cache/@noir-lang-noir-source-resolver-npm-1.0.0-8371ae11eb-08cb6b145b.zip/node_modules/@noir-lang/noir-source-resolver/",\ + ["npm:1.1.0", {\ + "packageLocation": "./.yarn/cache/@noir-lang-noir-source-resolver-npm-1.1.0-3b7f89ee66-c3077f6740.zip/node_modules/@noir-lang/noir-source-resolver/",\ "packageDependencies": [\ - ["@noir-lang/noir-source-resolver", "npm:1.0.0"]\ + ["@noir-lang/noir-source-resolver", "npm:1.1.0"]\ ],\ "linkType": "HARD"\ }]\ @@ -2096,7 +2096,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "packageLocation": "./.yarn/__virtual__/@noir-lang-noir_wasm-virtual-89aedf68ea/0/cache/@noir-lang-noir_wasm-npm-0.2.0-9bec92a-bf50bab9b9-3fc84a13f3.zip/node_modules/@noir-lang/noir_wasm/",\ "packageDependencies": [\ ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ - ["@noir-lang/noir-source-resolver", "npm:1.0.0"],\ + ["@noir-lang/noir-source-resolver", "npm:1.1.0"],\ ["@types/noir-lang__noir-source-resolver", null]\ ],\ "packagePeers": [\ diff --git a/yarn-project/acir-simulator/package.json b/yarn-project/acir-simulator/package.json index bdcb26222a1b..54cd71f70f6c 100644 --- a/yarn-project/acir-simulator/package.json +++ b/yarn-project/acir-simulator/package.json @@ -34,7 +34,7 @@ "devDependencies": { "@aztec/eslint-config": "workspace:^", "@jest/globals": "^29.4.3", - "@noir-lang/noir-source-resolver": "^1.0.0", + "@noir-lang/noir-source-resolver": "^1.1.0", "@noir-lang/noir_wasm": "0.2.0-9bec92a", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.4.0", diff --git a/yarn-project/acir-simulator/src/fixtures/index.ts b/yarn-project/acir-simulator/src/fixtures/index.ts index 2bcabae22704..5c0157863937 100644 --- a/yarn-project/acir-simulator/src/fixtures/index.ts +++ b/yarn-project/acir-simulator/src/fixtures/index.ts @@ -2,11 +2,9 @@ import { compile } from '@noir-lang/noir_wasm'; import { dirname, join as pathJoin } from 'path'; import { fileURLToPath } from 'url'; import fs from 'fs'; -import Resolver from '@noir-lang/noir-source-resolver'; +import { initialiseResolver } from '@noir-lang/noir-source-resolver'; import toml from 'toml'; -const initialiseResolver = Resolver.default; - const circuitsPath = pathJoin(dirname(fileURLToPath(import.meta.url)), 'circuits'); /** diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index b990600d1693..e573083eb1be 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -21,7 +21,7 @@ __metadata: dependencies: "@aztec/eslint-config": "workspace:^" "@jest/globals": ^29.4.3 - "@noir-lang/noir-source-resolver": ^1.0.0 + "@noir-lang/noir-source-resolver": ^1.1.0 "@noir-lang/noir_wasm": 0.2.0-9bec92a "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.4.0 @@ -1439,10 +1439,10 @@ __metadata: languageName: node linkType: hard -"@noir-lang/noir-source-resolver@npm:^1.0.0": - version: 1.0.0 - resolution: "@noir-lang/noir-source-resolver@npm:1.0.0" - checksum: 08cb6b145bccc521bb56cfe0af2a25369558b8266098b79bc432eb3cb653d3085cce8d7b5dacedf8c6f455a25128c709e5255bf54c69d0c435fb75c07d39b8db +"@noir-lang/noir-source-resolver@npm:^1.1.0": + version: 1.1.0 + resolution: "@noir-lang/noir-source-resolver@npm:1.1.0" + checksum: c3077f6740e613fd7866715ba01053f9711cff47c1196a780ff7b2683a5e500d08791ac304515ccbe906d32cdabf658df6fc825c775bb7d181abbf16e87cee92 languageName: node linkType: hard From 9a3faba793bf2ae68c13a3ea33f7b622acbd3ac9 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 21 Mar 2023 14:17:13 +0000 Subject: [PATCH 09/10] chore: also update noir_wasm --- yarn-project/.pnp.cjs | 14 +++++++------- yarn-project/acir-simulator/package.json | 2 +- yarn-project/yarn.lock | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/yarn-project/.pnp.cjs b/yarn-project/.pnp.cjs index 0f7255adb29f..ccc261bae80a 100755 --- a/yarn-project/.pnp.cjs +++ b/yarn-project/.pnp.cjs @@ -150,7 +150,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@aztec/eslint-config", "workspace:eslint-config"],\ ["@jest/globals", "npm:29.5.0"],\ ["@noir-lang/noir-source-resolver", "npm:1.1.0"],\ - ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ + ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.3.2-29b1f7df"],\ ["@rushstack/eslint-patch", "npm:1.2.0"],\ ["@types/jest", "npm:29.4.0"],\ ["@types/node", "npm:18.14.6"],\ @@ -2085,17 +2085,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { }]\ ]],\ ["@noir-lang/noir_wasm", [\ - ["npm:0.2.0-9bec92a", {\ - "packageLocation": "./.yarn/cache/@noir-lang-noir_wasm-npm-0.2.0-9bec92a-bf50bab9b9-3fc84a13f3.zip/node_modules/@noir-lang/noir_wasm/",\ + ["npm:0.3.2-29b1f7df", {\ + "packageLocation": "./.yarn/cache/@noir-lang-noir_wasm-npm-0.3.2-29b1f7df-8d8f235340-f5e61eb256.zip/node_modules/@noir-lang/noir_wasm/",\ "packageDependencies": [\ - ["@noir-lang/noir_wasm", "npm:0.2.0-9bec92a"]\ + ["@noir-lang/noir_wasm", "npm:0.3.2-29b1f7df"]\ ],\ "linkType": "SOFT"\ }],\ - ["virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a", {\ - "packageLocation": "./.yarn/__virtual__/@noir-lang-noir_wasm-virtual-89aedf68ea/0/cache/@noir-lang-noir_wasm-npm-0.2.0-9bec92a-bf50bab9b9-3fc84a13f3.zip/node_modules/@noir-lang/noir_wasm/",\ + ["virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.3.2-29b1f7df", {\ + "packageLocation": "./.yarn/__virtual__/@noir-lang-noir_wasm-virtual-257da628ef/0/cache/@noir-lang-noir_wasm-npm-0.3.2-29b1f7df-8d8f235340-f5e61eb256.zip/node_modules/@noir-lang/noir_wasm/",\ "packageDependencies": [\ - ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.2.0-9bec92a"],\ + ["@noir-lang/noir_wasm", "virtual:97973ff51783dc29efdf1c1cff3bd542763fb1d8ea565946db4f6425a5a443923944d5f46e5672160073e5b792b61ec2b3a0e9df4f007033f07c728780e0e4e7#npm:0.3.2-29b1f7df"],\ ["@noir-lang/noir-source-resolver", "npm:1.1.0"],\ ["@types/noir-lang__noir-source-resolver", null]\ ],\ diff --git a/yarn-project/acir-simulator/package.json b/yarn-project/acir-simulator/package.json index 54cd71f70f6c..957a7cf19968 100644 --- a/yarn-project/acir-simulator/package.json +++ b/yarn-project/acir-simulator/package.json @@ -35,7 +35,7 @@ "@aztec/eslint-config": "workspace:^", "@jest/globals": "^29.4.3", "@noir-lang/noir-source-resolver": "^1.1.0", - "@noir-lang/noir_wasm": "0.2.0-9bec92a", + "@noir-lang/noir_wasm": "0.3.2-29b1f7df", "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.4.0", "@types/node": "^18.7.23", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index e573083eb1be..66c2b057dd45 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -22,7 +22,7 @@ __metadata: "@aztec/eslint-config": "workspace:^" "@jest/globals": ^29.4.3 "@noir-lang/noir-source-resolver": ^1.1.0 - "@noir-lang/noir_wasm": 0.2.0-9bec92a + "@noir-lang/noir_wasm": 0.3.2-29b1f7df "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.4.0 "@types/node": ^18.7.23 @@ -1446,12 +1446,12 @@ __metadata: languageName: node linkType: hard -"@noir-lang/noir_wasm@npm:0.2.0-9bec92a": - version: 0.2.0-9bec92a - resolution: "@noir-lang/noir_wasm@npm:0.2.0-9bec92a" +"@noir-lang/noir_wasm@npm:0.3.2-29b1f7df": + version: 0.3.2-29b1f7df + resolution: "@noir-lang/noir_wasm@npm:0.3.2-29b1f7df" peerDependencies: - "@noir-lang/noir-source-resolver": 1.0.0 - checksum: 3fc84a13f3e43e2589fa48e039207efedee3f16a261b83af8000a57a45f77d73638547e7c6b86d7ab3a29a7542ff34a5bafd356d758bc82255f4e92b5222baee + "@noir-lang/noir-source-resolver": 1.1.0 + checksum: f5e61eb256783dca9d35345e77e9137d5fb2a6e3ecc8122b4a10ef0a6871e9e4b3842944f5b9fdbf82fef02bd6c1b27af28a6ed204728718ca89b9b394a09b32 languageName: node linkType: hard From 8214be8f50d01457478c45e9d4444c3e92da1f5c Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Wed, 22 Mar 2023 13:33:36 +0000 Subject: [PATCH 10/10] Update imports --- .../archiver/src/l2_block/l2_block.ts | 17 +------ yarn-project/archiver/src/running_promise.ts | 42 --------------- .../ethereum.js/src/eth_rpc/sent_tx.ts | 2 +- yarn-project/ethereum.js/src/eth_sign/sign.ts | 2 +- .../src/eth_transaction/sign_transaction.ts | 2 +- .../src/provider/json_rpc_provider.ts | 4 +- yarn-project/merkle-tree/src/bigint_buffer.ts | 51 ------------------- yarn-project/merkle-tree/src/indexed_tree.ts | 2 +- yarn-project/merkle-tree/src/serialise.ts | 29 ----------- yarn-project/merkle-tree/src/sibling_path.ts | 2 +- yarn-project/merkle-tree/src/standard_tree.ts | 2 +- yarn-project/p2p/src/memory_p2p_client.ts | 3 +- 12 files changed, 12 insertions(+), 146 deletions(-) delete mode 100644 yarn-project/archiver/src/running_promise.ts delete mode 100644 yarn-project/merkle-tree/src/bigint_buffer.ts delete mode 100644 yarn-project/merkle-tree/src/serialise.ts diff --git a/yarn-project/archiver/src/l2_block/l2_block.ts b/yarn-project/archiver/src/l2_block/l2_block.ts index fa1ff5492497..b91afe573305 100644 --- a/yarn-project/archiver/src/l2_block/l2_block.ts +++ b/yarn-project/archiver/src/l2_block/l2_block.ts @@ -1,3 +1,5 @@ +import { numToUInt32BE } from '@aztec/foundation'; + /** * A snapshot of an append only tree. */ @@ -236,21 +238,6 @@ export function bufferToAppendOnlyTreeSnapshot(buffer: Buffer): AppendOnlyTreeSn }; } -/** - * FUNCTIONS THAT SHOULD NOT BE HERE. - */ - -/** - * For serializing numbers to 32 byte big-endian form. - * @param n - The number to serialize. - * @param bufferSize - The size of the buffer to serialize to, defaults to 4. - */ -export function numToUInt32BE(n: number, bufferSize = 4): Buffer { - const buf = Buffer.alloc(bufferSize); - buf.writeUInt32BE(n, bufferSize - 4); - return buf; -} - /** * UNUSED TYPED THAT COULD BE USEFUL. */ diff --git a/yarn-project/archiver/src/running_promise.ts b/yarn-project/archiver/src/running_promise.ts deleted file mode 100644 index ea8b594ce732..000000000000 --- a/yarn-project/archiver/src/running_promise.ts +++ /dev/null @@ -1,42 +0,0 @@ -export class RunningPromise { - private running = false; - private runningPromise = Promise.resolve(); - private interruptPromise = Promise.resolve(); - private interruptResolve = () => {}; - constructor(private fn: () => Promise, private pollingInterval = 10000) {} - - /** - * Starts the running promise - */ - public start() { - this.running = true; - this.interruptPromise = new Promise(resolve => (this.interruptResolve = resolve)); - - const poll = async () => { - while (this.running) { - await this.fn(); - await this.interruptableSleep(this.pollingInterval); - } - }; - this.runningPromise = poll(); - } - - async stop(): Promise { - this.running = false; - this.interruptResolve(); - await this.runningPromise; - } - - private async interruptableSleep(timeInMs: number) { - let timeout!: NodeJS.Timeout; - const sleepPromise = new Promise(resolve => { - timeout = setTimeout(resolve, timeInMs); - }); - await Promise.race([sleepPromise, this.interruptPromise]); - clearTimeout(timeout); - } - - public isRunning() { - return this.running; - } -} diff --git a/yarn-project/ethereum.js/src/eth_rpc/sent_tx.ts b/yarn-project/ethereum.js/src/eth_rpc/sent_tx.ts index 91ed4a2ca661..ae336e6098fc 100644 --- a/yarn-project/ethereum.js/src/eth_rpc/sent_tx.ts +++ b/yarn-project/ethereum.js/src/eth_rpc/sent_tx.ts @@ -1,4 +1,4 @@ -import { retryUntil } from '../retry/index.js'; +import { retryUntil } from '@aztec/foundation'; import { EthereumRpc } from './ethereum_rpc.js'; import { TxHash } from './tx_hash.js'; import { TransactionReceipt } from './types/index.js'; diff --git a/yarn-project/ethereum.js/src/eth_sign/sign.ts b/yarn-project/ethereum.js/src/eth_sign/sign.ts index cf3d53b39c4c..60956de61b09 100644 --- a/yarn-project/ethereum.js/src/eth_sign/sign.ts +++ b/yarn-project/ethereum.js/src/eth_sign/sign.ts @@ -1,5 +1,5 @@ +import { numToUInt8 } from '@aztec/foundation'; import { EthAddress } from '../eth_address/index.js'; -import { numToUInt8 } from '../serialize/index.js'; import { keccak256 } from '../crypto/index.js'; import elliptic from 'elliptic'; import { hexToBuffer } from '../hex_string/index.js'; diff --git a/yarn-project/ethereum.js/src/eth_transaction/sign_transaction.ts b/yarn-project/ethereum.js/src/eth_transaction/sign_transaction.ts index 3e54608deb6d..a00c5eaa9b61 100644 --- a/yarn-project/ethereum.js/src/eth_transaction/sign_transaction.ts +++ b/yarn-project/ethereum.js/src/eth_transaction/sign_transaction.ts @@ -1,8 +1,8 @@ +import { numToUInt8 } from '@aztec/foundation'; import { decode, encode } from 'rlp'; import { EthTransaction } from './eth_transaction.js'; import { sign, EthSignature, recoverFromSignature } from '../eth_sign/index.js'; import { keccak256 } from '../crypto/index.js'; -import { numToUInt8 } from '../serialize/index.js'; export interface SignedEthTransaction { signature: EthSignature; diff --git a/yarn-project/ethereum.js/src/provider/json_rpc_provider.ts b/yarn-project/ethereum.js/src/provider/json_rpc_provider.ts index 2152357dd968..f3c314c0649e 100644 --- a/yarn-project/ethereum.js/src/provider/json_rpc_provider.ts +++ b/yarn-project/ethereum.js/src/provider/json_rpc_provider.ts @@ -1,6 +1,6 @@ +import { retry } from '@aztec/foundation'; +import { createDebugLogger } from '@aztec/foundation'; import { EthereumProvider, RequestArguments } from './ethereum_provider.js'; -import { retry } from '../retry/index.js'; -import { createDebugLogger } from '../log/index.js'; const log = createDebugLogger('json_rpc_provider'); diff --git a/yarn-project/merkle-tree/src/bigint_buffer.ts b/yarn-project/merkle-tree/src/bigint_buffer.ts deleted file mode 100644 index b04faaaf8644..000000000000 --- a/yarn-project/merkle-tree/src/bigint_buffer.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Convert a little-endian buffer into a BigInt. - * @param buf The little-endian buffer to convert - * @returns A BigInt with the little-endian representation of buf. - */ -export function toBigIntLE(buf: Buffer): bigint { - const reversed = Buffer.from(buf); - reversed.reverse(); - const hex = reversed.toString('hex'); - if (hex.length === 0) { - return BigInt(0); - } - return BigInt(`0x${hex}`); -} - -/** - * Convert a big-endian buffer into a BigInt - * @param buf The big-endian buffer to convert. - * @returns A BigInt with the big-endian representation of buf. - */ -export function toBigIntBE(buf: Buffer): bigint { - const hex = buf.toString('hex'); - if (hex.length === 0) { - return BigInt(0); - } - return BigInt(`0x${hex}`); -} - -/** - * Convert a BigInt to a little-endian buffer. - * @param num The BigInt to convert. - * @param width The number of bytes that the resulting buffer should be. - * @returns A little-endian buffer representation of num. - */ -export function toBufferLE(num: bigint, width: number): Buffer { - const hex = num.toString(16); - const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex'); - buffer.reverse(); - return buffer; -} - -/** - * Convert a BigInt to a big-endian buffer. - * @param num The BigInt to convert. - * @param width The number of bytes that the resulting buffer should be. - * @returns A big-endian buffer representation of num. - */ -export function toBufferBE(num: bigint, width: number): Buffer { - const hex = num.toString(16); - return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex'); -} diff --git a/yarn-project/merkle-tree/src/indexed_tree.ts b/yarn-project/merkle-tree/src/indexed_tree.ts index ca1199426676..c54a2ba82490 100644 --- a/yarn-project/merkle-tree/src/indexed_tree.ts +++ b/yarn-project/merkle-tree/src/indexed_tree.ts @@ -1,5 +1,5 @@ +import { toBigIntBE, toBufferBE } from '@aztec/foundation'; import { LevelUp } from 'levelup'; -import { toBigIntBE, toBufferBE } from './bigint_buffer.js'; import { MerkleTree } from './merkle_tree.js'; import { SiblingPath } from './sibling_path.js'; import { StandardMerkleTree } from './standard_tree.js'; diff --git a/yarn-project/merkle-tree/src/serialise.ts b/yarn-project/merkle-tree/src/serialise.ts deleted file mode 100644 index 2025d82ee80b..000000000000 --- a/yarn-project/merkle-tree/src/serialise.ts +++ /dev/null @@ -1,29 +0,0 @@ -// For serializing an array of fixed length elements. -export function serializeBufferArrayToVector(arr: Buffer[]) { - const lengthBuf = Buffer.alloc(4); - lengthBuf.writeUInt32BE(arr.length, 0); - return Buffer.concat([lengthBuf, ...arr]); -} - -export function deserializeBufferFromVector(vector: Buffer, offset = 0) { - const length = vector.readUInt32BE(offset); - const adv = 4 + length; - return { elem: vector.slice(offset + 4, offset + adv), adv }; -} - -export function deserializeArrayFromVector( - deserialize: (buf: Buffer, offset: number) => { elem: T; adv: number }, - vector: Buffer, - offset = 0, -) { - let pos = offset; - const size = vector.readUInt32BE(pos); - pos += 4; - const arr = new Array(size); - for (let i = 0; i < size; ++i) { - const { elem, adv } = deserialize(vector, pos); - pos += adv; - arr[i] = elem; - } - return { elem: arr, adv: pos - offset }; -} diff --git a/yarn-project/merkle-tree/src/sibling_path.ts b/yarn-project/merkle-tree/src/sibling_path.ts index ebedb51f1220..b683092fc794 100644 --- a/yarn-project/merkle-tree/src/sibling_path.ts +++ b/yarn-project/merkle-tree/src/sibling_path.ts @@ -1,5 +1,5 @@ +import { deserializeArrayFromVector, serializeBufferArrayToVector } from '@aztec/foundation'; import { Pedersen } from './pedersen.js'; -import { deserializeArrayFromVector, serializeBufferArrayToVector } from './serialise.js'; export class SiblingPath { public static ZERO(size: number, zeroElement: Buffer, pedersen: Pedersen) { diff --git a/yarn-project/merkle-tree/src/standard_tree.ts b/yarn-project/merkle-tree/src/standard_tree.ts index 714a4ba1eadb..531e6a3a7146 100644 --- a/yarn-project/merkle-tree/src/standard_tree.ts +++ b/yarn-project/merkle-tree/src/standard_tree.ts @@ -1,8 +1,8 @@ +import { toBufferLE, toBigIntLE } from '@aztec/foundation'; import { LevelUp, LevelUpChain } from 'levelup'; import { SiblingPath } from './sibling_path.js'; import { Hasher } from './hasher.js'; import { MerkleTree } from './merkle_tree.js'; -import { toBufferLE, toBigIntLE } from './bigint_buffer.js'; const MAX_DEPTH = 32; diff --git a/yarn-project/p2p/src/memory_p2p_client.ts b/yarn-project/p2p/src/memory_p2p_client.ts index 010b5a66bdff..20c9440f8477 100644 --- a/yarn-project/p2p/src/memory_p2p_client.ts +++ b/yarn-project/p2p/src/memory_p2p_client.ts @@ -1,4 +1,5 @@ -import { InterruptableSleep, L2BlockDownloader } from '@aztec/world-state'; +import { InterruptableSleep } from '@aztec/foundation'; +import { L2BlockDownloader } from '@aztec/world-state'; import { L2BlockSource, L2Block } from '@aztec/archiver'; import { InMemoryTxPool } from './tx_pool/memory_tx_pool.js';