Skip to content

Commit 83dadcf

Browse files
SurgeCodebucanerogagdiez
authored
Relayer nonce collisions (#2157)
* Relayer nonce collisions * Update docs/2.build/1.chain-abstraction/meta-transactions.md Co-authored-by: Damián Parrino <[email protected]> * Update docs/2.build/1.chain-abstraction/meta-transactions.md Co-authored-by: Damián Parrino <[email protected]> * Update meta-transactions.md * Update docs/2.build/1.chain-abstraction/meta-transactions.md --------- Co-authored-by: Damián Parrino <[email protected]> Co-authored-by: Guille <[email protected]>
1 parent ac09ac7 commit 83dadcf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/2.build/1.chain-abstraction/meta-transactions.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ Progress is being made to make this possible in the future.
106106

107107
</details>
108108

109+
### High volume parallel processing
110+
111+
When running a relayer that handles a large number of transactions, you will quickly run into a `nonce` collision problem. 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.
112+
113+
When multiple transactions are sent from the same access key simultaneously, their nonces might collide. Imagine the relayer creates 3 transactions `Tx1`, `Tx2`, `Tx3` and send them in very short distance from each other, and lets assume that `Tx3` has the largest nonce. If `Tx3` ends up being processed before `Tx1` (because of network delays, or a node picks `Tx3` first), then `Tx3` will execute, but `Tx1` and `Tx2` will fail, because they have smaller nonce!
114+
115+
One way to mitigate this is to sign each transaction with a different key. Adding multiple full access keys to the NEAR account used for relaying (up to 20 keys can make a significant difference) will help.
116+
117+
<details>
118+
<summary> Adding keys </summary>
119+
120+
```js
121+
const keyPair = nearAPI.KeyPair.fromRandom("ed25519");
122+
123+
const receipt = await account.addKey(keyPair.getPublicKey().toString())
124+
```
125+
126+
After saving these keys, its possible to rotate the private keys randomly when instantiating accounts before relaying ensuring you won't create a nonce collision.
127+
128+
</details>
109129

110130
### Gating the relayer
111131

0 commit comments

Comments
 (0)