Skip to content

Commit

Permalink
fix getUnconstrained
Browse files Browse the repository at this point in the history
  • Loading branch information
Trivo25 committed Oct 18, 2024
1 parent 33b7c6a commit 8e8cf88
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib/mina/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ super.init();

sender = {
self: this as SmartContract,

/**
* The public key of the current transaction's sender account.
*
Expand All @@ -878,7 +879,22 @@ super.init();
* Consider using `this.sender.getAndRequireSignature()` if you need to prove that the sender controls this account.
*/
getUnconstrained(): PublicKey {
let sender = this.getUnconstrained();
// TODO this logic now has some overlap with this.self, we should combine them somehow
// (but with care since the logic in this.self is a bit more complicated)
if (!Mina.currentTransaction.has()) {
throw Error(
`this.sender is not available outside a transaction. Make sure you only use it within \`Mina.transaction\` blocks or smart contract methods.`
);
}
let transactionId = Mina.currentTransaction.id();
let sender;
if (this.self.#_senderState?.transactionId === transactionId) {
sender = this.self.#_senderState.sender;
} else {
sender = Provable.witness(PublicKey, () => Mina.sender());
this.self.#_senderState = { transactionId, sender };
}

// we prove that the returned public key is not the empty key, in which case
// `createSigned()` would skip adding the account update, and nothing is proved
sender.x.assertNotEquals(0);
Expand Down

0 comments on commit 8e8cf88

Please sign in to comment.