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

Fix stack overflow for large witnesses #1334

Merged
merged 7 commits into from
Dec 18, 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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
_Removed_ for now removed features.
_Fixed_ for any bug fixes.
_Security_ in case of vulnerabilities.


-->

## [Unreleased](https://github.com/o1-labs/o1js/compare/7acf19d0d...HEAD)
Expand All @@ -25,6 +23,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- **ECDSA signature verification** exposed through `createEcdsa()` class factory https://github.com/o1-labs/o1js/pull/1240 https://github.com/o1-labs/o1js/pull/1007
- For an example, see `./src/examples/crypto/ecdsa`

### Fixed

- Fix stack overflows when calling provable methods with large inputs https://github.com/o1-labs/o1js/pull/1334

## [0.15.0](https://github.com/o1-labs/o1js/compare/1ad7333e9e...7acf19d0d)

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion src/bindings
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace Experimental {
export type Callback<Result> = Callback_<Result>;
}

Error.stackTraceLimit = 1000;
Error.stackTraceLimit = 100000;

// deprecated stuff
export { isReady, shutdown };
Expand Down
18 changes: 18 additions & 0 deletions src/lib/proof_system.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ it('pickles rule creation', async () => {
);
});

// compile works with large inputs

const N = 100_000;

const program = ZkProgram({
name: 'large-array-program',
methods: {
baseCase: {
privateInputs: [Provable.Array(Field, N)],
method(_: Field[]) {},
},
},
});

it('can compile program with large input', async () => {
await program.compile();
});

// regression tests for some zkprograms
const emptyMethodsMetadata = EmptyProgram.analyzeMethods();
expect(emptyMethodsMetadata.run).toEqual(
Expand Down
23 changes: 23 additions & 0 deletions src/lib/provable.unit-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { it } from 'node:test';
import { Provable } from './provable.js';
import { exists } from './gadgets/common.js';
import { Field } from './field.js';
import { expect } from 'expect';

it('can witness large field array', () => {
let N = 100_000;
let arr = Array<bigint>(N).fill(0n);

Provable.runAndCheck(() => {
// with exists
let fields = exists(N, () => arr);

// with Provable.witness
let fields2 = Provable.witness(Provable.Array(Field, N), () =>
arr.map(Field.from)
);

expect(fields.length).toEqual(N);
expect(fields2.length).toEqual(N);
});
});