Skip to content

Commit acf106c

Browse files
committed
Merge branch 'main' into shigoto/performance-regression-framework
2 parents 7969724 + 6124589 commit acf106c

File tree

9 files changed

+155
-78
lines changed

9 files changed

+155
-78
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
ref: ${{ inputs.target_ref || github.ref }}
6161
proof_systems_commit: ${{ inputs.proof_systems_commit }}
6262

63-
Lint-Format-and-TypoCheck:
63+
Lint-and-Format:
6464
strategy:
6565
matrix:
6666
node: [20]
@@ -108,16 +108,6 @@ jobs:
108108
- name: Run Markdown Format Check
109109
run: npm run format:md:check
110110

111-
- name: Run codespell
112-
if: steps.get_changed_files.outputs.files_changed == 'true' && github.event.pull_request.labels.*.name != 'no-typo-check'
113-
uses: codespell-project/actions-codespell@master
114-
with:
115-
check_filenames: true
116-
path: ${{ steps.get_changed_files.outputs.files }}
117-
skip: "*.json,./node_modules,./dist,./.husky,./.git,./src/mina/**/*,./src/bindings/compiled/**/*"
118-
check_hidden: false
119-
ignore_words_list: "tHi,modul,optin,deriver,PRing,toWords,iSelf"
120-
121111
Upload-bindings:
122112
name: upload bindings artifact
123113
if: ${{ inputs.proof_systems_commit == '' }}

.github/workflows/pull_requests.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
file_pattern: "npmDepsHash"
4242

4343

44-
Lint-Format-and-TypoCheck:
44+
Lint-and-Format:
4545
if: github.event.pull_request.labels.*.name != 'skip-lint'
4646
runs-on: ubuntu-latest
4747

@@ -77,14 +77,4 @@ jobs:
7777
run: xargs npm run lint:strict < changed_files.txt
7878

7979
- name: Run Markdown Format Check
80-
run: npm run format:md:check
81-
82-
- name: Run codespell
83-
if: github.event.pull_request.labels.*.name != 'no-typo-check'
84-
uses: codespell-project/actions-codespell@v2
85-
with:
86-
check_filenames: true
87-
path: ${{ steps.changed_files.outputs.files }}
88-
skip: "*.json,./node_modules,./dist,./.husky,./.git,./src/mina/**/*,./src/bindings/compiled/**/*"
89-
check_hidden: false
90-
ignore_words_list: "tHi,modul,optin,deriver,PRing,toWords,iSelf"
80+
run: npm run format:md:check

.prettierrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ module.exports = {
1313
},
1414
},
1515
],
16+
plugins: [require.resolve('prettier-plugin-organize-imports')],
1617
};

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-hvRlb/ZgfEnSW+OJG4UibamdL5UzygQQthMpUqh2W0w=
1+
sha256-ww0EdkEWiciR6XLTu2/lfqtDMbvIDBLj+gyPH+lpLTE=

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"oxlint": "^1.0.0",
109109
"pkg-pr-new": "^0.0.9",
110110
"prettier": "^3.6.2",
111+
"prettier-plugin-organize-imports": "^4.3.0",
111112
"replace-in-file": "^6.3.5",
112113
"rimraf": "^3.0.2",
113114
"ts-jest": "^28.0.8",
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Bytes, Field, Hash, Poseidon, UInt8, ZkProgram, verify } from 'o1js';
2+
3+
const SmallProgram = ZkProgram({
4+
name: 'small-program',
5+
publicOutput: Field,
6+
7+
methods: {
8+
poseidonHash: {
9+
privateInputs: [Field],
10+
async method(preimage: Field) {
11+
const digest = Poseidon.hash([preimage]);
12+
13+
return { publicOutput: digest };
14+
},
15+
},
16+
},
17+
});
18+
19+
class PoseidonProof extends SmallProgram.Proof {}
20+
class Bytes32 extends Bytes(32) {}
21+
22+
const BigProgram = ZkProgram({
23+
name: 'big-program',
24+
publicOutput: Bytes32,
25+
26+
methods: {
27+
combinedHash: {
28+
privateInputs: [PoseidonProof],
29+
async method(poseidonProof: PoseidonProof) {
30+
poseidonProof.verify();
31+
32+
const poseidonOutput = poseidonProof.publicOutput;
33+
const outputBits = poseidonOutput.toBits();
34+
35+
const byteChunks = Array.from({ length: 32 }, (_, i) => outputBits.slice(i * 8, i * 8 + 8));
36+
const outputBytes = byteChunks.map((byteChunks) => UInt8.fromBits(byteChunks));
37+
38+
const hash1 = Hash.SHA2_256.hash(outputBytes);
39+
const hash2 = Hash.BLAKE2B.hash(hash1);
40+
const hash3 = Hash.SHA3_512.hash(Bytes.from([...hash1.bytes, ...hash2.bytes]));
41+
const hash4 = Hash.Keccak256.hash(hash3);
42+
43+
return { publicOutput: hash4 };
44+
},
45+
},
46+
},
47+
});
48+
49+
const csSmall = await SmallProgram.analyzeMethods();
50+
console.log('small program rows: ', csSmall.poseidonHash.rows);
51+
52+
const csBig = await BigProgram.analyzeMethods();
53+
console.log('big program rows: ', csBig.combinedHash.rows, '\n');
54+
55+
console.time('compile small');
56+
await SmallProgram.compile();
57+
console.timeEnd('compile small');
58+
59+
console.time('compile big');
60+
const { verificationKey: verificationKeyBig } = await BigProgram.compile();
61+
console.timeEnd('compile big');
62+
63+
console.time('prove small');
64+
const proofSmall = await SmallProgram.poseidonHash(Field.random());
65+
console.timeEnd('prove small');
66+
67+
console.time('prove big');
68+
const { proof: proofBig } = await BigProgram.combinedHash(proofSmall.proof);
69+
console.timeEnd('prove big');
70+
71+
console.time('verify big');
72+
await verify(proofBig, verificationKeyBig);
73+
console.timeEnd('verify big');
74+
75+
console.log('Final Digest: ', proofBig.publicOutput.toHex());

