The ResetChurnableTopics function in the keeper does not check the error returned by the Clear method of churnableTopics. This could lead to silent failures and potential inconsistencies in the system state.
Vulnerability Detail
In the current implementation of ResetChurnableTopics:
The Clear method is called on k.churnableTopics, but its return value (which could be an error) is not checked. The function always returns nil, regardless of whether the clearing operation succeeded or failed.
Impact
Silent Failures: If the Clear operation fails for any reason (e.g., concurrency problems), the failure will go unnoticed.
Inconsistent State: The system may continue operating under the assumption that the churnable topics have been reset when they haven't, leading to incorrect behavior in subsequent operations.
Without cleaning churnable topics, The operation is going to continue on the Endblocker.
// ResetChurnReadyTopics clears all topics from the churn-ready set and resets related states.
func (k *Keeper) ResetChurnableTopics(ctx context.Context) error {
k.churnableTopics.Clear(ctx, nil)
return nil
}
Tool used
Manual Review
Recommendation
Modify the ResetChurnableTopics function to check and return the error from the Clear method:
defsec
High
Unchecked Error in ResetChurnableTopics Function
Summary
The
ResetChurnableTopics
function in the keeper does not check the error returned by theClear
method ofchurnableTopics
. This could lead to silent failures and potential inconsistencies in the system state.Vulnerability Detail
In the current implementation of
ResetChurnableTopics
:The
Clear
method is called onk.churnableTopics
, but its return value (which could be an error) is not checked. The function always returnsnil
, regardless of whether the clearing operation succeeded or failed.Impact
Clear
operation fails for any reason (e.g., concurrency problems), the failure will go unnoticed.Code Snippet
/x/emissions/keeper/keeper.go#L1750
Tool used
Manual Review
Recommendation
ResetChurnableTopics
function to check and return the error from theClear
method:ResetChurnableTopics
properly handle the returned error, for example:ResetChurnableTopics
function for successful clears as well, to aid in debugging and monitoring: