Rabi Siddique
267 words
1 minutes
What is Account Sequence in Blockchain

Recently, my teammate Fraz was troubleshooting a CI issue characterized by the following error:

Error: rpc error: code = Unknown desc = rpc error: code =c expected 63, got 62: incorrect account sequence [agoric-labs/cosmos-sdk@v0.46.16-alpha.agoric.2.4/x/auth/ante/sigverify.go:269] With gas wanted: '18446744073709551615' and gas used: '38588' : unknown request

This is the Workflow Link and here is the Issue Link.

This error led me to explore the concept of an account sequence and its purpose. After some research, I gained a better understanding of it.

What is an account sequence?#

In the Cosmos SDK, the sequence number is an integer associated with each account that ensures the correct order of transactions and prevents replay attacks. Every time an account signs a transaction, the sequence number for that account is incremented by 1.

  • Initialization: When creating an account, its sequence number is initialized to 0.
  • Transaction Signing: Each time an account signs a transaction, the current sequence number is included in the transaction.
  • Validation: When the transaction is broadcast to the network, the sequence number is validated against the sequence number stored on the blockchain for that account.
  • Increment: If the transaction is valid and successfully included in a block, the sequence number for that account on the blockchain is incremented by 1.
  • Preventing Replay Attacks: By ensuring that the sequence number is unique for each transaction, replay attacks (where the same transaction is broadcast multiple times) are prevented.

To experiment with sequence numbers, I transfer some tokens from one wallet to another in our testneet. Once the transaction is completed, I verified that the updated sequence number using our testnet endpoint.

For further reading on sequence numbers, check out this blog post.

What is Account Sequence in Blockchain
https://rabisiddique.com/posts/what-is-account-sequence/
Author
Rabi Siddique
Published at
2024-07-26