Lack of error handling when making blockless api call
The code that makes blockless API calls does not handle errors, only logging them. If the API call fails, the inference and loss data are not updated, leading to incorrect data.
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/131
Found by
0x416
Summary
Lack of error handling when making blockless api call
Vulnerability Detail
Error handling when making blockless api call is missing.
Impact
In topics_handler.go, we are calling PrepareProposalHandler
func (th *TopicsHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
Logger(ctx).Debug("\n ---------------- TopicsHandler ------------------- \n")
churnableTopics, err := th.emissionsKeeper.GetChurnableTopics(ctx)
if err != nil {
Logger(ctx).Error("Error getting max number of topics per block: " + err.Error())
return nil, err
}
var wg sync.WaitGroup
// Loop over and run epochs on topics whose inferences are demanded enough to be served
// Within each loop, execute the inference and weight cadence checks and trigger the inference and weight generation
for _, churnableTopicId := range churnableTopics {
wg.Add(1)
go func(topicId TopicId) {
defer wg.Done()
topic, err := th.emissionsKeeper.GetTopic(ctx, topicId)
if err != nil {
Logger(ctx).Error("Error getting topic: " + err.Error())
return // @audit should contninue?
}
@ th.requestTopicWorkers(ctx, topic)
@ th.requestTopicReputers(ctx, topic)
}(churnableTopicId)
}
wg.Wait()
// Return the transactions as they came
return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil
}
these two function requestTopicWorkers and requestTopicReputers trigger blockless api calls
for example,
the requestTopicReputers => go generateInferencesRequest => makeApiCall
err = makeApiCall(payloadStr)
if err != nil {
Logger(ctx).Warn(fmt.Sprintf("Error making API call: %s", err.Error()))
}
the api call can fail for many reason, and if it fails, the code only log the error and does not return the error and bubble the error up for error handling.
then it means that the loss and inference request is never set out and updated,
the PrepareProposalHandler will still sliently assume the call always success and go through,
this leads to loss and inference data severely out of scope.
Code Snippet
Tool used
Manual Review
Recommendation
handle the error from api call
Discussion
sherlock-admin3
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Error is not handled
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/458
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
The error returned by the API call is only logged and not propagated, so the caller continues as if the call succeeded.
Impact
If the API call fails, the inference and loss data are not updated, leading to severely out-of-scope data.
What the attacker needed
None
The fix
The error from the API call should be handled, for example by returning it to the caller.
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.
When a program makes a request to another service, it should check if the request worked. Here, the code ignores failures, so important data never gets updated. This can cause the system to use old or wrong information.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.