Skip to content
Business logic Audit finding Intermediate

Vesting contract cannot work with ETH, although it's supposed to

The vesting contract is designed to support ETH when the token address is set to a special value, but the deposit function always attempts a token transfer that reverts for that special address. As a result, the contract cannot be used with ETH at all.

0x4non Follow with AMOW, GatewayGuardians and 11 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-zap-protocol-judging/issues/54

Found by

0x4non, AMOW, GatewayGuardians, HonorLt, NickV, ZdravkoHr., bughuntoor, cats, enfrasico, klaus, merlin, s1ce, thank_you, ydlee

Summary

Vesting contract cannot work with native token, although it's supposed to.

Vulnerability Detail

Within the claim function, we can see that if token is set to address(1), the contract should operate with ETH

Solidity
    function claim() external {
        address sender = msg.sender;

        UserDetails storage s = userdetails[sender];
        require(s.userDeposit != 0, "No Deposit");
        require(s.index != vestingPoints.length, "already claimed");
        uint256 pctAmount;
        uint256 i = s.index;
        for (i; i <= vestingPoints.length - 1; i++) {
            if (block.timestamp >= vestingPoints[i][0]) {
                pctAmount += (s.userDeposit * vestingPoints[i][1]) / 10000;
            } else {
                break;
            }
        }
        if (pctAmount != 0) {
            if (address(token) == address(1)) {
                (bool sent, ) = payable(sender).call{value: pctAmount}("");  // @audit - here
                require(sent, "Failed to send BNB to receiver");
            } else {
                token.safeTransfer(sender, pctAmount);
            }
            s.index = uint128(i);
            s.amountClaimed += pctAmount;
        }
    }

However, it is actually impossible for the contract to operate with ETH, since updateUserDeposit always attempts to do a token transfer.

Solidity
    function updateUserDeposit(
        address[] memory _users,
        uint256[] memory _amount
    ) public onlyRole(DEFAULT_ADMIN_ROLE) {
        require(_users.length <= 250, "array length should be less than 250");
        require(_users.length == _amount.length, "array length should match");
        uint256 amount;
        for (uint256 i = 0; i < _users.length; i++) {
            userdetails[_users[i]].userDeposit = _amount[i];
            amount += _amount[i];
        }
        token.safeTransferFrom(distributionWallet, address(this), amount); // @audit - this will revert
    }

Since when the contract is supposed to work with ETH, token is set to address(1), calling safeTransferFrom on that address will always revert, thus making it impossible to call this function.

Impact

Vesting contract is unusable with ETH

Code Snippet

https://github.com/sherlock-audit/2024-03-zap-protocol/blob/main/zap-contracts-labs/contracts/Vesting.sol#L64

Tool used

Manual Review

Recommendation

make the following check

Solidity
        if (address(token) != address(1)) token.safeTransferFrom(distributionWallet, address(this), amount);

Discussion

shubham-antier

Removed ETH functionality from the contract.

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/Lithium-Ventures/zap-contracts-labs/pull/5

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by 0x4non. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 deposit function unconditionally calls a token transfer function even when the token address is set to a special value meant to represent ETH.

Impact

The vesting contract cannot be used with ETH, making that feature unusable.

What the attacker needed

Contract deployed with token set to address(1)

The fix

The protocol team removed ETH functionality from the contract, and the fix was verified.

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.

This contract is supposed to let people claim ETH rewards over time. But when someone tries to add ETH deposits, the code tries to move a token instead, which fails because ETH is not a token. So the ETH feature never works.

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.

More by 0x4non

View all

6 more disclosed reports, best first.

More from Zap Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.