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

[Bug]: Priority Nonce Mempool Nil Pointer Dereference (Next) #17392

Closed
davidterpay opened this issue Aug 15, 2023 · 1 comment · Fixed by #17668
Closed

[Bug]: Priority Nonce Mempool Nil Pointer Dereference (Next) #17392

davidterpay opened this issue Aug 15, 2023 · 1 comment · Fixed by #17668
Labels

Comments

@davidterpay
Copy link
Contributor

What happened?

At Skip, we're utilizing the priority nonce mempool for some custom ABCI++ proposal building. We came across an issue where there was a nil pointer dereference in the Next function on the Priority Nonce Mempool.

// We've reached a transaction with a priority lower than the next highest
// priority in the pool.
if i.mempool.cfg.TxPriority.Compare(key.priority, i.nextPriority) < 0 {
return i.iteratePriority()
} else if i.mempool.cfg.TxPriority.Compare(key.priority, i.nextPriority) == 0 {
// Weight is incorporated into the priority index key only (not sender index)
// so we must fetch it here from the scores map.
weight := i.mempool.scores[txMeta[C]{nonce: key.nonce, sender: key.sender}].weight
if i.mempool.cfg.TxPriority.Compare(weight, i.priorityNode.Next().Key().(txMeta[C]).weight) < 0 {
return i.iteratePriority()
}
}

Cosmos SDK Version

main

How to reproduce?

This issue can be replicated in the following way,

  • have the key.priority be the minimum value defined on the TxConfig
  • This will make the else if statement true (as it looks like i.nextPriority defaults to the same min val defined on the TxConfig but im not fully sure on this)
  • when it attempts to fetch i.priorityNode.Next().Key().(txMeta[C]).weight) it will attempt to dereference a nil pointer.

Simplest fix is likely just wrapping that code in an if i.priorityNode.Next() != nil....

@kocubinski
Copy link
Member

Thanks for finding this @davidterpay, especially the steps to reproduce. It may be a lot to ask, but do you have a failing test which could be added to priority_nonce_test.go? If not, I will get to it eventually, but this could speed things up depending on your urgency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants