Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocking SnarkyJS CI tests #997

Merged
merged 10 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tests/report/
tests/test-artifacts/
profiling.md
snarkyjs-reference
*.tmp.js
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +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 && 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": "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",
Expand All @@ -61,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",
Expand Down
4 changes: 4 additions & 0 deletions run-minimal-mina-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

./run src/tests/inductive-proofs-small.ts --bundle
2 changes: 1 addition & 1 deletion src/bindings
21 changes: 20 additions & 1 deletion src/build/buildExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ async function build(srcPath) {
target: 'esnext',
resolveExtensions: ['.node.js', '.ts', '.js'],
logLevel: 'error',
plugins: [typescriptPlugin(tsConfig), makeNodeModulesExternal()],
plugins: [
typescriptPlugin(tsConfig),
makeNodeModulesExternal(),
makeJsooExternal(),
],
});

let absPath = path.resolve('.', outfile);
Expand Down Expand Up @@ -103,6 +107,21 @@ function makeNodeModulesExternal() {
};
}

function makeJsooExternal() {
let isJsoo = /(bc.cjs|plonk_wasm.cjs|wrapper.js)$/;
return {
name: 'plugin-external',
setup(build) {
build.onResolve({ filter: isJsoo }, ({ path: filePath, resolveDir }) => {
return {
path: path.resolve(resolveDir, filePath),
external: true,
};
});
},
};
}

function findTsConfig() {
let tsConfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
if (tsConfigPath === undefined) return;
Expand Down
9 changes: 9 additions & 0 deletions src/build/copy-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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(
['src/bindings/compiled/node_bindings/'],
'node_bindings',
'_node_bindings'
);
8 changes: 8 additions & 0 deletions src/build/copy-to-dist.js
Original file line number Diff line number Diff line change
@@ -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/snarky.d.ts', 'src/bindings/compiled/_node_bindings'],
'src/',
'dist/node/'
);
16 changes: 16 additions & 0 deletions src/build/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fse from 'fs-extra';

export { copyFromTo };

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,
});
})
);
}
20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
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';
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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/circuit_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
provablePure,
HashInput,
NonMethods,
} from '../bindings/lib/provable-snarky.js';
import type {
InferJson,
InferProvable,
InferredProvable,
Expand Down
88 changes: 88 additions & 0 deletions src/tests/inductive-proofs-small.ts
Original file line number Diff line number Diff line change
@@ -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<Field, undefined>) {
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should this be explicit? I think we want to have to change things if the backend changes, right?

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<Field, void>) {
let jsonProof = proof.toJSON();
console.log(
'json roundtrip',
JSON.stringify({ ...jsonProof, proof: jsonProof.proof.slice(0, 10) + '..' })
);
return ProofClass.fromJSON(jsonProof);
}

shutdown();
Loading
Loading