lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.4
/**
 * @dev Remove time lock, only locker can remove
 * @param account The address want to remove time lock
 * @param index Time lock index
 */
function _removeTimeLock(address account, uint8 index) internal {
        require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid");

        uint256 len = _timeLocks[account].length;
        if (len - 1 != index) {
            // if it is not last item, swap it
            _timeLocks[account][index] = _timeLocks[account][len - 1];
        }
        _timeLocks[account].pop();
        emit TimeUnlocked(account);
    }
// Solidity 0.8.4
/**
 * @dev get total time locked amount of address
 * @param account The address want to know the time lock amount.
 * @return time locked amount
 */
function getTimeLockedAmount(address account) public view returns (uint256) {
        uint256 timeLockedAmount = 0;

        uint256 len = _timeLocks[account].length;
        for (uint256 i = 0; i < len; i++) {
            if (block.timestamp < _timeLocks[account][i].expiresAt) {
                timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount;
            }
        }
        return timeLockedAmount;
    }
// Solidity 0.8.4
/**
 * @dev Add investor lock, only locker can add
 * @param account investor lock account.
 * @param amount investor lock amount.
 * @param startsAt investor lock release start date.
 * @param period investor lock period.
 * @param count investor lock count. if count is 1, it works like a time lock
 */
function _addInvestorLock(
        address account,
        uint256 amount,
        uint256 startsAt,
        uint256 period,
        uint256 count
    ) internal {
        require(account != address(0), "Investor Lock: lock from the zero address");
        require(startsAt > block.timestamp, "Investor Lock: must set after now");
        require(amount > 0, "Investor Lock: amount is 0");
        require(period > 0, "Investor Lock: period is 0");
        require(count > 0, "Investor Lock: count is 0");
        _investorLocks[account] = InvestorLock(amount, startsAt, period, count);
        emit InvestorLocked(account);
    }
// Solidity 0.8.4
/**
 * @dev get total investor locked amount of address, locked amount will be released by 100%/months
 * if months is 5, locked amount released 20% per 1 month.
 * @param account The address want to know the investor lock amount.
 * @return investor locked amount
 */
function getInvestorLockedAmount(address account) public view returns (uint256) {
        uint256 investorLockedAmount = 0;
        uint256 amount = _investorLocks[account].amount;
        if (amount > 0) {
            uint256 startsAt = _investorLocks[account].startsAt;
            uint256 period = _investorLocks[account].period;
            uint256 count = _investorLocks[account].count;
            uint256 expiresAt = startsAt + period * (count - 1);
            uint256 timestamp = block.timestamp;
            if (timestamp < startsAt) {
                investorLockedAmount = amount;
            } else if (timestamp < expiresAt) {
                investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count;
            }
        }
        return investorLockedAmount;
    }
// Solidity 0.8.4
/**
 * @dev lock and pause before transfer token
 */
function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal override(ERC20) {
        super._beforeTokenTransfer(from, to, amount);

        require(!isLocked(from), "Lockable: token transfer from locked account");
        require(!isLocked(to), "Lockable: token transfer to locked account");
        require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account");
        require(!paused(), "Pausable: token transfer while paused");
        require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account");
    }
// Solidity 0.5.0
/**
 * @dev Function to mint tokens
 * @param value The amount of tokens to mint.
 * @return A boolean that indicates if the operation was successful.
 */
function mintOwner(uint256 value) public onlyMinter returns (bool) {
        
        require(msg.sender != address(0), "");
        require(msg.sender == _owner, "");

        _totalSupply = safeAdd(_totalSupply, value);

        balances[_owner] = safeAdd(balances[_owner], value);
        emit Transfer(address(0), _owner, value);

        return true;
    }
// Solidity 0.5.0
// Deposit ERC20's for saving
function depositToken(uint256 amount) public {
        require(isEnded != true, "Deposit ended");
        require(lockStartTime < now, 'Event has not been started yet');
        require(isAddrWhitelisted[msg.sender] == true, "Address is not whitelisted.");
        require(Add(currentCap, amount) <= HARD_CAP, 'Exceed limit total cap');
        require(Token(KAI_ADDRESS).transferFrom(msg.sender, address(this), amount));
        
        currentCap = Add(currentCap, amount);
        addrBalance[msg.sender] = Add(addrBalance[msg.sender], amount);
    }
