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

bin2chen - If WithdrawAddrEnabled = false, execute_claim() will fail #43

Open
sherlock-admin3 opened this issue Jun 23, 2024 · 8 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin3
Copy link
Contributor

sherlock-admin3 commented Jun 23, 2024

bin2chen

Medium

If WithdrawAddrEnabled = false, execute_claim() will fail

Summary

Currently, contracts that execute execute_claim() set DistributionMsg::SetWithdrawAddress first.
If WithdrawAddrEnabled = false, the execution will not succeed and the claim will not be executed.

Vulnerability Detail

Currently the contract executes claims rewards by setting DistributionMsg::SetWithdrawAddress first.

fn execute_claim(
    ctx: ExecuteContext,
    validator: Option<Addr>,
    recipient: Option<AndrAddr>,
) -> Result<Response, ContractError> {
...
    let res = Response::new()
@>      .add_message(DistributionMsg::SetWithdrawAddress {
            address: recipient.to_string(),
        })
        .add_message(DistributionMsg::WithdrawDelegatorReward {
            validator: validator.to_string(),
        })
        .add_attribute("action", "validator-claim-reward")
        .add_attribute("recipient", recipient)
        .add_attribute("validator", validator.to_string());

    Ok(res)
}

If the configuration WithdrawAddrEnabled is changed to false, setting DistributionMsg::SetWithdrawAddress will fail!
This will prevent the execution of the claim
https://github.com/cosmos/cosmos-sdk/tree/main/x/distribution#msgsetwithdrawaddress

MsgSetWithdrawAddress

By default, the withdraw address is the delegator address. To change its withdraw address, a delegator must send a MsgSetWithdrawAddress message. Changing the withdraw address is possible only if the parameter WithdrawAddrEnabled is set to true.

func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) error
 if k.blockedAddrs[withdrawAddr.String()] {
  fail with "`{withdrawAddr}` is not allowed to receive external funds"
 }

 if !k.GetWithdrawAddrEnabled(ctx) {
  fail with `ErrSetWithdrawAddrDisabled`
 }

 k.SetDelegatorWithdrawAddr(ctx, delegatorAddr, withdrawAddr)

Impact

can't claim reward

Code Snippet

https://github.com/sherlock-audit/2024-05-andromeda-ado/blob/main/andromeda-core/contracts/finance/andromeda-validator-staking/src/contract.rs#L231

Tool used

Manual Review

Recommendation

when set DistributionMsg::SetWithdrawAddress , SubMsg using ReplyOn.Error, which is ignored when this message returns an error, to avoid the whole execute_claim from failing!

@github-actions github-actions bot added the Medium A valid Medium severity issue label Jun 28, 2024
@sherlock-admin2 sherlock-admin2 changed the title Great Leather Tarantula - If WithdrawAddrEnabled = false, execute_claim() will fail bin2chen - If WithdrawAddrEnabled = false, execute_claim() will fail Jun 29, 2024
@sherlock-admin2 sherlock-admin2 added the Reward A payout will be made for this issue label Jun 29, 2024
@neko-nyaa
Copy link

Escalate

#15, #67, #68 are dupes of this issue. This family of issues shows various impacts when withdrawAddrEnabled is set to false, and the root cause of the revert is the message MsgSetWithdrawAddress failing.

@sherlock-admin3
Copy link
Contributor Author

Escalate

#15, #67, #68 are dupes of this issue. This family of issues shows various impacts when withdrawAddrEnabled is set to false, and the root cause of the revert is the message MsgSetWithdrawAddress failing.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@cvetanovv
Copy link

I agree with the escalation.

The root cause of the issue is when withdrawAddrEnabled is set to false. That's why I plan to duplicate all similar issues related to WithdrawAddrEnabled = false.

I am planning to accept the escalation and duplicate #15, #67, #68, and #52 with this issue.

@WangSecurity
Copy link

WangSecurity commented Jul 6, 2024

Result:
Medium
Has duplicates

@sherlock-admin2
Copy link

sherlock-admin2 commented Jul 6, 2024

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin3 sherlock-admin3 removed the Escalated This issue contains a pending escalation label Jul 6, 2024
@sherlock-admin4 sherlock-admin4 added the Escalation Resolved This issue's escalations have been approved/rejected label Jul 6, 2024
@WangSecurity WangSecurity added the Has Duplicates A valid issue with 1+ other issues describing the same vulnerability label Jul 22, 2024
@cowboy0015
Copy link

withdraw_fund function is now working as an emergency for withdrawing funds (including locked funds due to unexpected cases)

@sherlock-admin2
Copy link

The protocol team fixed this issue in the following PRs/commits:
andromedaprotocol/andromeda-core#559

@bin2chen66
Copy link
Collaborator

fix-reviews note:
andromedaprotocol/andromeda-core#559
This PR canceled the execution of SetWithdrawAddress.
After the reward is triggered, get back all the balance in the contract via execute_withdraw_fund()
Fixed this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Escalation Resolved This issue's escalations have been approved/rejected Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

8 participants