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

Pass in fee payer as a public key #635

Closed
mitschabaude opened this issue Dec 7, 2022 · 1 comment · Fixed by #652
Closed

Pass in fee payer as a public key #635

mitschabaude opened this issue Dec 7, 2022 · 1 comment · Fixed by #652
Assignees

Comments

@mitschabaude
Copy link
Member

mitschabaude commented Dec 7, 2022

I think we should change the way we pass fee payers to transactions.

Now: the fee payer in a transaction is either left undefined or passed in as a private key, or a more complicated object containing a private key:

Mina.transaction(() => { ... });
Mina.transaction(privateKey, () => { ... });
Mina.transaction({ feePayerKey: privateKey, ... }, () => { ... });

Why is this bad: In a real zkApp, the private key won't be available. That means, the only option is to leave the fee payer undefined. However, it is a very common feature request to be able to access the public key of the fee payer of the current transaction within a zkApp method, analogous to msg.sender in Solidity which people are used to. However, if the fee payer isn't passed in anywhere, we can't provide this feature.

Solution: We change the fee payer argument to be a public key, instead of a private key. We also make sure zkApp devs can access this public key from a wallet. We also establish the standard practice of passing in this public key, and provide a convenient API to access it similar to msg.sender.
I think it's ok to keep the option of leaving it undefined: we could make msg.sender throw an error in that case. Which means that, if you want your zkApp to use msg.sender, make sure that the fee payer public key is passed in.

Proposed API:

Mina.transaction(() => { ... });
Mina.transaction(publicKey, () => { ... });
Mina.transaction({ sender: publicKey, ... }, () => { ... });

If the transaction like also needs to be signed by the fee payer (for testing / non-browser usage), then the private key will have to be passed in to tx.sign(), like other signed account updates:

let tx = await Mina.transaction(publicKey, () => { ... });
await tx.sign([privateKey]).send();
@nicc
Copy link
Collaborator

nicc commented Dec 12, 2022

Can we overload this so that both types are supported to avoid a breakling chance? Ideally with deprecation message on receiving the PrivateKey type.

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 a pull request may close this issue.

2 participants