// Solidity 0.5.0
// Withdraw ERC20's to personal address
function withdrawToken() public {
        require(lockStartTime + lockDays * 1 days < now, "Locking period");
        uint256 amount = addrBalance[msg.sender];
        require(amount > 0, "withdraw only once");
        
        uint256 _interest = Mul(amount, interest) / 10000;

        bonus = Sub(bonus, _interest);
        amount = Add(amount, _interest);
        require(Token(KAI_ADDRESS).transfer(msg.sender, amount));
        addrBalance[msg.sender] = 0;
    }
// Solidity 0.4.16
/**
 * Initialization Construction
 */
function TokenERC20(uint256 _initialSupply, string _tokenName, string _tokenSymbol) public {
        totalSupply = _initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                     // Give the creator all initial tokens
        name = _tokenName;                                       // Set the name for display purposes
        symbol = _tokenSymbol;                                   // Set the symbol for display purposes
    }
// Solidity 0.4.16
/**
 * Internal Realization of Token Transaction Transfer
 */
function _transfer(address _from, address _to, uint _value) internal {
        require(_to != 0x0);                                            // Prevent transfer to 0x0 address. Use burn() instead
        require(balanceOf[_from] >= _value);                            // Check if the sender has enough    
        require(balanceOf[_to] + _value > balanceOf[_to]);              // Check for overflows

        uint previousBalances = balanceOf[_from] + balanceOf[_to];      // Save this for an assertion in the future
        balanceOf[_from] -= _value;                                     // Subtract from the sender
        balanceOf[_to] += _value;                                       // Add the same to the recipient
        Transfer(_from, _to, _value);                                   // Notify anyone listening that this transfer took place

        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);  // Use assert to check code logic
    }
// Solidity 0.4.18
/**
 	 * @dev convert bytes to address
 	 */
function bytesToAddress(bytes source) internal returns(address) {
        uint result;
        uint mul = 1;
        for(uint i = 20; i > 0; i--) {
          result += uint8(source[i-1])*mul;
          mul = mul*256;
        }
        return address(result);
    }
// Solidity 0.4.19
// gas estimation: 105340
function give (string name, uint maxValuePerOpen, string giver) payable {
       RedEnvelope storage e = envelopes[name];
       require(e.value == 0);
       require(msg.value > 0);
       e.balance = e.value = msg.value;
       e.maxValuePerOpen = maxValuePerOpen;
       e.giver = giver;
   }
// Solidity 0.4.19
// verify that the sender address does belong to a forum user
function _authenticate (string forumId, uint cbGasLimit) payable {
       require(stringToUint(forumId) < maxAllowedId);
       require(forumIdToAddr[forumId] == 0);
       require(msg.value >= oraclize_getPrice("URL", cbGasLimit));

       // looks like the page is too broken for oralize's xpath handler
       // bytes32 queryId = oraclize_query("URL", 'html(http://8btc.com/home.php?mod=space&do=doing&uid=250950).xpath(//*[@id="ct"]//div[@class="xld xlda"]/dl[1]/dd[2]/span/text())');

       bytes32 queryId = oraclize_query("URL", 
            /*
            "json(http://redproxy-1.appspot.com/getAddress.php).addr",
            concat("x", forumId) // buggy oraclize
            */
            concat("json(http://redproxy-1.appspot.com/getAddress.php?uid=", forumId, ").addr"),
            cbGasLimit            
       );
       pendingQueries[queryId] = forumId;
   }
// Solidity 0.4.19
// for now we don't use real randomness
// gas estimation: 57813 x 4 gwei = 0.0002356 eth * 1132 usd/eth = 0.27 usd
function open (string envelopeName) returns (uint value) {
        string forumId = addrToForumId[msg.sender];
        require(bytes(forumId).length > 0);

        RedEnvelope e = envelopes[envelopeName];
        require(e.balance > 0);
        require(e.takers[msg.sender] == 0);

        value = uint(keccak256(envelopeName, msg.sender)) % e.maxValuePerOpen;

        if (value > e.balance) {
            value = e.balance;
        }
        e.balance -= value;
        e.takers[msg.sender] = value;
        msg.sender.transfer(value);
   }
// Solidity 0.7.6
/// @dev user's staked information
function getUserStaked(address user)
        external
        view
        returns (
            uint256 amount,
            uint256 claimedBlock,
            uint256 claimedAmount,
            uint256 releasedBlock,
            uint256 releasedAmount,
            uint256 releasedTOSAmount,
            bool released
        )
    {
        return (
            userStaked[user].amount,
            userStaked[user].claimedBlock,
            userStaked[user].claimedAmount,
            userStaked[user].releasedBlock,
            userStaked[user].releasedAmount,
            userStaked[user].releasedTOSAmount,
            userStaked[user].released
        );
    }
// Solidity 0.8.12
// function to mint based off of whitelist allocation
function presaleMint(
        uint256 amount,
        bytes32 leaf,
        bytes32[] memory proof
    ) external payable {
        require(presaleActive, "Presale not active");

        // create storage element tracking user mints if this is the first mint for them
        if (!whitelistUsed[msg.sender]) {
            // verify that msg.sender corresponds to Merkle leaf
            require(keccak256(abi.encodePacked(msg.sender)) == leaf, "Sender doesn't match Merkle leaf");

            // verify that (leaf, proof) matches the Merkle root
            require(verify(merkleRoot, leaf, proof), "Not a valid leaf in the Merkle tree");

            whitelistUsed[msg.sender] = true;
        }

        require(amount <= MAX_AMOUNT_PER_MINT, "Minting too many at a time");
        require(msg.value == amount * presaleMintPrice, "Not enough ETH sent");
        require(amount + totalSupply() <= currentSupplyCap, "Would exceed max supply");

        _safeMint(msg.sender, amount);

        emit Mint(msg.sender, amount);
    }
// Solidity 0.8.12
// function to mint in public sale
function publicMint(uint256 amount) external payable {
        require(saleActive, "Public sale not active");
        require(amount <= MAX_AMOUNT_PER_MINT, "Minting too many at a time");
        require(msg.value == amount * publicMintPrice, "Not enough ETH sent");
        require(amount + totalSupply() <= currentSupplyCap, "Would exceed max supply");

        // _safeMint(msg.sender, amount);
        _mint(msg.sender, amount, "", false);

        emit Mint(msg.sender, amount);
    }
// Solidity 0.4.25
// how many tokens sold through crowdsale
//@dev fallback function, only accepts ether if ICO is running or Reject
function () payable public {
			require(icoEndDate > now);
			require(icoStartDate < now);
            require(!safeguard);
			uint ethervalueWEI=msg.value;
			// calculate token amount to be sent
			uint256 token = ethervalueWEI.mul(exchangeRate); //weiamount * price
			tokensSold = tokensSold.add(token);
			_transfer(this, msg.sender, token);              // makes the transfers
			forwardEherToOwner();
		}
// Solidity 0.5.10
/**
 * Internal transfer, only can be called by this contract
 *
 * @param _from The address of the sender
 * @param _to The address of the recipient
 * @param _value the amount to send
 */
function _transfer(address _from, address _to, uint _value) internal {
        // Check if the address is empty
        require(_to != address(0));
        // Check if the sender has enough
        require(balanceOf[_from] >= _value);
        // Check for overflows
        require(balanceOf[_to] + _value > balanceOf[_to]);
        // Save this for an assertion in the future
        uint previousBalances = balanceOf[_from] + balanceOf[_to];
        // Subtract from the sender
        balanceOf[_from] -= _value;
        // Add the same to the recipient
        balanceOf[_to] += _value;
        emit Transfer(_from, _to, _value);
        // Asserts are used to use static analysis to find bugs in your code. They should never fail
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
    }
// Solidity 0.6.12
/// @notice Causes the deposit of amount sender tokens.
/// @param _amount Amount of the tokens.
function deposit(uint256 _amount) whenNotPaused nonReentrant public override {
        uint256 _pool = balance();

        uint256 _before = IERC20(token).balanceOf(address(this));
        IERC20(token).safeTransferFrom(_msgSender(), address(this), _amount);
        uint256 _after = IERC20(token).balanceOf(address(this));
        _amount = _after.sub(_before); // Additional check for deflationary tokens

        uint256 shares = 0;
        if (totalSupply() == 0) {
            shares = _amount;
        } else {
            shares = (_amount.mul(totalSupply())).div(_pool);
        }
        _mint(_msgSender(), shares);
    }
// Solidity 0.6.12
/// @notice Causes the withdraw of amount sender shares.
/// @param _shares Amount of the shares.
function withdraw(uint256 _shares) whenNotPaused public override {
        uint256 r = (balance().mul(_shares)).div(totalSupply());
        _burn(_msgSender(), _shares);

        // Check balance
        uint256 b = IERC20(token).balanceOf(address(this));
        if (b < r) {
            uint256 _withdraw = r.sub(b);
            IController(controller).withdraw(_withdraw);
            uint256 _after = IERC20(token).balanceOf(address(this));
            require(_after >= r, "Not enough balance");
        }

        IERC20(token).safeTransfer(_msgSender(), r);
    }
// Solidity 0.7.6
/// @notice Set implementation contract
/// @param impl New implementation contract address
function upgradeTo(address impl) external onlyOwner {
        require(impl != address(0), "StakeTONProxy: input is zero");
        require(
            _implementation() != impl,
            "StakeTONProxy: The input address is same as the state"
        );
        _setImplementation(impl);
        emit Upgraded(impl);
    }
// Solidity 0.7.6
/// @dev fallback function , execute on undefined function call
function _fallback() internal {
        address _impl = _implementation();
        require(
            _impl != address(0) && !pauseProxy,
            "StakeTONProxy: impl is zero OR proxy is false"
        );

        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), _impl, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
                // delegatecall returns 0 on error.
                case 0 {
                    revert(0, returndatasize())
                }
                default {
                    return(0, returndatasize())
                }
        }
    }
// Solidity 0.7.6
/// @dev Approves function
/// @dev call by WTON
/// @param owner  who actually calls
/// @param spender  Who gives permission to use
/// @param tonAmount  how much will be available
/// @param data  Amount data to use with users
function onApprove(
        address owner,
        address spender,
        uint256 tonAmount,
        bytes calldata data
    ) external override returns (bool) {
        (address _spender, uint256 _amount) = _decodeStakeData(data);
        require(
            tonAmount == _amount && spender == _spender,
            "StakeTONProxy: tonAmount != stakingAmount "
        );
        require(
            stakeOnApprove(msg.sender, owner, _spender, _amount),
            "StakeTONProxy: stakeOnApprove fails "
        );
        return true;
    }
// Solidity 0.4.23
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces 
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
        if(tokens > 0 && spender != address(0)) {
            allowed[msg.sender][spender] = tokens;
            emit Approval(msg.sender, spender, tokens);
            return true;
        } else { return false; }
    }
// Solidity 0.7.6
/// @dev stake with WTON
/// @param from  WTON
/// @param _owner  who actually calls
/// @param _spender  Who gives permission to use
/// @param _amount  how much will be available
function stakeOnApprove(
        address from,
        address _owner,
        address _spender,
        uint256 _amount
    ) public returns (bool) {
        require(
            (paytoken == from && _amount > 0 && _spender == address(this)),
            "StakeTONProxy: stakeOnApprove init fail"
        );
        require(
            block.number >= saleStartBlock && block.number < startBlock,
            "StakeTONProxy: period not allowed"
        );

        require(
            !IStakeVaultStorage(vault).saleClosed(),
            "StakeTONProxy: end sale"
        );
        require(
            IIERC20(paytoken).balanceOf(_owner) >= _amount,
            "StakeTONProxy: insuffient"
        );

        LibTokenStake1.StakedAmount storage staked = userStaked[_owner];
        if (staked.amount == 0) totalStakers = totalStakers.add(1);

        staked.amount = staked.amount.add(_amount);
        totalStakedAmount = totalStakedAmount.add(_amount);
        require(
            IIERC20(from).transferFrom(_owner, _spender, _amount),
            "StakeTONProxy: transfer fail"
        );

        emit Staked(_owner, _amount);
        return true;
    }
