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

add protection against replay between accounts #5

Closed
wants to merge 1 commit into from

Conversation

JoranHonig
Copy link

Hey guys, super cool project!

I really like how you use the Accounts as a mechanism to separate and deal with authentication and replay attacks!

I think there is a slight gap left which would allow for replay attacks. The vector is not insanely significant (it only affects people that re-use keys between accounts), and the repo is still experimental, which is why I'm making this pr out in the open. (It could be cool to add a disclosure policy in the security tab so that people know when it's okay/not okay to submit bugs out in the open)

When a user creates two Accounts with the same private key, then the signatures valid for one, will also be valid for the other.

I think it's possible to harden the implementation by adding the address of the account to the message being signed. Unfortunately this isn't super easy with the current starknet interfaces. In this pr I've drafted a potential solution that creates a kind of "self()" precompile/library contract.

Lmk what you think!

@martriay martriay self-requested a review September 30, 2021 01:06
@martriay martriay self-assigned this Sep 30, 2021
@martriay
Copy link
Contributor

martriay commented Oct 1, 2021

Thanks for this! Definitely a valid point. I was hoping to see the problems that publickey/address decoupling could bring -- I knew it wasn't just features.

Cool hack btw, although to be honest I was hoping to see this solved at the StarkNet level.

Now that I think of it, we don't need the whole call -> get address thing, right? It's just a matter of checking against the internal storage. The only situation I see possible is someone replaying the tx in another contract that has a fake address in its state but I don't think that should be dangerous. What do you think?

@martriay martriay added bug Something isn't working enhancement New feature or request labels Oct 1, 2021
@JoranHonig
Copy link
Author

I was hoping to see the problems that publickey/address decoupling could bring -- I knew it wasn't just features.

I think that this actually improved the situation. When playing around with cairo & starknet I also built a token implementation and it had the same problem, but the impact was much worse. You could replay transactions between any token instance 🙈.

Cool hack btw, although to be honest I was hoping to see this solved at the StarkNet level.

I completely agree! The current state of manual authentication/ replay prevention is a very big footgun.

Now that I think of it, we don't need the whole call -> get address thing, right? It's just a matter of checking against the internal storage. The only situation I see possible is someone replaying the tx in another contract that has a fake address in its state but I don't think that should be dangerous. What do you think?

Maybe, although, couldn't you still have two Account instances with the same l1 address? (I guess it's a super weird edgecase though).

What's nice about using call -> get address thing is that it creates cross-instance replay mitigation decoupled from the business logic.

@martriay
Copy link
Contributor

martriay commented Oct 1, 2021

What's nice about using call -> get address thing is that it creates cross-instance replay mitigation decoupled from the business logic.

Mhh yeah but it also:

  • adds code complexity with extra contract<>contract calls
  • it requires an extra deployment
  • just checking against storage can be trivially changed to reading a get_self_address() function provided by starknet when it's ready

I think I still lean towards just checking locally, cross-instance risk should be fairly temporal and also super low prio, it would be pretty shady to care about a contract that claims to be on a false address ^^

@JoranHonig
Copy link
Author

I 100% agree with all of your points 👍

@martriay martriay mentioned this pull request Oct 7, 2021
@martriay martriay closed this in #8 Oct 7, 2021
@martriay
Copy link
Contributor

martriay commented Oct 7, 2021

Thanks again @JoranHonig for raising this. I've implemented the naive storage check in #8.

martriay pushed a commit that referenced this pull request Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants