Skip to content

Commit

Permalink
Merge branch 'main' into merge-main-v2-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Trivo25 committed Oct 21, 2024
2 parents da665b0 + 44eb218 commit 3f26345
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixes

- Performance regression when compiling recursive circuits is fixed https://github.com/o1-labs/o1js/pull/1874
- Decouple offchain state instances from their definitions https://github.com/o1-labs/o1js/pull/1834

## [1.9.0](https://github.com/o1-labs/o1js/compare/450943...f15293a69) - 2024-10-15
Expand Down
12 changes: 10 additions & 2 deletions src/lib/proof-system/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { jsEnvironment } from '../../bindings/crypto/bindings/env.js';
export { Cache, CacheHeader };

// internal API
export { readCache, writeCache, withVersion, cacheHeaderVersion };
export {
readCache,
writeCache,
withVersion,
cacheHeaderVersion,
LAGRANGE_BASIS_PREFIX,
};

/**
* Interface for storing and retrieving values, for caching.
Expand Down Expand Up @@ -90,6 +96,8 @@ type StepKeyHeader<Kind> = {
type WrapKeyHeader<Kind> = { kind: Kind; programName: string; hash: string };
type PlainHeader<Kind> = { kind: Kind };

const LAGRANGE_BASIS_PREFIX = 'lagrange-basis' as const;

/**
* A header that is passed to the caching layer, to support rich caching strategies.
*
Expand All @@ -101,7 +109,7 @@ type CacheHeader = (
| WrapKeyHeader<'wrap-pk'>
| WrapKeyHeader<'wrap-vk'>
| PlainHeader<'srs'>
| PlainHeader<'lagrange-basis'>
| PlainHeader<typeof LAGRANGE_BASIS_PREFIX>
) &
CommonHeader;

Expand Down
65 changes: 65 additions & 0 deletions src/lib/proof-system/cached-lagrange-basis.unit-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Cache, LAGRANGE_BASIS_PREFIX } from './cache.js';
import { SelfProof, ZkProgram } from './zkprogram.js';
import { Field } from '../provable/field.js';
import { it, describe, after, before } from 'node:test';
import { expect } from 'expect';
import { promises as fs } from 'fs';

const __cacheDirname = './.tmpcache';

const exampleProgram = ZkProgram({
name: 'example',
publicOutput: Field,
methods: {
init: {
privateInputs: [],
async method() {

Check failure on line 16 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / compatible

Type '() => Promise<Field>' is not assignable to type '(() => Promise<Field>) & ((...args: TupleToInstances<[]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 16 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / benchmarks (20, sdk-self-hosted-linux-amd64)

Type '() => Promise<Field>' is not assignable to type '(() => Promise<Field>) & ((...args: TupleToInstances<[]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 16 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / Prepare

Type '() => Promise<Field>' is not assignable to type '(() => Promise<Field>) & ((...args: TupleToInstances<[]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 16 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / master

Type '() => Promise<Field>' is not assignable to type '(() => Promise<Field>) & ((...args: TupleToInstances<[]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 16 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / benchmarks (20, sdk-self-hosted-linux-arm64)

Type '() => Promise<Field>' is not assignable to type '(() => Promise<Field>) & ((...args: TupleToInstances<[]>) => Promise<{ publicOutput: Field; }>)'.
return new Field(0);
},
},
run: {
privateInputs: [SelfProof],
async method(p: SelfProof<undefined, Field>) {

Check failure on line 22 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / compatible

Type '(p: SelfProof<undefined, Field>) => Promise<Field>' is not assignable to type '((p: SelfProof<undefined, Field>) => Promise<Field>) & ((...args: TupleToInstances<[typeof SelfProof]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 22 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / benchmarks (20, sdk-self-hosted-linux-amd64)

Type '(p: SelfProof<undefined, Field>) => Promise<Field>' is not assignable to type '((p: SelfProof<undefined, Field>) => Promise<Field>) & ((...args: TupleToInstances<[typeof SelfProof]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 22 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / Prepare

Type '(p: SelfProof<undefined, Field>) => Promise<Field>' is not assignable to type '((p: SelfProof<undefined, Field>) => Promise<Field>) & ((...args: TupleToInstances<[typeof SelfProof]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 22 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / master

Type '(p: SelfProof<undefined, Field>) => Promise<Field>' is not assignable to type '((p: SelfProof<undefined, Field>) => Promise<Field>) & ((...args: TupleToInstances<[typeof SelfProof]>) => Promise<{ publicOutput: Field; }>)'.

Check failure on line 22 in src/lib/proof-system/cached-lagrange-basis.unit-test.ts

View workflow job for this annotation

GitHub Actions / benchmarks (20, sdk-self-hosted-linux-arm64)

Type '(p: SelfProof<undefined, Field>) => Promise<Field>' is not assignable to type '((p: SelfProof<undefined, Field>) => Promise<Field>) & ((...args: TupleToInstances<[typeof SelfProof]>) => Promise<{ publicOutput: Field; }>)'.
return p.publicOutput.add(new Field(1));
},
},
},
});

describe('Compiling a program with a cache', () => {
const cache: Cache & { lagrangeBasisReadCount?: number } =
Cache.FileSystem(__cacheDirname);
const originalRead = cache.read;
cache.lagrangeBasisReadCount = 0;
cache.read = ({ persistentId, uniqueId, dataType }) => {
if (persistentId.startsWith(LAGRANGE_BASIS_PREFIX)) {
const readCount = cache.lagrangeBasisReadCount || 0;
cache.lagrangeBasisReadCount = readCount + 1;
}
return originalRead({ persistentId, uniqueId, dataType } as any);
};

before(async () => {
await fs.mkdir(__cacheDirname, { recursive: true });
});

after(async () => {
await fs.rm(__cacheDirname, { recursive: true });
});

/**
* This test is a regression test for https://github.com/o1-labs/o1js/issues/1869
* It ensures that the lagrange basis cache is accessed properly. If the file system cache is not
* read during compile, that means that the lagrange basis was returned from WASM on the first attempt.
*
* This is not necessarily a problem. If the WASM code is updated such that we expect the LB to be
* returned on the first try, and we explicitly skip the file system cache, then this test can be
* safely removed. Otherwise, a failure here probably indicates a performance regression.
*/
it('should attempt to read lagrange basis from the cache during compile', async () => {
cache.lagrangeBasisReadCount = 0;
await exampleProgram.compile({ cache });
expect(cache.lagrangeBasisReadCount).not.toBe(0);
cache.lagrangeBasisReadCount = 0;
});
});
2 changes: 1 addition & 1 deletion src/mina
Submodule mina updated 150 files

0 comments on commit 3f26345

Please sign in to comment.