Skip to content

Commit

Permalink
Merge pull request #1700 from o1-labs/feature/feature-flags-from-list
Browse files Browse the repository at this point in the history
Compute feature flag from list of zkProgram
  • Loading branch information
Trivo25 committed Jun 25, 2024
2 parents 1588ee5 + 5d8afb3 commit b553d60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- **SHA256 low-level API** exposed via `Gadgets.SHA256`. https://github.com/o1-labs/o1js/pull/1689 [@Shigoto-dev19](https://github.com/Shigoto-dev19)
- Added the option to specify custom feature flags for sided loaded proofs in the `DynamicProof` class.
- Feature flags are requires to tell Pickles what proof structure it should expect when side loading dynamic proofs and verification keys. https://github.com/o1-labs/o1js/pull/1688
- Added the option to specify custom feature flags for sided loaded proofs in the `DynamicProof` class. https://github.com/o1-labs/o1js/pull/1688
- Feature flags are required to tell Pickles what proof structure it should expect when side loading dynamic proofs and verification keys.
- `FeatureFlags` is now exported and provides a set of helper functions to compute feature flags correctly.

## [1.3.1](https://github.com/o1-labs/o1js/compare/1ad7333e9e...40c597775) - 2024-06-11

Expand Down
37 changes: 27 additions & 10 deletions src/lib/proof-system/zkprogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const Empty = Undefined;
type Void = undefined;
const Void: ProvablePureExtended<void, void, null> = EmptyVoid<Field>();

type AnalysableProgram = {
analyzeMethods: () => Promise<{
[I in keyof any]: UnwrapPromise<ReturnType<typeof analyzeMethod>>;
}>;
};

type FeatureFlags = {
rangeCheck0: boolean | undefined;
rangeCheck1: boolean | undefined;
Expand Down Expand Up @@ -135,23 +141,34 @@ const FeatureFlags = {
* Given a ZkProgram, return the feature flag configuration that fits the given program.
* This function considers all methods of the specified ZkProgram and finds a configuration that fits all.
*/
fromZkProgram: featureFlagsfromZkProgram,
fromZkProgram: async (program: AnalysableProgram) =>
await fromZkProgramList([program]),

/**
* Given a list of ZkPrograms, return the feature flag configuration that fits the given set of programs.
* This function considers all methods of all specified ZkPrograms and finds a configuration that fits all.
*/
fromZkProgramList,
};

async function featureFlagsfromZkProgram<
P extends {
analyzeMethods: () => Promise<{
[I in keyof any]: UnwrapPromise<ReturnType<typeof analyzeMethod>>;
}>;
async function fromZkProgramList(programs: Array<AnalysableProgram>) {
let flatMethodIntfs: Array<UnwrapPromise<ReturnType<typeof analyzeMethod>>> =
[];
for (const program of programs) {
let methodInterface = await program.analyzeMethods();
flatMethodIntfs.push(...Object.values(methodInterface));
}
>(program: P): Promise<FeatureFlags> {
let methodIntfs = await program.analyzeMethods();

return featureFlagsfromFlatMethodIntfs(flatMethodIntfs);
}

async function featureFlagsfromFlatMethodIntfs(
methodIntfs: Array<UnwrapPromise<ReturnType<typeof analyzeMethod>>>
): Promise<FeatureFlags> {
// compute feature flags that belong to each method
let flags = Object.entries(methodIntfs).map(([_, { gates }]) => {
let flags = methodIntfs.map(({ gates }) => {
return featureFlagsFromGates(gates);
});

if (flags.length === 0)
throw Error(
'The ZkProgram has no methods, in order to calculate feature flags, please attach a method to your ZkProgram.'
Expand Down

0 comments on commit b553d60

Please sign in to comment.