Skip to content

Relayer nonce collisions - #2157

Merged
gagdiez merged 5 commits into
near:masterfrom
SurgeCode:nonce-collision
Sep 2, 2024
Merged

Relayer nonce collisions#2157
gagdiez merged 5 commits into
near:masterfrom
SurgeCode:nonce-collision

Conversation

@SurgeCode

Copy link
Copy Markdown
Member

Added a small section to the relayer page about how to handle high throughput relaying

@SurgeCode
SurgeCode requested a review from bucanero as a code owner July 19, 2024 18:59
Comment thread docs/2.build/1.chain-abstraction/meta-transactions.md Outdated
Comment thread docs/2.build/1.chain-abstraction/meta-transactions.md Outdated
SurgeCode and others added 2 commits July 22, 2024 11:17
Co-authored-by: Damián Parrino <bucanero@users.noreply.github.com>
Co-authored-by: Damián Parrino <bucanero@users.noreply.github.com>
@gagdiez

gagdiez commented Jul 22, 2024

Copy link
Copy Markdown
Collaborator

I think what we actually need to explain goes more like this:

At the protocol level, transactions have a unique number that identifies them (nonce) that helps to mitigate reply attacks. Each key on an account has its own nonce, and the nonce is expected to increase with each signature the key creates.

When the relayer account (e.g. relayer.near) starts relaying a lot of transactions, it will quickly start to happen that nonces collide. For example, if 3 users interact with the relayer at the same time, the relayer will create 3 transactions Tx1, Tx2, Tx3 and send them in very short distance from each other. In our case, we can assume that Tx3 has the largest nonce, and Tx1 the smallest.

If Tx3 ends up being processed before Tx1 (because of some network issues one takes longer to be sent to the RPC, or simply because a node picks Tx3 before Tx1), then Tx3 will execute, but Tx1 and Tx2 will fail, because they have smaller nonce!

One way to mitigate this is to sign each transaction with a different key. Since nonce are key dependent, we can simply create 20 different keys for relayer.near, and go rotating which one we use to sign the transactions. This way, we can 20 transactions created simultaneously without the fear of them colliding on the nonce.

@DavidM-D

Copy link
Copy Markdown
Contributor

Can we just have "PAIN" in bold linking to this comment?

Comment thread docs/2.build/1.chain-abstraction/meta-transactions.md Outdated
@gagdiez
gagdiez merged commit 83dadcf into near:master Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀

Development

Successfully merging this pull request may close these issues.

4 participants