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

Build in replay protection for userland signatures? #720

Open
mitschabaude opened this issue Feb 9, 2023 · 0 comments
Open

Build in replay protection for userland signatures? #720

mitschabaude opened this issue Feb 9, 2023 · 0 comments
Labels
to-discuss Issues to be discussed further

Comments

@mitschabaude
Copy link
Member

mitschabaude commented Feb 9, 2023

Attack scenario:

zkApp guards some high-stakes action (like, paying out funds / voting) by requiring a signature from authorized users as input, and verify that signature. It will verify that

  • the public key on the signature matches the authorized user (which could be encoded in various ways, like hard-coded constant, on-chain state, leaf of a Merkle tree,...)
  • the signed message specifies the respective action

Two problems:

  • Signatures are deterministically derived from the message
  • and don't distinguish between different networks

So if you create a signature for a high-stakes action, and send it to me to include in a proof, that means I use it any number of times as proof input. For example, if your signature authorizes me to withdraw amount X to address Y, I could withdraw X to Y an infinite number of times.

In the case you have the same account address on testnet / mainnet, then your testnet signature could even be used to withdraw real mainnet funds.

Should we build in automatic defense against cases like that?

Ideas:

@ replay on different network:

  • automatically include the network type in the signature, and also hard-code it into every smart contract, such that our tooling (zk deploy) sets the right constant when deploying to either network
  • tag generated private keys with the network type, so that wallets can reject it if you want to restore a wallet for the wrong network

@ replay on the same network:

  • provide an interface that makes it easy for wallets to pass in the user's account nonce as an argument which becomes part of the message, plus an interface in snarkyjs that makes the circuit compare that nonce to the signer's account nonce and do a nonce increment on that account
@mitschabaude mitschabaude added the to-discuss Issues to be discussed further label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-discuss Issues to be discussed further
Projects
None yet
Development

No branches or pull requests

1 participant