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

Signature frontrun alternative fix #271

Closed
wants to merge 10 commits into from
Closed

Conversation

MathisGD
Copy link
Contributor

@MathisGD MathisGD commented Aug 11, 2023

Recap of the problem: anyone can frontrun authorizeWithSig and make the transactions revert. It is "just" a UX problem, and not really a security issue because the final state of Morpho is the same.

Quentin's fix #230 reverts on a wrong signature only if you were trying to change the authorization. The spec is a little bit complicated to me.

I propose something else: let people pass the nonce of their signature (btw now they pass the whole Authorization struct, which I find quite natural), revert only if the signature was not good with this nonce, but change the authorization and increment nonce only if the nonce of the signature matches the nonce of the contract.

@MathisGD MathisGD marked this pull request as ready for review August 11, 2023 12:30
@MathisGD MathisGD requested review from julien-devatom and a team and removed request for a team August 11, 2023 12:31
@MathisGD MathisGD self-assigned this Aug 11, 2023
@MathisGD MathisGD requested review from Rubilmax, MerlinEgalite, pakim249CAL, Jean-Grimal, makcandrov, QGarchery and peyha and removed request for a team August 11, 2023 12:31
MerlinEgalite
MerlinEgalite previously approved these changes Aug 11, 2023
src/interfaces/IBlue.sol Outdated Show resolved Hide resolved
pakim249CAL
pakim249CAL previously approved these changes Aug 11, 2023
@MathisGD MathisGD changed the base branch from refactor/authorization to main August 11, 2023 12:59
@MathisGD MathisGD dismissed stale reviews from pakim249CAL and MerlinEgalite August 11, 2023 12:59

The base branch was changed.

Copy link
Collaborator

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

Here's an edge case that is now possible and IMO unexpected:

  1. User signs authorization, sends the tx
  2. User changes mind, signs message to cancel authorization, sends tx 2
  3. Tx 1 message gets frontrunned
  4. Tx1 gets included without reverting
  5. Tx 2 gets included without reverting (because nonce is outdated), thus the user is not aware that their authorization is not cancelled

@MerlinEgalite
Copy link
Contributor

Here's an edge case that is now possible and IMO unexpected:

  1. User signs authorization, sends the tx
  2. User changes mind, signs message to cancel authorization, sends tx 2
  3. Tx 1 message gets frontrunned
  4. Tx1 gets included without reverting
  5. Tx 2 gets included without reverting (because nonce is outdated), thus the user is not aware that their authorization is not cancelled

True, can we really easily fix the frontrunning attack in fact?

@MathisGD
Copy link
Contributor Author

Then the way to abort a signature is to submit it and batch a dis-authorization again.

In your example, if the authorized is malicious they can already rug you.

@julien-devatom
Copy link
Contributor

Here's an edge case that is now possible and IMO unexpected:

  1. User signs authorization, sends the tx
  2. User changes mind, signs message to cancel authorization, sends tx 2
  3. Tx 1 message gets frontrunned
  4. Tx1 gets included without reverting
  5. Tx 2 gets included without reverting (because the nonce is outdated). Thus the user is not aware that their authorization is not canceled

We thought about that on Thursday w @QGarchery & @MathisGD, and it was my take always to revert, even if this is an edge case (you have to sign the same authorizer w the same nonce, with both authorized = true & authorized = false).

My point is that if you always revert, you can try/catch on top. For example, in the bulker case, we want the bulker batch not to revert. My tx will revert if the signature is extracted and submitted before my batch. But, we can add some logic before using the authorized signature in the bulker to submit the signature only if the signature was not used before.

if (BLUE.nonce(user) == input.nonce && BLUE.isauthorized(user, address(this)) == input.isAuthorized) return; 
else {

  // call blue with the signature
}

So the contract is unopinionated on edge cases and always reverts, delegating the check to the upper layer.

@MerlinEgalite
Copy link
Contributor

So should we close PRs?

@MathisGD MathisGD closed this Aug 13, 2023
@MathisGD MathisGD deleted the refactor/authorization-1 branch August 13, 2023 09:37
@QGarchery QGarchery restored the refactor/authorization-1 branch August 15, 2023 09:14
@QGarchery
Copy link
Contributor

Reopening this PR as I did not have the chance to give my opinion at the end of the week. Feel free to close this PR afterwards if you still have the same stance on this. I think that it's a good case where we can be a bit opinionated and fix the issue for most users by not reverting when no authorization change are asked.

First, the problem highlighted by @Rubilmax was not present in the original PR #230, because we had a check to revert when a change to the authorization is asked (and that the signature is not verified).

Also, to me the argument about being a primitive is not valid because we can also add a reverting case on top. So both options are as expressive. The decision is about which one is the "more standard" and most useful:

  • EIP712 specifies that an interaction involving a signature should be idempotent, which suggests that the standard is to not revert when no changes is required to the authorization
  • my view is that most integrations (including the bulker) will prefer not reverting on a transaction that has the intended behavior

Finally, as soon as someone sends a transaction containing a signature for the authorization it's possible for the authorized party to manage the account in whatever way he wants. So to me the case where there are multiple signatures lying around is already not supported, so it makes it less interesting to try to fix

@QGarchery QGarchery reopened this Aug 15, 2023
@MathisGD
Copy link
Contributor Author

We finally decided not to implement a "fix" because everyone does that and the spec of the EIP is not that clear about the topic. Also it's complete, like you can re-implement any behavior on top (not for free though).

@MathisGD MathisGD closed this Aug 15, 2023
@MerlinEgalite MerlinEgalite deleted the refactor/authorization-1 branch August 18, 2023 21:43
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.

6 participants