src/lib/proof-system/zkprogram.ts

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
1-
import { EmptyUndefined, EmptyVoid } from '../../bindings/lib/generic.js';
21
import {
32
Base64ProofString,
43
Base64VerificationKeyString,
4+
Gate,
5+
Pickles,
56
Snarky,
67
initializeBindings,
78
withThreadPool,
89
} from '../../bindings.js';
9-
import { Pickles, Gate } from '../../bindings.js';
10-
import { Field } from '../provable/wrapped.js';
11-
import { FlexibleProvable, InferProvable, ProvablePureExtended } from '../provable/types/struct.js';
12-
import { InferProvableType } from '../provable/types/provable-derivers.js';
13-
import { Provable } from '../provable/provable.js';
14-
import { assert, prettifyStacktracePromise } from '../util/errors.js';
10+
import { setSrsCache, unsetSrsCache } from '../../bindings/crypto/bindings/srs.js';
11+
import { prefixes } from '../../bindings/crypto/constants.js';
12+
import { prefixToField } from '../../bindings/lib/binable.js';
13+
import { EmptyUndefined, EmptyVoid } from '../../bindings/lib/generic.js';
14+
import { From, InferValue } from '../../bindings/lib/provable-generic.js';
15+
import { MlArray, MlBool, MlPair, MlResult } from '../ml/base.js';
16+
import { MlFieldArray, MlFieldConstArray } from '../ml/fields.js';
17+
import { FieldConst, FieldVar } from '../provable/core/fieldvar.js';
1518
import { ConstraintSystemSummary, snarkContext } from '../provable/core/provable-context.js';
1619
import { hashConstant } from '../provable/crypto/poseidon.js';
17-
import { MlArray, MlBool, MlResult, MlPair } from '../ml/base.js';
18-
import { MlFieldArray, MlFieldConstArray } from '../ml/fields.js';
19-
import { FieldVar, FieldConst } from '../provable/core/fieldvar.js';
20-
import { Cache, readCache, writeCache } from './cache.js';
21-
import { decodeProverKey, encodeProverKey, parseHeader } from './prover-keys.js';
22-
import { setSrsCache, unsetSrsCache } from '../../bindings/crypto/bindings/srs.js';
20+
import { Provable } from '../provable/provable.js';
21+
import { InferProvableType } from '../provable/types/provable-derivers.js';
2322
import { ProvableType, ToProvable } from '../provable/types/provable-intf.js';
24-
import { prefixToField } from '../../bindings/lib/binable.js';
25-
import { prefixes } from '../../bindings/crypto/constants.js';
26-
import { Subclass, Tuple, Get } from '../util/types.js';
23+
import { FlexibleProvable, InferProvable, ProvablePureExtended } from '../provable/types/struct.js';
24+
import { emptyWitness } from '../provable/types/util.js';
25+
import { Field } from '../provable/wrapped.js';
26+
import { mapObject, mapToObject, zip } from '../util/arrays.js';
27+
import { assert, prettifyStacktracePromise } from '../util/errors.js';
28+
import { Get, Subclass, Tuple } from '../util/types.js';
29+
import { Cache, readCache, writeCache } from './cache.js';
30+
import { featureFlagsFromGates, featureFlagsToMlOption } from './feature-flags.js';
2731
import {
28-
dummyProof,
2932
DynamicProof,
30-
extractProofs,
31-
extractProofTypes,
3233
Proof,
3334
ProofBase,
3435
ProofClass,
3536
ProofValue,
37+
dummyProof,
38+
extractProofTypes,
39+
extractProofs,
3640
} from './proof.js';
37-
import { featureFlagsFromGates, featureFlagsToMlOption } from './feature-flags.js';
38-
import { emptyWitness } from '../provable/types/util.js';
39-
import { From, InferValue } from '../../bindings/lib/provable-generic.js';
40-
import { DeclaredProof, ZkProgramContext } from './zkprogram-context.js';
41-
import { mapObject, mapToObject, zip } from '../util/arrays.js';
41+
import { decodeProverKey, encodeProverKey, parseHeader } from './prover-keys.js';
4242
import { VerificationKey } from './verification-key.js';
43+
import { DeclaredProof, ZkProgramContext } from './zkprogram-context.js';
4344

4445
// public API
45-
export { SelfProof, JsonProof, ZkProgram, verify, Empty, Undefined, Void, Method };
46+
export { Empty, JsonProof, Method, SelfProof, Undefined, Void, ZkProgram, verify };
4647

4748
// internal API
4849
export {
4950
CompiledTag,
50-
sortMethodArguments,
5151
MethodInterface,
5252
MethodReturnType,
53-
picklesRuleFromFunction,
54-
compileProgram,
55-
analyzeMethod,
53+
PrivateInput,
54+
Proof,
5655
Prover,
57-
dummyBase64Proof,
58-
computeMaxProofsVerified,
5956
RegularProver,
6057
TupleToInstances,
61-
PrivateInput,
62-
Proof,
58+
analyzeMethod,
59+
compileProgram,
60+
computeMaxProofsVerified,
61+
dummyBase64Proof,
6362
inCircuitVkHash,
63+
picklesRuleFromFunction,
64+
sortMethodArguments,
6465
};
6566

6667
type Undefined = undefined;
@@ -225,7 +226,7 @@ type InferMethodType<Config extends ConfigBaseType> = {
225226
*/
226227
function ZkProgram<
227228
Config extends ConfigBaseType,
228-
_ extends unknown = unknown // weird hack that makes methods infer correctly when their inputs are not annotated
229+
_ extends unknown = unknown, // weird hack that makes methods infer correctly when their inputs are not annotated
229230
>(
230231
config: Config & {
231232
name: string;
@@ -603,7 +604,7 @@ type ZkProgram<
603604
auxiliaryOutput?: ProvableType;
604605
};
605606
};
606-
}
607+
},
607608
> = ReturnType<typeof ZkProgram<Config>>;
608609

