From 26c2c61c6b7fe528c65027e99fe297b33ce617a4 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 16 Jun 2023 17:48:18 +0200 Subject: [PATCH 01/11] type import changes for no ts build --- src/index.ts | 20 ++++++++++++-------- src/lib/circuit_value.ts | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index b33f1d5539..0813d3da4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,19 +1,22 @@ -export { ProvablePure, Ledger } from './snarky.js'; +export type { ProvablePure } from './snarky.js'; +export { Ledger } from './snarky.js'; export { Field, Bool, Group, Scalar } from './lib/core.js'; export { Poseidon, TokenSymbol } from './lib/hash.js'; export * from './lib/signature.js'; +export type { + ProvableExtended, + FlexibleProvable, + FlexibleProvablePure, + InferProvable, +} from './lib/circuit_value.js'; export { CircuitValue, - ProvableExtended, prop, arrayProp, matrixProp, provable, provablePure, Struct, - FlexibleProvable, - FlexibleProvablePure, - InferProvable, } from './lib/circuit_value.js'; export { Provable } from './lib/provable.js'; export { Circuit, Keypair, public_, circuitMain } from './lib/circuit.js'; @@ -21,21 +24,22 @@ export { UInt32, UInt64, Int64, Sign } from './lib/int.js'; export { Types } from './bindings/mina-transaction/types.js'; export * as Mina from './lib/mina.js'; +export type { DeployArgs } from './lib/zkapp.js'; export { SmartContract, method, - DeployArgs, declareMethods, Account, VerificationKey, Reducer, } from './lib/zkapp.js'; export { state, State, declareState } from './lib/state.js'; + +export type { JsonProof } from './lib/proof_system.js'; export { Proof, SelfProof, verify, - JsonProof, Empty, Undefined, Void, @@ -49,13 +53,13 @@ export { ZkappPublicInput, } from './lib/account_update.js'; +export type { TransactionStatus } from './lib/fetch.js'; export { fetchAccount, fetchLastBlock, fetchTransactionStatus, checkZkappTransaction, fetchEvents, - TransactionStatus, addCachedAccount, setGraphqlEndpoint, setGraphqlEndpoints, diff --git a/src/lib/circuit_value.ts b/src/lib/circuit_value.ts index 0481c95d93..37ee2c8c69 100644 --- a/src/lib/circuit_value.ts +++ b/src/lib/circuit_value.ts @@ -6,6 +6,8 @@ import { provablePure, HashInput, NonMethods, +} from '../bindings/lib/provable-snarky.js'; +import type { InferJson, InferProvable, InferredProvable, From cd653bc46efb6e14ff0a23fe8e1273f7e08066d9 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 16 Jun 2023 17:49:51 +0200 Subject: [PATCH 02/11] run examples without requiring ts build --- package.json | 3 ++- src/bindings | 2 +- src/build/buildExample.js | 22 +++++++++++++++++++++- src/tests/test.ts | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/tests/test.ts diff --git a/package.json b/package.json index c6040520a8..a9afd0adc7 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,9 @@ "type-check": "tsc --noEmit", "dev": "npx tsc -p tsconfig.node.json && cp src/snarky.d.ts dist/node/snarky.d.ts", "make": "make -C ../../.. snarkyjs", + "make:no-types": "npm run clean && make -C ../../.. snarkyjs_no_types", "bindings": "cd ../../.. && ./scripts/update-snarkyjs-bindings.sh && cd src/lib/snarkyjs", - "build": "rimraf ./dist/node && npx tsc -p tsconfig.node.json && cp -r src/bindings/compiled/node_bindings dist/node/_node_bindings && node src/build/buildNode.js && cp src/snarky.d.ts dist/node/snarky.d.ts", + "build": "rimraf ./dist/node && npx tsc -p tsconfig.node.json && mkdir -p dist/node/bindings/compiled && cp -r src/bindings/compiled/node_bindings dist/node/bindings/compiled/_node_bindings && node src/build/buildNode.js && cp src/snarky.d.ts dist/node/snarky.d.ts", "build:test": "npx tsc -p tsconfig.test.json && cp src/snarky.d.ts dist/node/snarky.d.ts", "build:node": "npm run build", "build:web": "rimraf ./dist/web && node src/build/buildWeb.js", diff --git a/src/bindings b/src/bindings index 9f0acc0df1..505bf1a645 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 9f0acc0df12912d4b092cba8e3e053a36a9da066 +Subproject commit 505bf1a645ead87932784583fd4aeb3da726789e diff --git a/src/build/buildExample.js b/src/build/buildExample.js index 286cf74e1f..ef5929ba07 100644 --- a/src/build/buildExample.js +++ b/src/build/buildExample.js @@ -32,7 +32,11 @@ async function build(srcPath, isWeb = false) { logLevel: 'error', plugins: isWeb ? [typescriptPlugin(tsConfig)] - : [typescriptPlugin(tsConfig), makeNodeModulesExternal()], + : [ + typescriptPlugin(tsConfig), + makeNodeModulesExternal(), + makeJsooExternal(), + ], }); let absPath = path.resolve('.', outfile); @@ -105,6 +109,22 @@ function makeNodeModulesExternal() { }; } +function makeJsooExternal() { + let isJsoo = /(bc.cjs|plonk_wasm.cjs)$/; + return { + name: 'plugin-external', + setup(build) { + build.onResolve({ filter: isJsoo }, ({ path: filePath, resolveDir }) => { + filePath = filePath.replace('_node_bindings', 'node_bindings'); + return { + path: path.resolve(resolveDir, filePath), + external: true, + }; + }); + }, + }; +} + function findTsConfig() { let tsConfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists); if (tsConfigPath === undefined) return; diff --git a/src/tests/test.ts b/src/tests/test.ts new file mode 100644 index 0000000000..cd5dcb4445 --- /dev/null +++ b/src/tests/test.ts @@ -0,0 +1,4 @@ +import { Field } from '../index.js'; +// we can build snarkyjs and run tests without type checking +let wrongType: string = Field.random().toBigInt(); +console.log(wrongType); From 231b6cce778738aeabb67ab441a6853b9d8dad5c Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 16 Jun 2023 17:50:01 +0200 Subject: [PATCH 03/11] port inductive proofs example --- src/tests/inductive-proofs.ts | 156 ++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/tests/inductive-proofs.ts diff --git a/src/tests/inductive-proofs.ts b/src/tests/inductive-proofs.ts new file mode 100644 index 0000000000..10667aa312 --- /dev/null +++ b/src/tests/inductive-proofs.ts @@ -0,0 +1,156 @@ +import { + SelfProof, + Field, + Experimental, + isReady, + shutdown, + Proof, +} from '../index.js'; +import { tic, toc } from '../examples/zkapps/tictoc.js'; + +await isReady; + +let MaxProofsVerifiedZero = Experimental.ZkProgram({ + publicInput: Field, + + methods: { + baseCase: { + privateInputs: [], + + method(publicInput: Field) { + publicInput.assertEquals(Field(0)); + }, + }, + }, +}); + +let MaxProofsVerifiedOne = Experimental.ZkProgram({ + publicInput: Field, + + methods: { + baseCase: { + privateInputs: [], + + method(publicInput: Field) { + publicInput.assertEquals(Field(0)); + }, + }, + + mergeOne: { + privateInputs: [SelfProof], + + method(publicInput: Field, earlierProof: SelfProof) { + earlierProof.verify(); + earlierProof.publicInput.add(1).assertEquals(publicInput); + }, + }, + }, +}); + +let MaxProofsVerifiedTwo = Experimental.ZkProgram({ + publicInput: Field, + + methods: { + baseCase: { + privateInputs: [], + + method(publicInput: Field) { + publicInput.assertEquals(Field(0)); + }, + }, + + mergeOne: { + privateInputs: [SelfProof], + + method(publicInput: Field, earlierProof: SelfProof) { + earlierProof.verify(); + earlierProof.publicInput.add(1).assertEquals(publicInput); + }, + }, + + mergeTwo: { + privateInputs: [SelfProof, SelfProof], + + method( + publicInput: Field, + p1: SelfProof, + p2: SelfProof + ) { + p1.verify(); + p1.publicInput.add(1).assertEquals(p2.publicInput); + p2.verify(); + p2.publicInput.add(1).assertEquals(publicInput); + }, + }, + }, +}); +tic('compiling three programs..'); +await MaxProofsVerifiedZero.compile(); +await MaxProofsVerifiedOne.compile(); +await MaxProofsVerifiedTwo.compile(); +toc(); + +await testRecursion(MaxProofsVerifiedZero as any, 0); +await testRecursion(MaxProofsVerifiedOne as any, 1); +await testRecursion(MaxProofsVerifiedTwo, 2); + +async function testRecursion( + Program: typeof MaxProofsVerifiedTwo, + maxProofsVerified: number +) { + console.log(`testing maxProofsVerified = ${maxProofsVerified}`); + + let ProofClass = Experimental.ZkProgram.Proof(Program); + + tic('executing base case..'); + let initialProof = await Program.baseCase(Field(0)); + toc(); + initialProof = testJsonRoundtrip(ProofClass, initialProof); + initialProof.verify(); + initialProof.publicInput.assertEquals(Field(0)); + + if (initialProof.maxProofsVerified != maxProofsVerified) { + throw Error( + `Expected initialProof to have maxProofsVerified = ${maxProofsVerified} but has ${initialProof.maxProofsVerified}` + ); + } + + let p1, p2; + if (initialProof.maxProofsVerified === 0) return; + + tic('executing mergeOne..'); + p1 = await Program.mergeOne(Field(1), initialProof); + toc(); + p1 = testJsonRoundtrip(ProofClass, p1); + p1.verify(); + p1.publicInput.assertEquals(Field(1)); + if (p1.maxProofsVerified != maxProofsVerified) { + throw Error( + `Expected p1 to have maxProofsVerified = ${maxProofsVerified} but has ${p1.maxProofsVerified}` + ); + } + + if (initialProof.maxProofsVerified === 1) return; + tic('executing mergeTwo..'); + p2 = await Program.mergeTwo(Field(2), initialProof, p1); + toc(); + p2 = testJsonRoundtrip(ProofClass, p2); + p2.verify(); + p2.publicInput.assertEquals(Field(2)); + if (p2.maxProofsVerified != maxProofsVerified) { + throw Error( + `Expected p2 to have maxProofsVerified = ${maxProofsVerified} but has ${p2.maxProofsVerified}` + ); + } +} + +function testJsonRoundtrip(ProofClass: any, proof: Proof) { + let jsonProof = proof.toJSON(); + console.log( + 'json roundtrip', + JSON.stringify({ ...jsonProof, proof: jsonProof.proof.slice(0, 10) + '..' }) + ); + return ProofClass.fromJSON(jsonProof); +} + +shutdown(); From 22697290fb8832ade8bda66e2b4ae6b6dd8c91b3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 20 Jun 2023 09:53:14 +0200 Subject: [PATCH 04/11] add script to run minimal snarkyjs tests --- run-minimal-mina-tests.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 run-minimal-mina-tests.sh diff --git a/run-minimal-mina-tests.sh b/run-minimal-mina-tests.sh new file mode 100755 index 0000000000..c21d178aa4 --- /dev/null +++ b/run-minimal-mina-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +./run src/tests/inductive-proofs.ts --bundle From 6de50a154557f24d029b850fefaab22eeee75414 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 20 Jun 2023 10:01:28 +0200 Subject: [PATCH 05/11] minor --- src/tests/inductive-proofs.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/inductive-proofs.ts b/src/tests/inductive-proofs.ts index 10667aa312..61c1c9dc1d 100644 --- a/src/tests/inductive-proofs.ts +++ b/src/tests/inductive-proofs.ts @@ -84,7 +84,7 @@ let MaxProofsVerifiedTwo = Experimental.ZkProgram({ }, }, }); -tic('compiling three programs..'); +tic('compiling three programs'); await MaxProofsVerifiedZero.compile(); await MaxProofsVerifiedOne.compile(); await MaxProofsVerifiedTwo.compile(); @@ -102,7 +102,7 @@ async function testRecursion( let ProofClass = Experimental.ZkProgram.Proof(Program); - tic('executing base case..'); + tic('executing base case'); let initialProof = await Program.baseCase(Field(0)); toc(); initialProof = testJsonRoundtrip(ProofClass, initialProof); @@ -118,7 +118,7 @@ async function testRecursion( let p1, p2; if (initialProof.maxProofsVerified === 0) return; - tic('executing mergeOne..'); + tic('executing mergeOne'); p1 = await Program.mergeOne(Field(1), initialProof); toc(); p1 = testJsonRoundtrip(ProofClass, p1); @@ -131,7 +131,7 @@ async function testRecursion( } if (initialProof.maxProofsVerified === 1) return; - tic('executing mergeTwo..'); + tic('executing mergeTwo'); p2 = await Program.mergeTwo(Field(2), initialProof, p1); toc(); p2 = testJsonRoundtrip(ProofClass, p2); From 3a0c96ded1c8789f5f0e4729d9ced95cb88af78c Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 20 Jun 2023 12:58:31 +0200 Subject: [PATCH 06/11] use smaller example in test --- run-minimal-mina-tests.sh | 2 +- src/tests/inductive-proofs-small.ts | 88 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/tests/inductive-proofs-small.ts diff --git a/run-minimal-mina-tests.sh b/run-minimal-mina-tests.sh index c21d178aa4..3aae238cce 100755 --- a/run-minimal-mina-tests.sh +++ b/run-minimal-mina-tests.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -./run src/tests/inductive-proofs.ts --bundle +./run src/tests/inductive-proofs-small.ts --bundle diff --git a/src/tests/inductive-proofs-small.ts b/src/tests/inductive-proofs-small.ts new file mode 100644 index 0000000000..271a2bb6cc --- /dev/null +++ b/src/tests/inductive-proofs-small.ts @@ -0,0 +1,88 @@ +import { + SelfProof, + Field, + Experimental, + isReady, + shutdown, + Proof, +} from '../index.js'; +import { tic, toc } from '../examples/zkapps/tictoc.js'; + +await isReady; + +let MaxProofsVerifiedOne = Experimental.ZkProgram({ + publicInput: Field, + + methods: { + baseCase: { + privateInputs: [], + + method(publicInput: Field) { + publicInput.assertEquals(Field(0)); + }, + }, + + mergeOne: { + privateInputs: [SelfProof], + + method(publicInput: Field, earlierProof: SelfProof) { + earlierProof.verify(); + earlierProof.publicInput.add(1).assertEquals(publicInput); + }, + }, + }, +}); + +tic('compiling program'); +await MaxProofsVerifiedOne.compile(); +toc(); + +await testRecursion(MaxProofsVerifiedOne, 1); + +async function testRecursion( + Program: typeof MaxProofsVerifiedOne, + maxProofsVerified: number +) { + console.log(`testing maxProofsVerified = ${maxProofsVerified}`); + + let ProofClass = Experimental.ZkProgram.Proof(Program); + + tic('executing base case'); + let initialProof = await Program.baseCase(Field(0)); + toc(); + initialProof = testJsonRoundtrip(ProofClass, initialProof); + initialProof.verify(); + initialProof.publicInput.assertEquals(Field(0)); + + if (initialProof.maxProofsVerified != maxProofsVerified) { + throw Error( + `Expected initialProof to have maxProofsVerified = ${maxProofsVerified} but has ${initialProof.maxProofsVerified}` + ); + } + + let p1; + if (initialProof.maxProofsVerified === 0) return; + + tic('executing mergeOne'); + p1 = await Program.mergeOne(Field(1), initialProof); + toc(); + p1 = testJsonRoundtrip(ProofClass, p1); + p1.verify(); + p1.publicInput.assertEquals(Field(1)); + if (p1.maxProofsVerified != maxProofsVerified) { + throw Error( + `Expected p1 to have maxProofsVerified = ${maxProofsVerified} but has ${p1.maxProofsVerified}` + ); + } +} + +function testJsonRoundtrip(ProofClass: any, proof: Proof) { + let jsonProof = proof.toJSON(); + console.log( + 'json roundtrip', + JSON.stringify({ ...jsonProof, proof: jsonProof.proof.slice(0, 10) + '..' }) + ); + return ProofClass.fromJSON(jsonProof); +} + +shutdown(); From 69f46283514edd724ae43e9237d04a14b497bdfd Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 20 Jun 2023 20:55:22 +0200 Subject: [PATCH 07/11] add a script to copy files --- .gitignore | 1 + package.json | 8 ++++---- src/build/buildExample.js | 3 +-- src/build/copy-to-dist.js | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 src/build/copy-to-dist.js diff --git a/.gitignore b/.gitignore index c41b02b8b5..fcb737b159 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tests/report/ tests/test-artifacts/ profiling.md snarkyjs-reference +*.tmp.js diff --git a/package.json b/package.json index a9afd0adc7..f97f093ba5 100644 --- a/package.json +++ b/package.json @@ -44,11 +44,11 @@ }, "scripts": { "type-check": "tsc --noEmit", - "dev": "npx tsc -p tsconfig.node.json && cp src/snarky.d.ts dist/node/snarky.d.ts", + "dev": "npx tsc -p tsconfig.node.json && node src/build/copy-to-dist.js", "make": "make -C ../../.. snarkyjs", "make:no-types": "npm run clean && make -C ../../.. snarkyjs_no_types", "bindings": "cd ../../.. && ./scripts/update-snarkyjs-bindings.sh && cd src/lib/snarkyjs", - "build": "rimraf ./dist/node && npx tsc -p tsconfig.node.json && mkdir -p dist/node/bindings/compiled && cp -r src/bindings/compiled/node_bindings dist/node/bindings/compiled/_node_bindings && node src/build/buildNode.js && cp src/snarky.d.ts dist/node/snarky.d.ts", + "build": "rimraf ./src/bindings/compiled/_node_bindings && cp -r src/bindings/compiled/node_bindings src/bindings/compiled/_node_bindings && rimraf ./dist/node && npx tsc -p tsconfig.node.json && node src/build/copy-to-dist.js && node src/build/buildNode.js", "build:test": "npx tsc -p tsconfig.test.json && cp src/snarky.d.ts dist/node/snarky.d.ts", "build:node": "npm run build", "build:web": "rimraf ./dist/web && node src/build/buildWeb.js", @@ -62,8 +62,8 @@ "bootstrap": "npm run build && node src/build/extractJsooMethods.cjs && npm run build", "format": "prettier --write --ignore-unknown **/*", "test": "./run-jest-tests.sh", - "clean": "rimraf ./dist", - "clean-all": "rimraf ./dist && rimraf ./tests/report && rimraf ./tests/test-artifacts", + "clean": "rimraf ./dist && rimraf ./src/bindings/compiled/_node_bindings", + "clean-all": "npm run clean && rimraf ./tests/report && rimraf ./tests/test-artifacts", "test:integration": "./run-integration-tests.sh", "test:unit": "./run-unit-tests.sh", "test:e2e": "rimraf ./tests/report && rimraf ./tests/test-artifacts && npx playwright test", diff --git a/src/build/buildExample.js b/src/build/buildExample.js index ef5929ba07..a7f75c3038 100644 --- a/src/build/buildExample.js +++ b/src/build/buildExample.js @@ -110,12 +110,11 @@ function makeNodeModulesExternal() { } function makeJsooExternal() { - let isJsoo = /(bc.cjs|plonk_wasm.cjs)$/; + let isJsoo = /(bc.cjs|plonk_wasm.cjs|wrapper.js)$/; return { name: 'plugin-external', setup(build) { build.onResolve({ filter: isJsoo }, ({ path: filePath, resolveDir }) => { - filePath = filePath.replace('_node_bindings', 'node_bindings'); return { path: path.resolve(resolveDir, filePath), external: true, diff --git a/src/build/copy-to-dist.js b/src/build/copy-to-dist.js new file mode 100644 index 0000000000..a338d0a1e9 --- /dev/null +++ b/src/build/copy-to-dist.js @@ -0,0 +1,22 @@ +// copy some files from /src to /dist/node that tsc doesn't copy because +// we have .d.ts files for them +import fse from 'fs-extra'; + +let files = ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings']; + +await copyToDist(files); + +async function copyToDist(files) { + let promises = []; + for (let source of files) { + let target = source.replace('src/', 'dist/node/'); + promises.push( + fse.copy(source, target, { + recursive: true, + overwrite: true, + dereference: true, + }) + ); + } + await Promise.all(promises); +} From ce1fca7d09311d517d18a9152d79f4f8812cdf07 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 20 Jun 2023 21:07:01 +0200 Subject: [PATCH 08/11] simplify --- package.json | 2 +- src/build/copy-artifacts.js | 8 ++++++++ src/build/copy-to-dist.js | 28 +++++++--------------------- src/build/utils.js | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 src/build/copy-artifacts.js create mode 100644 src/build/utils.js diff --git a/package.json b/package.json index f97f093ba5..c6ada8e394 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "make": "make -C ../../.. snarkyjs", "make:no-types": "npm run clean && make -C ../../.. snarkyjs_no_types", "bindings": "cd ../../.. && ./scripts/update-snarkyjs-bindings.sh && cd src/lib/snarkyjs", - "build": "rimraf ./src/bindings/compiled/_node_bindings && cp -r src/bindings/compiled/node_bindings src/bindings/compiled/_node_bindings && rimraf ./dist/node && npx tsc -p tsconfig.node.json && node src/build/copy-to-dist.js && node src/build/buildNode.js", + "build": "node src/build/copy-artifacts.js && rimraf ./dist/node && npm run dev && node src/build/buildNode.js", "build:test": "npx tsc -p tsconfig.test.json && cp src/snarky.d.ts dist/node/snarky.d.ts", "build:node": "npm run build", "build:web": "rimraf ./dist/web && node src/build/buildWeb.js", diff --git a/src/build/copy-artifacts.js b/src/build/copy-artifacts.js new file mode 100644 index 0000000000..b5a218e8b1 --- /dev/null +++ b/src/build/copy-artifacts.js @@ -0,0 +1,8 @@ +// copy some files from /src to /dist/node that tsc doesn't copy because we have .d.ts files for them +import { copyFromTo } from './utils.js'; + +await copyFromTo( + ['src/bindings/compiled/node_bindings/'], + 'node_bindings', + '_node_bindings' +); diff --git a/src/build/copy-to-dist.js b/src/build/copy-to-dist.js index a338d0a1e9..635f761594 100644 --- a/src/build/copy-to-dist.js +++ b/src/build/copy-to-dist.js @@ -1,22 +1,8 @@ -// copy some files from /src to /dist/node that tsc doesn't copy because -// we have .d.ts files for them -import fse from 'fs-extra'; +// copy some files from /src to /dist/node that tsc doesn't copy because we have .d.ts files for them +import { copyFromTo } from './utils.js'; -let files = ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings']; - -await copyToDist(files); - -async function copyToDist(files) { - let promises = []; - for (let source of files) { - let target = source.replace('src/', 'dist/node/'); - promises.push( - fse.copy(source, target, { - recursive: true, - overwrite: true, - dereference: true, - }) - ); - } - await Promise.all(promises); -} +await copyFromTo( + ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings'], + 'src', + 'dist/node' +); diff --git a/src/build/utils.js b/src/build/utils.js new file mode 100644 index 0000000000..6eb7635fa9 --- /dev/null +++ b/src/build/utils.js @@ -0,0 +1,18 @@ +import fse from 'fs-extra'; + +export { copyFromTo }; + +async function copyFromTo(files, srcDir = undefined, targetDir = undefined) { + let promises = []; + for (let source of files) { + let target = source.replace(`${srcDir}/`, `${targetDir}/`); + promises.push( + fse.copy(source, target, { + recursive: true, + overwrite: true, + dereference: true, + }) + ); + } + await Promise.all(promises); +} From 4a8e9e925b18e6230e4aafdc5b42dab96bab245b Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 22 Jun 2023 14:55:28 +0200 Subject: [PATCH 09/11] delete pointless file --- src/tests/test.ts | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/tests/test.ts diff --git a/src/tests/test.ts b/src/tests/test.ts deleted file mode 100644 index cd5dcb4445..0000000000 --- a/src/tests/test.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Field } from '../index.js'; -// we can build snarkyjs and run tests without type checking -let wrongType: string = Field.random().toBigInt(); -console.log(wrongType); From 95a324f70fa295697d125f0e3a68eb83ebe56880 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 22 Jun 2023 15:01:37 +0200 Subject: [PATCH 10/11] clean up some build logic --- src/build/copy-artifacts.js | 3 ++- src/build/copy-to-dist.js | 4 ++-- src/build/utils.js | 18 ++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/build/copy-artifacts.js b/src/build/copy-artifacts.js index b5a218e8b1..116abfab56 100644 --- a/src/build/copy-artifacts.js +++ b/src/build/copy-artifacts.js @@ -1,4 +1,5 @@ -// copy some files from /src to /dist/node that tsc doesn't copy because we have .d.ts files for them +// copy compiled jsoo/wasm artifacts from a folder in the source tree to the folder where they are imported from +// (these are not the same folders so that we don't automatically pollute the source tree when rebuilding artifacts) import { copyFromTo } from './utils.js'; await copyFromTo( diff --git a/src/build/copy-to-dist.js b/src/build/copy-to-dist.js index 635f761594..96bc96937b 100644 --- a/src/build/copy-to-dist.js +++ b/src/build/copy-to-dist.js @@ -3,6 +3,6 @@ import { copyFromTo } from './utils.js'; await copyFromTo( ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings'], - 'src', - 'dist/node' + 'src/', + 'dist/node/' ); diff --git a/src/build/utils.js b/src/build/utils.js index 6eb7635fa9..346ba82a0d 100644 --- a/src/build/utils.js +++ b/src/build/utils.js @@ -2,17 +2,15 @@ import fse from 'fs-extra'; export { copyFromTo }; -async function copyFromTo(files, srcDir = undefined, targetDir = undefined) { - let promises = []; - for (let source of files) { - let target = source.replace(`${srcDir}/`, `${targetDir}/`); - promises.push( - fse.copy(source, target, { +function copyFromTo(files, srcDir = undefined, targetDir = undefined) { + return Promise.all( + files.map((source) => { + let target = source.replace(srcDir, targetDir); + return fse.copy(source, target, { recursive: true, overwrite: true, dereference: true, - }) - ); - } - await Promise.all(promises); + }); + }) + ); } From 6825cbdcb6794b79db3a8bf1d62b3bbf898bcb78 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 22 Jun 2023 15:41:36 +0200 Subject: [PATCH 11/11] bindings --- src/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings b/src/bindings index 505bf1a645..4a1dbc2ad0 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 505bf1a645ead87932784583fd4aeb3da726789e +Subproject commit 4a1dbc2ad00727febe39a03cf9d2213a49b014dc