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

Allow non-pure provable types as inputs/outputs in zkprogram #1828

Open
wants to merge 131 commits into
base: main
Choose a base branch
from

Conversation

ymekuria
Copy link
Contributor

@ymekuria ymekuria commented Sep 18, 2024

Summary

This PR updates ZkProgram to allow non-pure provable types as inputs and outputs.

Addresses #1675

Impact

Currently only pure provable types can be used as inputs and outputs to a ZkProgram. This PR improves the DX with changes that allow a developer to update rich provable types like a IndexedMerkleMap or a MerkleList in a ZkProgram.

…e for better clarity and consistency in naming conventions
…e auxData parameter for additional flexibility and reusability
Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

lmk when the PR is ready for a more thorough review!

await MyProgram.compile();
console.log('compile done');

let input = new MyStruct({ label: 'input', value: Field(5) });
Copy link
Member

Choose a reason for hiding this comment

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

this is missing the description property

console.log('proof', proof);

assert(ok, 'proof not valid!');
// assert(proof.publicOutput.label === 'inCircuit');
Copy link
Member

Choose a reason for hiding this comment

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

once the PR is ready we should re-enable this check

@@ -161,12 +161,30 @@ const FeatureFlags = {
};

function createProgramState() {
let nonPureDataCache: Map<string, any[]> = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

we could just reuse the method cache for this too, would make it a bit cleaner but we would have to differenciate between nonpure auxiliary data and the auxiliary output its currently keeping track. both are valid imo

result = (await func(input, ...finalArgs)) as any;
}

console.log('result input', result);
if (result.publicOutput) {
Copy link
Member

Choose a reason for hiding this comment

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

this should probably be result?.publicOutput since result is unfornately typed

Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

(approved by accident, sorry)

…ld from MyStruct and add assertion to check for 'label' value in proof.publicOutput
…to use optional chaining for improved readability and null safety
@Trivo25
Copy link
Member

Trivo25 commented Nov 11, 2024

@ymekuria please rebase too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants