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, itssequence number
is initialized to0
.Transaction Signing
: Each time an account signs a transaction, the currentsequence number
is included in the transaction.Validation
: When the transaction is broadcast to the network, thesequence number
is validated against thesequence number
stored on the blockchain for that account.Increment
: If the transaction is valid and successfully included in a block, thesequence number
for that account on the blockchain is incremented by1
.Preventing Replay Attacks
: By ensuring that thesequence 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.