The issue of SLOW ABCI METHODS has not been resolved
The SafeApplyFuncOnAllActiveEpochEndingTopics function in the ABCI EndBlocker iterates over active topics with pagination, but the pagination limits can either skip topics (leaving their state outdated) or cause excessive computation that slows block production and could halt the chain.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/110
Found by
LZ_security
Summary
SLOW ABCI METHODS - SafeApplyFuncOnAllActiveEpochEndingTopics is called by the GetAndUpdateActiveTopicWeights function, which is called in the EndBlocker() function in abci.go.
Vulnerability Detail
Taking the SafeApplyFuncOnAllActiveEpochEndingTopics function as an example
// Apply a function on all active topics that also have an epoch ending at this block
// Active topics have more than a globally-set minimum weight, a function of revenue and stake
// "Safe" because bounded by max number of pages and apply running, online operations.
func SafeApplyFuncOnAllActiveEpochEndingTopics(
ctx sdk.Context,
k keeper.Keeper,
block BlockHeight,
fn func(sdkCtx sdk.Context, topic *types.Topic) error,
topicPageLimit uint64,
maxTopicPages uint64,
) error {
topicPageKey := make([]byte, 0)
i := uint64(0)
@> for {
topicPageRequest := &types.SimpleCursorPaginationRequest{Limit: topicPageLimit, Key: topicPageKey}
topicsActive, topicPageResponse, err := k.GetIdsOfActiveTopics(ctx, topicPageRequest)
if err != nil {
Logger(ctx).Warn(fmt.Sprintf("Error getting ids of active topics: %s", err.Error()))
continue
}
@> for _, topicId := range topicsActive {
topic, err := k.GetTopic(ctx, topicId)
if err != nil {
Logger(ctx).Warn(fmt.Sprintf("Error getting topic: %s", err.Error()))
continue
}
if k.CheckCadence(block, topic) {
// All checks passed => Apply function on the topic
err = fn(ctx, &topic)
if err != nil {
Logger(ctx).Warn(fmt.Sprintf("Error applying function on topic: %s", err.Error()))
continue
}
}
}
// if pageResponse.NextKey is empty then we have reached the end of the list
@> if topicsActive == nil || i > maxTopicPages {
break
}
topicPageKey = topicPageResponse.NextKey
i++
}
return nil
}
In the SafeApplyFuncOnAllActiveEpochEndingTopics function, although topicPageLimit and maxTopicPages have been added to control the number of iterations, this introduces new issues. Below are two scenarios:
1. topicPageLimit * maxTopicPages < totalTopicNumbers:
In this case, because the number of topics iterated over is less than the total number of topics, some topics will never be processed, causing their state to be out of date.
2. topicPageLimit * maxTopicPages >= totalTopicNumbers:
In this case, all topics can be processed, but this introduces a high computational cost, such as multiple nested loops, which could slow down the execution of nodes and block production. In the worst case, this could lead to a halt of the chain.
Impact
The topic data could become out of date, or multiple nested loops could slow down the execution of nodes and block production, potentially leading to a halt of the chain in the worst case.
Code Snippet
Tool used
Manual Review
Recommendation
It is recommended to simplify the logic implemented in these ABCI handlers, estimating their computational complexity and ensuring they will scale correctly with the application's usage growth.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Slow ABCI method could cause halt of chain potentially
relyt29
SafeApplyFuncOnAllActiveEpochEndingTopics renamed to GetAllActiveEpochEndingTopics and some of the logic reworked in 9d6b84d3fffecb3a9753cb075381b7306157360f
Then later GetAllActiveEpochEndingTopics deleted in 9d6b84d3fffecb3a9753cb075381b7306157360f as we went to a different management of active set of topics. This active set management is not O(n) over the number of topics, thankfully
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/542
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the pagination logic in SafeApplyFuncOnAllActiveEpochEndingTopics does not correctly bound the total number of topics processed, leading to either incomplete processing or excessive computation.
Impact
Topic data could become out of date, or multiple nested loops could slow down node execution and block production, potentially leading to a chain halt in the worst case.
What the attacker needed
Many active topics; pagination limits misconfigured
The fix
The function was renamed and its logic reworked, and later the function was deleted as active set management was changed to avoid O(n) over the number of topics.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A blockchain node runs special code at the end of each block to update topic weights. This code loops over all active topics, but it uses page limits that can either miss some topics or do too much work, slowing down the node and potentially stopping the chain.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.