Rewards distribution fails if no tokens are bonded for bLuna
Impact
The hub’s UpdateGlobalIndex message sends the UpdateGlobalIndex message to the reward contract, which will return an error if the amount of bonded Luna tokens towards bLuna is zero in anchor-bAsset-contracts/contracts/anchor_basset_reward/src/global.rs. This error will prevent any reward distribution.
Proof of Concept
Contract : anchor-bAsset-contracts/contracts/anchor_basset_reward/src/global.rs
Function : pub fn execute_update_global_index(...)
Line 70 :
// Zero staking balance check
if state.total_balance.is_zero() {
return Err(StdError::generic_err("No asset is bonded by Hub"));
}
Recommended Mitigation Steps
Its recommended to return Ok instead of returning an error.
// Zero staking balance check
if state.total_balance.is_zero() {
return Ok(Response::new());
}
Lines of code
https://github.com/code-423n4/2022-02-anchor/blob/7af353e3234837979a19ddc8093dc9ad3c63ab6b/contracts/anchor-bAsset-contracts/contracts/anchor_basset_reward/src/global.rs#L70-L73
Vulnerability details
Rewards distribution fails if no tokens are bonded for bLuna
Impact
The hub’s UpdateGlobalIndex message sends the UpdateGlobalIndex message to the reward contract, which will return an error if the amount of bonded Luna tokens towards bLuna is zero in anchor-bAsset-contracts/contracts/anchor_basset_reward/src/global.rs. This error will prevent any reward distribution.
Proof of Concept
Contract : anchor-bAsset-contracts/contracts/anchor_basset_reward/src/global.rs Function : pub fn execute_update_global_index(...) Line 70 :
Recommended Mitigation Steps
Its recommended to return Ok instead of returning an error.