Smart-Contract-Vulnerabilities-DB / Base Sample / gasless_send / gasless_send_4.sol
gasless_send_4.sol
Raw
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract Wallet {
    mapping(address => uint256) private balances;

    event Payment(address indexed from, address indexed to, uint256 amount, bool successful);

    modifier balance(uint256 amount) {
        require(balances[msg.sender] >= amount, "Insifficient funds");
        _;
    }

    function deposit() external payable {
        balances[msg.sender] += msg.value;
    }

    function transferMethods(uint8 method, uint256 amount, address to) internal returns (bool){
        if(method == 0) {
            balances[msg.sender] -= amount;
            balances[to] += amount;
            return true;
        } else if (method == 1) {
            balances[msg.sender] -= amount;
            payable(to).transfer(amount); return true;
        } else if (method == 2) {
            balances[msg.sender] -= amount;
            return (payable(to).send(amount));
        } else if (method == 3) {
            balances[msg.sender] -= amount;
            (bool ok, ) = to.call{value: amount}("");
            return (ok);
        } else {
            revert("Invalid payment");
        }
    }

    function transfer(address to, uint256 amount) public balance(amount) returns(bool) {
        bool success = transferMethods(0, amount, to);
        emit Payment(msg.sender, to, amount, success);

        return success;
    }

    function advancedTransfer(address to, uint256 amount, uint8 method) public balance(amount) returns (bool) {
        bool success = transferMethods(method, amount, to);
        emit Payment(msg.sender, to, amount, success);

        return success;
    }

    function withdraw(uint256 amount) external balance(amount) returns (bool) {
        bool success = advancedTransfer(msg.sender, amount, 1);

        return success;
    }

    function checkBalance() external view returns (uint256) {
        return balances[msg.sender];
    }
}

contract receiver{
    receive() external payable {
        for(uint i = 0; i < 10; i++){
            uint a = 2;
            a++;
        }
    }
}