// Solidity 0.7.6
/// @dev set initial storage
/// @param _addr the array addresses of token, paytoken, vault, defiAddress
/// @param _registry the registry address
/// @param _intdata the array valued of saleStartBlock, stakeStartBlock, periodBlocks
function setInit(
        address[4] memory _addr,
        address _registry,
        uint256[3] memory _intdata
    ) external onlyOwner {
        require(token == address(0), "StakeTONProxy: already initialized");

        require(
            _registry != address(0) &&
                _addr[2] != address(0) &&
                _intdata[0] < _intdata[1],
            "StakeTONProxy: setInit fail"
        );
        token = _addr[0];
        paytoken = _addr[1];
        vault = _addr[2];
        defiAddr = _addr[3];

        stakeRegistry = _registry;

        tokamakLayer2 = address(0);

        saleStartBlock = _intdata[0];
        startBlock = _intdata[1];
        endBlock = startBlock.add(_intdata[2]);
    }
// Solidity 0.4.26
/**
 * @dev Checks whether or not there is sufficient allowance for this contract to move amount from `from` and
 *      whether or not `from` has a balance of at least `amount`. Does NOT do a transfer.
 */
function checkTransferIn(address asset, address from, uint amount) internal view returns (Error) {

        EIP20Interface token = EIP20Interface(asset);

        if (token.allowance(from, address(this)) < amount) {
            return Error.TOKEN_INSUFFICIENT_ALLOWANCE;
        }

        if (token.balanceOf(from) < amount) {
            return Error.TOKEN_INSUFFICIENT_BALANCE;
        }

        return Error.NO_ERROR;
    }
// Solidity 0.4.26
/**
 * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and returns an explanatory
 *      error code rather than reverting.  If caller has not called `checkTransferIn`, this may revert due to
 *      insufficient balance or insufficient allowance. If caller has called `checkTransferIn` prior to this call,
 *      and it returned Error.NO_ERROR, this should not revert in normal conditions.
 *
 *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
 *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
 */
function doTransferIn(address asset, address from, uint amount) internal returns (Error) {
        EIP20NonStandardInterface token = EIP20NonStandardInterface(asset);

        bool result;

        token.transferFrom(from, address(this), amount);

        assembly {
            switch returndatasize()
                case 0 {                      // This is a non-standard ERC-20
                    result := not(0)          // set result to true
                }
                case 32 {                     // This is a complaint ERC-20
                    returndatacopy(0, 0, 32)
                    result := mload(0)        // Set `result = returndata` of external call
                }
                default {                     // This is an excessively non-compliant ERC-20, revert.
                    revert(0, 0)
                }
        }

        if (!result) {
            return Error.TOKEN_TRANSFER_FAILED;
        }

        return Error.NO_ERROR;
    }
// Solidity 0.4.26
/**
 * @dev Calculates a new balance based on a previous balance and a pair of interest indices
 *      This is defined as: `The user's last balance checkpoint is multiplied by the currentSupplyIndex
 *      value and divided by the user's checkpoint index value`
 *
 *      TODO: Is there a way to handle this that is less likely to overflow?
 */
function calculateBalance(uint startingBalance, uint interestIndexStart, uint interestIndexEnd) pure internal returns (Error, uint) {
        if (startingBalance == 0) {
            // We are accumulating interest on any previous balance; if there's no previous balance, then there is
            // nothing to accumulate.
            return (Error.NO_ERROR, 0);
        }
        (Error err0, uint balanceTimesIndex) = mul(startingBalance, interestIndexEnd);
        if (err0 != Error.NO_ERROR) {
            return (err0, 0);
        }

        return div(balanceTimesIndex, interestIndexStart);
    }