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

represent whether signed and/or proven within Transaction type + rework prove method #1567

Merged
merged 27 commits into from
Apr 17, 2024

Conversation

harrysolovay
Copy link
Collaborator

@harrysolovay harrysolovay commented Apr 12, 2024

Closes #1514

Updates the Transaction and TransactionPromise types with two type params Proven extends boolean and Signed extends boolean. This enables us to do the following.

1. conditionally include/exclude members based on stage of method chaining.

const a = Mina.transaction(sender, async () => {
  await zkapp.increment()
})
a satisfies TransactionPromise<false, false>
a.prove // exists
a.sign // exists
a.proofs // does not yet exist

const b = a.prove()
b satisfies TransactionPromise<true, false>
b.prove // no longer exists
b.sign // exists
b.proofs // now exists

const c = b.sign([senderKey])
c satisfies TransactionPromise<true, true>
c.prove // does not exist
b.sign // no longer exists
b.proofs // exists

2. Constrain transaction-accepting methods based on the transaction stage.

declare function acceptsSignedTxsOnly(transaction: Transaction<boolean, true>): void

An additional change that was needed to make this possible: the prove method no longer directly returns the proofs, but rather a Transaction<true, Signed>, where true is the boolean type param representing whether the transaction has been proven. TransactionPromise has a corresponding prove method, which produces a TransactionPromise<Signed, true>.

In order to access the actual proofs, one can utilize the proofs method of a given Transaction<true, boolean> or TransactionPromise<true, boolean>.

const proofs = await Mina.transaction(sender, async () => {
  await zkapp.increment();
})
  .sign([...keys])
  .prove()
  .proofs();

proofs; // `(Proof<ZkappPublicInput, undefined> | undefined)[]`

Copy link
Member

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

@harrysolovay it would be nice if you added an entry about all of the new chaining methods in CHANGELOG.md

The prove() change in particular belongs under breaking changes because .prove() returns the proofs in a different format now

@harrysolovay
Copy link
Collaborator Author

it would be nice if you added an entry about all of the new chaining methods in CHANGELOG.md

Given that the changelog is part of the codebase, the commit range would be self-referential. I'm not sure what the o1js workflow is for including this range. Any guidance for where to / how to set up the contents for the next changelog?

@harrysolovay harrysolovay changed the title enable chaining of prove represent whether signed and/or proven within Transaction type + rework prove method Apr 12, 2024
@mitschabaude
Copy link
Member

Given that the changelog is part of the codebase, the commit range would be self-referential.

Don't change any commit range - just include a bullet point with your change and a link to this PR

src/lib/mina/mina.ts Outdated Show resolved Hide resolved
src/lib/mina/transaction.ts Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@mitschabaude
Copy link
Member

Hey @harrysolovay, as a next step it would be nice to merge main, so that we can run the ci pipeline again

…ansaction.prove() to correctly get proof data

This change is necessary because the previous implementation was not correctly extracting the proof data from the transaction.prove() promise.
@MartinMinkov MartinMinkov merged commit 2f83cbb into o1-labs:main Apr 17, 2024
11 of 13 checks passed
@MartinMinkov MartinMinkov deleted the prove-in-chain branch April 17, 2024 21:24
@harrysolovay
Copy link
Collaborator Author

@MartinMinkov thank you for getting this passed the finish line!

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.

Transaction.prove and Transaction.send result method chaining
3 participants