609610
/**
@@ -1059,7 +1060,7 @@ function toFieldAndAuxConsts<T>(type: Provable<T>, value: T) {
10591060

10601061
ZkProgram.Proof = function <
10611062
PublicInputType extends FlexibleProvable<any>,
1062-
PublicOutputType extends FlexibleProvable<any>
1063+
PublicOutputType extends FlexibleProvable<any>,
10631064
>(program: {
10641065
name: string;
10651066
publicInputType: PublicInputType;
@@ -1111,11 +1112,12 @@ function Prover<ProverData>() {
11111112

11121113
// helper types
11131114

1114-
type Infer<T> = T extends Subclass<typeof ProofBase>
1115-
? InstanceType<T>
1116-
: T extends ProvableType
1117-
? InferProvableType<T>
1118-
: never;
1115+
type Infer<T> =
1116+
T extends Subclass<typeof ProofBase>
1117+
? InstanceType<T>
1118+
: T extends ProvableType
1119+
? InferProvableType<T>
1120+
: never;
11191121

11201122
type TupleToInstances<T> = {
11211123
[I in keyof T]: Infer<T[I]>;
@@ -1133,21 +1135,21 @@ type MethodReturnType<PublicOutput, AuxiliaryOutput> = PublicOutput extends void
11331135
auxiliaryOutput: AuxiliaryOutput;
11341136
}
11351137
: AuxiliaryOutput extends undefined
1136-
? {
1137-
publicOutput: PublicOutput;
1138-
}
1139-
: {
1140-
publicOutput: PublicOutput;
1141-
auxiliaryOutput: AuxiliaryOutput;
1142-
};
1138+
? {
1139+
publicOutput: PublicOutput;
1140+
}
1141+
: {
1142+
publicOutput: PublicOutput;
1143+
auxiliaryOutput: AuxiliaryOutput;
1144+
};
11431145

11441146
type Method<
11451147
PublicInput,
11461148
PublicOutput,
11471149
MethodSignature extends {
11481150
privateInputs: Tuple<PrivateInput>;
11491151
auxiliaryOutput?: ProvableType;
1150-
}
1152+
},
11511153
> = PublicInput extends undefined
11521154
? {
11531155
method(
@@ -1176,7 +1178,7 @@ type RegularProver<
11761178
PublicInputType,
11771179
PublicOutput,
11781180
Args extends Tuple<PrivateInput>,
1179-
AuxiliaryOutput
1181+
AuxiliaryOutput,
11801182
> = (
11811183
publicInput: From<PublicInputType>,
11821184
...args: TupleFrom<Args>
@@ -1190,7 +1192,7 @@ type Prover<
11901192
PublicInputType,
11911193
PublicOutput,
11921194
Args extends Tuple<PrivateInput>,
1193-
AuxiliaryOutput
1195+
AuxiliaryOutput,
11941196
> = PublicInput extends undefined
11951197
? (...args: TupleFrom<Args>) => Promise<{
11961198
proof: Proof<PublicInput, PublicOutput>;
@@ -1210,8 +1212,8 @@ type ProvableOrVoid<A> = A extends undefined ? typeof Void : ToProvable<A>;
12101212
type InferProvableOrUndefined<A> = A extends undefined
12111213
? undefined
12121214
: A extends ProvableType
1213-
? InferProvable<A>
1214-
: InferProvable<A> | undefined;
1215+
? InferProvable<A>
1216+
: InferProvable<A> | undefined;
12151217
type InferProvableOrVoid<A> = A extends undefined ? void : InferProvable<A>;
12161218

12171219
type UnwrapPromise<P> = P extends Promise<infer T> ? T : never;

0 commit comments

Comments
 (0)