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

zkApps composability, pt 3: witness Party #294

Merged
merged 19 commits into from
Jul 26, 2022
Merged

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Jul 20, 2022

This adds the capability to "witness a Party" -- i.e., doing something like Circuit.witness(() => party). (Which isn't possible with Circuit.witness directly).

Motivation: This was the main hurdle to take for implementing zkApp composability. When calling another zkApp, we actually don't want to run its computation inside the caller's circuit. Instead, we want the callee to be its own party, with its own proof. In the caller's circuit we just want to pull the result of the call out of our hat (= witness it). That result is the callee's party, plus the input and output arguments of the call. We connect it to the actual computation & its proof by having the callee's party's hash as part of the public input in the caller circuit.

To create a party witness we want to leverage the auto-generated party structure from OCaml -- to avoid hard-coding the party structure again. So, this PR

  • expands the capabilities of the code using that autogenerated structure, to be able to output auxiliary parts of the party in addition to its field elements, and create a party from fields + aux data.
  • makes a couple of changes to achieve that Party implements Types.Party. I.e., the Party class exactly conforms to the TS type that is generated. The changes needed were
    • have an extra class for the Sign that's part of Int64, so that in the party we can have the Balance be a Uint64 + Sign instead of an Int64 directly
    • move "lazy" forms of authorization to a separate property on Party, away from the authorization field which has to be compatible with the OCaml type

The PR also significantly changes the generated js-layout, by changing the js deriver (see Mina companion), but this is actually an orthogonal change, only a small part of it was really needed here.

@mitschabaude mitschabaude changed the base branch from feature/child-parties to feature/composability-misc July 20, 2022 19:14
@mitschabaude mitschabaude changed the title zkApps composability, pt 2: witness Party zkApps composability, pt 3: witness Party Jul 20, 2022
Base automatically changed from feature/composability-misc to main July 21, 2022 18:23
@@ -404,14 +430,9 @@ class Int64 extends CircuitValue implements BalanceChange {

// --- circuit-compatible operations below ---
// the assumption here is that all Int64 values that appear in a circuit are already checked as valid
// this is because Circuit.witness calls .check
// this is because Circuit.witness calls .check, which calls .check on each prop, i.e. UInt64 and Sign
// so we only have to do additional checks if an operation on valid inputs can have an invalid outcome (example: overflow)
Copy link
Member

Choose a reason for hiding this comment

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

did you mean to remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment? No. I did mean to remove the custom check method, because now the check method on the base class does what we need

return fields.pop()!;
},
Bool(fields: Field[]) {
return Bool.Unsafe.ofField(fields.pop()!);
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 only invoked on generated code we control from the json layout right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! So it's safe because we know the field we're reading out was a Bool originally

@mitschabaude mitschabaude mentioned this pull request Jul 25, 2022
@mitschabaude mitschabaude merged commit 9aca07b into main Jul 26, 2022
@mitschabaude mitschabaude deleted the feature/composability branch July 26, 2022 10:15
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.

4 participants